netfilter: nftables: restrict linklayer and network header writes
authorFlorian Westphal <fw@strlen.de>
Tue, 9 Jun 2026 11:51:54 +0000 (13:51 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 30 Jun 2026 04:45:53 +0000 (06:45 +0200)
commitdf07998dfd40796a05fff7ffea2661ad65ed42a7
tree8b5d2617f3c4377e54d0b1119d71ddc98529a641
parent54f34607d184c1cc056c59a5b3d86d96dd6a515c
netfilter: nftables: restrict linklayer and network header writes

Don't permit arbitrary writes to linklayer and network header data.
Several spots in network stack trust header validation performed in
ipv4/ipv6 before PRE_ROUTING hook.

For linklayer, allow writes for netdev ingress. For other hooks, only
allow link layer writes that do not spill into network header.

For network header, check the offset/length combinations:
 - changing dscp requires store at offset 0 for checsum fixups, so
 make sure ip version + length field isn't altered.
 - ip6 dscp starts directly after the version field, so make sure it
   remains 6.

Several of these checks could already be done at rule insertion time.
Risk is that this might cause ruleset load failures for existing
rulesets. With this change such writes are silently skipped and packet
passes unchanged.

Transport and inner header bases are not checked / restricted.

Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/nft_payload.c