Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4452346imw; Tue, 19 Jul 2022 06:56:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sTf+lYAJmnJpOae2A3/IVWIz7xRrHuJe/IksbM3l8WmoF0bDpRfQELUVVvZwiPsJV1Wl5M X-Received: by 2002:a17:907:168d:b0:72b:5b67:83e6 with SMTP id hc13-20020a170907168d00b0072b5b6783e6mr31103395ejc.709.1658238972962; Tue, 19 Jul 2022 06:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238972; cv=none; d=google.com; s=arc-20160816; b=Vd0BXZv7JusYj+rE9Z7PlidLXQB6DHf33xq5YoG/ew0JlH6YnuDGmIVyxuR90FJtWS Fge74FST3Qdfparc+eFPXTW5KnhiOF9zbgzAiaLN8dyhGXXcNxCUe4wxwsV3UEkAo7F/ B9m6ny/WxmzAwqfSbsnWfCbaKxhFh8B8rZ2kfpRVbutsYUdylc/zd1F3Kpw6sv4BoJci n2w8R1lQUedH0FGzv4CcSeeCGM/t2YQYadsm/Q7KIzJ64kV6T8G9A6AX1eA64HPN7cjL +nbX4GnRv74Zrb4Z7U700ofUtanvuG69S9wQ8iu+3Ph/mzmSyeyEDr/iYyVv/EExjIyi z7Gg== 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=c4Kzw891QCS9c1UiyMzcbKuw+Qw4WxR6xM+Wp4mD5ng=; b=FVggAcYnsNSSRW2bT0YruQpk024o8t2jaLRlNytY8+2aESepmTdR5fLAdZ7iOxmjT8 jqe2eN3p1b9CaV1nSbKzsUI+HRSP/K+EqZ0GhYWnEtivmjJzEJuaFxpO5RWS0ZIRRjDB gopflKD6Cpy1KVy39HJcONb1fWef5R/jwBXOfBL3S9l/9lI6qNjlKyetcERkLzbMicpx Xx1/8ThtJzUYxS8b6bkblnAucO+JvG8+sNWuGiB+gRoMDJ8SRspnoeaOnb7E9yIcMoU2 n+2iOPsSco28xomzRO5XX0Az5LZ21IISKyvfyfHJq06fCYr4ulmUIBbKYw2+Blcsg681 1J1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y+zIaQY7; 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 j30-20020a056402239e00b0043ba52ffd16si302576eda.453.2022.07.19.06.55.48; Tue, 19 Jul 2022 06:56:12 -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=y+zIaQY7; 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 S234329AbiGSMV0 (ORCPT + 99 others); Tue, 19 Jul 2022 08:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239780AbiGSMTy (ORCPT ); Tue, 19 Jul 2022 08:19:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2FB599F1; Tue, 19 Jul 2022 05:07:16 -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 5C6D5B81B31; Tue, 19 Jul 2022 12:06:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF7DEC341C6; Tue, 19 Jul 2022 12:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232412; bh=Tanvov2tDXLHsQ3vBMTvXUmEUNLrX0p75EV+44Ib+JI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y+zIaQY7YzJ4g94pEEZ1xIVucKPLPvjA+Yw32558HTH2r44zq9Vg+Q84gGoIom5i0 AnwJkQhB7UeLZ1iJX4cgBAP7CFoWmW5OcOOF6haIK9xcpswcdxBcRMPe6mttuYoiO6 1Ug2By0FDDu5WxQeZlc34bI1TzE/TC1Ilaw5qw4w= 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 047/112] sysctl: Fix data races in proc_dointvec_jiffies(). Date: Tue, 19 Jul 2022 13:53:40 +0200 Message-Id: <20220719114631.015837807@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 e877820877663fbae8cb9582ea597a7230b94df3 ] 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_jiffies() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_dointvec_jiffies() 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index e7409788db64..83241a56539b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1276,9 +1276,12 @@ static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, if (write) { if (*lvalp > INT_MAX / HZ) return 1; - *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); + if (*negp) + WRITE_ONCE(*valp, -*lvalp * HZ); + else + WRITE_ONCE(*valp, *lvalp * HZ); } else { - int val = *valp; + int val = READ_ONCE(*valp); unsigned long lval; if (val < 0) { *negp = true; -- 2.35.1