Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4446127imw; Tue, 19 Jul 2022 06:48:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vtYlvtcYGeqXoNwBrB2tFhsRL/g3PVnFuuXzRNMMH74oYRT9mMZlDMxdmuqxnC+PhIL86k X-Received: by 2002:a17:906:8a69:b0:72b:40d3:7b6c with SMTP id hy9-20020a1709068a6900b0072b40d37b6cmr30766980ejc.624.1658238525003; Tue, 19 Jul 2022 06:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238524; cv=none; d=google.com; s=arc-20160816; b=GX/LYBSCtpjgySoPb0QSv4kMamcCJIGKrGHrlt1p1wT2G5wjLBCBJcf0NZGfBj/XEZ eHfZ35bAvJQMzeAJi47pl7xl2d/FIoGHBnuwEtger55SH3whsW7vF3650tH7Hxz3XdYJ x+/3p6+AkjFiWIRrdX0IAYBpkCTK9DCPJpd9pqgl3V3569gkCvU8RyolbYtydTjo9K4t IoW5wFlpuE94Cf2JGcQ7iHU/HaIMlhQn81TSwZco38NToR/SU9s07rm1D5w5D39EBrC7 kFdESKVJHPuSafGozqCOGBwlcespYucTqJW1EtxV5bKvFsMt3zobYbYVbBXCf6yjM4p+ /0MQ== 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=jgxCExJy69yHqSdjDHlTyrABl8RU40YgUmEHa6GMs2c=; b=Ggni2h52J5m+rvocr8WfZiaFgIxYt56otS8JxeljjLckhXk+cKgRccTcyrU8nNS+zt n2SUfWhTjc9lhc6VlSH7aeqCGElAXZweqmEuFGBy9CISLx+RtL7ydTDKlbMgZ9LKE911 PGKHzFUKHq9HqrIO/vwt7NhF8M4UgZiRe37eVfj6/ZTjBjQAGLkUIufj6QT+/WDLDZiT 2x5b3UdOQGOETfUI0x/qWAdI3h4ufIvzzoc+11G0voVNjn8xkXodkEIDXZRXpSCE1CRF yeydp+E2cTP2ZUoNrbEU9j3/QnJRiSGtkZ0goctry75Q98xmniKYIhQWKrZxrqRVvJfK 5TpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nyx8t9Vm; 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 qa36-20020a17090786a400b006feb3a01b16si19711840ejc.683.2022.07.19.06.48.20; Tue, 19 Jul 2022 06:48:44 -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=nyx8t9Vm; 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 S240340AbiGSMdj (ORCPT + 99 others); Tue, 19 Jul 2022 08:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233786AbiGSMdI (ORCPT ); Tue, 19 Jul 2022 08:33:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BEDB7358B; Tue, 19 Jul 2022 05:12:38 -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 C54FFB81B1A; Tue, 19 Jul 2022 12:12:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35156C341CF; Tue, 19 Jul 2022 12:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232756; bh=E2/fWrdznifDX8AkHMSJOC4G5mDAciLTGgAmMjUvb4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nyx8t9VmFbuyJGBbeOO/xOLBqO1wFm3pTC943WfiaZlDnua5/g+1Zx4fcbCNiyBu5 NLx/U3tuiQ+tehUa70yeGHbl3cpPDdZc9PEELpsTmx1eKYpeyP6irz7zI/2Vw8+cID 1bbno/eLdlfCm9VBIL1iFXK5HXyKjMIsYtRoFr7o= 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.15 055/167] sysctl: Fix data races in proc_doulongvec_minmax(). Date: Tue, 19 Jul 2022 13:53:07 +0200 Message-Id: <20220719114701.918591935@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@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 bdb2f17b723f..9a68da5e1551 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1281,9 +1281,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