Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3866076imw; Mon, 11 Jul 2022 18:13:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sp6TmW5qGKvJNfOOnHLqoT/3/bA0XJR8Ac9XuiS6sa+W7i9sWCE7sQMiplEfiIJL4G/qQM X-Received: by 2002:a17:907:3d8a:b0:726:396d:1848 with SMTP id he10-20020a1709073d8a00b00726396d1848mr21129405ejc.339.1657588390949; Mon, 11 Jul 2022 18:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657588390; cv=none; d=google.com; s=arc-20160816; b=yuzj28aM26TIx1+tbT6VViK2WxZAqOFXyUAWsdjAlFriwb3/OwmxHbE2vrG9cHJgD0 vcVveXUWWlyYBXWsyZb+dh8qZi7VhYsZWiCN7ZajJExGkyILrIGfmulleq5gVZDs4X1m e4MLfcrFJo+GioaG4A8waxd1rZcHwKG7Uc2L85ncZPxeOAnCw/9xj8pFiDObLwxMdzXc rwcxxJqNaT9+GX4otfM9fVhH6McQWypZgHxEBL3wbKcDcGuwVCaL1NmCZRXlhpyApsdU 445e4sQrFm3x1prF78e4a4gj48hzsY+xbjoCOhC2uNGEw4SlkXDqcxTFRDhOiQIgu9ak eCxQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VgYMgd7mG3X3zYeyUnGTBZlnYzPIOrvkC3oXi4J3rKE=; b=SfRobaSM3vB2E9b2Mb7cCSOQYuVM1Btfq+Uto38+YquhkgIxb8a9GTbLTNt/9AU7Fz K4yv6D2yJbfmujLj0oOPXO8doxCL5IOF7dbe4ZfDw7QpSDZGKHcYXtbYzVIsQAQClC0a 0iLSQ+t0CBDuIDo914muo1ZmnOHAOrmDVlhqmooTZsmChEm5q7B+zZbQAITY4d61Yuo5 Lojl26AmhwJU53N5KqbIX7+RdHQSam1zQOgYH+2JQi/xKsSyJk/WKpGZDd62KrYXMOve 9qh7ngJ7RfkYL6yNRDvcpjOEq0ETS6Tp9m4pEB89Dxp2hcqyIKiMybUEyPlInyXGYJZc zkZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=eegtiPFH; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp28-20020a1709073e1c00b0072b4ad153dasi10583981ejc.635.2022.07.11.18.12.43; Mon, 11 Jul 2022 18:13:10 -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=@amazon.com header.s=amazon201209 header.b=eegtiPFH; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232094AbiGLASv (ORCPT + 99 others); Mon, 11 Jul 2022 20:18:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231502AbiGLASY (ORCPT ); Mon, 11 Jul 2022 20:18:24 -0400 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 278A73C16E; Mon, 11 Jul 2022 17:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1657585023; x=1689121023; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VgYMgd7mG3X3zYeyUnGTBZlnYzPIOrvkC3oXi4J3rKE=; b=eegtiPFHlZQ4BTtN29d/ykgHkdfwbhbowBPQ518uvYv2s3gt2LTVLPmo Sm7KcsGD8nj124UQx3ea5t9Ly4ljS9AVydD199lclaIQiCiN2yISUgcc8 QE7VxC3O61Td2mBHO+A5cIv7LSlpiYxVo+Ep720K+HsxrhZlsCjH1Gkj/ A=; Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-c275e159.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP; 12 Jul 2022 00:16:48 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2b-c275e159.us-west-2.amazon.com (Postfix) with ESMTPS id 6F77681591; Tue, 12 Jul 2022 00:16:48 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 12 Jul 2022 00:16:45 +0000 Received: from 88665a182662.ant.amazon.com.com (10.43.161.185) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.9; Tue, 12 Jul 2022 00:16:42 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Luis Chamberlain , Kees Cook , Iurii Zaikin CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Subject: [PATCH v1 net 02/15] sysctl: Fix data-races in proc_dointvec_ms_jiffies(). Date: Mon, 11 Jul 2022 17:15:20 -0700 Message-ID: <20220712001533.89927-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220712001533.89927-1-kuniyu@amazon.com> References: <20220712001533.89927-1-kuniyu@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.43.161.185] X-ClientProxiedBy: EX13D04UWB002.ant.amazon.com (10.43.161.133) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 --- kernel/sysctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index b016d68da08a..d99bc3945445 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1224,9 +1224,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; @@ -1294,8 +1294,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.30.2