Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_tables: set pktinfo->thoff at AH header if found

Phil Sutter reports that IPv6 AH header matching is broken. From
userspace, nft generates bytecode that expects to find the AH header at
NFT_PAYLOAD_TRANSPORT_HEADER both for IPv4 and IPv6. However,
pktinfo->thoff is set to the inner header after the AH header in IPv6,
while in IPv4 pktinfo->thoff points to the AH header indeed. This
behaviour is inconsistent. This patch fixes this problem by updating
ipv6_find_hdr() to get the IP6_FH_F_AUTH flag so this function stops at
the AH header, so both IPv4 and IPv6 pktinfo->thoff point to the AH
header.

This is also inconsistent when trying to match encapsulated headers:

1) A packet that looks like IPv4 + AH + TCP dport 22 will *not* match.
2) A packet that looks like IPv6 + AH + TCP dport 22 will match.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

+4 -2
+4 -2
include/net/netfilter/nf_tables_ipv6.h
··· 9 9 struct sk_buff *skb, 10 10 const struct nf_hook_state *state) 11 11 { 12 + unsigned int flags = IP6_FH_F_AUTH; 12 13 int protohdr, thoff = 0; 13 14 unsigned short frag_off; 14 15 15 16 nft_set_pktinfo(pkt, skb, state); 16 17 17 - protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, NULL); 18 + protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags); 18 19 if (protohdr < 0) { 19 20 nft_set_pktinfo_proto_unspec(pkt, skb); 20 21 return; ··· 33 32 const struct nf_hook_state *state) 34 33 { 35 34 #if IS_ENABLED(CONFIG_IPV6) 35 + unsigned int flags = IP6_FH_F_AUTH; 36 36 struct ipv6hdr *ip6h, _ip6h; 37 37 unsigned int thoff = 0; 38 38 unsigned short frag_off; ··· 52 50 if (pkt_len + sizeof(*ip6h) > skb->len) 53 51 return -1; 54 52 55 - protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, NULL); 53 + protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags); 56 54 if (protohdr < 0) 57 55 return -1; 58 56