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 --- 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