Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4448333imw; Tue, 19 Jul 2022 06:51:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vp8M/6Vj2XWKWjBX9tlk9pnCiwyuqYtV3SHx+oiV+4mXg7jK3hCL93pwujO9WkTOpDM+Jq X-Received: by 2002:a05:6402:294c:b0:43a:91a9:a691 with SMTP id ed12-20020a056402294c00b0043a91a9a691mr44114592edb.182.1658238674791; Tue, 19 Jul 2022 06:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238674; cv=none; d=google.com; s=arc-20160816; b=RRuPKII14oMgmRp+yr4mVxnOVejo3wN0gQ40xmtyWy+AwZ35I+zL3lnpYftMZDOwWj EsQMvcGnTWvhv+sgKunxed4AYqjsOA0+/spWQg2lGifq6bxzs3Qi3r8TdvspKtfj6XVE LtfNVf1EiNJdcPWafuhEwRqJpNV1z639zZM3DFxHIoMttOeb7zZODgju/M9ecXfidY/I jd2ort3qfcYNrgW7+nsdleeUrxrcMJL87BULxqM41YIKM+vDTOKdsNZ3MwzZFQT+/wYb zR1K38BVj1YS8Hlih83wX1l8FzM28VNWxMsSMv/O2ujhT9ud5gxvzRjWtyymDz13kjJ8 2RcQ== 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=Z33A8OmoDMNNK+Vzc447aDWUa3L2z+7xv91fdnvbrqm7836Uq40lt4beX+UykZBCvX NR+gmQqih9xF9WVfWMo8X2X16gfrzGQmdc8TJvIWOmdPWb57HffVZa4dIB05V3dXpezv FcD2tZiT01Isl9rFWIaAbcamyBGU8XkJvJPd1uFNay58EY+zRI/vc1Ti74d0lT93iUDb Y1zifDBm+T+CwI71QAjgxSxC5eicZBWnIpSbGmYxN/Jxk9NbHL37To883ZHhUa+jnC/z hPHrfZyyqdysUZH8o33s5XwMkRpef//WDdXQwKYQ7GY1qIBPRvMivRtGA7Uc7MxFUHz4 lI+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n47MBeSe; 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 ga4-20020a1709070c0400b00726ab8af824si22835107ejc.788.2022.07.19.06.50.50; Tue, 19 Jul 2022 06:51:14 -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=n47MBeSe; 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 S238756AbiGSMMW (ORCPT + 99 others); Tue, 19 Jul 2022 08:12:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239073AbiGSMKI (ORCPT ); Tue, 19 Jul 2022 08:10:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EADE951A34; Tue, 19 Jul 2022 05:03:12 -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 8898CB81B13; Tue, 19 Jul 2022 12:03:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEC35C341C6; Tue, 19 Jul 2022 12:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232190; bh=YoR3SsG5TDiknuUKLDadyj3jZcIc9UalePU1JVhKyTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n47MBeSeo8suXbDxRlqz5IR/ZHMyCCkp6ueNLbOEEZYnxuIbxuImD9nOApTYtSrjT g0DT69R5DKVFsgXpoB1j68AZ+qDkQ4zjT3a7+9FpSU42dCJBocQnC5QbY02NLPll/A JxLzwmMiOLQXujLTJ9pVuJHj/yhZKgI5VEPvm82c= 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.4 26/71] inetpeer: Fix data-races around sysctl. Date: Tue, 19 Jul 2022 13:53:49 +0200 Message-Id: <20220719114554.791944112@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114552.477018590@linuxfoundation.org> References: <20220719114552.477018590@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