From: netdev-bot+sashiko@kernel.org
To: florian.fainelli@broadcom.com
Cc: netdev@vger.kernel.org, pablo@netfilter.org, fw@strlen.de,
phil@nwl.cc, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
shuah@kernel.org, toshiaki.makita1@gmail.com,
linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org,
coreteam@netfilter.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY
Date: Sun, 22 Nov 2026 21:17:24 +0000 [thread overview]
Message-ID: <179538224441.3135.6950839726802616846@kernel.org> (raw)
In-Reply-To: <20261118201250.2075007-2-florian.fainelli@broadcom.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new NF_FLOW_HW_DYING guard in nf_flow_offload_work_alloc()
(net/netfilter/nf_flow_table_offload.c) does not close the bug class…
- [Low] The commit message describes the race mechanism and the affected
work types imprecisely.
--
netfilter: flowtable: do not queue offload work after DESTROY
This patch makes nf_flow_offload_work_alloc() refuse to queue any work
other than FLOW_CLS_DESTROY once NF_FLOW_HW_DYING is set. The goal is to
stop a packet path reader from queueing REPLACE work for a flow that GC
is already removing, because the offload worker could then use the flow
after it has been freed.
> once the DESTROY work has run and cleared the bit, a reader can take it
> again and queue a REPLACE (or STATS) work for a flow which is already
> being removed.
[Severity: Low]
Is the STATS part accurate? The packet path only reaches
nf_flow_offload_refresh() through flow_offload_refresh(), and that queues
FLOW_CLS_REPLACE.
nf_flow_offload_stats() has a single caller, nf_flow_offload_gc_step(),
and GC skips any flow that has NF_FLOW_PENDING set:
if (test_bit(NF_FLOW_PENDING, &flow->flags))
return;
GC also never runs concurrently with itself. So STATS work that GC queues
cannot race with GC freeing the same flow.
For STATS, the only effect of this patch is that GC stops queueing STATS
for CLOSING && HW && DYING flows whose hardware rule DESTROY has already
removed.
> GC removes a hardware flow after NF_FLOW_HW_DEAD is set, and frees it after
> an RCU grace period, which the reader can outlive in a preemptible RCU
> read-side section.
Could this be worded more precisely? A reader cannot outlive a grace
period that started while it was inside its read-side section, because
the call_rcu() in flow_offload_free() waits for it.
What outlives the grace period is the REPLACE work that the reader queued
on nf_flow_offload_add_wq before rcu_read_unlock().
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6a..62f460d38efa2 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -1088,6 +1088,19 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
> if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
> return NULL;
>
> + /* GC only removes a hardware flow after its DESTROY work has run, and
> + * NF_FLOW_PENDING keeps another one from being queued, so nothing can
> + * free the flow while this work is pending, unless DESTROY was queued
> + * before we took the pending bit. A reader which found the flow before
> + * it was torn down must not queue more work then, as the flow could be
> + * freed before that work runs.
> + */
> + if (cmd != FLOW_CLS_DESTROY &&
> + test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
> + clear_bit(NF_FLOW_PENDING, &flow->flags);
> + return NULL;
> + }
[Severity: High]
Does the claim that "nothing can free the flow while this work is pending"
hold for flows that GC frees through its software-only branch?
flow_offload_add() publishes both tuples in the rhashtable before
nf_flow_offload_add() sets NF_FLOW_HW:
net/netfilter/nf_flow_table_core.c:flow_offload_add() {
...
err = rhashtable_insert_fast(&flow_table->rhashtable,
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
nf_flow_offload_rhash_params);
...
nf_ct_refresh(flow->ct, NF_CT_DAY);
if (nf_flowtable_hw_offload(flow_table))
nf_flow_offload_add(flow_table, flow);
...
}
In that window, nf_flow_offload_gc_step() can decide to tear the flow
down while NF_FLOW_HW is still clear. The teardown can come from a dying
ct, a stale dst, or NF_FLOW_TEARDOWN set by another CPU after a FIN/RST
arrives on the already-published REPLY tuple. GC then takes this branch:
if (teardown) {
if (test_bit(NF_FLOW_HW, &flow->flags)) {
...
} else {
flow_offload_del(flow_table, flow);
}
That path removes the rhashtable entries, releases the dsts and calls
call_rcu() on the flow. It never takes NF_FLOW_PENDING and never sets
NF_FLOW_HW_DYING.
The creating CPU then carries on:
CPU1 (creator) CPU2 (GC)
flow_offload_add()
rhashtable_insert_fast(REPLY)
rhashtable_insert_fast(ORIGINAL)
nf_flow_offload_gc_step()
teardown, NF_FLOW_HW clear
flow_offload_del()
flow_offload_free()
call_rcu()
nf_flow_offload_add()
set_bit(NF_FLOW_HW)
nf_flow_offload_refresh()
nf_flow_offload_work_alloc()
test_and_set_bit(NF_FLOW_PENDING) succeeds
NF_FLOW_HW_DYING clear, new check passes
queue FLOW_CLS_REPLACE
Suppose the work runs after CPU1 leaves its RCU read-side section and the
grace period ends. Would flow_offload_work_handler() then use the freed
flow in flow_offload_work_add(), in nf_flow_offload_alloc(), in
set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status), and in
clear_bit(NF_FLOW_PENDING, &offload->flow->flags)?
If the work runs earlier, it seems it would still install a hardware rule
for a flow that is no longer in the table. GC would never DESTROY that
rule.
That is the same use-after-free and stale rule outcome the commit message
describes. As far as I can tell, no later change in this series touches
this path.
Would it make sense for GC's non-HW branch to claim NF_FLOW_PENDING, or
set a dying marker, before freeing the flow? Another option would be to
set NF_FLOW_HW before the flow is published.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118201250.2075007-1-florian.fainelli%40broadcom.com
next prev parent reply other threads:[~2026-11-22 21:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 20:12 [PATCH net 0/4] netfilter: flowtable: Preliminary fixes Florian Fainelli
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
2026-11-21 23:23 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko [this message]
2026-11-22 22:16 ` Pablo Neira Ayuso
2026-11-18 20:12 ` [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown Florian Fainelli
2026-11-21 23:10 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY Florian Fainelli
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown Florian Fainelli
2026-11-22 21:17 ` netdev-bot+sashiko
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=179538224441.3135.6950839726802616846@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=shuah@kernel.org \
--cc=toshiaki.makita1@gmail.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
all inboxes | Powered by JetHome®