]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - rt-patches/0357-net-add-a-lock-around-icmp_sk.patch
rt_patches: required rebase due to printk change
[hercules2020/nv-tegra/linux-4.4.git] / rt-patches / 0357-net-add-a-lock-around-icmp_sk.patch
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()
5
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.
9
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>
13 ---
14  net/ipv4/icmp.c | 8 ++++++++
15  1 file changed, 8 insertions(+)
16
17 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
18 index 288d20f..a6f6c9b 100644
19 --- a/net/ipv4/icmp.c
20 +++ b/net/ipv4/icmp.c
21 @@ -78,6 +78,7 @@
22  #include <linux/string.h>
23  #include <linux/netfilter_ipv4.h>
24  #include <linux/slab.h>
25 +#include <linux/locallock.h>
26  #include <net/snmp.h>
27  #include <net/ip.h>
28  #include <net/route.h>
29 @@ -205,6 +206,8 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES+1];
30   *
31   *     On SMP we have one ICMP socket per-cpu.
32   */
33 +static DEFINE_LOCAL_IRQ_LOCK(icmp_sk_lock);
34 +
35  static struct sock *icmp_sk(struct net *net)
36  {
37         return *this_cpu_ptr(net->ipv4.icmp_sk);
38 @@ -216,12 +219,14 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
39  
40         local_bh_disable();
41  
42 +       local_lock(icmp_sk_lock);
43         sk = icmp_sk(net);
44  
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.
48                  */
49 +               local_unlock(icmp_sk_lock);
50                 local_bh_enable();
51                 return NULL;
52         }
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)
55  {
56         spin_unlock_bh(&sk->sk_lock.slock);
57 +       local_unlock(icmp_sk_lock);
58  }
59  
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,
62         struct sock *sk;
63         struct sk_buff *skb;
64  
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);
72         }
73 +       local_unlock(icmp_sk_lock);
74  }
75  
76  /*
77 -- 
78 1.9.1
79