]> git.hungrycats.org Git - linux/commit
tcp: Clear sk_send_head after purging the write queue
authorBen Hutchings <ben@decadent.org.uk>
Sat, 3 Aug 2019 16:11:42 +0000 (17:11 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 20 Aug 2019 18:01:55 +0000 (19:01 +0100)
commit3157fbc900bdb366b2186e5a6e506cc5e4697cf0
treeb328c48d2b042daab514bcfd32df38f715b9ebf2
parent01de23e3018bc24808c658a8399f3896a7f9fbaf
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.

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>
include/net/tcp.h