Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Florian Fainelli" <florian.fainelli@broadcom.com>
Cc: "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
	<devicetree@vger.kernel.org>,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes
Date: Tue, 17 Nov 2026 22:33:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-219751@kernel.org> (raw)
In-Reply-To: <20261116222519.1416501-4-florian.fainelli@broadcom.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] netfilter: flowtable: race in
  nf_flow_table_extend_ct_timeout() on teardown
It also noticed 2 related pre-existing issues this patch does not
introduce:
- [Critical] netfilter: flowtable: use-after-free in
  flow_offload_work_handler() [1]
- [Medium] netfilter: flowtable: missing GRE timeout fixup in
  flow_offload_fixup_ct() [2]
--

commit b8d898f427299669723392171cb227b67d8f7493
Author: Florian Fainelli <florian.fainelli@broadcom.com>

netfilter: flowtable: retain offload ownership until deletion completes

This commit delays clearing IPS_OFFLOAD_BIT from flow_offload_teardown()
to flow_offload_del() so a replacement flow cannot claim the conntrack
entry before hash removal and asynchronous hardware deletion finish, and
adds KUnit tests covering flow teardown ownership.

> diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
> index 2aa2647ed9df0..4c82097cd50bc 100644
> --- a/net/netfilter/nf_flow_table_core.c
> +++ b/net/netfilter/nf_flow_table_core.c
> @@ -393,12 +393,15 @@ static void flow_offload_del(struct nf_flowtable *flow_table,
>  	rhashtable_remove_fast(&flow_table->rhashtable,
>  			       &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
>  			       nf_flow_offload_rhash_params);
> +	/* Release admission only after both hashes and async hardware state
> +	 * have gone. An older owner must not clear its replacement's status.
> +	 */
> +	clear_bit_unlock(IPS_OFFLOAD_BIT, &flow->ct->status);
>  	flow_offload_free(flow);
>  }
>  
>  void flow_offload_teardown(struct flow_offload *flow)
>  {
> -	clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);

[Severity: Medium]
Can nf_flow_table_extend_ct_timeout() now race with flow_offload_teardown()
and overwrite the repaired ct->timeout back to NF_CT_DAY?

Previously, flow_offload_teardown() cleared IPS_OFFLOAD_BIT before calling
flow_offload_fixup_ct(), and nf_flow_table_extend_ct_timeout() relied on
testing IPS_OFFLOAD_BIT after sampling ct->timeout to abort if teardown had
already lowered the timeout.  With IPS_OFFLOAD_BIT kept set until
flow_offload_del(), a teardown that runs after nf_flow_offload_gc_step()
samples NF_FLOW_TEARDOWN as false is no longer detected:

CPU0 (datapath)                   CPU1 (GC workqueue)
                                  nf_flow_offload_gc_step()
                                    teardown = test_bit(NF_FLOW_TEARDOWN, ...)
                                    // false
flow_offload_teardown(flow)
  test_and_set_bit(NF_FLOW_TEARDOWN, ...)
  flow_offload_fixup_ct(flow)
    nf_ct_refresh(ct, timeout)
                                    nf_flow_table_extend_ct_timeout(flow->ct)
                                      ct_timeout = READ_ONCE(ct->timeout)
                                      test_bit(IPS_OFFLOAD_BIT, &ct->status)
                                      // still true
                                      cmpxchg(&ct->timeout, ct_timeout,
                                              new_timeout)  <-- sets NF_CT_DAY

Because NF_FLOW_TEARDOWN is already set, flow_offload_fixup_ct() will not
run again when the flow is deleted, leaving the torn-down conntrack entry
with a 24-hour timeout if no further slow-path packets arrive.  Checking
NF_FLOW_TEARDOWN on flow->flags inside nf_flow_table_extend_ct_timeout()
after reading ct->timeout would close this window.

>  	if (!test_and_set_bit(NF_FLOW_TEARDOWN, &flow->flags))

[Severity: Critical]
This problem wasn't introduced by this patch, but can flow_offload_refresh()
queue hardware offload work after teardown has started [1], causing a
use-after-free in flow_offload_work_handler()?

flow_offload_refresh() checks NF_FLOW_CLOSING before calling
nf_flow_offload_refresh(), but does not check NF_FLOW_TEARDOWN or
NF_FLOW_HW_DYING:

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);
}

If the datapath refreshes a flow while the garbage collector tears it down
and deletes it, the queued FLOW_CLS_REPLACE work item can outlive the flow:

CPU0 (datapath)                   CPU1 (GC & workqueue)
flow_offload_refresh()
  nf_flow_offload_work_alloc()
    test_and_set_bit(NF_FLOW_HW_PENDING,
                     &flow->flags)
                                  nf_flow_offload_gc_step()
                                    nf_flow_offload_del(flow_table, flow)
                                    ...
                                    flow_offload_del(flow_table, flow)
                                      flow_offload_free(flow)
                                  flow_offload_work_handler()
                                    clear_bit(..., &offload->flow->flags)
                                      <-- use-after-free

>  		flow_offload_fixup_ct(flow);
>  }

[Severity: Medium]
This problem wasn't introduced by this patch, but does
flow_offload_fixup_ct() leave offloaded IPPROTO_GRE connections with an
NF_CT_DAY timeout on teardown [2]?

flow_offload_add() sets ct->timeout to NF_CT_DAY for all offloaded flows,
including GRE v0 flows admitted by nft_flow_offload_eval(), but
flow_offload_fixup_ct() only restores timeouts for IPPROTO_TCP and
IPPROTO_UDP and returns early for other protocols.  If no further packets
go through the slow path, a torn-down GRE conntrack entry stays in the
table for up to 24 hours instead of expiring after the GRE conntrack
timeout.

[1] https://sashiko.dev/#/bug/linux-f53f0af6-15c0-4a1b-b9e3-375ce214f143
[2] https://sashiko.dev/#/bug/linux-e64b7493-5a95-4afe-8a7a-6a28c113967a

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116222519.1416501-1-florian.fainelli@broadcom.com?part=3

  reply	other threads:[~2026-11-17 22:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:25 [PATCH net-next 0/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 1/9] net: ethernet: bgmac: validate RX length against the DMA packet capacity Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 2/9] netfilter: flowtable: reject non-host IPv4 packets before lookup Florian Fainelli
2026-11-17 22:33   ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 3/9] netfilter: flowtable: retain offload ownership until deletion completes Florian Fainelli
2026-11-17 22:33   ` sashiko-bot [this message]
2026-11-16 22:25 ` [PATCH net-next 4/9] dt-bindings: net: describe the Northstar flow accelerator Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 5/9] net: dsa: add Broadcom FA metadata and IPv4 exception paths Florian Fainelli
2026-11-17 22:33   ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 6/9] net: flow_offload: allow drivers to validate and invalidate cached paths Florian Fainelli
2026-11-16 22:25 ` [PATCH net-next 7/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-11-17 22:33   ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 8/9] net: add KUnit coverage for FA and flowtable path validation Florian Fainelli
2026-11-17 22:34   ` sashiko-bot
2026-11-16 22:25 ` [PATCH net-next 9/9] docs: net: document Northstar FA setup and NAT qualification Florian Fainelli
2026-11-16 22:38 ` [PATCH net-next 0/9] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload netdev-bot+sinfo
2026-11-16 22:45   ` 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=sashiko-outbox-219751@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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