tcp: drop skb dst in tcp_rcv_established()
Subsystems (3)
PATCH 1/1 tcp: drop skb dst in tcp_rcv_established()
From: Eric Dumazet <[email protected]>
In commit f84af32cbca7 ("net: ip_queue_rcv_skb() helper") I dropped the skb dst in tcp_data_queue().
This only dealt with so-called TCP input slow path.
When fast path is taken, tcp_rcv_established() calls tcp_queue_rcv() while skb still has a dst.
This was mostly fine, because most dsts at this point are not refcounted (thanks to early demux)
However, TCP packets sent over loopback have refcounted dst.
Then commit 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists") came and had the effect of delaying skb freeing for an arbitrary time.
If during this time the involved netns is dismantled, cleanup_net() frees the struct net with embedded net->ipv6.ip6_dst_ops.
Then when eventually dst_destroy_rcu() is called, if (dst->ops->destroy) ... triggers an use-after-free.
It is not clear if ip6_route_net_exit() lacks a rcu_barrier() as syzbot reported similar issues before the blamed commit.
( https://groups.google.com/g/syzkaller-bugs/c/CofzW4eeA9A/m/009WjumTAAAJ )
--- net/ipv4/tcp_input.c | 1 + 1 file changed, 1 insertion(+)
net/ipv4/tcp_input.c +1 -0
@@ -5928,6 +5928,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPHPHITS );/* Bulk data transfer: receiver */ +skb_dst_drop (skb);__skb_pull (skb, tcp_header_len); eaten =tcp_queue_rcv (sk, skb, &fragstolen);
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
Quoted 42 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
In commit
f84af32cbca7("net:ip_queue_rcv_skb()helper") I dropped the skb dst intcp_data_queue().This only dealt with so-called TCP input slow path.
When fast path is taken,
tcp_rcv_established()callstcp_queue_rcv()while skb still has a dst.This was mostly fine, because most dsts at this point are not refcounted (thanks to early demux)
However, TCP packets sent over loopback have refcounted dst.
Then commit
68822bdf76f1("net: generalize skb freeing deferral to per-cpu lists") came and had the effect of delaying skb freeing for an arbitrary time.If during this time the involved netns is dismantled,
cleanup_net()frees the struct net with embeddednet->ipv6.ip6_dst_ops.Then when eventually
dst_destroy_rcu()is called, if (dst->ops->destroy) ... triggers an use-after-free.It is not clear if
ip6_route_net_exit()lacks arcu_barrier()as syzbot reported similar issues before the blamed commit.( https://groups.google.com/g/syzkaller-bugs/c/CofzW4eeA9A/m/009WjumTAAAJ )
Fixes 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists")Signed-off-by Eric Dumazet <[email protected]>--- net/ipv4/tcp_input.c | 1 + 1 file changed, 1 insertion(+)net/ipv4/tcp_input.c +0
-0
net/ipv4/tcp_input.c void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)
Quoted 8 lines
net/ipv4/tcp_input.c +1
-1@@ -5928,6 +5928,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPHPHITS );/* Bulk data transfer: receiver */ +skb_dst_drop (skb);__skb_pull (skb, tcp_header_len); eaten =tcp_queue_rcv (sk, skb, &fragstolen); --
Nice catch. Thanks, Eric!
neal
Soheil Hassas Yeganeh
Acked-byQuoted 51 lines · Neal Cardwell
Quoted 49 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
In commit
f84af32cbca7("net:ip_queue_rcv_skb()helper") I dropped the skb dst intcp_data_queue().This only dealt with so-called TCP input slow path.
When fast path is taken,
tcp_rcv_established()callstcp_queue_rcv()while skb still has a dst.This was mostly fine, because most dsts at this point are not refcounted (thanks to early demux)
However, TCP packets sent over loopback have refcounted dst.
Then commit
68822bdf76f1("net: generalize skb freeing deferral to per-cpu lists") came and had the effect of delaying skb freeing for an arbitrary time.If during this time the involved netns is dismantled,
cleanup_net()frees the struct net with embeddednet->ipv6.ip6_dst_ops.Then when eventually
dst_destroy_rcu()is called, if (dst->ops->destroy) ... triggers an use-after-free.It is not clear if
ip6_route_net_exit()lacks arcu_barrier()as syzbot reported similar issues before the blamed commit.( https://groups.google.com/g/syzkaller-bugs/c/CofzW4eeA9A/m/009WjumTAAAJ )
Fixes 68822bdf76f1 ("net: generalize skb freeing deferral to per-cpu lists")Signed-off-by Eric Dumazet <[email protected]>--- net/ipv4/tcp_input.c | 1 + 1 file changed, 1 insertion(+)net/ipv4/tcp_input.c +1
-0@@ -5928,6 +5928,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPHPHITS );/* Bulk data transfer: receiver */ +skb_dst_drop (skb);__skb_pull (skb, tcp_header_len); eaten =tcp_queue_rcv (sk, skb, &fragstolen);
Quoted 7 lines
Quoted 1 line
--
Nice catch. Thanks, Eric!
Acked-by Neal Cardwell <[email protected]>neal
Thank you for the fix!
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 8 lines · On Fri, 29 Apr 2022 18:15:23 -0700 you wrote:
From: Eric Dumazet <[email protected]>
In commit
f84af32cbca7("net:ip_queue_rcv_skb()helper") I dropped the skb dst intcp_data_queue().This only dealt with so-called TCP input slow path.
[...]
Here is the summary with links:
- [net-next] tcp: drop skb dst in tcp_rcv_established()
https://git.kernel.org/netdev/net-next/c/783d108dd71d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html