Re: [PATCH nf] netfilter: nft_exthdr: pull the IPv6 header before ipv6_find_hdr()
From: Pablo Neira Ayuso
Date: Wed Nov 25 2026 - 19:39:26 EST
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.
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;