Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4369329imw; Tue, 19 Jul 2022 05:29:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v9lgbwkFMWvq5pIfWoxsprMrddScXbCB6butQdr3w1IWffMAgAndRQraT51S4fK+USdqp0 X-Received: by 2002:a17:907:7632:b0:72b:4d5d:ecce with SMTP id jy18-20020a170907763200b0072b4d5deccemr31518378ejc.11.1658233787435; Tue, 19 Jul 2022 05:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233787; cv=none; d=google.com; s=arc-20160816; b=w4rbUlyOLTtb54wH05QL4zTXEnFmglLVphKV4shsyo1GEeEdq/jreCTx2o651x74QR 7SqkP0PLYqLx4Tdi0psKuHOAZvo2hsMZ8Ny+HOv104ulKZuT0Av8+JhH2iOMZobsKQDG jQMGMJUrHd/ivu7ORLiTcppPTJhBdxhF0th9xXR4p7hE3y4fI9+HbEE/F25IXZa+PNKB UjicrG+TUbolo8OMj9aM60ULGOoDrUCE2hn5IyiRBO0dyWmmy8GH32Ulks5+YByqmSA9 MsUzlDhvswOTHBi+Wplxoi3R3HhzqKQLyzW9SkHJudfEWIwpYC486CwsduL+CwWGJI9V lrjg== 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=gb2lGa5l0ysHn4nWQSewR9HZrlM2TacgIQpscHew+Uw=; b=TQQpSQVrW0FEnpfAKDReHeVTSrpedFhOj0A3LE2RezqGxLi7pUQvLuBSoL2cEG5cPa tfYQR1iAVbTU3KoN413SmEFX/0gv2npufcOry9wB+eZF/cNHjt9gici18xpIVs/yicez 1/dithF55+HHfYWV1kN32H0K7+TFNY/TeCRhkE0HX9/N/BGXFZyEbOeEOcfJpF+lWbfL 7v5trckMh7vE+OdTGUCvNE94kZ3Zjx2kHjHyyrQ0HJ8uZTo9Saaav7JkgttfxRvn6Rzz eWOBkVnqvpwcGkTXohco292HU4Q+HwPN8v0ekL1A6OXoEoF0TXIRWBLFH3wwi08OPHMB RKbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hWIMneR/"; 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 t12-20020a056402524c00b0043a9a95d32fsi22300619edd.433.2022.07.19.05.29.23; Tue, 19 Jul 2022 05:29:47 -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="hWIMneR/"; 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 S237302AbiGSMUl (ORCPT + 99 others); Tue, 19 Jul 2022 08:20:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238831AbiGSMSq (ORCPT ); Tue, 19 Jul 2022 08:18:46 -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 583CE491EA; Tue, 19 Jul 2022 05:06:45 -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 3BE7E6163C; Tue, 19 Jul 2022 12:06:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4C99C341C6; Tue, 19 Jul 2022 12:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232403; bh=0k7NVlTxXI8x9mbUNxoxezqIaOjOC0jRo8R2W4G+jCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hWIMneR/LCZBIRzPjJJMjylEcjPLfYbePh2RvgkIilAeXzK36MlWbU73/EyOljBvx OF2+WazU46EcQkCSzG1pnTnr5cCT0qAB9ex8DYzIzN/IIRKFZDuxn0NIsNvzGy5PZR SIIIMCSJnpkPwSxYDDKTT5rdnRh2gtk8cbfwMBpA= 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 045/112] sysctl: Fix data races in proc_douintvec_minmax(). Date: Tue, 19 Jul 2022 13:53:38 +0200 Message-Id: <20220719114630.797438336@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 2d3b559df3ed39258737789aae2ae7973d205bc1 ] 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_douintvec_minmax() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_douintvec_minmax() itself is tolerant to a data-race, but we still need to add annotations on the other subsystem's side. Fixes: 61d9b56a8920 ("sysctl: add unsigned int range support") 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 1800907da60c..df6090ba1d0b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1025,7 +1025,7 @@ static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, (param->max && *param->max < tmp)) return -ERANGE; - *valp = tmp; + WRITE_ONCE(*valp, tmp); } return 0; -- 2.35.1