Skip to contentSkip to conversation

ipv6: tcp: fix potential NULL deref in tcp_v6_send_reset()

PATCH Applied Eric Dumazet 2 participants 2 messages Jun 7, 2019 – Jun 10, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: tcp: fix potential NULL deref in tcp_v6_send_reset()

syzbot found a crash in tcp_v6_send_reset() caused by my latest change.

Problem is that if an skb has been queued to socket prequeue, skb_dst(skb)->dev can not anymore point to the device.

Fortunately in this case the socket pointer is not NULL.

A similar issue has been fixed in commit 0f85feae6b71 ("tcp: fix more NULL deref after prequeue changes"), I should have known better.

Fixes 323a53c41292 ("ipv6: tcp: enable flowlabel reflection in some RST packets")
---
 net/ipv6/tcp_ipv6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +1 -1
index d8d18386c99a82e112dd3a1aeee01e4c328ba5d7..c1da52c7f990f2fa3e020e3f3a33934149ad225e 100644
@@ -934,7 +934,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
 	if (!sk && !ipv6_unicast_destination(skb))
 		return;
 
-	net = dev_net(skb_dst(skb)->dev);
+	net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev);
 #ifdef CONFIG_TCP_MD5SIG
 	rcu_read_lock();
 	hash_location = tcp_parse_md5sig_option(th);
Signature · 1 line
2.22.0.rc2.383.gf4fbbf30c2-goog
maintainer Applied
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Fri, 7 Jun 2019 12:23:48 -0700

Quoted 6 lines

syzbot found a crash in tcp_v6_send_reset() caused by my latest change.

Problem is that if an skb has been queued to socket prequeue, skb_dst(skb)->dev can not anymore point to the device.

Quoted 8 lines

Fortunately in this case the socket pointer is not NULL.

A similar issue has been fixed in commit 0f85feae6b71 ("tcp: fix more NULL deref after prequeue changes"), I should have known better.

Fixes 323a53c41292 ("ipv6: tcp: enable flowlabel reflection in some RST packets")

Applied.