* [PATCH] net: diag: Fix refcnt leak in error path destroying socket
@ 2016-08-24 4:05 David Ahern
2016-08-24 6:12 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: David Ahern @ 2016-08-24 4:05 UTC (permalink / raw)
To: netdev, lorenzo; +Cc: eric.dumazet, David Ahern
inet_diag_find_one_icsk takes a reference to a socket that is not
released if sock_diag_destroy returns an error. Fix by changing
tcp_diag_destroy to manage the refcnt for all cases and remove
the sock_put calls from tcp_abort.
Fixes: c1e64e298b8ca ("net: diag: Support destroying TCP sockets")
Reported-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
net/ipv4/tcp.c | 2 --
net/ipv4/tcp_diag.c | 7 ++++++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index f1a9a0a8a1f3..54c5d0a8f6e9 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3176,7 +3176,6 @@ int tcp_abort(struct sock *sk, int err)
local_bh_enable();
return 0;
}
- sock_gen_put(sk);
return -EOPNOTSUPP;
}
@@ -3205,7 +3204,6 @@ int tcp_abort(struct sock *sk, int err)
bh_unlock_sock(sk);
local_bh_enable();
release_sock(sk);
- sock_put(sk);
return 0;
}
EXPORT_SYMBOL_GPL(tcp_abort);
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index 4d610934fb39..a748c74aa8b7 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -54,11 +54,16 @@ static int tcp_diag_destroy(struct sk_buff *in_skb,
{
struct net *net = sock_net(in_skb->sk);
struct sock *sk = inet_diag_find_one_icsk(net, &tcp_hashinfo, req);
+ int err;
if (IS_ERR(sk))
return PTR_ERR(sk);
- return sock_diag_destroy(sk, ECONNABORTED);
+ err = sock_diag_destroy(sk, ECONNABORTED);
+
+ sock_gen_put(sk);
+
+ return err;
}
#endif
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: diag: Fix refcnt leak in error path destroying socket
2016-08-24 4:05 [PATCH] net: diag: Fix refcnt leak in error path destroying socket David Ahern
@ 2016-08-24 6:12 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-08-24 6:12 UTC (permalink / raw)
To: dsa; +Cc: netdev, lorenzo, eric.dumazet
From: David Ahern <dsa@cumulusnetworks.com>
Date: Tue, 23 Aug 2016 21:05:27 -0700
> inet_diag_find_one_icsk takes a reference to a socket that is not
> released if sock_diag_destroy returns an error. Fix by changing
> tcp_diag_destroy to manage the refcnt for all cases and remove
> the sock_put calls from tcp_abort.
>
> Fixes: c1e64e298b8ca ("net: diag: Support destroying TCP sockets")
> Reported-by: Lorenzo Colitti <lorenzo@google.com>
> Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Applied and queued up for -stable.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-24 6:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-24 4:05 [PATCH] net: diag: Fix refcnt leak in error path destroying socket David Ahern
2016-08-24 6:12 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox