Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4447185imw; Tue, 19 Jul 2022 06:49:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tTSa0wMjyA40c4v+vzo1oyI091sQnOew+CpYikdfVIGqNxwtvUaorrdXp9fyryLXqsPvBM X-Received: by 2002:a17:907:7255:b0:72b:50b8:82d6 with SMTP id ds21-20020a170907725500b0072b50b882d6mr6451873ejc.677.1658238592828; Tue, 19 Jul 2022 06:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238592; cv=none; d=google.com; s=arc-20160816; b=z5xtRBcLFgHi171oePFpzIE/eLyThjfDusNIM0dY93kXLpz3MT2EUNFqQIMTlWhcIq IHNYxWP7GP/Pb2tAV1Y6FcK+B5XaV1jsVdxQQz1b0KPcA6qsgpUgLxrmLKJk8hC6d3kD /luppbEueX/Og+XtCuADaWqIkhJx8Y2AbMCeR9TyDSljZCHwnS6IZxfKLRNKYTCXgEcG h+fjnG6YXKD0paA1CfPjn8RnwsIFNhe9lByRQ3nn1gNV5t/EgU5DafajugPiVGkgGEfO 9vo8S45hEK5RyRHa1Gy451hJeFeIxGMfBJE21g0FlYO+JtWQ3NRU0Dx41StbDWXMg8Px TSgg== 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=FAYK/xsEpaCpv/bJ87YGVTTG6HGzrBsunQFkD3ApYnQ=; b=QKe+0mm4LhcTzJl65M82mXjUezX+rIUABaxD4E8Nf5b+ptg1TkRnqNp/s0t9W29bWt PwCO+L8jT+U+4nMV2fOIVM+kmvW0ynY79UQL3Qcie8Wk38ZSkZx42uC2A2/YxVNO75+X 3z5yukrjYkhybc61JTOBAg1USNAlDD3UiV9eoCpqxOnMmEbNpH1IvL4TZQQivk70WEYT oNynDXmXiIhi7nnItytSAOaZDB3OwVx6rye4braZvg+PPx9m1ToG1Eulll4YrjlYBMgz G0RAUL61O/JIQm6SIO3TKDj3ehRjHhcWYUO7U7wtBAOEGuZ6bgo5GRCAItNksv50TQph kD2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LMDclzab; 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 b17-20020a50ccd1000000b0043aca113dc9si21757698edj.342.2022.07.19.06.49.28; Tue, 19 Jul 2022 06:49:52 -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=LMDclzab; 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 S230049AbiGSMUv (ORCPT + 99 others); Tue, 19 Jul 2022 08:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239273AbiGSMSr (ORCPT ); Tue, 19 Jul 2022 08:18:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 788714D4F7; Tue, 19 Jul 2022 05:06:48 -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 ams.source.kernel.org (Postfix) with ESMTPS id 42AE7B81B36; Tue, 19 Jul 2022 12:06:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84D05C341C6; Tue, 19 Jul 2022 12:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232394; bh=a/sAmAYMs3H7B9lRQaCSEPbIAzVS79fHzsO5WLh7RgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LMDclzabAErfBHTFnyLW9wel+GeOlXLzpMijluw+Asp04xaXLxDpaFTHve/yQC5ks YutpP7CpcRBgEPmC3jX6y+TARd62CHQY3i/B9CiZ5xnpBEbbNIxxlEzMtkKq+6l1W2 zvcyqypDWZfGQMg7uqnN2vOdAusEmhyudhadsif8= 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 042/112] sysctl: Fix data races in proc_dointvec(). Date: Tue, 19 Jul 2022 13:53:35 +0200 Message-Id: <20220719114630.454008327@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 1f1be04b4d48a2475ea1aab46a99221bfc5c0968 ] 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() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_dointvec() 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8832440a4938..81657b13bd53 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -557,14 +557,14 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, if (*negp) { if (*lvalp > (unsigned long) INT_MAX + 1) return -EINVAL; - *valp = -*lvalp; + WRITE_ONCE(*valp, -*lvalp); } else { if (*lvalp > (unsigned long) INT_MAX) return -EINVAL; - *valp = *lvalp; + WRITE_ONCE(*valp, *lvalp); } } else { - int val = *valp; + int val = READ_ONCE(*valp); if (val < 0) { *negp = true; *lvalp = -(unsigned long)val; -- 2.35.1