🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9632

Re: [PATCH net] tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()

#9632
From: Jiayuan Chen
Date: Mon, 02 Nov 2026 13:00
101 lines
12651 bytes
On 11/2/26 3:54 PM, Eric Dumazet wrote:
> When IPV6_FL_F_REFLECT is set on a listener, or the
> net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED,
> tcp_v6_send_synack() reflects the flowlabel of the SYN packet,
> reading it from the skb stored in ireq->pktopts.
>
> Since commit 079096f103fa ("tcp/dccp: install syn_recv requests
> into ehash table"), request sockets are processed without holding
> the listener lock. A cpu can then process a retransmitted SYN for a
> request socket, and send a SYNACK from tcp_check_req(), while another
> cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock()
> consumes ireq->pktopts when it wins the hashdance, and the first cpu
> reads a freed skb:
>
>   BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
>   Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076
>
>   Call Trace:
>    <IRQ>
>    tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
>    tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
>    tcp_check_req (net/ipv4/tcp_minisocks.c:762)
>    tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
>    ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
>    ip6_input_finish (net/ipv6/ip6_input.c:534)
>    ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
>    ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)
>
>   Freed by task 5074 on cpu 0 at 15.412249s:
>    kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
>    tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
>    tcp_check_req (net/ipv4/tcp_minisocks.c:934)
>    tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
>    ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
>    ip6_input_finish (net/ipv6/ip6_input.c:534)
>
> Request socket migration has the same issue: reqsk_migrate_reset()
> transfers ireq->pktopts to the clone, which can be freed while
> another cpu holding a reference on the old request socket is still
> sending a SYNACK.
>
> The SYNACK timer itself is not an issue, because
> inet_csk_reqsk_queue_drop() calls timer_delete_sync().


Unlike v4, I don't think this part hold here:
tcp_v6_syn_recv_sock() consumes pktopts before inet_csk_complete_hashdance() calls timer_delete_sync()


> Save the flowlabel of the SYN in the request socket instead, so that
> tcp_v6_send_synack() no longer needs ireq->pktopts.
>
> As a side effect, the flowlabel is also reflected for SYN packets
> reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.
>
> Fixes: e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
> Fixes: 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
> Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
> Reported-by: Anvik Loitongbam <permissiontogallop@gmail.com>
> Reported-by: Yingjie Wang <x-professor@outlook.com>
> Closes: https://lore.kernel.org/netdev/82c31e4d5043f3dbd11b44177cfba779d335aae3.1793599929.git.x-professor@outlook.com/
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>


Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>


> ---
> Initially reported to security@ mailing list by Anvik Loitongbam, with a patch.
> Anvik Loitongbam provided a reproducer.
> I was able to trigger the ASAN warning before the patch, and checked
> the warning can no longer trigger.
>
> Yingjie Wang also sent a public patch later, very similar to Anvik's one.

I was just looking at that patch...


I think that misses the syncookie path:

tcp_v6_do_rcv
    // skb is final ack
    cookie_v6_check
       // inc ref
       refcount_inc(&skb->users);
       ireq->pktopts = skb;
       tcp_get_cookie_sock
         tcp_v6_syn_recv_sock    <== consume_skb() removed, and ireq->pktopts still point to the ACK


Then the same ACK is delivered to the child
tcp_v6_do_rcv
   tcp_v6_cookie_check
   tcp_child_process
     tcp_data_queue
        __kfree_skb(skb)       <== frees it regardless of skb->users

req->pktopts is now dangling, and tcp_v6_reqsk_destructor() will
consume_skb() it later at accept() time.
Technical Details
Message-ID: <3ee84772-9aa6-433e-bac7-40adc599f90d@linux.dev>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354682-linux-kernel-netdev=dewy.ru
References: <20261102075441.3771550-1-edumazet@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354682-linux-kernel-netdev=dewy.ru
From: jiayuan.chen@linux.dev (Jiayuan Chen)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: ipv6: do not read ireq->pktopts from
 tcp_v6_send_synack()
Date: Mon, 2 Nov 2026 21:00:24 +0800
Organization: Usenet Network
Message-ID: <3ee84772-9aa6-433e-bac7-40adc599f90d@linux.dev>
References: <20261102075441.3771550-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2926705"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:PZ1MW3l6OWybAAZrT+jTVJaZFVE= sha256:QoX1dsUmuz9RGOVO99HUmH5EDRTq1CKsuf7+4UFHHYY=
	sha1:S+vN7tcifa/fdOSy4I3IC1TDaJc= sha256:IMh8uQmoQgnrva5ORRM+y2hvtaH5ah+2RcgAnFmdT/M=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id D58371124FE; Mon,  2 Nov 2026 16:05:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.051
