All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH nf] netfilter: xt_nat: drop packet when conntrack is missing or invalid
       [not found] <CALZdHNroZj41WOBd9g4+csZ91h_yEzHP496Sm_esQypv-mztVA@mail.gmail.com>
@ 2026-11-27  9:05 ` Florian Westphal
  2026-11-28 17:40   ` jack
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2026-11-27  9:05 UTC (permalink / raw)
  To: Jack Satu Rumah Net; +Cc: netfilter-devel, coreteam

Jack Satu Rumah Net <Jack@saturumah.net> wrote:
> Hello Netfilter maintainers,
> 
> When an SNAT or DNAT target in net/netfilter/xt_nat.c processes a packet
> where nf_ct_get() returns NULL or ctinfo is outside the allowed states,
> WARN_ON() only logs a warning and still calls nf_nat_setup_info(),
> resulting in a NULL pointer dereference in nf_ct_net(ct).

> Drop the packet with NF_DROP after WARN_ON_ONCE() when conntrack is
> missing or ctinfo does not match the target's allowed states across
> SNAT and DNAT targets (v0, v1, v2).
> 
> Signed-off-by: Jack Satu Rumah Net <jack@saturumah.net>
> ---
> Observed on Linux v6.12.119 (commit
> e2e4b92c2b2a3ae78423cb343951cb5d2241b405)
> with CONFIG_NF_NAT=y when packets marked NOTRACK in the raw table hit a
> SNAT or DNAT rule.

You need to figure out why and how such packets end up in xt_nat
frontend code.

skb with no conntrack must not ever end up in nat frontend code
to begin with.

nf_nat_inet_fn() returns NF_ACCEPT if ct is NULL, so I have no idea
how what you describe can happen.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH nf] netfilter: xt_nat: drop packet when conntrack is missing or invalid
  2026-11-27  9:05 ` [PATCH nf] netfilter: xt_nat: drop packet when conntrack is missing or invalid Florian Westphal
@ 2026-11-28 17:40   ` jack
  0 siblings, 0 replies; 2+ messages in thread
From: jack @ 2026-11-28 17:40 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel, coreteam

Pada 2026-11-27 16:05, Florian Westphal menulis:
> Jack Satu Rumah Net <Jack@saturumah.net> wrote:
>> Hello Netfilter maintainers,
>> 
>> When an SNAT or DNAT target in net/netfilter/xt_nat.c processes a 
>> packet
>> where nf_ct_get() returns NULL or ctinfo is outside the allowed 
>> states,
>> WARN_ON() only logs a warning and still calls nf_nat_setup_info(),
>> resulting in a NULL pointer dereference in nf_ct_net(ct).
> 
>> Drop the packet with NF_DROP after WARN_ON_ONCE() when conntrack is
>> missing or ctinfo does not match the target's allowed states across
>> SNAT and DNAT targets (v0, v1, v2).
>> 
>> Signed-off-by: Jack Satu Rumah Net <jack@saturumah.net>
>> ---
>> Observed on Linux v6.12.119 (commit
>> e2e4b92c2b2a3ae78423cb343951cb5d2241b405)
>> with CONFIG_NF_NAT=y when packets marked NOTRACK in the raw table hit 
>> a
>> SNAT or DNAT rule.
> 
> You need to figure out why and how such packets end up in xt_nat
> frontend code.
> 
> skb with no conntrack must not ever end up in nat frontend code
> to begin with.
> 
> nf_nat_inet_fn() returns NF_ACCEPT if ct is NULL, so I have no idea
> how what you describe can happen.

Florian,

You are right, and I retract the patch. I traced the actual reachability 
on my tree (v6.12.119, commit e2e4b92c2b2a) and the vulnerable path you 
described is fully closed. Two facts from the tree:

1. `xt_nat_target_reg[0]` (revision 0) has `.family = NFPROTO_IPV4`. 
Instantiating it from a bridge-family rule via `nft_compat` returns 
`-EOPNOTSUPP` because `xt_request_find_target(NFPROTO_BRIDGE, "SNAT", 
0)` finds no matching registration.

2. Revisions 1 and 2 use `xt_nat_checkentry()`, which rejects every 
family outside `{ NFPROTO_IPV4, NFPROTO_IPV6, NFPROTO_INET }` with 
`-EINVAL`:

```c
switch (par->family) {
case NFPROTO_IPV4:
case NFPROTO_IPV6:
case NFPROTO_INET:
         break;
default:
         return -EINVAL;
}
```

So there is no way to reach `xt_snat_target_v0/v1/v2` with `ct == NULL` 
through `nft_compat` from an unsupported family. `nf_nat_setup_info()` 
still dereferences `nf_ct_net(ct)` without a NULL check, but the only 
path to it would be through a family that checkentry refuses to install.

I confirmed this with a bridge-family `nft_compat` rule using `xt target 
SNAT`. The kernel rejects the batch with `-EOPNOTSUPP` (rev 0, family 
field mismatch) or `-EINVAL` (rev 1/2, checkentry guard). No KASAN 
splat, no NULL dereference.

My original commit message was also wrong about the ingress path. 
NOTRACK packets do not reach the NAT target through the standard 
iptables NAT table either, because `nf_nat_inet_fn()` returns 
`NF_ACCEPT` for `ct == NULL`. I was chasing a symptom whose root cause I 
had misidentified.

Patch withdrawn. Thanks for the correction — it forced me to actually 
read the reachability chain, which was educational.

Jack

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 17:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CALZdHNroZj41WOBd9g4+csZ91h_yEzHP496Sm_esQypv-mztVA@mail.gmail.com>
2026-11-27  9:05 ` [PATCH nf] netfilter: xt_nat: drop packet when conntrack is missing or invalid Florian Westphal
2026-11-28 17:40   ` jack

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.