Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4371363imw; Tue, 19 Jul 2022 05:31:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v5tSyXCnHtaBKWBK/rVsYaG03J4ymMzPJvKldwf+npTZcnDH/2MzZ6tXwbQ24MJIfp4VUH X-Received: by 2002:a05:6402:1d4a:b0:43a:ca49:abc6 with SMTP id dz10-20020a0564021d4a00b0043aca49abc6mr43274343edb.376.1658233918953; Tue, 19 Jul 2022 05:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233918; cv=none; d=google.com; s=arc-20160816; b=LZmwIyHHjKgVU86YaAPsKnM/UODVDV8TrApGdzE3no6atBAKkIssFMFrTde9C0KNhe 9hVAfzITHeyHZnGkJIYeeBptiywMc6uNcrUjzuqVoMwm+B3TTsfSi1iNLa6nQwLTV+yx crKH8QdNKKwXzkECF3DEQxWAKAwFp+NtP7E03W2vbR15DV8CSdTczP97Hv9ijZTwGr7P liX9x4xBewWHeEdV88ObJ6mCg+juGCmG2xsgKPfXq8yemzLHJrZvf4pAYXXFe074WnAr Dq6brwm04EGrKRdblTsFNdXlWfoUq4hldPCQYlyBLPxDtmRRgNOz1qS8err4yzsLJP7u tqsw== 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=jR+QRV+VGUb+kCgvmUm5NnydMBIvuvVW35ohgEV11cY=; b=ABTDsBtxxIMg19CWLhHRow8YTvFfDYsvnFvP16iHeRKWFAR3Vuo2Us+pfSu4zvIy06 dwnlFqiieevM5IafEwGXdHsn0eyux3kGYrD21p4afTPf5VxcX2x5fjAvijgT5k8jUM+F oT/J1EyyCZk3+XiQ4bHYtGHOteM9c+6pUAAgc5F0O0KPsu5cEC5KkjFJVh0hw3ue1H0P UxMxKhCSsBXW5cQvIbioZiwsFQyhOs8MsR/lXhOEUkz97KrAvl9IjMml/Rj8F7D92tSa jH13kU7gsrDTrvfUnfIXsEZ9duV1tQGaMN/3ipSeNibprrms1e8WotZdReBmuG+146vJ Aiow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KeeCsNcs; 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 d1-20020a1709061f4100b0072edee8a633si2548269ejk.187.2022.07.19.05.31.34; Tue, 19 Jul 2022 05:31:58 -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=KeeCsNcs; 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 S239202AbiGSMVK (ORCPT + 99 others); Tue, 19 Jul 2022 08:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239579AbiGSMTb (ORCPT ); Tue, 19 Jul 2022 08:19:31 -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 B8C0258871; Tue, 19 Jul 2022 05:07:00 -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 A0D81616FD; Tue, 19 Jul 2022 12:06:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70EDEC341C6; Tue, 19 Jul 2022 12:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232417; bh=YoR3SsG5TDiknuUKLDadyj3jZcIc9UalePU1JVhKyTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KeeCsNcszjHmz30OtbwDt2zdrf6l3w7j2FazUL2unfdXyug1p3kiBOC23Gn9jHB9t POM0OFmCZeQCnUqHv6OxxndH/jjIAhzGLitT3MaXjnTlLs51kWz6VMPDMuJigzgsHs usSzGQ4B081A8Nl7d+XruAFmAWZIdyjPvAvsiau8= 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 049/112] inetpeer: Fix data-races around sysctl. Date: Tue, 19 Jul 2022 13:53:42 +0200 Message-Id: <20220719114631.227105942@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 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 ff327a62c9ce..a18668552d33 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -148,16 +148,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