Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451182imw; Tue, 19 Jul 2022 06:54:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ugMc8G1JxkhbgbhEq51C41C5t5BpZ9yqCxeh+UIeBIUEd8PiW4g373IIx3Q6n5sBXotfuS X-Received: by 2002:a17:907:2c48:b0:72b:57c2:843c with SMTP id hf8-20020a1709072c4800b0072b57c2843cmr30803882ejc.72.1658238890453; Tue, 19 Jul 2022 06:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238890; cv=none; d=google.com; s=arc-20160816; b=Gqb8Y1uHBPr3RMw7PBkto2GrqVS0vIPp1sdUCG1BmE60ACxJXQTPeSNdFRmpTX9lpZ KStAJ+B8c5RB94uNMlQDs5mBI7fNq/22qN4xkPe2I6/hYQ3XrTF2S2wNI85/m6zf9JjK 9m3boLzVic4WQst4pxg1+KgrnAlERGXsgFLc4ZdW9gI67wEh9agQPQxXxmjC7j2eMgrK vPvrYd8hojzdAIlA2hJy1zrPJQ7iOHqZXxo5I5DDJlrjArcW/7T8Y+DdXCQcgDw529tv vBlTHNvBC4Cb3lio+X5h29ywyKeQHIU0pjbDWWZO+950XT0S9laBo/W0VQYWol/2tFcH iERg== 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=JGMbZ+CnS8ApP2sbSbPx1sM+6+o63Ut3/sAMOldfKFM=; b=gSnO8s0omab/zSwdS91lkgw3lRXYoKXy7w8lfL/Q+3E3dXrVlvDHQrPjcWBbZ4GpiB 3vQ3kCSSOUxqK28K96EcgvNfNOInMs/1wflTuuyW/MvzeMuH65HO5D4AzwyUhcTRAe4Y zzJyq/9a1w0+WvBoXpBx0Ro9IUBsSMM+VKTzH71rLJHSByekGiVnkhsLgr1qYNhSNjNj 10a5pLkbWeLZkvC9BAZcBFL0MiV4oNTwpQQ1MrZ1qThZNFHo2o6/J1UC1bZeFE6xuZUG XKbbFyuf9QUDz8VIV0Uoso9lh4B+V8lm6a84McdDHKU3EldjYLI1EQQ1T31BxR0ieTtP eHQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wRNkK1zp; 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 u18-20020aa7d892000000b0043a9ecde711si16899532edq.388.2022.07.19.06.54.26; Tue, 19 Jul 2022 06:54:50 -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=wRNkK1zp; 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 S238988AbiGSMN3 (ORCPT + 99 others); Tue, 19 Jul 2022 08:13:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238919AbiGSMMh (ORCPT ); Tue, 19 Jul 2022 08:12:37 -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 48F1952DF7; Tue, 19 Jul 2022 05:03:51 -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 4B2306171F; Tue, 19 Jul 2022 12:03:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F3EFC341C6; Tue, 19 Jul 2022 12:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232230; bh=uVoT/5u5HAXi7mBTKdcbZJAAIrh99J+aHCAY23AI2eA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wRNkK1zp0buizbjk/OiyfCU8uaWZhSSbcm+VIm3Kid8z5n75rxSiL9EwK4QNx54s6 etDAF8bwEuU1D4EyTcOpzmK40QNchwxnM/FQsBvekWiH+7VIfTlyNAFj0zv1LI5Nh9 KOaESD9eT/Vxh8+tgUjM4tKeN/LOvUOQLncjeG1U= 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 29/71] icmp: Fix data-races around sysctl. Date: Tue, 19 Jul 2022 13:53:52 +0200 Message-Id: <20220719114555.163037962@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 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 f86f948a4b4c..a590ff81e5f8 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