From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E25AF2D1907 for ; Mon, 24 Aug 2026 03:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787542478; cv=none; b=QjrZuzHWZ40oh+Qs/FTuP9ePBogGo5gg1Vfqun3ivTD/Q8duuk+ZJwXwiMdPIjGn7FyrD05lwiImCbMZaNYPqo6RBWdOuLJlj++KWRenJlG6DIRoJJMjddOs3o4sp8kVHXoiKGECSm3F7JTh47BLwqOf90QSdofsewpMTrgblfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787542478; c=relaxed/simple; bh=iKlmSYal/we//DbFxdnR+qq4NS2r621URuMIi6uUWaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IGxJrMgnP2jUxZzYH+o6ifpDIVpsmKhgDSMQSxWdoXfxONglzpkcrLiXEMIT99kSmsVlVKzeNUCU9kadXgJD8BS2zjUf968OpUH7sCCQtQ0Rbkqa8PeyjIva1j5W1deKh6kJ501Eyskas8zdJOvgH99DQPGgYMua4gy/EhLCLMw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GKaJC2df; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GKaJC2df" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-38101f85591so3251563a91.1 for ; Sun, 23 Aug 2026 20:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787542476; x=1788147276; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=F7loPKjk85S1XKwGILHvPGhD2hPmSAD1/re7dQ/3iUc=; b=GKaJC2dfS09SwGoGo9Dsv4oZdaaydJdk03fu2ZJHwxCbiq5r2AFDDf4vfFcRodeArt smuEfj49loWgVB1I44xGBQ0f3sG/D2gxJ3ASBx/x8ixrSdxZODdIS2lJDQttR9COhqMb CU7yeHkEtpSnqIhUHU8jXBImS1csD2JFjewXwFyhAezWtMeafmp5loNPEqTvBy1QSVCe 9Isq10WjIIHnx0c8jL/roME67dAE+eMmRSc4TNkkCetV33pKHv3aiiUdQ3+Y9/+vHlYB FmjHidnAj+1z+UzDyI+M0w6z/qTfHJuROq9mDti2q4tCj8xDxn/SXB0bo84UehD/bfU2 diyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787542476; x=1788147276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=F7loPKjk85S1XKwGILHvPGhD2hPmSAD1/re7dQ/3iUc=; b=C/lTREX5xCF0c3zyACFYHWzMvvthfC87myC8zzmDBRMYTY+z+Uy8jgbMOkNushk7GO 7NLaQaaxk7JE6TNFCm0hfeK3bcuFvD8bBMBhgKzOVwln8fA23uvGgs5Yzml+uqxb4LBR UyyW3W6hPHrKYAnXYJeJRqtDzJ6BQILuVgJyeXg80Or69a417x3FJ2qTrntl/8vfbSrp aZ8evIYPDxAk7WEi9qmnpwTCnnTkY8Qvjn3bPRfaZCi/L+5TxJgtlI+QRdTfP+vNXDk0 B7CkWF51oXKwZ5BXN6zHEDuvSSvWGzMxw99Q1YFHabC2jE09GcUCJPzti6Jq/Z9yYy17 /K4g== X-Forwarded-Encrypted: i=1; AHgh+RolLDeuFgTYa8CacaDWnP3/LlStQoxd2e3XRfBfG+DvmziesaU/WgG5Je1lVwtDLRpWVouNDIsdjwLUCkY=@vger.kernel.org X-Gm-Message-State: AFuF++lfxVS+JP9cwcsjMq7F9/n2Ri4xpZcFsVBb1RKc5/0csIY8sWaq tf9BPKsQHPg+hckz573bopXho9VKriDtSU/4En5fJ/jVJEOYu0xU3qBn X-Gm-Gg: AR+sD12lryFGgA+5aq84sZcBmevQvuw29jRkpO1jnOmv7goPQGgu1LzsJolLrWPxuFe BzrfMroslwM7f0mr2qlWySKY/pEXclE58llrKGf0uEU202VVcb0xGB/nwXbW5LFVsmCnacYVNI2 SThr0n1IGmYHByTz2t+d9x1LhVE0SX+JFNPVCtMU46PVj9qkVTOWsXV6AspIdeEc8Z6PhmJYVy3 5W1suiED1bdvCiMDnFXOfDM6k1SwK1hQiCIxKNC7mHE6yWjecWaX5XWeVUQCYYZoxIlWsIDuehj aReHX4Kt3W2N625OwABKSSRGpzdR+3nU+X3+rgBtwA0aY55C88ZWin871u99KwGeYzsqQEVkv7S 0IcqyVGqwcGcl9iWEJ38zkuSI7vOiQe7LbA+evWinYYZZ4QH7wo7cOSrEx6NL1Te1kDe5B97LAf 62Ww1F83j0YGi3JfCUxV2Sw0YmNjBBIJzHBUz0YdAR+0ni+1263Nhj2rLkHNqbcN7XLBO1oc/Gh 0EPZbAwJG4= X-Received: by 2002:a17:90b:3e8d:b0:38e:9ca8:e99 with SMTP id 98e67ed59e1d1-395c4fa444bmr13960149a91.5.1787542476163; Sun, 23 Aug 2026 20:34:36 -0700 (PDT) Received: from v4bel.. ([58.123.110.97]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-395c8fd34d9sm4227256a91.1.2026.08.23.20.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2026 20:34:35 -0700 (PDT) From: Hyunwoo Kim 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 Message-ID: <20260824033331.1084971-6-imv4bel@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824033331.1084971-1-imv4bel@gmail.com> References: <20260824033331.1084971-1-imv4bel@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 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 --- 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