tcp: tcp_child_process() related UAF
Subsystems (3)
PATCH 1/1 tcp: tcp_child_process() related UAF
tcp_child_process( .. child ...) currently calls sock_put(child).
Unfortunately @child (named @nsk in callers) can be used after this point to send a RST packet.
To fix this UAF, I remove the sock_put() from tcp_child_process() and let the callers handle this after it is safe.
Remove @rsk variable in tcp_v4_do_rcv() and change tcp_v6_do_rcv() so that both functions look the same.
--- net/ipv4/tcp_ipv4.c | 14 ++++++-------- net/ipv4/tcp_minisocks.c | 2 +- net/ipv6/tcp_ipv6.c | 13 ++++++++----- 3 files changed, 15 insertions(+), 14 deletions(-)
net/ipv4/tcp_ipv4.c +6 -8
@@ -1827,7 +1827,6 @@ INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,int tcp_v4_do_rcv (struct sock *sk,struct sk_buff *skb) {enum skb_drop_reason reason; -struct sock *rsk; reason =psp_sk_rx_policy_check (sk, skb);if (reason)
@@ -1863,24 +1862,21 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)return 0 ;if (nsk != sk) { reason =tcp_child_process (sk, nsk, skb); -if (reason) { - rsk = nsk; +sock_put (nsk); +if (reason) goto reset; - }return 0 ; } }else sock_rps_save_rxhash (sk, skb); reason =tcp_rcv_state_process (sk, skb); -if (reason) { - rsk = sk; +if (reason) goto reset; - }return 0 ; reset: -tcp_v4_send_reset (rsk, skb,sk_rst_convert_drop_reason (reason)); +tcp_v4_send_reset (sk, skb,sk_rst_convert_drop_reason (reason)); discard:sk_skb_reason_drop (sk, skb, reason);/* Be careful here. If this function gets more complicated and
@@ -2193,8 +2189,10 @@ int tcp_v4_rcv(struct sk_buff *skb) rst_reason =sk_rst_convert_drop_reason (drop_reason);tcp_v4_send_reset (nsk, skb, rst_reason); +sock_put (nsk); goto discard_and_relse; } +sock_put (nsk);sock_put (sk);return 0 ; }
net/ipv4/tcp_minisocks.c +1 -1
@@ -1012,6 +1012,6 @@ enum skb_drop_reason tcp_child_process(struct sock *parent, struct sock *child, }bh_unlock_sock (child); -sock_put (child); +return reason; }
net/ipv6/tcp_ipv6.c +8 -5
@@ -1617,12 +1617,13 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)if (sk->sk_state ==TCP_LISTEN ) {struct sock *nsk =tcp_v6_cookie_check (sk, skb); +if (!nsk) +return 0 ;if (nsk != sk) { -if (nsk) { - reason =tcp_child_process (sk, nsk, skb); -if (reason) - goto reset; - } + reason =tcp_child_process (sk, nsk, skb); +sock_put (nsk); +if (reason) + goto reset;return 0 ; } }else
@@ -1827,8 +1828,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) rst_reason =sk_rst_convert_drop_reason (drop_reason);tcp_v6_send_reset (nsk, skb, rst_reason); +sock_put (nsk); goto discard_and_relse; } +sock_put (nsk);sock_put (sk);return 0 ; }
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Quoted 9 lines · Eric Dumazet
tcp_child_process( .. child ...) currently calls
sock_put(child).Unfortunately @child (named @nsk in callers) can be used after this point to send a RST packet.
To fix this UAF, I remove the
sock_put()fromtcp_child_process()and let the callers handle this after it is safe.
Quoted 6 lines
Remove @rsk variable in
tcp_v4_do_rcv()and changetcp_v6_do_rcv()so that both functions look the same.Fixes cfb6eeb4c860 ("[TCP]: MD5 Signature Option (RFC2385) support.")Reported-by Damiano Melotti <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 5 May 2026 15:39:27 +0000 you wrote:
tcp_child_process( .. child ...) currently calls
sock_put(child).Unfortunately @child (named @nsk in callers) can be used after this point to send a RST packet.
To fix this UAF, I remove the
sock_put()fromtcp_child_process()and let the callers handle this after it is safe.[...]
Here is the summary with links:
- [net] tcp: tcp_child_process() related UAF
https://git.kernel.org/netdev/net/c/c8f7244c8ccc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html