X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	HK_RANDOM_FROM=1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id IpC6tMa_vW_U;
	Mon,  2 Nov 2026 16:05:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-354682-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id EBD481124E7; Mon,  2 Nov 2026 16:05:06 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id A4FFE2C48C; Mon,  2 Nov 2026 13:00:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793624446;
	b=kYHDafuL0xqPHD+gHzrXLImmfXp7baTiHxjU/Wggo7V9ZSQiX7E1+cR46J8myvH/Wgbb
	 T0W3zBJLan/rA/ejUJe/TSxPS/Opv4y+1DetZ0Z1cuCQ46tjL2Ta31JTa2lUGC7Nlm/Ew
	 cy3ItF25A/G+GmYuyvKGyHW86sOKOwDgJ69NgDxDztN5LZIDXrKMRyXxAieQQOyIWjBvJ
	 7OraVxFGLsIjmWHeW0tZRF9U3l+n2LnNm9u3w7/FpuA4E22+9C3U4gsIlSQI05gHVdamp
	 eXo/wLLA0wUJGWEVY1zr1qyvk7Ej93fJGFRj0cvSlW9HecPWLe4n92hXkmn2Tp2XvlA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793624446;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=21gt7xEfR2u3AUi1YN0gEZzmBDhKnP/sCxBQCob5mMg=;
	b=1C6GDJ1h4CdR98jy+dXLGIWeqI6E4Y1GTmOXqfCyWMoPC6RM/m46VnxNvhJ96Wd9EZsd
	 LdTxrKq6J0dXulNkwCEQ05CvfgYBH6z7ZRYiOWUPd+by7t81eROD+cIMFg/wdp7MNxDsT
	 c3LFjFN9lofeGkvsoWbKPv3vKJhcxMvTVDtmm34lV6GBxnI9P3mf7sJAcST+xqtQrOTL1
	 woYXtUz8WedPcf1gsCxJLNOCNBeqh+CnLiJKT+KP9rxFcfhxDkaMnQaYrEJOtskcHTIn3
	 MhQUUvHsQvtbtzgBaIR/p+Dno0C4wE77WJmzSqIU8an90bK9Lj36G9csG1Uy8DuWGRA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AXMwqlWO;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id E8216606A331;
	Mon,  2 Nov 2026 13:00:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AXMwqlWO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.208
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793624445;
	b=sP8XE5BvR/b66bs7cevJs2K2ysIaHlRJfst8CAUQiimfdX21IcRpibCJ83iLe6cnEFDE
	 lZvayU05SP3Y6I9wTcbXy7AJHSwScnVjhuWt4DoGzmUaq1dfDr/A9baqKtXUD16NZ5Cry
	 bPFYyHt4Y3aElrkSvyK++bnzu1+OWqplsmgcf9YzogiSw6aV6qwC1Uho6L0OQ3Gijnabk
	 2TQE48d2u+V2uirz+xDUc2cobhN50ersioVv0+eFlRDKdf2LPhkbJ62ySwbOifcIJwp86
	 y4ZPwt24z8BehCc3PuXmF/Vijm1IcMNa7BMUdPWWBVUcXNI+SxboJUvtdu42BDDRd+g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793624445;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=21gt7xEfR2u3AUi1YN0gEZzmBDhKnP/sCxBQCob5mMg=;
	b=Drf4J+i0x1/nCLdXKjucEIoZSlsz06AOMLpQsQhsbHkCXZex7YSgRno7u1oO4x4SU4E8
	 W9pqHv9CZCOorVCDTmBZAYP2BbjwV4PYVGmq2Ew1k1fJnJP0//DH4hTeiprTb4O93Gm8N
	 iUnX+Aq1wgbZ1jVXWilku1G8HWaeosFjRyrKqgkCuklFzBkmdfop7LdJFbPgFMIH4i90J
	 2htDGEp5hFXsrsoE4dPaoXlq3DBPNiq1LQDWdzKaysNa62YqW4AM7DQ1fBENIFzCWCsxZ
	 qfaR6UfOlmtcPDBLf0uqTONF2Yo/VbuSJG/p00MHdtqIcHfDNCiNQ8T7WipCn2YmVkQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AXMwqlWO;
	arc=none smtp.remote-ip=91.218.175.208
X-Received: from mta0.migadu.com (out-208.mta0.migadu.com [91.218.175.208])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16E78606A326
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 13:00:43 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16E78606A326
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=jThf718hluzGgF+y7XM56/xWJWlb1Eyj+wKob1SacCw=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1793624442; v=1; x=1794229242;
 b=AXMwqlWO5jrcsIs1sBO+mlrFosOYHkMf8qzVXdcHOUqSit4ODziPJGp9JhYxthwSQ3itw2n9
 RYJjnqmkv9Iwt/Ow0C/VmsHh8xhokvcf9MiwT/ctviHxJMaT147C6NtscX05FYzfCqrms9ViHvk
 IDDOV+1bev4+8a7Pvy/po2Dw=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 96670a589e3b8f7a;
	Mon, 02 Nov 2026 13:00:30 +0000
X-Mizu-Trace-ID: 96670a589e3b8f7a
X-Migadu-Flow: FLOW_OUT
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, Simon Horman <horms@kernel.org>,
 netdev@vger.kernel.org, Anvik Loitongbam <permissiontogallop@gmail.com>,
 Yingjie Wang <x-professor@outlook.com>
X-In-Reply-To: <20261102075441.3771550-1-edumazet@kernel.org>