netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: tcp: deal with listen sockets properly in tcp_abort.
@ 2015-12-21 15:03 Lorenzo Colitti
  2015-12-21 16:20 ` Eric Dumazet
  2015-12-22 21:02 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Lorenzo Colitti @ 2015-12-21 15:03 UTC (permalink / raw)
  To: netdev; +Cc: davem, eric.dumazet, tom, Lorenzo Colitti

When closing a listen socket, tcp_abort currently calls
tcp_done without clearing the request queue. If the socket has a
child socket that is established but not yet accepted, the child
socket is then left without a parent, causing a leak.

Fix this by setting the socket state to TCP_CLOSE and calling
inet_csk_listen_stop with the socket lock held, like tcp_close
does.

Tested using net_test. With this patch, calling SOCK_DESTROY on a
listen socket that has an established but not yet accepted child
socket results in the parent and the child being closed, such
that they no longer appear in sock_diag dumps.

Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
---
 net/ipv4/tcp.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index cc7aaa5..7bb1b09 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3099,6 +3099,11 @@ int tcp_abort(struct sock *sk, int err)
 	/* Don't race with userspace socket closes such as tcp_close. */
 	lock_sock(sk);
 
+	if (sk->sk_state == TCP_LISTEN) {
+		tcp_set_state(sk, TCP_CLOSE);
+		inet_csk_listen_stop(sk);
+	}
+
 	/* Don't race with BH socket closes such as inet_csk_listen_stop. */
 	local_bh_disable();
 	bh_lock_sock(sk);
-- 
2.6.0.rc2.230.g3dd15c0

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

* Re: [PATCH] net: tcp: deal with listen sockets properly in tcp_abort.
  2015-12-21 15:03 [PATCH] net: tcp: deal with listen sockets properly in tcp_abort Lorenzo Colitti
@ 2015-12-21 16:20 ` Eric Dumazet
  2015-12-22 21:02 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2015-12-21 16:20 UTC (permalink / raw)
  To: Lorenzo Colitti; +Cc: netdev, davem, tom

On Tue, 2015-12-22 at 00:03 +0900, Lorenzo Colitti wrote:
> When closing a listen socket, tcp_abort currently calls
> tcp_done without clearing the request queue. If the socket has a
> child socket that is established but not yet accepted, the child
> socket is then left without a parent, causing a leak.
> 
> Fix this by setting the socket state to TCP_CLOSE and calling
> inet_csk_listen_stop with the socket lock held, like tcp_close
> does.
> 
> Tested using net_test. With this patch, calling SOCK_DESTROY on a
> listen socket that has an established but not yet accepted child
> socket results in the parent and the child being closed, such
> that they no longer appear in sock_diag dumps.
> 
> Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
> Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
> ---

Acked-by: Eric Dumazet <edumazet@google.com>

Thanks !

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

* Re: [PATCH] net: tcp: deal with listen sockets properly in tcp_abort.
  2015-12-21 15:03 [PATCH] net: tcp: deal with listen sockets properly in tcp_abort Lorenzo Colitti
  2015-12-21 16:20 ` Eric Dumazet
@ 2015-12-22 21:02 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-12-22 21:02 UTC (permalink / raw)
  To: lorenzo; +Cc: netdev, eric.dumazet, tom

From: Lorenzo Colitti <lorenzo@google.com>
Date: Tue, 22 Dec 2015 00:03:44 +0900

> When closing a listen socket, tcp_abort currently calls
> tcp_done without clearing the request queue. If the socket has a
> child socket that is established but not yet accepted, the child
> socket is then left without a parent, causing a leak.
> 
> Fix this by setting the socket state to TCP_CLOSE and calling
> inet_csk_listen_stop with the socket lock held, like tcp_close
> does.
> 
> Tested using net_test. With this patch, calling SOCK_DESTROY on a
> listen socket that has an established but not yet accepted child
> socket results in the parent and the child being closed, such
> that they no longer appear in sock_diag dumps.
> 
> Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
> Signed-off-by: Lorenzo Colitti <lorenzo@google.com>

Applied to net-next, which I assume is the intended target tree for
this patch.

Please make that explicit, always, in future submissions.

Thanks.

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

end of thread, other threads:[~2015-12-22 21:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-21 15:03 [PATCH] net: tcp: deal with listen sockets properly in tcp_abort Lorenzo Colitti
2015-12-21 16:20 ` Eric Dumazet
2015-12-22 21:02 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).