Re: [PATCH nf] netfilter: bpf: reject a repeated bpf_ct_set_nat_info()
From: Fernando Fernandez Mancera
Date: Tue Nov 24 2026 - 05:09:46 EST
On 11/20/26 6:13 PM, Andrey Misiurov wrote:
bpf_ct_set_nat_info() checks the l3 protocol and the manip type and thenReviewed-by: Fernando Fernandez Mancera <fmancera@xxxxxxx>
calls nf_nat_setup_info(). It does not check whether NAT for that manip was
already set up.
A BPF program holding an unconfirmed nf_conn___init can call it twice with
the same manip. The first call sets IPS_SRC_NAT_DONE (or IPS_DST_NAT_DONE).
On the second call nf_nat_setup_info() hits WARN_ON(nf_nat_initialized()):
WARNING: CPU: 1 PID: 21673 at net/netfilter/nf_nat_core.c:674 nf_nat_setup_info+0x251/0x2b0 [nf_nat]
CPU: 1 PID: 21673 Comm: loader
RIP: 0010:nf_nat_setup_info+0x251/0x2b0 [nf_nat]
Call Trace:
bpf_ct_set_nat_info+0x81/0xb0 [nf_nat]
bpf_prog_e4b00ba35d2f7a6b_nf_skb_ct_nat_twice+0x110/0x13f
bpf_test_run+0x172/0x2e0
bpf_prog_test_run_skb+0x2e5/0x4f0
__sys_bpf+0x7f8/0xe90
__x64_sys_bpf+0x1a/0x30
do_syscall_64+0x5f/0xe0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
With panic_on_warn this is a DoS.
Reject the call with -EEXIST when NAT for that manip is already initialised,
before nf_nat_setup_info() is reached.
Fixes: 0fabd2aa199f ("net: netfilter: add bpf_ct_set_nat_info kfunc helper")
Signed-off-by: Andrey Misiurov <amisiurov@xxxxxxxxxxxxxx>
Thanks!