From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Fainelli <florian.fainelli@broadcom.com>
Cc: netdev@vger.kernel.org, Florian Westphal <fw@strlen.de>,
Phil Sutter <phil@nwl.cc>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Toshiaki Makita <toshiaki.makita1@gmail.com>,
open list <linux-kernel@vger.kernel.org>,
"open list:NETFILTER" <netfilter-devel@vger.kernel.org>,
"open list:NETFILTER" <coreteam@netfilter.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<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 00:23:48 +0100 [thread overview]
Message-ID: <awIoBL3Rz5GbNs1l@chamomile> (raw)
In-Reply-To: <20261118201250.2075007-2-florian.fainelli@broadcom.com>
On Wed, Nov 18, 2026 at 12:12:47PM -0800, Florian Fainelli wrote:
> nf_flow_offload_refresh() can be reached by a packet path reader which
> looked the flow up before it was torn down. NF_FLOW_PENDING keeps the
> DESTROY work from being queued while another work item is pending, but
> 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.
>
> 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. The queued work then dereferences a freed flow and
> the flowtable, and can program the hardware again with a rule keyed by
> the freed flow's cookie.
>
> NF_FLOW_HW_DYING is set when DESTROY is queued, and DESTROY needs
> NF_FLOW_PENDING, so a work item which holds the pending bit and finds
> NF_FLOW_HW_DYING clear prevents DESTROY from being queued until it
> completes. Check it after taking the pending bit, and do not queue
> anything other than DESTROY when it is set.
>
> Not reproduced: this is a race between a long RCU read-side section and
> the GC and offload workers. Found by review of a related change.
>
> Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
> ---
> net/netfilter/nf_flow_table_offload.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6..62f460d38efa 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;
> + }
Maybe address by checking for the _CLOSING + _TEARDOWN flag? If those
are set on, then hardware will be scheduled for removal soon.
I guess there is also another hypothetical case where _CLOSING is set
on, but HW_DYING was not set on yet?
Probably the HW_DYING bit can go away, _CLOSING was added for hw
offload specifically, to schedule the removal in hardware while the
flow still remains with IPS_OFFLOAD.
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 11434cfb105b..7104d332d98a 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -1132,7 +1132,8 @@ void nf_flow_offload_refresh(struct nf_flowtable *flowtable,
if (!offload)
return;
- if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
+ if (test_bit(NF_FLOW_CLOSING, &flow->flags) ||
+ test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
clear_bit(NF_FLOW_PENDING, &flow->flags);
kfree(offload);
return
> +
> offload = kmalloc_obj(struct flow_offload_work, GFP_ATOMIC);
> if (!offload) {
> clear_bit(NF_FLOW_PENDING, &flow->flags);
> --
> 2.53.0
>
>
next prev parent reply other threads:[~2026-11-21 23:23 UTC|newest]
Thread overview: 7+ 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 [this message]
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-18 20:12 ` [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY Florian Fainelli
2026-11-18 20:12 ` [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown Florian Fainelli
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=awIoBL3Rz5GbNs1l@chamomile \
--to=pablo@netfilter.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=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