From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org,
pabeni@redhat.com, edumazet@google.com, horms@kernel.org,
fw@strlen.de, ja@ssi.bg
Subject: [PATCH net 11/13] netfilter: flowtable: publish GC-visible tuple last
Date: Mon, 10 Aug 2026 21:06:19 +0200 [thread overview]
Message-ID: <20260810190621.894119-12-pablo@netfilter.org> (raw)
In-Reply-To: <20260810190621.894119-1-pablo@netfilter.org>
From: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
nf_flow_table_iterate() only treats original-direction tuple nodes as
owning entries. Publishing the original node first lets GC observe and
free a flow while flow_offload_add() is still inserting the reply node.
Publish the reply node first and the original node last so GC never
sees a partially installed flow.
KASAN can trigger slab-use-after-free read and write reports in the
flowtable/rhashtable path (rht_deferred_worker, jhash, flow_offload_del,
flow_offload_lookup, etc.).
Fixes: ac2a66665e23 ("netfilter: add generic flow table infrastructure")
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
Assisted-by: Codex:gpt-5
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_flow_table_core.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index b66e65439341..8b1165f2b5a4 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -332,17 +332,18 @@ int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
flow->timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow);
err = rhashtable_insert_fast(&flow_table->rhashtable,
- &flow->tuplehash[0].node,
+ &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
nf_flow_offload_rhash_params);
if (err < 0)
return err;
+ /* GC only iterates original-direction entries; publish original last. */
err = rhashtable_insert_fast(&flow_table->rhashtable,
- &flow->tuplehash[1].node,
+ &flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
nf_flow_offload_rhash_params);
if (err < 0) {
rhashtable_remove_fast(&flow_table->rhashtable,
- &flow->tuplehash[0].node,
+ &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
nf_flow_offload_rhash_params);
return err;
}
--
2.47.3
next prev parent reply other threads:[~2026-08-10 19:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 19:06 [PATCH net 00/13] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 01/13] netfilter: ipset: fix refcount race between list:set GC and swap Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 02/13] netfilter: bridge: release template ct on non-IP path Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 03/13] ipvs: add totalconns for dest Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 04/13] ipvs: properly update the overload flag on dest edit Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 05/13] ipvs: separate destination availability state Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 06/13] netfilter: nf_conntrack: defer invalid log until after unlock Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 07/13] netfilter: nfnetlink_log: wait for rcu grace period before freeing pernet state Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 08/13] ipvs: clear IPv4 options after rebasing tunnel ICMP errors Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 09/13] ipvs: revalidate ihl to prevent out-of-bounds access Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 10/13] netfilter: nf_tables_offload: suppress WARN_ON_ONCE for ENOMEM in abort path Pablo Neira Ayuso
2026-08-10 19:06 ` Pablo Neira Ayuso [this message]
2026-08-10 19:06 ` [PATCH net 12/13] netfilter: ipset: fix list type element drift bug Pablo Neira Ayuso
2026-08-10 19:06 ` [PATCH net 13/13] netfilter: ipset: let destroy callbacks adjust ext mem size Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260810190621.894119-12-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox