All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [PATCH net] net: Do not hold the reference for the same sk_rx_dst.
@ 2017-03-16  8:08 Kevin Xu
  2017-03-16 10:01 ` Jakub Sitnicki
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Kevin Xu @ 2017-03-16  8:08 UTC (permalink / raw)
  To: davem; +Cc: netdev, Kevin Xu

In some rare cases, inet_sk_rx_dst_set() may be called multiple times
on the same dst, causing reference count leakage. Eventually, it
prevents net_device to be destroyed. The bug then manifested as

unregister_netdevice: waiting for lo to become free. Usage count = 1

in the kernel log, preventing new network namespace creation.

The patch works around the issue by checking whether the socket already
has the same dst set.

Signed-off-by: Kevin Xu <kaiwen.xu@hulu.com>
---
 net/ipv4/tcp_ipv4.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 575e19d..f425c14 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1807,9 +1807,14 @@ void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
 {
 	struct dst_entry *dst = skb_dst(skb);
 
-	if (dst && dst_hold_safe(dst)) {
-		sk->sk_rx_dst = dst;
-		inet_sk(sk)->rx_dst_ifindex = skb->skb_iif;
+	if (dst) {
+		if (unlikely(dst == sk->sk_rx_dst))
+			return;
+
+		if (dst_hold_safe(dst)) {
+			sk->sk_rx_dst = dst;
+			inet_sk(sk)->rx_dst_ifindex = skb->skb_iif;
+		}
 	}
 }
 EXPORT_SYMBOL(inet_sk_rx_dst_set);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-03-20 21:58 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16  8:08 [PATCH] [PATCH net] net: Do not hold the reference for the same sk_rx_dst Kevin Xu
2017-03-16 10:01 ` Jakub Sitnicki
2017-03-16 10:12   ` Kevin Xu
2017-03-16 10:45     ` Jakub Sitnicki
2017-03-16 18:18       ` Kaiwen Xu
2017-03-16 18:42         ` Cong Wang
2017-03-16 18:16 ` David Miller
2017-03-19  1:48   ` [PATCH net v2] " Kevin Xu
2017-03-19  3:49     ` Cong Wang
2017-03-19  4:03       ` Kaiwen Xu
2017-03-20  4:09         ` Cong Wang
2017-03-20 21:23           ` Kaiwen Xu
2017-03-16 21:33 ` [PATCH] [PATCH net] " Eric Dumazet
2017-03-16 23:13   ` Cong Wang
2017-03-16 23:29     ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.