* [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion
@ 2026-11-16 15:52 Zihan Xi
2026-11-16 15:52 ` [PATCH net 1/1] xfrm: espintcp: select receive path by skb protocol Zihan Xi
2026-11-25 10:53 ` [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion Sabrina Dubroca
0 siblings, 2 replies; 3+ messages in thread
From: Zihan Xi @ 2026-11-16 15:52 UTC (permalink / raw)
To: netdev, ipsec
Cc: steffen.klassert, herbert, davem, edumazet, pabeni, horms, sd,
vega, zihanx
Hi Linux kernel maintainers,
We found an issue in net/xfrm/espintcp.c. An IPv6 dual-stack socket can accept
an IPv4 connection as a v4-mapped peer. The accepted socket remains AF_INET6,
but the received skb is IPv4. ESP-in-TCP selected the XFRM receive path from
the socket family and passed the IPv4 skb to xfrm6_rcv_encap(), where IPv4
header bytes were interpreted as an IPv6 header.
This patch selects the receive path from skb->protocol, matching the packet
family and preventing the type-confused IPv6 processing.
An LLM was used to help create this patch.
This bug is tracked at:
https://bugtracker.nebusec.ai/f/5016 (5016)
Bug details:
The vulnerable path is reachable by an unprivileged user using an AF_INET6
listener with IPV6_V6ONLY disabled, an IPv4 connection, and TCP_ULP=espintcp.
The historical supplied QEMU run observed xfrm6_rcv_encap() on the IPv4-backed
skb and an XfrmInNoStates increment; it did not produce a crash. The selected
origin/main baseline still contains the family-based dispatch. The fix is a
one-line protocol-based dispatch change.
Reproducer details:
- Use the static-build and unprivileged user/network-namespace commands in the
reproducer instructions.
- Explain why a custom socket PoC is used instead of packetdrill.
- Include the observed normal output and tracing evidence, and explain why no
crash-log exists.
Reproducer:
Build and run as an ordinary user in the guest:
gcc -static -O2 -pthread poc.c -o poc
unshare -Urn sh -c 'ip link set lo up; exec ./poc'
The custom C PoC is used because the trigger depends on AF_INET6 dual-stack
socket creation, v4-mapped accept state, and TCP_ULP=espintcp. Packetdrill
does not naturally express this socket API and ULP state combination.
Historical QEMU run output:
accepted socket domain=10
peer=::ffff:127.0.0.1 port=41512
recv=0 errno=0
The historical tracing additionally showed:
xfrm6_rcv_encap <-espintcp_rcv
and XfrmInNoStates increased by one (before=1004 after=1005 delta=1). The run
followed the no-state/error path without a KASAN report, oops, or crash-log,
so no crash-log is attached.
We run the PoC in a 2 vCPU, 2 GB RAM x86 QEMU environment.
------BEGIN PoC------
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <sched.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
static int port = 31338;
static volatile int ready;
static void die(const char *msg)
{
perror(msg);
exit(1);
}
static void *server_thread(void *arg)
{
int ls = socket(AF_INET6, SOCK_STREAM, 0);
int zero = 0, one = 1;
struct sockaddr_in6 addr = {0};
struct sockaddr_storage peer;
struct sockaddr_in6 peer6 = {0};
socklen_t peerlen = sizeof(peer);
socklen_t peer6len = sizeof(peer6);
char ulp[] = "espintcp";
char addrbuf[INET6_ADDRSTRLEN];
char rx[128];
int as;
int fam;
socklen_t flen = sizeof(fam);
ssize_t n;
(void)arg;
if (ls < 0)
die("socket(AF_INET6)");
if (setsockopt(ls, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)) < 0)
die("setsockopt(IPV6_V6ONLY=0)");
if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0)
die("setsockopt(SO_REUSEADDR)");
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(port);
addr.sin6_addr = in6addr_any;
if (bind(ls, (struct sockaddr *)&addr, sizeof(addr)) < 0)
die("bind");
if (listen(ls, 1) < 0)
die("listen");
__atomic_store_n(&ready, 1, __ATOMIC_SEQ_CST);
as = accept(ls, (struct sockaddr *)&peer, &peerlen);
if (as < 0)
die("accept");
if (getsockopt(as, SOL_SOCKET, SO_DOMAIN, &fam, &flen) < 0)
die("getsockopt(SO_DOMAIN)");
fprintf(stderr, "accepted socket domain=%d\n", fam);
if (getpeername(as, (struct sockaddr *)&peer6, &peer6len) < 0)
die("getpeername");
if (!inet_ntop(AF_INET6, &peer6.sin6_addr, addrbuf, sizeof(addrbuf)))
die("inet_ntop");
fprintf(stderr, "peer=%s port=%u\n", addrbuf, ntohs(peer6.sin6_port));
if (setsockopt(as, IPPROTO_TCP, TCP_ULP, ulp, sizeof(ulp)) < 0)
die("setsockopt(TCP_ULP=espintcp)");
n = recv(as, rx, sizeof(rx), 0);
fprintf(stderr, "recv=%zd errno=%d\n", n, errno);
close(as);
close(ls);
return NULL;
}
int main(void)
{
pthread_t th;
int cs;
struct sockaddr_in a = {0};
unsigned char msg[10] = {
0x00, 0x0a,
0x12, 0x34, 0x56, 0x78,
0xaa, 0xbb, 0xcc, 0xdd,
};
if (pthread_create(&th, NULL, server_thread, NULL) != 0)
die("pthread_create");
while (!__atomic_load_n(&ready, __ATOMIC_SEQ_CST))
sched_yield();
cs = socket(AF_INET, SOCK_STREAM, 0);
if (cs < 0)
die("socket(AF_INET)");
a.sin_family = AF_INET;
a.sin_port = htons(port);
if (inet_pton(AF_INET, "127.0.0.1", &a.sin_addr) != 1)
die("inet_pton");
if (connect(cs, (struct sockaddr *)&a, sizeof(a)) < 0)
die("connect");
if (send(cs, msg, sizeof(msg), 0) < 0)
die("send");
close(cs);
pthread_join(th, NULL);
return 0;
}
------END PoC--------
Best regards,
Zihan Xi
Zihan Xi (1):
xfrm: espintcp: select receive path by skb protocol
net/xfrm/espintcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH net 1/1] xfrm: espintcp: select receive path by skb protocol
2026-11-16 15:52 [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion Zihan Xi
@ 2026-11-16 15:52 ` Zihan Xi
2026-11-25 10:53 ` [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion Sabrina Dubroca
1 sibling, 0 replies; 3+ messages in thread
From: Zihan Xi @ 2026-11-16 15:52 UTC (permalink / raw)
To: netdev, ipsec
Cc: steffen.klassert, herbert, davem, edumazet, pabeni, horms, sd,
vega, zihanx
An IPv6 socket can accept an IPv4 connection through a v4-mapped
address. Such a socket still receives IPv4 skbs, but espintcp selected
the XFRM receive path from the socket family.
Use the skb protocol when selecting the receive path so IPv4 packets are
not passed to the IPv6 XFRM parser.
Fixes: 26333c37fc28 ("xfrm: add IPv6 support for espintcp")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Signed-off-by: Zihan Xi <zihanx@nebusec.ai>
---
net/xfrm/espintcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
index 4052ae5bbb2e..ec37a32ecb00 100644
--- a/net/xfrm/espintcp.c
+++ b/net/xfrm/espintcp.c
@@ -48,7 +48,7 @@ static void handle_esp(struct sk_buff *skb, struct sock *sk)
}
local_bh_disable();
#if IS_ENABLED(CONFIG_IPV6)
- if (sk->sk_family == AF_INET6)
+ if (skb->protocol == htons(ETH_P_IPV6))
xfrm6_rcv_encap(skb, IPPROTO_ESP, 0, TCP_ENCAP_ESPINTCP);
else
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion
2026-11-16 15:52 [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion Zihan Xi
2026-11-16 15:52 ` [PATCH net 1/1] xfrm: espintcp: select receive path by skb protocol Zihan Xi
@ 2026-11-25 10:53 ` Sabrina Dubroca
1 sibling, 0 replies; 3+ messages in thread
From: Sabrina Dubroca @ 2026-11-25 10:53 UTC (permalink / raw)
To: Zihan Xi
Cc: netdev, ipsec, steffen.klassert, herbert, davem, edumazet, pabeni,
horms, vega
Hello,
2026-11-16, 15:52:28 +0000, Zihan Xi wrote:
> Historical QEMU run output:
I'm not sure what "historical" means here. Your reproducer will output
the same thing before/after the patch.
> accepted socket domain=10
> peer=::ffff:127.0.0.1 port=41512
> recv=0 errno=0
>
> The historical tracing additionally showed:
>
> xfrm6_rcv_encap <-espintcp_rcv
>
> and XfrmInNoStates increased by one (before=1004 after=1005 delta=1). The run
Which is expected either way since you haven't configured any xfrm states.
> followed the no-state/error path without a KASAN report, oops, or crash-log,
> so no crash-log is attached.
So this is just a "regular" bug where things don't work as expected,
right? No other issue after we pass the packet up? (still worth
fixing of course, the patch looks ok)
Earlier you say "the vulnerable path", and call the reproducer a PoC,
I want to be clear on the problem ("vulnerable" and "PoC" sound like a
security issue).
> We run the PoC in a 2 vCPU, 2 GB RAM x86 QEMU environment.
--
Sabrina
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 10:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 15:52 [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion Zihan Xi
2026-11-16 15:52 ` [PATCH net 1/1] xfrm: espintcp: select receive path by skb protocol Zihan Xi
2026-11-25 10:53 ` [PATCH net 0/1] xfrm: espintcp: fix IPv4/IPv6 receive path confusion Sabrina Dubroca
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox