1 From c4315faf41f4c1f8da0b5cc375a67e9de700dbf1 Mon Sep 17 00:00:00 2001
2 From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
3 Date: Wed, 31 Aug 2016 17:54:09 +0200
4 Subject: [PATCH 357/366] net: add a lock around icmp_sk()
6 It looks like the this_cpu_ptr() access in icmp_sk() is protected with
7 local_bh_disable(). To avoid missing serialization in -RT I am adding
8 here a local lock. No crash has been observed, this is just precaution.
10 Cc: stable-rt@vger.kernel.org
11 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
12 Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
14 net/ipv4/icmp.c | 8 ++++++++
15 1 file changed, 8 insertions(+)
17 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
18 index 288d20f..a6f6c9b 100644
22 #include <linux/string.h>
23 #include <linux/netfilter_ipv4.h>
24 #include <linux/slab.h>
25 +#include <linux/locallock.h>
28 #include <net/route.h>
29 @@ -205,6 +206,8 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES+1];
31 * On SMP we have one ICMP socket per-cpu.
33 +static DEFINE_LOCAL_IRQ_LOCK(icmp_sk_lock);
35 static struct sock *icmp_sk(struct net *net)
37 return *this_cpu_ptr(net->ipv4.icmp_sk);
38 @@ -216,12 +219,14 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
42 + local_lock(icmp_sk_lock);
45 if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
46 /* This can happen if the output path signals a
47 * dst_link_failure() for an outgoing ICMP packet.
49 + local_unlock(icmp_sk_lock);
53 @@ -231,6 +236,7 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
54 static inline void icmp_xmit_unlock(struct sock *sk)
56 spin_unlock_bh(&sk->sk_lock.slock);
57 + local_unlock(icmp_sk_lock);
60 int sysctl_icmp_msgs_per_sec __read_mostly = 1000;
61 @@ -359,6 +365,7 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
65 + local_lock(icmp_sk_lock);
66 sk = icmp_sk(dev_net((*rt)->dst.dev));
67 if (ip_append_data(sk, fl4, icmp_glue_bits, icmp_param,
68 icmp_param->data_len+icmp_param->head_len,
69 @@ -381,6 +388,7 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
70 skb->ip_summed = CHECKSUM_NONE;
71 ip_push_pending_frames(sk, fl4);
73 + local_unlock(icmp_sk_lock);