Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451102imw; Tue, 19 Jul 2022 06:54:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tCSKP5RPmz4UxRwApkM4YRzkI1/HEHdNZnF3Q/kLAEgCS8L8VSAPyWNHp8WkraSkRMBjbi X-Received: by 2002:a05:6402:3907:b0:431:6776:64e7 with SMTP id fe7-20020a056402390700b00431677664e7mr43831671edb.0.1658238883458; Tue, 19 Jul 2022 06:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238883; cv=none; d=google.com; s=arc-20160816; b=fS0qolN/P5BIl+UmcUtIkMqL/mH3fdydTadeH2zJQPIt6lMXfzNIkGYyHvUzWbdxkl gZPixqozGdRuH8oPDpKZeyJhEtVJB/i+4g/ef1bjIWWNRn4a2uON13kjYWXAokhI29dz 4FgxfaURS2JWd23BSMUpSZ+lXImFJl8T4oQGg1zg3jhzwC3JL/GuNCYH4jCITtlKwaex /xpuQ1MEuYGYeQKXoXPtZnqBWbVqdbjU6Yq7t0DDemc6/rlCPwT6EuCzE5oJYnArooaU jrPbZnGk/XPtt2U054IQNzecy+Fw9rrZUYDBfyatGjpbXzwJJCC2l29bSUH0ryRtS0Aw o3vA== 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=HKGP7ZKCajwRhlfpLqCTw5BK5o/mCKiVncFFtlHIyK0=; b=V6ntB+/Z0qDpilxFpPm6boJtP4nUJ/TlHwlXSj4IGpafuQcdKC6qbLfokj+ngHz14c ESmdHHEIG/2/aVNA2gXHLcr02j/UgK9z4gQLpjJ4kfxUnicjb5e7oaQOKuNYNIAjM6tw k+sECWugw333idu6NLPJWXLeb9O6rV4vpd7DuhMeiUquWElTCZjjoGgtJNcEur8EmQkO wmRpvk1z2F1SApfDK152UA1tC1OtRHjsncDwHAQwDLW0KokfrhRvhUSS/XNMY8jJg0ud Paga0asNtNeAdU4uIk3emThAe99tlUhwdW4/2d8Vm4bH45evlkcE2qeA5xLoSX7VnreS RxUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OIAeVyxt; 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 sg33-20020a170907a42100b0072b53e673bbsi13947393ejc.913.2022.07.19.06.54.18; Tue, 19 Jul 2022 06:54:43 -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=OIAeVyxt; 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 S242260AbiGSMz3 (ORCPT + 99 others); Tue, 19 Jul 2022 08:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242303AbiGSMyT (ORCPT ); Tue, 19 Jul 2022 08:54:19 -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 8A15395B37; Tue, 19 Jul 2022 05:21:28 -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 3E0DE618E1; Tue, 19 Jul 2022 12:21:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B3A2C341C6; Tue, 19 Jul 2022 12:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233286; bh=jJR98GNYKZguEJn8h6u7x/r0+5rwLCzLvq/012by7hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIAeVyxtxc7zyZm0EJkgiTvbg7OiGR+ucsGq8Kj8U3nhjYF25sNeVn1o2JIg8gAny Xtsgz5BK1qFSt+oKT65GZ2tjvXNnBnjZWPYJ5xgq+D1Pf+O3w7j67p/0pXv625QuIu 4CJy/M2VNnP9wsZS23rbeNaKs0j/TnSEjkQ/dyqs= 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.18 071/231] sysctl: Fix data races in proc_dointvec_minmax(). Date: Tue, 19 Jul 2022 13:52:36 +0200 Message-Id: <20220719114720.647024554@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114714.247441733@linuxfoundation.org> References: <20220719114714.247441733@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 6c61e2992fed..22ebf3f5eefe 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -929,7 +929,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