Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4476667imw; Tue, 19 Jul 2022 07:20:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sFaKKJIb4mKgWQ7xEb+rnStYxpodewG/UhdGIRwBzcgKq1tmKwerK/ApwkHEn7o1Yl/XVM X-Received: by 2002:a17:906:9beb:b0:72b:4a68:ffdf with SMTP id de43-20020a1709069beb00b0072b4a68ffdfmr31232488ejc.21.1658240401005; Tue, 19 Jul 2022 07:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240400; cv=none; d=google.com; s=arc-20160816; b=EOLIueuiCUpT8CEe3PNlfYO+GkCUhjtWC7ozoPm9iuM1waCAwfOgm6euGqwqJe0u92 aLbtIt3CT0nqGW0O60+MS7ahQ2047w20QA1YeYbDowKMRKQDtWwSJc0sbiPvchBu8p/3 JqMPRllIJ2eyDnscuP4U0nQwuU6g/zJlQn/jiKHO0u7w27hjXicUGjuAHzFnBXnZ3Qg9 IfTEYVlqAkR/k/zcVUI9czcPPsCzEua+vM8cu2FRmUL+njgkbBi8PCDzJtZf6w20B76Y 4ditIjWi6caJZe6zTAP0cp17I/u2hZzpSiVp6VP3Ki9Yn8fh7DgZrkiB3+OB+9exLNf+ eDlg== 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=w/wjPmpDnRr+dWkkYa4YnBTDesSglL5kwubw5zcpG14=; b=UNfOXiJGNH734AfLlNK18XAUUlH+O6N560PZTxi2BkKx7deXIXqpMIvI3bZLmvCikR smHxB8SLpHn+rBwDqcdc2wRNIfpAfkUCrqdxY53vX59UNxz4M7u3W0ZCYdt7m/KOxPu/ NOq87wiEviJINrtRU0fbwlNrfzrZGOeS1hzuDoYFmLQC5Lp62azksvIkTVPi1Q59LqAo U9/J0oxQS2GcuwQuo0rbdMjp4Mc5t5RW2yb/Zw+kHK1XcZkVRTYBtyxpxqkfSXq6FtLH l4x+yeuAkkPj2DGv6i/z+jXMZD1XlGdviMNjL3XxQyZ/2elpN9/UiYlNE6Q1aDZaqNWC RCTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GqZG01IG; 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 hq28-20020a1709073f1c00b0072ed047f2e6si22999831ejc.583.2022.07.19.07.19.36; Tue, 19 Jul 2022 07:20:00 -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=GqZG01IG; 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 S234440AbiGSMfI (ORCPT + 99 others); Tue, 19 Jul 2022 08:35:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240435AbiGSMdr (ORCPT ); Tue, 19 Jul 2022 08:33:47 -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 3572952DD6; Tue, 19 Jul 2022 05:12:56 -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 546D3617B2; Tue, 19 Jul 2022 12:12:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 216D3C341C6; Tue, 19 Jul 2022 12:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232765; bh=wB6wc6y/Dtx3NEjnGvFvSrVcgCQ3JRyJxsff8TxVPik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GqZG01IG/QqNnmGvT3G5S+qayFGZ2rDHO77Cuv3tCXUaVSLGIibyJdETON+YhRsEX /QkKp3eQF0qCLWPCh8HnkHaxzfIzjgLEXMcRQey9wBDLXe2RpY7DELQswsr1fMz/uV wC08wy2fd8KoepETEWPoqgMvkMxtVbf+NziO96cs= 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 058/167] inetpeer: Fix data-races around sysctl. Date: Tue, 19 Jul 2022 13:53:10 +0200 Message-Id: <20220719114702.179963698@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 3d32edf1f3c38d3301f6434e56316f293466d7fb ] While reading inetpeer sysctl variables, they can be changed concurrently. So, we need to add READ_ONCE() to avoid data-races. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/inetpeer.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index da21dfce24d7..e9fed83e9b3c 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -141,16 +141,20 @@ static void inet_peer_gc(struct inet_peer_base *base, struct inet_peer *gc_stack[], unsigned int gc_cnt) { + int peer_threshold, peer_maxttl, peer_minttl; struct inet_peer *p; __u32 delta, ttl; int i; - if (base->total >= inet_peer_threshold) + peer_threshold = READ_ONCE(inet_peer_threshold); + peer_maxttl = READ_ONCE(inet_peer_maxttl); + peer_minttl = READ_ONCE(inet_peer_minttl); + + if (base->total >= peer_threshold) ttl = 0; /* be aggressive */ else - ttl = inet_peer_maxttl - - (inet_peer_maxttl - inet_peer_minttl) / HZ * - base->total / inet_peer_threshold * HZ; + ttl = peer_maxttl - (peer_maxttl - peer_minttl) / HZ * + base->total / peer_threshold * HZ; for (i = 0; i < gc_cnt; i++) { p = gc_stack[i]; -- 2.35.1