Netdev 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; 3+ 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] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_exthdr: pull the IPv6 header before ipv6_find_hdr()
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-26  0:29 UTC (permalink / raw)
  To: Xiang Mei
  Cc: Florian Westphal, Phil Sutter, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	netfilter-devel, coreteam, netdev, linux-kernel, stable,
	co+85229ab197510ca7

On Wed, Nov 25, 2026 at 05:11:51PM -0700, Xiang Mei wrote:
> 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,

Are you referring to a skbuff with vlan offload or with the vlan tag
in the payload?

netdev calls pskb_may_pull() to ensure the IPv6 header is linear.

Then, this only works with the skb->protocol check on IPv6.

I find these text generated by LLM of very low quality for a human to
understand.

> 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	[flat|nested] 3+ messages in thread

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

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

On Thu, Nov 26, 2026 at 01:29:55AM +0100, Pablo Neira Ayuso wrote:
> On Wed, Nov 25, 2026 at 05:11:51PM -0700, Xiang Mei wrote:
[...]
> > Pull the header before the call, as act_ct, virtio_net_hdr_to_skb() and
> > nft_set_pktinfo_ipv6_ingress() already do.

I prefer this patch (see attachment).

Please, don't take, I will submit it myself including your
Reported-by: tag.

Thanks.

[-- Attachment #2: linearize-nh.patch --]
[-- Type: text/x-diff, Size: 1546 bytes --]

diff --git a/include/net/netfilter/nf_tables_ipv4.h b/include/net/netfilter/nf_tables_ipv4.h
index e715405a73cb..5df31948c42d 100644
--- a/include/net/netfilter/nf_tables_ipv4.h
+++ b/include/net/netfilter/nf_tables_ipv4.h
@@ -21,14 +21,13 @@ static inline void nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt)
 static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt,
 						  int nhoff)
 {
-	struct iphdr *iph, _iph;
 	u32 len, thoff, skb_len;
+	struct iphdr *iph;
 
-	iph = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb) + nhoff,
-				 sizeof(*iph), &_iph);
-	if (!iph)
+	if (!pskb_may_pull(pkt->skb, sizeof(*iph)))
 		return -1;
 
+	iph = ip_hdr(pkt->skb);
 	if (iph->ihl < 5 || iph->version != 4)
 		return -1;
 
diff --git a/include/net/netfilter/nf_tables_ipv6.h b/include/net/netfilter/nf_tables_ipv6.h
index d7b8c559b795..06c0a57d54f0 100644
--- a/include/net/netfilter/nf_tables_ipv6.h
+++ b/include/net/netfilter/nf_tables_ipv6.h
@@ -30,17 +30,16 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt, int n
 {
 #if IS_ENABLED(CONFIG_IPV6)
 	unsigned int flags = IP6_FH_F_AUTH;
-	struct ipv6hdr *ip6h, _ip6h;
 	unsigned int thoff = nhoff;
 	unsigned short frag_off;
+	struct ipv6hdr *ip6h;
 	u32 pkt_len, skb_len;
 	int protohdr;
 
-	ip6h = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb) + nhoff,
-				  sizeof(*ip6h), &_ip6h);
-	if (!ip6h)
+	if (!pskb_may_pull(pkt->skb, sizeof(*ip6h)))
 		return -1;
 
+	ip6h = ipv6_hdr(pkt->skb);
 	if (ip6h->version != 6)
 		return -1;
 

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

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

Thread overview: 3+ 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

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