Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Zhiyu Zhang
Wed, 28 Oct 2026 15:31
[BUG] tcp: cross-family IPv4 option echo stack overwrite
Author: Zhiyu Zhang
Date: Wed, 28 Oct 2026 15:31
Date: Wed, 28 Oct 2026 15:31
69 lines
14605 bytes
14605 bytes
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
Re: [BUG] tcp: cross-family IPv4 option echo stack overwrite
Author: 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,
Re: [BUG] tcp: cross-family IPv4 option echo stack overwrite
Author: Zhiyu Zhang
Date: Wed, 28 Oct 2026 16:39
Date: Wed, 28 Oct 2026 16:39
239 lines
21137 bytes
21137 bytes
Hi Eric,
I'm sorry for the noise. The Cc to security@ was unnecessary.
We already have the patches ready (tested). I sent the report first to get a
public URL for the Closes: tags. I'll post the patch asap.
Best,
Zhiyu
Eric Dumazet <edumazet@kernel.org> 于2026年10月29日周四 00:22写道:
>
> 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,
Re: [BUG] tcp: cross-family IPv4 option echo stack overwrite
Author: Zhiyu Zhang
Date: Thu, 29 Oct 2026 06:15
Date: Thu, 29 Oct 2026 06:15
404 lines
28167 bytes
28167 bytes
Hi Eric, Kuniyuki,
I kept Eric's tcp_ipv6.c change unchanged and added the missing MPTCP
coverage. Two MPTCP paths called tcp_disconnect() directly, bypassing the
protocol-specific disconnect callback. The changes below route them through
ssk->sk_prot->disconnect(), so IPv6 subflows run tcp_v6_disconnect() as
well.
I tested the combined change on net.git at 94cea342e891 with both TCP and
MPTCP by reconnecting an AF_INET6 socket from a v4-mapped peer to a native
IPv6 peer after connect(AF_UNSPEC).
The related watch_queue report and patch are:
Report: https://lore.kernel.org/lkml/CALf2hKveij_sHgANY9Aktm1dPa4wfKjKNkHyp9yPbjORWFXagA@mail.gmail.com/
Patch: https://lore.kernel.org/lkml/20261029054136.1174216-1-zhiyuzhang999@gmail.com/
I have not posted a standalone [PATCH net] to avoid duplicating Kuniyuki's
work. If you would like me to submit this completed version, I can send it
right away:
From ffa42bc88b0221619f6eadb3a7f5c38328a258cb Mon Sep 17 00:00:00 2001
From: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Date: Thu, 29 Oct 2026 01:58:37 -0400
Subject: [PATCH] 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.
MPTCP subflows override sk_prot, and two teardown paths call
tcp_disconnect() directly. Route those calls through the protocol-specific
disconnect operation so IPv6 MPTCP subflows receive the same restoration.
Tested with TCP and MPTCP by reconnecting an AF_INET6 socket from a
v4-mapped peer to a native IPv6 peer after connect(AF_UNSPEC).
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>
Closes: https://lore.kernel.org/netdev/CALf2hKvp0NPVLwr=a3+jUHtPohxbra8gox+aYAfWathJnn-J+Q@mail.gmail.com/
Link: https://lore.kernel.org/netdev/CAL4WiiqFJpmcV4=TWRpukCq6q=-729658FwGvieNcPXe97kLvQ@mail.gmail.com/
Link: https://lore.kernel.org/lkml/20261029054136.1174216-1-zhiyuzhang999@gmail.com/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Co-developed-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Signed-off-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
---
net/ipv6/tcp_ipv6.c | 37 ++++++++++++++++++++++++++++---------
net/mptcp/protocol.c | 4 ++--
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index e006a30360ea..a93410aab66e 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,
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 7a22e9388e0e..fdfbc7de2ec0 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2608,7 +2608,7 @@ static void __mptcp_subflow_disconnect(struct sock *ssk,
/* The MPTCP code never wait on the subflow sockets, TCP-level
* disconnect should never fail
*/
- WARN_ON_ONCE(tcp_disconnect(ssk, 0));
+ WARN_ON_ONCE(ssk->sk_prot->disconnect(ssk, 0));
mptcp_subflow_ctx_reset(subflow);
} else {
tcp_shutdown(ssk, SEND_SHUTDOWN);
@@ -3287,7 +3287,7 @@ void mptcp_subflow_shutdown(struct sock *sk,
struct sock *ssk, int how)
break;
fallthrough;
case TCP_SYN_SENT:
- WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
+ WARN_ON_ONCE(ssk->sk_prot->disconnect(ssk, O_NONBLOCK));
break;
default:
if (__mptcp_check_fallback(mptcp_sk(sk))) {
--
2.34.1
Thanks,
Zhiyu
Eric Dumazet <edumazet@kernel.org> 于2026年10月29日周四 00:22写道:
>
> 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,
Re: [BUG] tcp: cross-family IPv4 option echo stack overwrite
Author: Zhiyu Zhang
Date: Fri, 30 Oct 2026 03:43
Date: Fri, 30 Oct 2026 03:43
11 lines
12273 bytes
12273 bytes
> Please do so. > > I'd keep the original author as Eric. Done. I kept Eric as the author. The patch is available here: https://lore.kernel.org/netdev/179333098042.3327.6001182207228154005@kernel.org/ > P.S. do not top-post on lkml. Sorry about that, and thanks for pointing it out.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads