summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2019-08-13 12:53:17 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-08-16 10:13:47 +0200
commite99e7745d03fc50ba7c5b7c91c17294fee2d5991 (patch)
tree5af1c9ee0fc7095488e2872a92a2ef727448bd59 /include
parentcd31e7c5d5c4b6dae2ee3628129077fab5d39834 (diff)
downloadlinux-stable-e99e7745d03fc50ba7c5b7c91c17294fee2d5991.tar.gz
linux-stable-e99e7745d03fc50ba7c5b7c91c17294fee2d5991.tar.bz2
linux-stable-e99e7745d03fc50ba7c5b7c91c17294fee2d5991.zip
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/tcp.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 7994e569644e..9de2c8cdcc51 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1613,6 +1613,8 @@ static inline void tcp_init_send_head(struct sock *sk)
sk->sk_send_head = NULL;
}
+static inline void tcp_init_send_head(struct sock *sk);
+
/* write queue abstraction */
static inline void tcp_write_queue_purge(struct sock *sk)
{
@@ -1621,6 +1623,7 @@ static inline void tcp_write_queue_purge(struct sock *sk)
tcp_chrono_stop(sk, TCP_CHRONO_BUSY);
while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL)
sk_wmem_free_skb(sk, skb);
+ tcp_init_send_head(sk);
sk_mem_reclaim(sk);
tcp_clear_all_retrans_hints(tcp_sk(sk));
tcp_init_send_head(sk);