blob: e70255f6030d006b382d4cea46bb7da6d39fd451 [file] [log] [blame]
From 74a78cb9f0ff8fd0ef0dc84d7ce401f3b32b8457 Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Thu, 21 Sep 2017 14:42:04 +0200
Subject: [PATCH] net: use trylock in icmp_sk
The locking path can be recursive (same as for sk->sk_lock.slock) and
therefore we need a trylock version for the locallock, too.
Cc: rt-stable@vger.kernel.org
Reported-by: Jacek Konieczny <jajcus@jajcus.net>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index bfa889e804f1..fe3332b850b6 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -217,12 +217,16 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
{
struct sock *sk;
+ if (!local_trylock(icmp_sk_lock))
+ return NULL;
+
sk = icmp_sk(net);
if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
/* This can happen if the output path signals a
* dst_link_failure() for an outgoing ICMP packet.
*/
+ local_unlock(icmp_sk_lock);
return NULL;
}
return sk;
@@ -231,6 +235,7 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
static inline void icmp_xmit_unlock(struct sock *sk)
{
spin_unlock(&sk->sk_lock.slock);
+ local_unlock(icmp_sk_lock);
}
int sysctl_icmp_msgs_per_sec __read_mostly = 1000;
@@ -420,7 +425,6 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
/* Needed by both icmp_global_allow and icmp_xmit_lock */
local_bh_disable();
- local_lock(icmp_sk_lock);
/* global icmp_msgs_per_sec */
if (!icmpv4_global_allow(net, type, code))
@@ -465,7 +469,6 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
out_unlock:
icmp_xmit_unlock(sk);
out_bh_enable:
- local_unlock(icmp_sk_lock);
local_bh_enable();
}
@@ -661,7 +664,6 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
/* Needed by both icmp_global_allow and icmp_xmit_lock */
local_bh_disable();
- local_lock(icmp_sk_lock);
/* Check global sysctl_icmp_msgs_per_sec ratelimit, unless
* incoming dev is loopback. If outgoing dev change to not be
@@ -750,7 +752,6 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
out_unlock:
icmp_xmit_unlock(sk);
out_bh_enable:
- local_unlock(icmp_sk_lock);
local_bh_enable();
out:;
}
--
2.1.4