Commit 8a3cf98c authored by Ben Hutchings's avatar Ben Hutchings Committed by Todd Kjos
Browse files

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 7f582b24 ("tcp:
purge write queue in tcp_connect_init()") and does not exist upstream
because of earlier changes in commit 75c119af ("tcp: implement
rb-tree based retransmit queue").  The latter is a major change that's
not suitable for stable.

Reported-by: default avatarDenis Andzakovic <denis.andzakovic@pulsesecurity.co.nz>
Bisected-by: default avatarSalvatore Bonaccorso <carnil@debian.org>
Fixes: 7f582b24 ("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: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 143009752
(cherry picked from commit e99e7745)
Signed-off-by: default avatarMatthias Maennich <maennich@google.com>

Change-Id: Ie325f18e7fe1c327a45e149034b90d2e74922263
parent 14c1a0fc
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment