diff options
| author | Florian Westphal <fw@strlen.de> | 2026-10-29 17:54:45 +0100 |
|---|---|---|
| committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2026-11-05 13:31:11 +0100 |
| commit | d1bb235aa409a4e5aeba6c748d953d948625b1e9 (patch) | |
| tree | e4a59524cd86bff38ef6f1fb87e913cf0ce779a2 /rust/kernel/alloc/kvec | |
| parent | 17c2e41736b62cfe444c64d67860b1fbc1e886ac (diff) | |
netfilter: nat: zero newrange before filling it in
nf_nat_masquerade_ipv4(), nf_nat_masquerade_ipv6(), netmap_tg4() and
netmap_tg6() each build a stack-local struct nf_nat_range2 from the
caller-supplied range, inheriting range->flags unmodified. Two of them
only memset() the min_addr/max_addr members, the other two don't
memset() anything at all, so newrange.base_proto is left as stack
garbage.
If the inherited flags include NF_NAT_RANGE_PROTO_OFFSET,
nf_nat_l4proto_unique_tuple() reads range->base_proto.all to compute
the NAT port offset. Neither the NETMAP nor the MASQUERADE targets
mask the flags field in their checkentry callback, so this
uninitialized stack value can end up feeding the NAT port selection.
The per-member memset()s are not enough: they have to enumerate every
field that must be cleared, and base_proto was missed when
NF_NAT_RANGE_PROTO_OFFSET/base_proto was added to the struct. memset()
the whole struct instead, so every member is covered regardless of
which ones get explicitly assigned afterwards.
There are other places that miss this, but those hardcode .flags so
nat core won't read from the uninitialized fields.
C99 initializers would be preferrable, but this is a more intrusive
change. Lets followup in nf-next and convert others as well.
This is an LLM finding.
Fixes: 2eb0f624b709 ("netfilter: add NAT support for shifted portmap ranges")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'rust/kernel/alloc/kvec')
0 files changed, 0 insertions, 0 deletions
