hc
2023-11-23 7d07b3ae8ddad407913c5301877e694430a3263f
kernel/net/ipv4/icmp.c
....@@ -77,6 +77,7 @@
7777 #include <linux/string.h>
7878 #include <linux/netfilter_ipv4.h>
7979 #include <linux/slab.h>
80
+#include <linux/locallock.h>
8081 #include <net/snmp.h>
8182 #include <net/ip.h>
8283 #include <net/route.h>
....@@ -204,6 +205,8 @@
204205 *
205206 * On SMP we have one ICMP socket per-cpu.
206207 */
208
+static DEFINE_LOCAL_IRQ_LOCK(icmp_sk_lock);
209
+
207210 static struct sock *icmp_sk(struct net *net)
208211 {
209212 return *this_cpu_ptr(net->ipv4.icmp_sk);
....@@ -214,12 +217,16 @@
214217 {
215218 struct sock *sk;
216219
220
+ if (!local_trylock(icmp_sk_lock))
221
+ return NULL;
222
+
217223 sk = icmp_sk(net);
218224
219225 if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
220226 /* This can happen if the output path signals a
221227 * dst_link_failure() for an outgoing ICMP packet.
222228 */
229
+ local_unlock(icmp_sk_lock);
223230 return NULL;
224231 }
225232 return sk;
....@@ -228,6 +235,7 @@
228235 static inline void icmp_xmit_unlock(struct sock *sk)
229236 {
230237 spin_unlock(&sk->sk_lock.slock);
238
+ local_unlock(icmp_sk_lock);
231239 }
232240
233241 int sysctl_icmp_msgs_per_sec __read_mostly = 1000;