From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net-next 01/13] netfilter: flowtable: do not hw offload flows in teardown state
Date: Tue, 17 Nov 2026 00:22:44 +0000 [thread overview]
Message-ID: <179487496421.3136.13242797618262399074@kernel.org> (raw)
In-Reply-To: <20261116001612.2806263-2-pablo@netfilter.org>
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 fix is incomplete.
- [Low] The commit message for "netfilter: flowtable: do not hw offload
flows in teardown state" fixes a real race in…
--
netfilter: flowtable: do not hw offload flows in teardown state
This commit changes nf_flow_offload_refresh() to check NF_FLOW_TEARDOWN
again after NF_FLOW_PENDING has been taken. If the flow is already being
torn down, the FLOW_CLS_REPLACE work is dropped instead of queued. The
fix depends on GC skipping flows that have NF_FLOW_PENDING set.
> Sashiko reports that refreshing hw offload from packet path is racy
> since the flow might be already torn down.
>
> Since commit 7c549fb7eecd ("netfilter: flowtable: generalize pending
> status bit"), GC skips flow entries that are still pending to be
> offloaded. Let's just check for the teardown status bit after the
> pending bit is set on to address this race.
[Severity: Low]
Should this have a Fixes: tag? The Sashiko report is credited in the
text, but there is no Reported-by: or Link: tag.
The fix only works because of this early return in
nf_flow_offload_gc_step():
if (test_bit(NF_FLOW_PENDING, &flow->flags))
return;
That return was added by 7c549fb7eecd. A stable backport without that
commit would leave the race open. Could the dependency be noted for
backporters?
The message also doesn't say what goes wrong. A hardware rule gets
reinstalled after GC's DESTROY, and the flow is then freed while that
rule is still in hardware.
Other fixes in this series do have Fixes: tags, for example
"netfilter: flowtable: purge entries immediately when destroying the
flowtable" and "netfilter: flowtable: do not scrub as crossing netns".
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6a..3a18fa48cadb0 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -1120,6 +1120,12 @@ void nf_flow_offload_refresh(struct nf_flowtable *flowtable,
> if (!offload)
> return;
>
> + if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
> + clear_bit(NF_FLOW_PENDING, &flow->flags);
> + kfree(offload);
> + return;
> + }
> +
> flow_offload_queue_work(offload);
> }
[Severity: High]
Is NF_FLOW_TEARDOWN the only bit that needs checking here?
NF_FLOW_CLOSING also leads to the hardware rule being removed. That bit
is still checked only in the caller, before NF_FLOW_PENDING is taken:
net/netfilter/nf_flow_table_core.c:flow_offload_refresh() {
...
if (likely(!nf_flowtable_hw_offload(flow_table)) ||
test_bit(NF_FLOW_CLOSING, &flow->flags))
return;
if (test_bit(NF_FLOW_HW, &flow->flags))
nf_flow_offload_refresh(flow_table, flow);
}
This is the same check-before-lock pattern the patch fixes for
TEARDOWN. Can the following happen?
CPU A (packet path)
flow_offload_refresh()
sees CLOSING == 0, HW == 1
stalls before test_and_set_bit(NF_FLOW_PENDING) in
nf_flow_offload_work_alloc()
CPU B (packet path)
nf_flow_state_check()
FIN/RST sets NF_FLOW_CLOSING
GC
nf_flow_offload_gc_step()
PENDING clear, teardown false, CLOSING && HW && !HW_DYING
nf_flow_offload_del()
takes PENDING, sets NF_FLOW_HW_DYING, queues FLOW_CLS_DESTROY
flow_offload_work_handler()
flow_offload_work_del() removes the rule, sets NF_FLOW_HW_DEAD
clears PENDING
CPU A resumes
nf_flow_offload_work_alloc()
test_and_set_bit(NF_FLOW_PENDING) succeeds
nf_flow_offload_refresh()
test_bit(NF_FLOW_TEARDOWN) is 0, queues FLOW_CLS_REPLACE
flow_offload_work_add()
puts the rule back in hardware, with no HW_DYING or HW_DEAD check
The flow now has CLOSING|HW|HW_DYING|HW_DEAD set and a live hardware
rule. GC never sends another DESTROY, because the CLOSING branch
requires !HW_DYING. When the flow later expires, nf_flow_offload_gc_step()
takes this path:
if (teardown) {
if (test_bit(NF_FLOW_HW, &flow->flags)) {
if (!test_bit(NF_FLOW_HW_DYING, &flow->flags))
nf_flow_offload_del(flow_table, flow);
else if (test_bit(NF_FLOW_HW_DEAD, &flow->flags))
flow_offload_del(flow_table, flow);
Does this leak the hardware rule? The flow and conntrack get freed, but
the rule stays installed with a cookie that points at freed memory.
Destroying the flowtable doesn't clean it up either.
nf_flow_table_do_purge(), added by the later "purge entries immediately
when destroying the flowtable" commit, skips the hardware purge when
NF_FLOW_HW_DEAD is set. No later patch in the series touches
flow_offload_refresh() or nf_flow_offload_refresh().
A wider interleaving could also give a use-after-free. Suppose a later
GC step reads PENDING == 0 just before CPU A's test_and_set_bit(). In
that same step the flow becomes a teardown (expired, ct dying, dst check
failure, or custom gc).
GC then sees the HW_DYING|HW_DEAD left over from the earlier DESTROY and
calls flow_offload_del(). The flow and ct are freed through call_rcu()
while the REPLACE work is still queued. flow_offload_work_handler() then
dereferences offload->flow, offload->flow->ct and offload->flow->flags
outside any RCU read section.
Would it work to also check NF_FLOW_HW_DYING (or NF_FLOW_CLOSING) here,
next to TEARDOWN? HW_DYING is always set while PENDING is held, before
the DESTROY work clears PENDING, so one check would cover both teardown
paths.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116001612.2806263-2-pablo%40netfilter.org
next prev parent reply other threads:[~2026-11-17 0:22 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 0:15 [PATCH net-next,v2 00/13] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 01/13] netfilter: flowtable: do not hw offload flows in teardown state Pablo Neira Ayuso
2026-11-16 0:23 ` netdev-bot+sinfo
2026-11-16 0:27 ` Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko [this message]
2026-11-16 0:16 ` [PATCH net-next 02/13] netfilter: flowtable: retrieve stats on flow deletion Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 03/13] net: ethernet: mtk_ppe: update " Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 04/13] net: airoha: " Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 05/13] netfilter: xt_time: fix monthday computation for dates past 2039 Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 06/13] netfilter: nft_flow_offload: do not offload multicast Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 07/13] netfilter: flowtable: purge entries immediately when destroying the flowtable Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 08/13] selftests: netfilter: nf_queue: drop the no-op loop initializer Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 09/13] netfilter: flowtable: do not scrub as crossing netns Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 10/13] netfilter: flowtable: tunnel device poisons h_source of fast-path frames Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 11/13] netfilter: flowtable: do not clear the offload bit twice Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 12/13] netfilter: nfnetlink_queue: make skb writable before writing NFQA_L2HDR Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 13/13] selftests: netfilter: add UDP flowtable offload test Pablo Neira Ayuso
2026-11-17 0:22 ` 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=179487496421.3136.13242797618262399074@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--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 \
--cc=pablo@netfilter.org \
/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