Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2581138ybc; Mon, 25 Nov 2019 00:21:09 -0800 (PST) X-Google-Smtp-Source: APXvYqyWZRWe0ZIJcLdwHsW/x7Awqeozaejx/1agW7mhQk98J7wwtnKpSbb8DmbQf5dtH8vhvmTR X-Received: by 2002:a17:906:27cc:: with SMTP id k12mr36491860ejc.181.1574670069370; Mon, 25 Nov 2019 00:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574670069; cv=none; d=google.com; s=arc-20160816; b=E3O2555EkctjbR9pkSEsrAr1UN0YJ6Nf5J5ZpXHjBqPuAV3tTp4AiUR2IQ9HDVOcUr v60vYfkA6I3ueGJUl8bwzSqVZ0+FzTjII7twPMkPP8dpdXw/XMj1lAf8LGlmMC9Ptb+M NWlwlwSUT3UQXPbZE5iWlaq2zF4Krs8e1xfAD/93WJLUomhrNHZ4fO3ed8Qd2mp8Ppe1 NpWfixdXDNm9HyG8Wu7w4HSJWJpvBOM3tI/zOafn1zLOzG1YDEqiUFvSvWWCqUIwDkwZ hyh6U7PhlhQMC6JXKhS0aJwjeBN5pCPafpEoJTD6gz/24xZqEsaBl28KXrOUCKfrRIMq bo3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=lOceex5ZTNpnEtJcbqIA8dGROTk/oV2XttwnID/BQt8=; b=PyCh1f/NgBavwJnbJcXDklFl0CnuzZulSa94to8Sya4OElJQ6FsP5fiMkYeeCkmkOx TaD/ew/59Nl9WFTosgSZUkQACDZYfnch4R42w4+Z97vEdeJ45Phis8k4TXsyCFdPNeGg KjpDAwEscTmSEWKxX/cZJmIC73a5L1qal0VfTigqespQk3HlFE44axo/Cz9CZCnkJZGW ZaaIyz3u1OPfJ3nUwiQM6YmJduQYLbDWp2unZKuzY7FsFAOQYeWlcfun1lSY83Hn1Fk3 4tMFYTVUjpA8ODlSSmQFuqoyoTtQ3DC8DLbjwXwHn2jsRnMf2+w2MD5XPGg/YYQyTxi1 wTyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s46si5166017edd.336.2019.11.25.00.20.46; Mon, 25 Nov 2019 00:21:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbfKYITb (ORCPT + 99 others); Mon, 25 Nov 2019 03:19:31 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:38705 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727164AbfKYIT1 (ORCPT ); Mon, 25 Nov 2019 03:19:27 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iZ9aV-0001Sg-Pl; Mon, 25 Nov 2019 09:19:15 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 689411C1AF2; Mon, 25 Nov 2019 09:19:12 +0100 (CET) Date: Mon, 25 Nov 2019 08:19:12 -0000 From: "tip-bot2 for Will Deacon" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/refcount: Ensure integer operands are treated as signed Cc: Will Deacon , Ard Biesheuvel , Kees Cook , Hanjun Guo , Ard Biesheuvel , Elena Reshetova , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , x86 , LKML In-Reply-To: <20191121115902.2551-3-will@kernel.org> References: <20191121115902.2551-3-will@kernel.org> MIME-Version: 1.0 Message-ID: <157466995234.21853.622267729095000985.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: 97a1420adf0cdf0cf6f41bab0b2acf658c96b94b Gitweb: https://git.kernel.org/tip/97a1420adf0cdf0cf6f41bab0b2acf658c96b94b Author: Will Deacon AuthorDate: Thu, 21 Nov 2019 11:58:54 Committer: Ingo Molnar CommitterDate: Mon, 25 Nov 2019 09:14:57 +01:00 locking/refcount: Ensure integer operands are treated as signed In preparation for changing the saturation point of REFCOUNT_FULL to INT_MIN/2, change the type of integer operands passed into the API from 'unsigned int' to 'int' so that we can avoid casting during comparisons when we don't want to fall foul of C integral conversion rules for signed and unsigned types. Since the kernel is compiled with '-fno-strict-overflow', we don't need to worry about the UB introduced by signed overflow here. Furthermore, we're already making heavy use of the atomic_t API, which operates exclusively on signed types. Signed-off-by: Will Deacon Reviewed-by: Ard Biesheuvel Reviewed-by: Kees Cook Tested-by: Hanjun Guo Cc: Ard Biesheuvel Cc: Elena Reshetova Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: https://lkml.kernel.org/r/20191121115902.2551-3-will@kernel.org Signed-off-by: Ingo Molnar --- include/linux/refcount.h | 14 +++++++------- lib/refcount.c | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/refcount.h b/include/linux/refcount.h index 79f62e8..89066a1 100644 --- a/include/linux/refcount.h +++ b/include/linux/refcount.h @@ -28,7 +28,7 @@ typedef struct refcount_struct { * @r: the refcount * @n: value to which the refcount will be set */ -static inline void refcount_set(refcount_t *r, unsigned int n) +static inline void refcount_set(refcount_t *r, int n) { atomic_set(&r->refs, n); } @@ -44,13 +44,13 @@ static inline unsigned int refcount_read(const refcount_t *r) return atomic_read(&r->refs); } -extern __must_check bool refcount_add_not_zero_checked(unsigned int i, refcount_t *r); -extern void refcount_add_checked(unsigned int i, refcount_t *r); +extern __must_check bool refcount_add_not_zero_checked(int i, refcount_t *r); +extern void refcount_add_checked(int i, refcount_t *r); extern __must_check bool refcount_inc_not_zero_checked(refcount_t *r); extern void refcount_inc_checked(refcount_t *r); -extern __must_check bool refcount_sub_and_test_checked(unsigned int i, refcount_t *r); +extern __must_check bool refcount_sub_and_test_checked(int i, refcount_t *r); extern __must_check bool refcount_dec_and_test_checked(refcount_t *r); extern void refcount_dec_checked(refcount_t *r); @@ -79,12 +79,12 @@ extern void refcount_dec_checked(refcount_t *r); # ifdef CONFIG_ARCH_HAS_REFCOUNT # include # else -static inline __must_check bool refcount_add_not_zero(unsigned int i, refcount_t *r) +static inline __must_check bool refcount_add_not_zero(int i, refcount_t *r) { return atomic_add_unless(&r->refs, i, 0); } -static inline void refcount_add(unsigned int i, refcount_t *r) +static inline void refcount_add(int i, refcount_t *r) { atomic_add(i, &r->refs); } @@ -99,7 +99,7 @@ static inline void refcount_inc(refcount_t *r) atomic_inc(&r->refs); } -static inline __must_check bool refcount_sub_and_test(unsigned int i, refcount_t *r) +static inline __must_check bool refcount_sub_and_test(int i, refcount_t *r) { return atomic_sub_and_test(i, &r->refs); } diff --git a/lib/refcount.c b/lib/refcount.c index 48b78a4..719b0bc 100644 --- a/lib/refcount.c +++ b/lib/refcount.c @@ -61,7 +61,7 @@ * * Return: false if the passed refcount is 0, true otherwise */ -bool refcount_add_not_zero_checked(unsigned int i, refcount_t *r) +bool refcount_add_not_zero_checked(int i, refcount_t *r) { unsigned int new, val = atomic_read(&r->refs); @@ -101,7 +101,7 @@ EXPORT_SYMBOL(refcount_add_not_zero_checked); * cases, refcount_inc(), or one of its variants, should instead be used to * increment a reference count. */ -void refcount_add_checked(unsigned int i, refcount_t *r) +void refcount_add_checked(int i, refcount_t *r) { WARN_ONCE(!refcount_add_not_zero_checked(i, r), "refcount_t: addition on 0; use-after-free.\n"); } @@ -180,7 +180,7 @@ EXPORT_SYMBOL(refcount_inc_checked); * * Return: true if the resulting refcount is 0, false otherwise */ -bool refcount_sub_and_test_checked(unsigned int i, refcount_t *r) +bool refcount_sub_and_test_checked(int i, refcount_t *r) { unsigned int new, val = atomic_read(&r->refs);