Article View: linux.kernel.netdev
Article #8304Re: [BUG] tcp: cross-family IPv4 option echo stack overwrite
From: Eric Dumazet
Date: Wed, 28 Oct 2026 16:22
Date: Wed, 28 Oct 2026 16:22
219 lines
17188 bytes
17188 bytes
Le mer. 28 oct. 2026 ร 16:31, Zhiyu Zhang <zhiyuzhang999@gmail.com> a รฉcrit :
>
> Hello Linux Kernel Developers and Maintainers,
>
> We found a TCP address-family mismatch that lets an IPv6 packet reach an IPv4
> reply path. The IPv4 path interprets IPv6 skb control-block fields as IPv4
> options and copies a packet-controlled length into a 40-byte stack buffer. We
> used it as the write primitive in a demonstrated unprivileged uid-to-root
> chain.
>
> The complete path is present in v7.3
> (c03c1a14507dfaf8b856c2608f9ac216021fc222), where we reproduced the
> privilege escalation with KASLR, STACKPROTECTOR_STRONG, PTI and IBT enabled.
> It is also present by inspection in v6.12.95. CONFIG_IPV6 is required.
>
> Current mainline d135ab453a7400a34930bdda1ef4bdc8acfac80e contains
> 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between ehash and
> lhash2."), which rejects the exact socket transition used by our reproducer.
> We therefore do not claim that the complete chain works at that mainline
> revision. The unsafe cross-family option handling and unbounded option echo
> remain relevant to maintained trees without that transition restriction.
>
> Root cause:
>
> tcp_v6_connect() changes icsk_af_ops and sk_backlog_rcv to the mapped-IPv4
> implementations after a successful v4-mapped connect. On affected kernels,
> connect(AF_UNSPEC) returns the socket to TCP_CLOSE without restoring those
> pointers, and listen() reuses it. A pure-IPv6 accepted child can consequently
> have IPv6 lookup state but tcp_v4_do_rcv as its backlog callback.
>
> For an [IPv6][DSTOPTS][TCP] packet, tcp_v6_fill_cb() stores inet6_skb_parm in
> TCP_SKB_CB(skb)->header.h6. If the packet is drained through tcp_v4_do_rcv(),
> tcp_v4_send_reset() passes the same union bytes as header.h4.opt. The aliased
> metadata directs __ip_options_echo() to read a packet-controlled option length
> and copy it into the 40-byte dopt->__data buffer. Our trigger produces a
> 254-byte overwrite across the canary and return address in
> ip_send_unicast_reply().
>
> The receiving process runs as uid 65534 without capabilities or a user
> namespace. A root helper is used only to inject the crafted IPv6 packet with
> a raw socket inside our single-VM test; the packet may instead arrive from an
> IPv6 peer.
>
> This is the memory-corruption half of the demonstrated privilege-escalation
> chain. A separately reported watch_queue disclosure supplies the same task's
> stack canary and KASLR slide. We will reply with that report's Message-ID as
> soon as it has been posted.
>
> Reproduction and fix:
>
> We have a source reproducer, exact config, QEMU instructions and a full-chain
> exploit. In accordance with the kernel policy, we are not posting them publicly.
> We can provide the source-only reproducer privately if a maintainer requests it.
>
> Our build- and QEMU-tested fix has two layers: the IPv4 TCP reset and ACK paths
> only pass IPv4 option state for ETH_P_IP skbs, and __ip_options_echo() validates
> each option against the declared source area, the actual skb header area and
> the remaining destination space. We will post it separately as a mergeable
> [PATCH net] email and link that thread here.
>
> AI-agent tooling assisted in identifying and analyzing the issue, developing
> the reproducer, and preparing the initial fix. The reporters reviewed the
> affected paths and reproduced the issue and the fixed result in QEMU.
>
> Reported-by: Tong Liu <lyutoon@gmail.com>
> Reported-by: Qi Tang <tpluszz77@gmail.com>
> Reported-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
>
> Best regards,
> Zhiyu Zhang
Worst report I got this week, and trust me I got many security reports
in the last 3 days
Why don't you ask your LLM to prepare a patch ?
Why CCing security@ at all, since you made this report public ?
Have you read Documentation/process/security-bugs.rst ?
MPTCP is not yet covered in this untested WIP:
Kuniyuki, can you take over, thanks.
commit 5108a64604b6f2fad06383386d8d5bc44f0cf35b (HEAD -> net-4)
Author: Eric Dumazet <edumazet@kernel.org>
Date: Wed Oct 28 17:14:04 2026 +0100
tcp: restore IPv6 af_ops on disconnect of a v4-mapped socket
A successful connect() of an IPv6 socket to a v4-mapped address
switches icsk_af_ops, sk_backlog_rcv and af_specific to their
IPv4-mapped variants. These are only restored if the connect() fails.
After connect(AF_UNSPEC), the socket can be reused for listen() or
for a native IPv6 connect(), while still using the mapped handlers.
IPv6 packets processed from the socket backlog are then handled by
tcp_v4_do_rcv(). tcp_v4_send_reset() and tcp_v4_send_ack() interpret
TCP_SKB_CB(skb)->header.h6 as IPv4 options, and __ip_options_echo()
can overflow its 40-byte destination buffer.
Commit 8cc3aef0cb19 ("tcp: Do not allow buggy transitions between
ehash and lhash2.") prevents listen() after connect(AF_UNSPEC), but
a native IPv6 connect() is still allowed.
Add tcp_v6_disconnect() to restore the IPv6 handlers when a v4-mapped
socket is disconnected, and use the same helper in the connect()
error path.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Tong Liu <lyutoon@gmail.com>
Reported-by: Qi Tang <tpluszz77@gmail.com>
Reported-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index e006a30360eae1b43a4d53173b46b931ae668825..a93410aab66e6f441d70cf70c67e6d92fbb5fb26
100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -130,6 +130,19 @@ static int tcp_v6_pre_connect(struct sock *sk,
struct sockaddr_unsized *uaddr,
return BPF_CGROUP_RUN_PROG_INET6_CONNECT(sk, uaddr, &addr_len);
}
+/* Undo the v4-mapped setup done by tcp_v6_connect(). */
+static void tcp_v6_restore_af_ops(struct sock *sk)
+{
+ /* Paired with READ_ONCE() in tcp_(get|set)sockopt() */
+ WRITE_ONCE(inet_csk(sk)->icsk_af_ops, &ipv6_specific);
+ if (sk_is_mptcp(sk))
+ mptcpv6_handle_mapped(sk, false);
+ sk->sk_backlog_rcv = tcp_v6_do_rcv;
+#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO)
+ tcp_sk(sk)->af_specific = &tcp_sock_ipv6_specific;
+#endif
+}
+
static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
int addr_len)
{
@@ -243,14 +256,7 @@ static int tcp_v6_connect(struct sock *sk, struct
sockaddr_unsized *uaddr,
if (err) {
icsk->icsk_ext_hdr_len = exthdrlen;
- /* Paired with READ_ONCE() in tcp_(get|set)sockopt() */
- WRITE_ONCE(icsk->icsk_af_ops, &ipv6_specific);
- if (sk_is_mptcp(sk))
- mptcpv6_handle_mapped(sk, false);
- sk->sk_backlog_rcv = tcp_v6_do_rcv;
-#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO)
- tp->af_specific = &tcp_sock_ipv6_specific;
-#endif
+ tcp_v6_restore_af_ops(sk);
goto failure;
}
np->saddr = sk->sk_v6_rcv_saddr;
@@ -2093,6 +2099,19 @@ static int tcp_v6_init_sock(struct sock *sk)
return 0;
}
+static int tcp_v6_disconnect(struct sock *sk, int flags)
+{
+ int ret = tcp_disconnect(sk, flags);
+
+ /* A socket used for a v4-mapped connection must not keep IPv4
+ * handlers when it is reused for listen() or a native IPv6 connect().
+ */
+ if (sk->sk_backlog_rcv == tcp_v4_do_rcv)
+ tcp_v6_restore_af_ops(sk);
+
+ return ret;
+}
+
#ifdef CONFIG_PROC_FS
/* Proc filesystem TCPv6 sock list dumping. */
static void get_openreq6(struct seq_file *seq,
@@ -2283,7 +2302,7 @@ struct proto tcpv6_prot = {
.close = tcp_close,
.pre_connect = tcp_v6_pre_connect,
.connect = tcp_v6_connect,
- .disconnect = tcp_disconnect,
+ .disconnect = tcp_v6_disconnect,
.accept = inet_csk_accept,
.ioctl = tcp_ioctl,
.init = tcp_v6_init_sock,
Technical Details
Message-ID:
<CAL4WiiqFJpmcV4=TWRpukCq6q=-729658FwGvieNcPXe97kLvQ@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352940-linux-kernel-netdev=dewy.ruReferences:
<CALf2hKvp0NPVLwr=a3+jUHtPohxbra8gox+aYAfWathJnn-J+Q@mail.gmail.com>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-352940-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [BUG] tcp: cross-family IPv4 option echo stack overwrite
Date: Wed, 28 Oct 2026 17:22:26 +0100
Organization: Usenet Network
Message-ID: <CAL4WiiqFJpmcV4=TWRpukCq6q=-729658FwGvieNcPXe97kLvQ@mail.gmail.com>
References: <CALf2hKvp0NPVLwr=a3+jUHtPohxbra8gox+aYAfWathJnn-J+Q@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1812660"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:lLABhzAVqDriPEy3rjC4V3FwF7c= sha256:w2tUlYVEaFiNDTWVkLTbFC8cg9UiSkoOSGKo1oWG9EM=
sha1:+4LaWalrgM5MgyQrRHB7ThMEy5w= sha256:EG840jg9UQ8ijcPKtd7qJ0O+mWnAWnhyyAMIJiVJ7dA=
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 E12DD125C42; Wed, 28 Oct 2026 19:27:12 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.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 (2048-bit key)
header.d=kernel.org
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 WvvwHoB_dXjp;
Wed, 28 Oct 2026 19:27:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352940-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id D550F125C40; Wed, 28 Oct 2026 19:26:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 2815927123; Wed, 28 Oct 2026 16:22:41 +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=1793204561;
b=vO/4pKsyMllQp0JrrfWxgb8t8XITwBabJW+nwD3di6FC33NH08BBLyUlMLeoEQgT7sDv
VdqZQgnVp/fPvnGdErgJRCKgG9uNeGVGl0LWVjXdpqPGzPMxKiTDNPumIjWjd72++0XFB
iwVlq+CtH/J/TCTdvSNt66Ki3O/dSUChfbOv1PA6NZKVoRIYa4pRe+QmEiiIAznszYVbq
sNJDN/vmv2DA/FEL96YO/ne7IW0MyItLWpBwrtYJUhY/b/R4vCRmghxevlcTLuI2jdeA6
4YaIoHddYR2m4PT3OLtlh4Lwhor4J0teuPr5wVO4ubOf3qw+i6HOq9185U93Y9t92Zg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793204561;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Gm-Message-State:X-Received:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=LPnEsZ87SQg7JuBssg3knDigJumxWAPQLrNmp7RbkGU=;
b=I5EJdXZ69nITfvus9GgNOEGfZBiTx/R03YUPCx5BwKewyJ7MmG1AyILQKRhtUQeLNkRo
28t80jU8OVgpi4BDKLkGpTxG1pSexFgg+9QciOjdwYGMliXSQQBjEM1KhTKvQGTvymGxi
t+yBa1NGaotgkhRPqHsmXSI60Jp0+VQyRY2Ly7LBMTYnNuB9O+M/+1PRP1zWBtctD64a6
x9E+mbXh+CEj68Yo5tnj5tmTQE+5fP+oIZptXhpppJwjh7loStWy3gpHVNnLLo1UoyuDy
WQPsT05BepfvyjPal5acbufACjVzHfAOw+nQFahZGyPiAIruQBww6iorLXtKOQoYTfQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q3XCKkFg;
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 F3F75606A320;
Wed, 28 Oct 2026 16:22:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q3XCKkFg
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793204560;
b=dBSS2ZFXB4WTz/JT+gN5Jn1rr37qpsQmQdWSVUanSWZHLpwegHJLaHRlXetMSznxXoxh
L+2AqMVEcwR9sgDptQdRaL/4vtSgNTmG+pBABHxF6ZXpAEDNMalZzXkROSBM1WSifibRA
awYCxUEhDag32U/OO/OlQnODAL5Kpl1nkMZjBA2DNNxWCwZa8wAqpyX8kBgFgNuh8/QBU
wCu3LEdRZLViPK6crtfu39EX0D6IViO8I8XXN+cYDGR5StdE4cC3oLAQfECbuiLbwpFVE
0ACWzh73nZzfoq3zzKSr0smXw4U+YwZhvMk3hqLQzPP3crRItHuWxOXXbdf+XOWL6RQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793204560;
h=Received:DKIM-Signature:Received:X-Gm-Message-State:X-Received:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=LPnEsZ87SQg7JuBssg3knDigJumxWAPQLrNmp7RbkGU=;
b=iyYyPjY02CeNyr/GsJDL7iC9Qmit5d2ovXl4toScDDn+u+uat4gy+otpfFL+ImPzvuMc
lDafti96KZgVcN4217mFP8Y1mzsRRv/SrUXELmuvlCXjbLPXL0S0YAjE+TUQ/XbDt+4J7
T/OiE3l3EdLztJZ2cr4/jvk1mvAVJtb/mzCZDDIQp1QmnEGqIDQ5loE9HZiHf1eo+sb+h
ZpneQLN2VUJmqNtGsUqZigxWQv3KnpEHcJFDDjNpdc0RBT9EW7SHs5I48mJMptPLbEOOr
8hd6kgKseHdgcs+uMeaeQ7Ow4PugLBEBkbKByB9z139swpk1BJISrpFClZZgkmZX6pA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q3XCKkFg;
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B257606A31D
for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 16:22:39 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA4CE1F01825
for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 16:22:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1793204558;
bh=LPnEsZ87SQg7JuBssg3knDigJumxWAPQLrNmp7RbkGU=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=Q3XCKkFgPHPKp6gqmQKsJwRqQJuSfwVNKgMJw929jSWeA3EeDHYgisCRIepBEMPXt
z/wAJH9jCTH6WxqPx3Z5G/pdCB5Cz5i2ma8z9R/EpRUHtsuUWAFWbJozYHoSixDAmu
IsTVUvNO5gQgHsVzET0rEW0c+dgdoDZ8NmMbdGFcRwyM0FguLQkhYO9/OaE+M8RXuH
YPqpfgszyqeDJ6vOFNwydL2edVQ6+xF/dCncrhGFqv/fMS24Csz7YMiwzRsC83vdtb
mGRn0T7Wp25MKwSS7rpDV4qYIIxExX0WrOuTmJbSu8y6BjGMiZ4w3v/DEYFufMW06M
AYl9JNASNYKLg==
X-Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-4a6f2825dd6so347185fac.2
for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 09:22:38 -0700 (PDT)
X-Gm-Message-State: AFq9FYIBee+CzIaq5i83XhWfxZhbk5FCQ4QJsmtcGicJntbNO2UhCNdM
5YlP+nNDrT0hvu89ta4qekMxBWTeQRloiMA8oKeWfgUymNq3Z75iKYRPHWw1pc+6Mj3LOPpapsW
VLZvMI5MqKGZvaofDlqi6HLQof7HOEaA=
X-Received: by 2002:a05:6870:1410:b0:48f:e21e:1e7b with SMTP id
586e51a60fabf-4a8bb5cd6bbmr1938619fac.59.1793204558218; Wed, 28 Oct 2026
09:22:38 -0700 (PDT)
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-In-Reply-To: <CALf2hKvp0NPVLwr=a3+jUHtPohxbra8gox+aYAfWathJnn-J+Q@mail.gmail.com>
X-Gmail-Original-Message-ID: <CAL4WiiqFJpmcV4=TWRpukCq6q=-729658FwGvieNcPXe97kLvQ@mail.gmail.com>
X-Gm-Features: AclHuK9Ib5neXJt_tER1R8PJmj4tWIK_9yLZR_Pwu3If9gy_DONTRjPsPWsSK5s
X-Cc: netdev@vger.kernel.org, ncardwell@google.com, kuniyu@google.com,
dsahern@kernel.org, idosch@nvidia.com, brauner@kernel.org,
dhowells@redhat.com, security@kernel.org, lyutoon@gmail.com,
tpluszz77@gmail.com