[RAMEN9610-21380]tcp: Clear sk_send_head after purGing the write queue
authorBen Hutchings <ben@decadent.org.uk>
Tue, 13 Aug 2019 11:53:17 +0000 (12:53 +0100)
committerlingsen1 <lingsen1@lenovo.com>
Wed, 19 Feb 2020 01:39:09 +0000 (09:39 +0800)
commit1eb83a56e2dace5465b6da7f4d4b620359fb30dd
tree06a4c1c7641733796ce8d624fe9ef1516f22b483
parent8baf465f2446f636c55d6815f277563ad30d40f1
[RAMEN9610-21380]tcp: Clear sk_send_head after purGing the write queue

Denis Andzakovic discovered a potential use-after-free in older kernel
versions, using syzkaller.  tcp_write_queue_purge() frees all skbs in
the TCP write queue and can leave sk->sk_send_head pointing to freed
memory.  tcp_disconnect() clears that pointer after calling
tcp_write_queue_purge(), but tcp_connect() does not.  It is
(surprisingly) possible to add to the write queue between
disconnection and reconnection, so this needs to be done in both
places.

This bug was introduced by backports of commit 7f582b248d0a ("tcp:
purge write queue in tcp_connect_init()") and does not exist upstream
because of earlier changes in commit 75c119afe14f ("tcp: implement
rb-tree based retransmit queue").  The latter is a major change that's
not suitable for stable.

Change-Id: I993e67fce84bf59ef86bb432229802b3e1d8821c
Reported-by: Denis Andzakovic <denis.andzakovic@pulsesecurity.co.nz>
Bisected-by: Salvatore Bonaccorso <carnil@debian.org>
Fixes: 7f582b248d0a ("tcp: purge write queue in tcp_connect_init()")
Cc: <stable@vger.kernel.org> # before 4.15
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/net/tcp.h