* [PATCH] netfilter: bpf: reject a repeated bpf_ct_set_nat_info()
@ 2026-11-19 16:33 Andrey Misiurov
2026-11-20 11:00 ` Fernando Fernandez Mancera
0 siblings, 1 reply; 2+ messages in thread
From: Andrey Misiurov @ 2026-11-19 16:33 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Jozsef Kadlecsik, Phil Sutter, Fernando Fernandez Mancera,
netfilter-devel, coreteam, linux-kernel, Andrey Misiurov
bpf_ct_set_nat_info() checks the l3 protocol and the manip type but not
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); the ct is still
unconfirmed, so the second call passes the confirmed check and reaches
WARN_ON(nf_nat_initialized()) in nf_nat_setup_info():
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. It is the same BPF-reachable WARN class
that 16d464013ec2 closed for an invalid manip value; the repeated-setup
case was left open.
Reject the call with -EEXIST when NAT for that manip is already initialised,
before nf_nat_setup_info() is reached.
Fixes: 16d464013ec2 ("netfilter: bpf: reject invalid NAT manipulation types")
Signed-off-by: Andrey Misiurov <amisiurov@cloudlinux.com>
---
Found during a backport review.
Reproduced on almalinux9 5.14.0-687.61.1 with a BPF_PROG_TEST_RUN SCHED_CLS
prog that calls bpf_ct_set_nat_info() with NF_NAT_MANIP_SRC twice: without
the fix the second call returns -ENOMEM and WARNs as above; with the fix it
returns -EEXIST and there is no WARN.
net/netfilter/nf_nat_bpf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/netfilter/nf_nat_bpf.c b/net/netfilter/nf_nat_bpf.c
--- a/net/netfilter/nf_nat_bpf.c
+++ b/net/netfilter/nf_nat_bpf.c
@@ -42,6 +42,10 @@
if (manip != NF_NAT_MANIP_SRC && manip != NF_NAT_MANIP_DST)
return -EINVAL;
+ /* a repeated manip on an unconfirmed ct would WARN */
+ if (nf_nat_initialized(ct, manip))
+ return -EEXIST;
+
memset(&range, 0, sizeof(struct nf_nat_range2));
range.flags = NF_NAT_RANGE_MAP_IPS;
range.min_addr = *addr;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] netfilter: bpf: reject a repeated bpf_ct_set_nat_info()
2026-11-19 16:33 [PATCH] netfilter: bpf: reject a repeated bpf_ct_set_nat_info() Andrey Misiurov
@ 2026-11-20 11:00 ` Fernando Fernandez Mancera
0 siblings, 0 replies; 2+ messages in thread
From: Fernando Fernandez Mancera @ 2026-11-20 11:00 UTC (permalink / raw)
To: Andrey Misiurov, Pablo Neira Ayuso, Florian Westphal
Cc: Jozsef Kadlecsik, Phil Sutter, netfilter-devel, coreteam, linux-kernel
On 11/19/26 5:33 PM, Andrey Misiurov wrote:
> bpf_ct_set_nat_info() checks the l3 protocol and the manip type but not
> 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); the ct is still
> unconfirmed, so the second call passes the confirmed check and reaches
What confirmed check passes? I think there is no such check at all.
> WARN_ON(nf_nat_initialized()) in nf_nat_setup_info():
>
> 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. It is the same BPF-reachable WARN class
> that 16d464013ec2 closed for an invalid manip value; the repeated-setup
> case was left open.
Yes, although this is a completely different issue.
>
> Reject the call with -EEXIST when NAT for that manip is already initialised,
> before nf_nat_setup_info() is reached.
>
> Fixes: 16d464013ec2 ("netfilter: bpf: reject invalid NAT manipulation types")
I think this fixes tag is incorrect. That fix was checking a completely
different problem. In any case it would be:
Fixes: 0fabd2aa199f ("net: netfilter: add bpf_ct_set_nat_info kfunc helper")
> Signed-off-by: Andrey Misiurov <amisiurov@cloudlinux.com>
> ---
> Found during a backport review.
>
> Reproduced on almalinux9 5.14.0-687.61.1 with a BPF_PROG_TEST_RUN SCHED_CLS
> prog that calls bpf_ct_set_nat_info() with NF_NAT_MANIP_SRC twice: without
> the fix the second call returns -ENOMEM and WARNs as above; with the fix it
> returns -EEXIST and there is no WARN.
>
> net/netfilter/nf_nat_bpf.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/netfilter/nf_nat_bpf.c b/net/netfilter/nf_nat_bpf.c
> --- a/net/netfilter/nf_nat_bpf.c
> +++ b/net/netfilter/nf_nat_bpf.c
> @@ -42,6 +42,10 @@
> if (manip != NF_NAT_MANIP_SRC && manip != NF_NAT_MANIP_DST)
> return -EINVAL;
>
> + /* a repeated manip on an unconfirmed ct would WARN */
This comment is a bit too verbose. Can we just drop it? The check is
simple enough to be self-documented.
In addition, please use [PATCH nf] for the next revision of this patch
so we know we tree should we use for the fix.
Thanks,
Fernando.
> + if (nf_nat_initialized(ct, manip))
> + return -EEXIST;
> +
> memset(&range, 0, sizeof(struct nf_nat_range2));
> range.flags = NF_NAT_RANGE_MAP_IPS;
> range.min_addr = *addr;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 11:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 16:33 [PATCH] netfilter: bpf: reject a repeated bpf_ct_set_nat_info() Andrey Misiurov
2026-11-20 11:00 ` Fernando Fernandez Mancera
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®