Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4445307imw; Tue, 19 Jul 2022 06:47:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vbPIoO93mri+sXVPQQLrBR8zJU31DqgmQ8k++CFrlE2y+bWQ+ofLTYy/uHpOT4LGt5+zss X-Received: by 2002:a17:907:7e94:b0:72b:53d2:c004 with SMTP id qb20-20020a1709077e9400b0072b53d2c004mr31268041ejc.387.1658238472597; Tue, 19 Jul 2022 06:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238472; cv=none; d=google.com; s=arc-20160816; b=OhRgRsoAo2jUYXOygC5+srfYXH2o7Nj/ALj1drF/Xp++NNU6Bqxhv8Lazba9y0tKUG 69a82UaSOlsnwO0B5qDl3CGjt1KagDdYEBGLhQp48auGif3Llset14WbeiJfiKW8MUqp E2M/XxKaiwjAUx6UkXm9jggIw+oCnNXZN7vhBvINQyj/wn9wU7ShUXz3/Bg5xoyJ6hAA 0gEqtiFSWAGAQCCWHoUu0u8uR0grCGyIaFrxZ+BbNzbCZH3Jmw0esNJ3FU4PSMLA8zuj /SHE1rOv8A9C4evrypIA9GZBeNqsArHEaCvhTHFmyllrSTbb+mWxWNp2enFXYZK+a52n DeVg== 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=kgyvAy4pGBINT/aBAmWA3fV9aPSq0EHckddCLg8hcdo=; b=AV0yHIq0wsQR9xcMewTBe4q1+syDEUy8Xd2l1dXmSOQtugrO98icKjXdKs/eig9rk8 ec0lOOaC9FhJ/NvouzDpIrR7/YnnNM8C0AU/g5wpnhSgmtFjXQ7ty6C57VjEWV3eIytN 9nlMqAXWyRXYyKYyFUH9KTJxNL6dJ50aUzejg9rk3ZpjwJ8azjtFiLbJB4X5RTfWPcym bexb9o3b8qiCz9Y38AvQnkF5orxJRO1ZPGi08Nq2JVMWR55hBYm4cpFgXYuhBGDYSCGx GcZ57Qu7ft1oxK2aoWLQgjgw9+QL2fXa4EB6o+6ntK8E0t1ZuqSs+ryBXVvMWddty460 0OMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V1mVD2AT; 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 i14-20020a1709064fce00b0072aa56cd0a3si19977508ejw.28.2022.07.19.06.47.28; Tue, 19 Jul 2022 06:47: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=V1mVD2AT; 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 S239746AbiGSMZe (ORCPT + 99 others); Tue, 19 Jul 2022 08:25:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239888AbiGSMYV (ORCPT ); Tue, 19 Jul 2022 08:24:21 -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 B421C50049; Tue, 19 Jul 2022 05:09:11 -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 AAC4261772; Tue, 19 Jul 2022 12:08:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79D30C341C6; Tue, 19 Jul 2022 12:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232490; bh=9v52TZRoTJnRUxmxr3USsn+2bLYA/S73f9ZuYakPHVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1mVD2ATHs+n3ojJyKtBatimAXhpPPzOHvao6yK9w82fG7oer/RlPr6TqTHUvgYV/ IJtc+7Rbzc+7F8T9DSvDWhjrifwZRTH477zMTB0ixW6UQ9x1ugg12p0ebwXVW6VKdR jmCWDLnV2dol6h20WWlyjyG6pBOvw8yc6TMUO2aM= 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 058/112] sysctl: Fix data-races in proc_dointvec_ms_jiffies(). Date: Tue, 19 Jul 2022 13:53:51 +0200 Message-Id: <20220719114632.080124039@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 7d1025e559782b58824b36cb8ad547a69f2e4b31 ] 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_ms_jiffies() to use READ_ONCE() and WRITE_ONCE() internally to fix data-races on the sysctl side. For now, proc_dointvec_ms_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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 83241a56539b..642dc51b6503 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1327,9 +1327,9 @@ static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, if (jif > INT_MAX) return 1; - *valp = (int)jif; + WRITE_ONCE(*valp, (int)jif); } else { - int val = *valp; + int val = READ_ONCE(*valp); unsigned long lval; if (val < 0) { *negp = true; @@ -1397,8 +1397,8 @@ int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, * @ppos: the current position in the file * * Reads/writes up to table->maxlen/sizeof(unsigned int) integer - * values from/to the user buffer, treated as an ASCII string. - * The values read are assumed to be in 1/1000 seconds, and + * values from/to the user buffer, treated as an ASCII string. + * The values read are assumed to be in 1/1000 seconds, and * are converted into jiffies. * * Returns 0 on success. -- 2.35.1