Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451843imw; Tue, 19 Jul 2022 06:55:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uY2gnmTPuCmu2VsX0MdYIoqc4MIPBGnLjrHxxHds95Vc90t8+TmraEU3/bjfbV2G8RDzHi X-Received: by 2002:a17:907:16ab:b0:72c:7533:7262 with SMTP id hc43-20020a17090716ab00b0072c75337262mr28888499ejc.288.1658238934033; Tue, 19 Jul 2022 06:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238934; cv=none; d=google.com; s=arc-20160816; b=I0+NifuiV7FCEheECfB7pxigLJasAu7JQbwh2bumBil88K1Xua7YImC9L4O+jAYPQD I5h+mjEO5EZC/Ed9e0CKoCLrRk8EiciCIEhddOyA4QNL6kJsuS2iJF0MRA4aO1R/sZPK NaLA5m3Kxoxadh6N9UbOpuEvh+o0ON62HFvq8NSQXwvDmqEPH6jfEr7hiM9gg8Xuy34k 1Y/S00yHsnqcd5cFWR2yUI/95pRxEJXQEZs4uaF09URXRGqffiwnResEMfBZX3W7HPEP Y2NQ2SIdH4U4AntftluK+u5J7cfAzCG6Y1upUbJ0JgHOGtLvg4XIxM0IgHC+V68IoLWz vigw== 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=w0WPaZ3vrH/WTT8TzZQVJejO8WEjJlCOXFMS/8XY/p8=; b=hciTkRhM7J0m0KaFN/1cH+76/iwj1ijvWO2l0v8J47TU92/Q0xBn1ge8i8EPW9oxDB TieqZ3lDnqIUoIPSoICoDpDNsWexRxjseBw/XfwH1Gaob+oNgdeoHGFQJEF/Z2eh2vV5 CG6bJByXcBTdLoJSsscZV5oX+jzt/CzJeWVnCC9YMOTUv1jeFyNzIrsbmP3gedujHfi9 wrylvaG6sKleWgkN0fsnaCqnwNbf63scJPGvI5OSiDEVGjNjIj953jdUd2dz2FMM+OV/ LwWMV/4xtXZfrAXgiRyBxmo352fXXCbFD7pMrVRNGD9udG4QOo6/jOA8jRFBYcTpXW1j DrWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fqGe4uOx; 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 y7-20020a056402440700b0043a6defcbafsi20321643eda.219.2022.07.19.06.55.09; Tue, 19 Jul 2022 06:55:34 -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=fqGe4uOx; 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 S237817AbiGSME4 (ORCPT + 99 others); Tue, 19 Jul 2022 08:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237536AbiGSMDV (ORCPT ); Tue, 19 Jul 2022 08:03:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 737B447B9C; Tue, 19 Jul 2022 04:59:34 -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 8EF6061654; Tue, 19 Jul 2022 11:59:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69FF6C341C6; Tue, 19 Jul 2022 11:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231972; bh=GnkSSBq8bI997RF20QEVq5hZwp4DjkpQFBZk8XgRBHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqGe4uOxTKa+11MrizHbCxjsovxtrl4Q8l4HdkH3R9CCcD9LflGF3ANywRPb2Ex6t Fw4pRrSCxjD3AR5d+LhkWrA4UX+sg3Gxx4ExWa78NU3gKVVUzZz4uXX1w49drNlhQ5 JZ1Cx6ADhTFXVQ1GAu9EkiPYhAi1iGxRDx8WMilk= 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 4.19 17/48] icmp: Fix data-races around sysctl. Date: Tue, 19 Jul 2022 13:53:54 +0200 Message-Id: <20220719114521.333068238@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114518.915546280@linuxfoundation.org> References: <20220719114518.915546280@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 fe10a565b7d8..953cc70851cf 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -266,11 +266,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