From patchwork Thu Sep 21 17:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 142974 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5187527vqi; Thu, 21 Sep 2023 15:48:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1XzeeUdB0n5MikzFd2pZvBgdlVrGa993yyc2gEwO4nx7O7OTriL/xY/Ppak21YpU7Cae8 X-Received: by 2002:a05:6358:98a8:b0:135:47e8:76e2 with SMTP id q40-20020a05635898a800b0013547e876e2mr6336792rwa.4.1695336533495; Thu, 21 Sep 2023 15:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336533; cv=none; d=google.com; s=arc-20160816; b=iad7wSkrEV2CSQn8eRaOQKlgPABYvkQZ25A0ymiABJYNUerWLcFrZZEzqi5QbSb1v6 izBPsL4rzFw5aUBe3W7rkZZTVGjiOqerLWp03f8NlNwa+JBEC4V7vZRN+poH41EvZuqA 1pRIvi62tf8qgS3T4c/IjKP7AzX4f5MRUIwnh3ubkyudRS4nQN0Hen5hOGQRg8cZb//U cTVwf8Mb9YvBKZi3dR3sPTD3UYrNV+pbew9s27GQ8g0kb/8oPhEYWQSzB7gQMTyexSoE FEa3vE/W9Legdd5gvU9VPW9XVg5147/x4hrURwtDqGbXBQopBSGZjmH/7+WmQ0vLJN7j GLoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=5wU6UI6p5QQCQf2w0UwpMQsy++mNe/HQqCp2ajQz9M0=; fh=OLJGSWHwN9Ti+GR4AByPoKXEFKK/D9ARGqUCqKnaSEU=; b=Qij0hqqX0Q9mRUAx2LoER1b8i+uuPLQcXLfoazKU1sijQNcOjwUlIY4WYqeKKu/i1N we/2b0WEBzI+SzeNk473G6Km3r0lpWe4Gnf8YYdX5pklMFNWu+CoVZKYshT13tS8XXP0 2iN4V0hQwxR6iYbD+WjKtmiFcc0xz3eRWsZklGwHmKBpnOLqSOWRyEx2jCu8KnkqXKOC rdtQm1UjvWGGlGPYy8JycWdCNX+Vk7lmXkmQO5F2cW7GxHDsdFaNxAEi4NLwL3PtTMcf wRtFcq4wx83jZdj09KtKnu6o/BfxePI0Af3c3Z08LGGh94aT9wjQ4w3yWt9Wwslt0OBn f5+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aEFYaAhw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=pkq47KvN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b00563dfffe7b9si2459366pgj.810.2023.09.21.15.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:48:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aEFYaAhw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=pkq47KvN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CB7638313D01; Thu, 21 Sep 2023 13:28:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231980AbjIUU1x (ORCPT + 29 others); Thu, 21 Sep 2023 16:27:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbjIUU11 (ORCPT ); Thu, 21 Sep 2023 16:27:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA20181FFC; Thu, 21 Sep 2023 10:36:34 -0700 (PDT) Date: Thu, 21 Sep 2023 17:36:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695317765; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5wU6UI6p5QQCQf2w0UwpMQsy++mNe/HQqCp2ajQz9M0=; b=aEFYaAhwG9PpzwceGAJ5O8Wiq9aZFIcNTO0hZrdsS+uGrdwxzi/LD+INXumqwlM/p6rcX8 PA9a+shrIKLnloBfj5V7N1OiSwykdyxUpAI7ZAotKY2t68ZuFRZiBcsfW9xb2r48S/Fy5e +ZInjB3HvcxPYosMMb2MRILohKcbWnemHhTwWA+3cKDqzegNMyvkfuBzb/SGz25h+F59Ww ydM4ncmCRbkeV/Wsgr/J+oBEvoSKOJ4L+6yuMQLcMly69x+QzDvBq2Jl3lvH9asHH4T3o1 EcipimSV5yFHhr2smE68Qoz1SBlsmbCuuwaC8OKtQAz0a50tvPmK812g3jP0uw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695317765; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5wU6UI6p5QQCQf2w0UwpMQsy++mNe/HQqCp2ajQz9M0=; b=pkq47KvNYoPg0V4z8r45o73Nhwxdi5vyMgjLQF6Ag6LWE2g5jVff8gssaor+pVrRk9Dk4H 19dtRFuUx7oeG1BA== From: "tip-bot2 for peterz@infradead.org" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] futex: Validate futex value against futex size Cc: "Peter Zijlstra (Intel)" , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230921105247.828934099@noisy.programming.kicks-ass.net> References: <20230921105247.828934099@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Message-ID: <169531776519.27769.7035834121938466591.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:28:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777682264664315274 X-GMAIL-MSGID: 1777689200803700277 The following commit has been merged into the locking/core branch of tip: Commit-ID: 698eb826383616ce0e817d2384da6413d1439fb6 Gitweb: https://git.kernel.org/tip/698eb826383616ce0e817d2384da6413d1439fb6 Author: peterz@infradead.org AuthorDate: Thu, 21 Sep 2023 12:45:09 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 21 Sep 2023 19:22:06 +02:00 futex: Validate futex value against futex size Ensure the futex value fits in the given futex size. Since this adds a constraint to an existing syscall, it might possibly change behaviour. Currently the value would be truncated to a u32 and any high bits would get silently lost. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Link: https://lore.kernel.org/r/20230921105247.828934099@noisy.programming.kicks-ass.net --- kernel/futex/futex.h | 10 ++++++++++ kernel/futex/syscalls.c | 3 +++ 2 files changed, 13 insertions(+) diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h index 68fc052..a3f1fce 100644 --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -85,6 +85,16 @@ static inline bool futex_flags_valid(unsigned int flags) return true; } +static inline bool futex_validate_input(unsigned int flags, u64 val) +{ + int bits = 8 * futex_size(flags); + + if (bits < 64 && (val >> bits)) + return false; + + return true; +} + #ifdef CONFIG_FAIL_FUTEX extern bool should_fail_futex(bool fshared); #else diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c index 948ac24..2339f9c 100644 --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -209,6 +209,9 @@ static int futex_parse_waitv(struct futex_vector *futexv, if (!futex_flags_valid(flags)) return -EINVAL; + if (!futex_validate_input(flags, aux.val)) + return -EINVAL; + futexv[i].w.flags = flags; futexv[i].w.val = aux.val; futexv[i].w.uaddr = aux.uaddr;