summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKuniyuki Iwashima <kuniyu@amazon.com>2022-07-06 16:40:02 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-07-21 20:40:31 +0200
commit1740e5922fbb705637ae9fa5203db132fc45f9f6 (patch)
tree72b3f6231d259b8c76130d5d6090d3bcb6c8012c
parent2764f82bbc158d106693ae3ced3675cf4b963b35 (diff)
downloadlinux-1740e5922fbb705637ae9fa5203db132fc45f9f6.tar.gz
linux-1740e5922fbb705637ae9fa5203db132fc45f9f6.tar.bz2
linux-1740e5922fbb705637ae9fa5203db132fc45f9f6.zip
icmp: Fix data-races around sysctl.
[ 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 <kuniyu@amazon.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--net/ipv4/icmp.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index e27ebd00bff2..ada92153b0db 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -268,11 +268,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.