Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4449093imw; Tue, 19 Jul 2022 06:52:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tk+CI2PNNmvgDpQOuHHb7xFpzMmWb92wQr+ltGA6hZpa3Ou9tLyGub9KtNanC1UyV2oM79 X-Received: by 2002:a05:6402:26c8:b0:43a:c404:a553 with SMTP id x8-20020a05640226c800b0043ac404a553mr44115139edd.53.1658238727160; Tue, 19 Jul 2022 06:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238727; cv=none; d=google.com; s=arc-20160816; b=eQ8xVOkfQn8B6fGTnVkZmOGVM8Qu6XKhZQKJXd8IxfwOUCZ/VSjEQXsGbRChi2GfnJ Pjz7aqTRxh/6IH49mK2hhmZ2hg0Gzyv4enXVXKKI6j4cB/puT805bdF5FFb/EvrZxvps mW01vz+rPDwX3KrY8VaBHPWCyCzLq6HwuFbdarKJSk6MfRlpMIMfqGeFNk3oZvXFawxH 7RokHfi/CWjZeTz5uIMkFzbHPtmP4C+kjlzYP/M1hVLe9XqAfRAdyv0XC+Z+U630jRog qspMhGrcvRUxCpzcg/Kjiv3zy8SI8AQ9iU4BeG641rCm9uOn8Mdq0TzWXPf5ese/36HD oJvA== 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=14of+XcWajsUPZX7idY3GknbZ7cQOwTs6w+0JZQ9ZTc=; b=y5Kr7f8TgweBW/hQmllsOqXcpqBFtWD4+czvcMRD0R/zsxhS9LMG84SGxYKSjosf/3 oBFEGLnqs65mxo+eD0m8MMoSRTwxZEkXZLnOyA/ZFHtlmaORsDliXOJ+mw4txHG4dZDA G7/g7K2HT8FFeoY98y9rMPYNw0sQ0BIdkIXYKUA2E3ZTf1s8/BOdK5rlamd/U+rLw9Ns b09vQnYKtimnaF/mfuw8f/Kg9W4G6wBd9lGSc2XjVz99dOLHYjV0UMPB6aW8/UPIdDjI 1fTauTURZ3HHEoVDmkojBqMByP+8f/5QaLEQgw5NFugK7Jj9ShysaZOskdYPXZFGPTEc 9hRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VIYA+ABA; 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 g9-20020a056402428900b004357a6c5e3bsi13854554edc.151.2022.07.19.06.51.42; Tue, 19 Jul 2022 06:52:07 -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=VIYA+ABA; 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 S234378AbiGSMU1 (ORCPT + 99 others); Tue, 19 Jul 2022 08:20:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239121AbiGSMRr (ORCPT ); Tue, 19 Jul 2022 08:17:47 -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 C2FB157216; Tue, 19 Jul 2022 05:06:39 -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 766A4616F3; Tue, 19 Jul 2022 12:06:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AA7DC341C6; Tue, 19 Jul 2022 12:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232397; bh=jBwL2Hzav/uiDZZWKt1O+svrUTp3QIg2jT5a2Uo04Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VIYA+ABAjCDUr8Iwjx9pxAW9/IIjMIvcpQDACKIjcWbNT9fzsdw6fbHIWpJ6EkzQf O16rTHGrzM4kNsgIQlXYSRujKGbHnSLc3AesPCVJraf6MkSD/NbjbcC+T8pVDRWrUo SmPfukWFup4Gpiw8xj2n+cUzKCu78AXCZwMuF3cw= 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 043/112] sysctl: Fix data races in proc_douintvec(). Date: Tue, 19 Jul 2022 13:53:36 +0200 Message-Id: <20220719114630.574536484@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 4762b532ec9539755aab61445d5da6e1926ccb99 ] 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() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_douintvec() itself is tolerant to a data-race, but we still need to add annotations on the other subsystem's side. Fixes: e7d316a02f68 ("sysctl: handle error writing UINT_MAX to u32 fields") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- kernel/sysctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 81657b13bd53..30681afbdb70 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -583,9 +583,9 @@ static int do_proc_douintvec_conv(unsigned long *lvalp, if (write) { if (*lvalp > UINT_MAX) return -EINVAL; - *valp = *lvalp; + WRITE_ONCE(*valp, *lvalp); } else { - unsigned int val = *valp; + unsigned int val = READ_ONCE(*valp); *lvalp = (unsigned long)val; } return 0; -- 2.35.1