Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 868d8dae authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Subash Abhinov Kasiviswanathan
Browse files

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.

[Backport of net-next 2010b93e9317cc12acd20c4aed385af7f9d1681e]

CRs-fixed: 1009682
Change-Id: I2066a77a6b8358c15bb3d61e9bfb448622bfedb9
Reported-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Git-commit: 476c6cef
Git-repo: https://android.googlesource.com/kernel/common/


Signed-off-by: default avatarJerome Stanislaus <jeromes@codeaurora.org>
parent 19fdb2db
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3067,6 +3067,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);