* [PATCH nf] netfilter: nf_nat: don't kill an unconfirmed conntrack on oif change
@ 2026-12-03 9:49 Xingyuan Mo
0 siblings, 0 replies; only message in thread
From: Xingyuan Mo @ 2026-12-03 9:49 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal, Phil Sutter, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman
Cc: open list:NETFILTER, open list:NETFILTER, Xingyuan Mo, stable
nf_nat_inet_fn() runs nf_ct_kill_acct() on the conntrack when a
connection that has already been set up for masquerade shows up at
POST_ROUTING with an output device other than the one the masquerade
target recorded. Nothing guarantees that this conntrack was confirmed
by then.
ipmr forwards a multicast packet by cloning the skb for every vif and
running each clone through NF_INET_FORWARD and ip_output(), so every
clone reaches POST_ROUTING with its own output device while the
conntrack created at PRE_ROUTING is still unconfirmed, because
ip_mr_input() is a dst.input handler and LOCAL_IN with its nf_confirm
hook is never crossed. If the first clone gets masqueraded and is then
dropped by a postrouting hook that runs before nf_confirm, the second
clone finds NAT already initialised for the connection, takes the
oif_changed path and calls nf_ct_delete() on the unconfirmed
conntrack. clean_from_lists() then unlinks
tuplehash[IP_CT_DIR_ORIGINAL].hnnode, whose pprev is NULL until
confirmation, and writes through the NULL pointer.
An unconfirmed conntrack is not linked into any list, so there is
nothing to delete. Drop the packet and leave the conntrack to be
released by the last skb holding a reference to it.
KASAN report:
BUG: KASAN: null-ptr-deref in __nf_ct_delete_from_lists+0x1b3/0x290
Write of size 8 at addr 0000000000000000 by task poc119/577
Call Trace:
__nf_ct_delete_from_lists+0x1b3/0x290
nf_ct_delete.part.0+0x119/0x320
nf_ct_kill_acct+0xbe/0xd0
nf_nat_inet_fn+0x2aa/0x450
nf_nat_ipv4_out+0x96/0x200
nf_hook_slow+0x69/0x140
ip_mc_output+0x413/0x500
ip_mr_output+0x119/0x810
ipmr_queue_fwd_xmit.constprop.0+0x512/0x520
ip_mr_forward+0x5d9/0x5e0
ip_mr_input+0x273/0x730
Fixes: c65ef8dc7b1c ("netfilter: nf_nat: Also handle non-ESTABLISHED routing changes in MASQUERADE")
Cc: stable@vger.kernel.org
Signed-off-by: Xingyuan Mo <hdthky0@gmail.com>
---
net/netfilter/nf_nat_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 5329881ce2fff..f9e9a6e5b1594 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -959,6 +959,9 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb,
return nf_nat_packet(ct, ctinfo, state->hook, skb);
oif_changed:
+ if (!nf_ct_is_confirmed(ct))
+ return NF_DROP;
+
nf_ct_kill_acct(ct, ctinfo, skb);
return NF_DROP;
}
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-03 9:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 9:49 [PATCH nf] netfilter: nf_nat: don't kill an unconfirmed conntrack on oif change Xingyuan Mo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox