a06df9a
From: Eric Dumazet <edumazet@google.com>
a06df9a
Date: 2016-08-17 12:56:26
a06df9a
Subject: [PATCH net] tcp: fix use after free in tcp_xmit_retransmit_queue()
a06df9a
a06df9a
When tcp_sendmsg() allocates a fresh and empty skb, it puts it at the
a06df9a
tail of the write queue using tcp_add_write_queue_tail()
a06df9a
a06df9a
Then it attempts to copy user data into this fresh skb.
a06df9a
a06df9a
If the copy fails, we undo the work and remove the fresh skb.
a06df9a
a06df9a
Unfortunately, this undo lacks the change done to tp->highest_sack and
a06df9a
we can leave a dangling pointer (to a freed skb)
a06df9a
a06df9a
Later, tcp_xmit_retransmit_queue() can dereference this pointer and
a06df9a
access freed memory. For regular kernels where memory is not unmapped,
a06df9a
this might cause SACK bugs because tcp_highest_sack_seq() is buggy,
a06df9a
returning garbage instead of tp->snd_nxt, but with various debug
a06df9a
features like CONFIG_DEBUG_PAGEALLOC, this can crash the kernel.
a06df9a
a06df9a
This bug was found by Marco Grassi thanks to syzkaller.
a06df9a
a06df9a
Fixes: 6859d49475d4 ("[TCP]: Abstract tp->highest_sack accessing & point to next skb")
a06df9a
Reported-by: Marco Grassi <marco.gra@gmail.com>
a06df9a
Signed-off-by: Eric Dumazet <edumazet@google.com>
a06df9a
Cc: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
a06df9a
Cc: Yuchung Cheng <ycheng@google.com>
a06df9a
Cc: Neal Cardwell <ncardwell@google.com>
a06df9a
---
a06df9a
 include/net/tcp.h |    2 ++
a06df9a
 1 file changed, 2 insertions(+)
a06df9a
a06df9a
diff --git a/include/net/tcp.h b/include/net/tcp.h
a06df9a
index c00e7d51bb18..7717302cab91 100644
a06df9a
--- a/include/net/tcp.h
a06df9a
+++ b/include/net/tcp.h
a06df9a
@@ -1523,6 +1523,8 @@ static inline void tcp_check_send_head(struct sock *sk, struct sk_buff *skb_unli
a06df9a
 {
a06df9a
 	if (sk->sk_send_head == skb_unlinked)
a06df9a
 		sk->sk_send_head = NULL;
a06df9a
+	if (tcp_sk(sk)->highest_sack == skb_unlinked)
a06df9a
+		tcp_sk(sk)->highest_sack = NULL;
a06df9a
 }
a06df9a
 
a06df9a
 static inline void tcp_init_send_head(struct sock *sk)
a06df9a