Skip to content

Commit

Permalink
netfilter: nf_tables_ipv6: consider network offset in netdev/egress v…
Browse files Browse the repository at this point in the history
…alidation

From netdev/egress, skb->len can include the ethernet header, therefore,
subtract network offset from skb->len when validating IPv6 packet length.

Fixes: 42df6e1 ("netfilter: Introduce egress hook")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Pablo Neira Ayuso committed Aug 27, 2024
1 parent 5fd0628 commit 70c261d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/net/netfilter/nf_tables_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
struct ipv6hdr *ip6h, _ip6h;
unsigned int thoff = 0;
unsigned short frag_off;
u32 pkt_len, skb_len;
int protohdr;
u32 pkt_len;

ip6h = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb),
sizeof(*ip6h), &_ip6h);
Expand All @@ -43,7 +43,8 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
return -1;

pkt_len = ntohs(ip6h->payload_len);
if (pkt_len + sizeof(*ip6h) > pkt->skb->len)
skb_len = pkt->skb->len - skb_network_offset(pkt->skb);
if (pkt_len + sizeof(*ip6h) > skb_len)
return -1;

protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);
Expand Down

0 comments on commit 70c261d

Please sign in to comment.