Skip to contentSkip to conversation

net: tcp: deal with listen sockets properly in tcp_abort.

PATCH Applied Lorenzo Colitti 3 participants 3 messages Dec 21, 2015 – Dec 22, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: tcp: deal with listen sockets properly in tcp_abort.

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.

---
 net/ipv4/tcp.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ipv4/tcp.c +5 -0
index cc7aaa5..7bb1b09 100644
@@ -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);
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · 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.

Quoted 8 lines

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.

---

Thanks !

maintainer Applied
#2 lore raw
In reply to Lorenzo Colitti

From: Lorenzo Colitti <[email protected]>
Date: Tue, 22 Dec 2015 00:03:44 +0900

Quoted 9 lines

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.

Quoted 7 lines

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.

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

Please make that explicit, always, in future submissions.

Thanks.