Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4473655imw; Tue, 19 Jul 2022 07:16:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKs1KESrR3kjIdSXAK4pKLBkDDLHIxEVqaC7t0LbRsRKe3thFCJeXzy8CmBgnY+UtIR8w1 X-Received: by 2002:a17:906:7b82:b0:6f3:ee8d:b959 with SMTP id s2-20020a1709067b8200b006f3ee8db959mr31185407ejo.458.1658240210632; Tue, 19 Jul 2022 07:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240210; cv=none; d=google.com; s=arc-20160816; b=vhiazBt08WL4CsDU30zkAm0OjafGMtiu4OTR044KHmj/wgb4Vl0CviVXa7n9GzzZkj RPyj1TQJxapS6VQQIwLG+2YN4M+LP/I075K+FglmfJm6SItuKD6NHJAOlQeC6FeQg/kn 3tzo0t/kE3UtM4HkeiCDo+suy8NqNMpD+nKFj9nkrH5smZM5YQnsZiXIHwDKx+LMrHF9 QfAY+fW4WEetkpLq7C+RFCMe/P5V8SDgKFIpIRe/k3g8qvkSaU0+RvgsRvZ2jinDXWRh 6N0U1ZNMUd/62pqVq9IaWHyBP68uuTufyhvw8VnzQ6fLTSKqMX/OMgpm7NDOIMooFFdx Y2tw== 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=6PhLnwyEtey3PGMcmSTJVmYghOrBLdQHVLOhI7hyWPQ=; b=i33C1xZ1Sh/M/kVaP5Jg4X0UgklciUpq94Ly9VJvNQOvAxX9oh/O1RJrsi7pYRcdFR LPODiqGF96x0DLLAVPlIK1JJUfIXNucRI3OW1ES3+NegiPlkbxcQOtTBcpF3xrWjkRmE yqz0VK6AFNaR+bQZ6gpmaIlYIZOnRWCD33TmnQGPNzWPJlwqGE76+uzETQMRlNeY0mXO ThF2rL3Y+2GojvMTLYpKfb0MRFB5c8bOtlML3YaSft2wh4Cqj27iPEY4rSwJQYbF+Kxi FmoLpxWA2+4fcMPHpyNR3uWHk6fO7OErqc7MfoxVu/5yCrFeN3z6vHEkWCWZlXtmu+Ca s2iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nemFESH4; 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 bt13-20020a0564020a4d00b0043acee93208si18568452edb.319.2022.07.19.07.16.26; Tue, 19 Jul 2022 07:16:50 -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=nemFESH4; 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 S242176AbiGSMz6 (ORCPT + 99 others); Tue, 19 Jul 2022 08:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242405AbiGSMyb (ORCPT ); Tue, 19 Jul 2022 08:54:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B6E97487; Tue, 19 Jul 2022 05:21:34 -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 097066177D; Tue, 19 Jul 2022 12:21:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFEEBC341D2; Tue, 19 Jul 2022 12:21:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233292; bh=F3A7SXHYjof7BlkLaf1dpEJWq0dRZbv4zt/6zVtRX98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nemFESH4bgiGA4WZbRuNJTKMsS3lswaZ5y4aRJ7pEYaJxfWvhsOa6ssHQQF0BJDO/ x1bZvBE0NIe79an+Z2ImiDVsLhQWbrmkGb7ea1lmBeu6mCI2wpNSHuFmRYcoyg6+Zu Pq8il7ip0XGF2qSSGdyIm05j5DcSkYp5k5cqRHqI= 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 073/231] sysctl: Fix data races in proc_doulongvec_minmax(). Date: Tue, 19 Jul 2022 13:52:38 +0200 Message-Id: <20220719114720.843625906@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 c31bcc8fb89fc2812663900589c6325ba35d9a65 ] 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_doulongvec_minmax() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_doulongvec_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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index a769f64a78ed..7a8899f237a2 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1162,9 +1162,9 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, err = -EINVAL; break; } - *i = val; + WRITE_ONCE(*i, val); } else { - val = convdiv * (*i) / convmul; + val = convdiv * READ_ONCE(*i) / convmul; if (!first) proc_put_char(&buffer, &left, '\t'); proc_put_long(&buffer, &left, val, false); -- 2.35.1