From: Hyunwoo Kim <imv4bel@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, ncardwell@google.com, dsahern@kernel.org,
idosch@nvidia.com, kuniyu@google.com, horms@kernel.org,
willemb@google.com, andrew+netdev@lunn.ch, kees@kernel.org,
jiayuan.chen@linux.dev
Cc: kerneljasonxing@gmail.com, ij@kernel.org, martin.lau@kernel.org,
shakeel.butt@linux.dev, matttbe@kernel.org, martineau@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
imv4bel@gmail.com, stable@vger.kernel.org
Subject: [PATCH net v2 5/8] tcp: do not inherit out_of_order_queue from parent
Date: Mon, 24 Aug 2026 12:32:49 +0900 [thread overview]
Message-ID: <20260824033331.1084971-6-imv4bel@gmail.com> (raw)
In-Reply-To: <20260824033331.1084971-1-imv4bel@gmail.com>
A child gets a copy of the parent's out_of_order_queue, which can be non
empty when/if parent morphs from listener to active session. Parent and
child then point at the same rbtree.
The parent is no longer a listener, so inet_csk_reqsk_queue_add() forgets
the child immediately, and tcp_disconnect() frees the skbs the parent
still owns. The parent's own root and ooo_last_skb are left alone, so it
keeps using those skbs. That is a use-after-free, and the parent frees
them a second time when it closes.
In short:
peers the socket owner
socket(AF_INET6)
setsockopt(TCP_DEFER_ACCEPT, 30)
bind(), listen()
connect(the listener)
// bare ACK deferred, the request stays
connect(AF_UNSPEC)
connect(the new peer)
send(the new connection)
// it starts one byte past rcv_nxt, so it lands out of order
tcp_data_queue()
tcp_data_queue_ofo() // the parent's queue fills up
send(the old connection)
tcp_check_req()
tcp_v6_syn_recv_sock()
tcp_create_openreq_child() // the child gets the same rbtree
inet_csk_complete_hashdance()
inet_csk_reqsk_queue_add()
inet_child_forget()
tcp_disconnect()
skb_rbtree_purge() // the parent's skbs are freed
send(the new connection)
tcp_data_queue()
tcp_data_queue_ofo()
rb_link_node() // use-after-free write
KASAN log:
BUG: KASAN: slab-use-after-free in tcp_data_queue+0x1708/0x1df0
Write of size 8 at addr ffff888012ad5408 by task repro/135
...
Call Trace:
<IRQ>
tcp_data_queue+0x1708/0x1df0
tcp_rcv_established+0x441/0x1830
tcp_v4_do_rcv+0x47e/0x730
tcp_v4_rcv+0x171c/0x2040
ip_protocol_deliver_rcu+0x5c/0x280
ip_local_deliver_finish+0x15a/0x2e0
ip_local_deliver+0x107/0x370
ip_rcv+0x3b1/0x3d0
...
Allocated by task 135:
__alloc_skb+0xd0/0x370
alloc_skb_with_frags+0x7d/0x330
sock_alloc_send_pskb+0x490/0x4e0
raw_sendmsg+0xd52/0x1850
...
Freed by task 133:
kmem_cache_free+0x26f/0x5f0
skb_rbtree_purge+0x73/0x90
tcp_disconnect+0x1be/0xd60
inet_child_forget+0x41/0x140
inet_csk_complete_hashdance+0x4d0/0x520
tcp_check_req+0x9f9/0xff0
tcp_v6_rcv+0xb9f/0x1e90
...
The buggy address belongs to the object at ffff888012ad5400
which belongs to the cache skbuff_head_cache of size 232
The buggy address is located 8 bytes inside of
freed 232-byte region [ffff888012ad5400, ffff888012ad54e8)
We need to make sure this can not happen, by initializing the queue after
socket cloning.
Very similar to commit 8b485ce69876 ("tcp: do not inherit fastopen_req
from parent")
Fixes: 9f5afeae5152 ("tcp: use an RB tree for ooo receive queue")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
Changes in v2:
- Add the trigger sequence and the KASAN log to the commit message.
- v1: https://lore.kernel.org/all/20260817090319.3897799-4-imv4bel@gmail.com/
---
net/ipv4/tcp_minisocks.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 0c3b35a381e327..7fe318d9e0aed2 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -591,6 +591,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
newtp->total_retrans = req->num_retrans;
tcp_init_xmit_timers(newsk);
+ newtp->out_of_order_queue = RB_ROOT;
WRITE_ONCE(newtp->write_seq, newtp->pushed_seq = treq->snt_isn + 1);
if (sock_flag(newsk, SOCK_KEEPOPEN))
--
2.43.0
next prev parent reply other threads:[~2026-08-24 3:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 3:32 [PATCH net v2 0/8] net: fixes for requests completing on a socket that no longer listens Hyunwoo Kim
2026-08-24 3:32 ` [PATCH net v2 1/8] tcp: fix use-after-free of the listener's ipv6_pinfo after IPV6_ADDRFORM Hyunwoo Kim
2026-08-24 3:32 ` [PATCH net v2 2/8] tcp: fix imbalanced icsk_accept_queue count in tcp_check_req() Hyunwoo Kim
2026-08-24 3:32 ` [PATCH net v2 3/8] ipv6: fix request socket use-after-free after IPV6_ADDRFORM Hyunwoo Kim
2026-08-24 3:32 ` [PATCH net v2 4/8] net: fix out-of-bounds write in sk_clone() racing with IPV6_ADDRFORM Hyunwoo Kim
2026-08-24 3:32 ` Hyunwoo Kim [this message]
2026-08-24 3:32 ` [PATCH net v2 6/8] tcp: fix use-after-free in the lockless listener path Hyunwoo Kim
2026-08-24 3:32 ` [PATCH net v2 7/8] net: clear sk_tsq_flags in sk_clone() Hyunwoo Kim
2026-08-24 3:32 ` [PATCH net v2 8/8] tcp: do not inherit retransmit state from parent Hyunwoo Kim
2026-08-24 8:30 ` [PATCH net v2 0/8] net: fixes for requests completing on a socket that no longer listens David Laight
2026-08-24 12:56 ` Hyunwoo Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824033331.1084971-6-imv4bel@gmail.com \
--to=imv4bel@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ij@kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=kees@kernel.org \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martineau@kernel.org \
--cc=matttbe@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®