Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4370615imw; Tue, 19 Jul 2022 05:31:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfSzi6CGooCB1SI8QB/sCSZ9BIdODNX1EbcMoNFo++5omSPXExv+s3VQbZqQ00H/oB5E+w X-Received: by 2002:aa7:c2d7:0:b0:43a:78af:6e57 with SMTP id m23-20020aa7c2d7000000b0043a78af6e57mr43043982edp.163.1658233873807; Tue, 19 Jul 2022 05:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233873; cv=none; d=google.com; s=arc-20160816; b=uHWC80iSK7WR3EZN3RLnp8aJEGfWUB/F7SY28536ssUK0M7yMldRaU+cG/lEcIji/G mhV1EbxuUHbeJwdeZbjXBLk6s8vdAz6JegsL6S5Mb14FsokpwuH+PEvEDQrKxkmbPydr vvrBkmvAJB+TMJXXp8q/JdETEoszCcwRqiDl0+NjIiMaWlEHAW4KV7woi/XhXDajwdn8 DaT2LS7guuLpLHaaLOp1xtv7EUAAJU4A9OxtPyc/or5RI37BnW0AD52Yab7JuDuVLJ/W /B9ysAJRe3hGpZNCfPYbfQaoiv5YapLlTSXjt87+JeuA/mLzJUujMud5drDz+EJmLvmw VZyg== 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=ItzeEdmCdOHTm9gx2pXGS1HcPkqSfUJON/MkMon3Kho=; b=ZyBBb9QnXyHayvjf45NMhe1wBrtl4uhdo0rcCMpsSBPop3smBY04VAzQ3Rz1Nhpjd2 tMVoBI3QvM1DEVRaL6yTNAnPl7kJ+Us8i26YFwiUL9zLVUu5lJv7C2KGpmohUPUhuiH0 Jk/xAozYyXDOsf7OIMiHDDzIrz97AufDNw29qQhgTwlNJ6jkxM4wQn99oWTEcST0Xnhf UlhTQTsjgrawjJlezFOY7UiMevpaT24bgLjCW3c+Z+4+OJUNBeCzZKiH7YPA/1UzmM2Y MvAUsdYj4fnwHKtpAtKTuvIYLjwFZATe8ewMHA34pehBS8KhMyHYPrOa7WBiuYywgC+P kFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xlzHAmyv; 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 y13-20020a170906914d00b0072b4a91908esi15173422ejw.895.2022.07.19.05.30.46; Tue, 19 Jul 2022 05:31:13 -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=xlzHAmyv; 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 S239383AbiGSMVR (ORCPT + 99 others); Tue, 19 Jul 2022 08:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239681AbiGSMTl (ORCPT ); Tue, 19 Jul 2022 08:19:41 -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 1B81A5926F; Tue, 19 Jul 2022 05:07:08 -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 0D28961746; Tue, 19 Jul 2022 12:07:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3B36C341CB; Tue, 19 Jul 2022 12:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232426; bh=m7GY7Ogs4G+I6c2GSI1Bq4lwILtf//Jw8gGCR0w1jpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xlzHAmyv9ecaewmAF6F8f2ICMYm0WkmRCcaZ712X0kM8DFMZcl06/iLURRF0flt+j OlwuU7f04aJG4s8o9yzFez82SX7i4UGaX4ugKWaVAhDZGUxc8UX+Rw6mlCXxadf0/F Gqqlskc8ESc/9WVRw4PBynJkdB3iJ3qJXlKBcU1Q= 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 052/112] icmp: Fix data-races around sysctl. Date: Tue, 19 Jul 2022 13:53:45 +0200 Message-Id: <20220719114631.487387269@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 48d7ee321ea5182c6a70782aa186422a70e67e22 ] While reading icmp sysctl variables, they can be changed concurrently. So, we need to add READ_ONCE() to avoid data-races. Fixes: 4cdf507d5452 ("icmp: add a global rate limitation") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/icmp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index cd65d3146c30..f22c0d55f479 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -261,11 +261,12 @@ bool icmp_global_allow(void) spin_lock(&icmp_global.lock); delta = min_t(u32, now - icmp_global.stamp, HZ); if (delta >= HZ / 50) { - incr = sysctl_icmp_msgs_per_sec * delta / HZ ; + incr = READ_ONCE(sysctl_icmp_msgs_per_sec) * delta / HZ; if (incr) WRITE_ONCE(icmp_global.stamp, now); } - credit = min_t(u32, icmp_global.credit + incr, sysctl_icmp_msgs_burst); + credit = min_t(u32, icmp_global.credit + incr, + READ_ONCE(sysctl_icmp_msgs_burst)); if (credit) { /* We want to use a credit of one in average, but need to randomize * it for security reasons. -- 2.35.1