The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nft_exthdr: pull the IPv6 header before ipv6_find_hdr()
@ 2026-11-26  0:11 Xiang Mei
  2026-11-26  0:29 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Xiang Mei @ 2026-11-26  0:11 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Florian Westphal, Phil Sutter, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman
  Cc: netfilter-devel, coreteam, netdev, linux-kernel, stable,
	co+85229ab197510ca7, Xiang Mei

nft_exthdr_ipv6_eval() checks only skb->protocol before calling
ipv6_find_hdr(), whose prologue reads ipv6_hdr(skb)->nexthdr from the
linear area without a pull. The expression is usable from every family,
and the netdev ingress hook does not normalise the skb: an 18-byte
802.1Q frame with an ETH_P_IPV6 inner type has no IPv6 header, so the
read lands past skb_tail_pointer(), and an AF_PACKET frame larger than a
page leaves the header in frags, so it lands past skb_headlen(). With
NFT_EXTHDR_F_PRESENT, it decides the result, and 256 "exthdr ipv6 type=T
exists counter" rules hand it to an unprivileged user running in its own
user and network namespace.

Raising the device headroom puts the skb head in kmalloc-1k. With freed
struct net_bridge_port objects sprayed under it, a uid 1000 run on
current mainline read back kernel-written data, byte 2 of
WORK_STRUCT_NO_POOL in query_queue_work.data, and bits 16..23 of the
query_queue.prev self-pointer, i.e. of direct-map heap addresses:

  read offset 570 = byte 2 of the 8-byte slot at 568
    freed net_bridge_port (32 probes):
      byte 0xe0 (224): 15/32
  read offset 554 = byte 2 of the 8-byte slot at 552
    freed net_bridge_port (32 probes):
      byte 0x15 ( 21): 2/32
      byte 0x21 ( 33): 2/32
      byte 0x59 ( 89): 1/32
      byte 0xb2 (178): 2/32
      byte 0xc3 (195): 1/32
      byte 0xd8 (216): 2/32
      ...

Pull the header before the call, as act_ct, virtio_net_hdr_to_skb() and
nft_set_pktinfo_ipv6_ingress() already do. For the ipv6 and inet
families ipv6_rcv() has already pulled it, so this is a length check.

Cc: stable@vger.kernel.org
Fixes: 96518518cc41 ("netfilter: add nftables")
Reported-by: co+85229ab197510ca7@bugs.sh
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
 net/netfilter/nft_exthdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
index 861bab93f435..a7c2f7553af8 100644
--- a/net/netfilter/nft_exthdr.c
+++ b/net/netfilter/nft_exthdr.c
@@ -52,7 +52,8 @@ static void nft_exthdr_ipv6_eval(const struct nft_expr *expr,
 	unsigned int offset = 0;
 	int err;
 
-	if (pkt->skb->protocol != htons(ETH_P_IPV6))
+	if (pkt->skb->protocol != htons(ETH_P_IPV6) ||
+	    !pskb_network_may_pull(pkt->skb, sizeof(struct ipv6hdr)))
 		goto err;
 
 	err = ipv6_find_hdr(pkt->skb, &offset, priv->type, NULL, NULL);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26  2:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  0:11 [PATCH nf] netfilter: nft_exthdr: pull the IPv6 header before ipv6_find_hdr() Xiang Mei
2026-11-26  0:29 ` Pablo Neira Ayuso
2026-11-26  0:39   ` Pablo Neira Ayuso
2026-11-26  1:43     ` Xiang Mei
2026-11-26  2:23       ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox