Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4445983imw; Tue, 19 Jul 2022 06:48:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sQdlo9y77USJ+AL9wFuC7dj4vb0P/RM8WY/dmRmwnERLPsP9EvyKd60MUv5beWIVbhadJR X-Received: by 2002:aa7:c58d:0:b0:43b:96b3:af1c with SMTP id g13-20020aa7c58d000000b0043b96b3af1cmr3105027edq.141.1658238514812; Tue, 19 Jul 2022 06:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238514; cv=none; d=google.com; s=arc-20160816; b=OnXUTfMIuTMQHZHJ2f0wuGv7RgcAjflm4RVG9ogApY053aWEHR/ZYjTgpdcm052qbq T3BJPXJ4P3o/KZ8T9Q+QD5+lmHZ9PZom0I3FA7gvw4JlQBgwrS6SA+oIORRlfla8KTjb gkBOYzsVvlBz7YkojWQJpY46bERAWpp8apC3KN7Il2XOThym5p3RHR1wvMzpaIB2ZkdK hbNq9E9GlyKi6MRHbT6MYJ4YKe2mBAgCnNx0fOYWWakSOZgsNXCk5R9qgZrOrgixfWDx drtGfmr7CRliQikJOnCd3RWVeNQfPgwhnexjv1X4lC/Ft446ZNZ3lc+o3oGONW49uLop 0y0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=68gSK181OXCRqMfGLgWK4FWblSZt7u3n9SSTvo/KNmk=; b=RjZBT5/Ul+KOXZQIlV4PKNgbac1HH54KQ5ErcU4CJEXV6cR/qonyeOuCYokL6kj49I Vyi8SuS2citkqt0eSCq2qGWVTvYDpwegR//Xfoa416fvymlJOFJ5UbGZqVX1ZwmvReGI 0iLoeaqYmQFqeobVBGl5yw8H7erUm8QFWbB2WSQMathbOYwMMVpF0CNy/6MiuHHgG/gZ u0XftnKjtZcOd+bjkswb8xLrTVMVKW7CMJKeE8F+OZYKeYxm/ESyC15EmaOgZJ/4X2VO Aas3eoXRjl66QdLWQakh+kZZHo9acrtFvNIx/BdzH1v1IHBeguN+h+H0YQPy+5hSRPYr BQJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tdwJoNhu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la26-20020a170907781a00b0072f248d5288si7302701ejc.144.2022.07.19.06.48.09; Tue, 19 Jul 2022 06:48:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tdwJoNhu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234526AbiGSMUb (ORCPT + 99 others); Tue, 19 Jul 2022 08:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239335AbiGSMRt (ORCPT ); Tue, 19 Jul 2022 08:17:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6521A558EB; Tue, 19 Jul 2022 05:06:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4EC2461768; Tue, 19 Jul 2022 12:06:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E275C341C6; Tue, 19 Jul 2022 12:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232400; bh=/aLEQFCmFGIlnMdi7S7nNRU3mfK34kJHakA0v4YusS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tdwJoNhu1pC6pCFmTaNcagiQDZJSykWPafKBvAMLIUOc2omHYQCP2I2mQtA+FIXYh ICuYqkcx7EcGB6yRzRF1Qp6q3t/PthIWzXLRTiFgG5j4qwnouT/4LSkDc6EtTIaBwU oD9y2+WPNCl+WfPH48/YmjOy1/8n8AbzRs0QS59o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 044/112] sysctl: Fix data races in proc_dointvec_minmax(). Date: Tue, 19 Jul 2022 13:53:37 +0200 Message-Id: <20220719114630.697790436@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima [ Upstream commit f613d86d014b6375a4085901de39406598121e35 ] A sysctl variable is accessed concurrently, and there is always a chance of data-race. So, all readers and writers need some basic protection to avoid load/store-tearing. This patch changes proc_dointvec_minmax() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_dointvec_minmax() itself is tolerant to a data-race, but we still need to add annotations on the other subsystem's side. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- kernel/sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 30681afbdb70..1800907da60c 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -959,7 +959,7 @@ static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, if ((param->min && *param->min > tmp) || (param->max && *param->max < tmp)) return -EINVAL; - *valp = tmp; + WRITE_ONCE(*valp, tmp); } return 0; -- 2.35.1