Article View: linux.kernel.netdev
Article #20527Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 21:17
Date: Sun, 22 Nov 2026 21:17
156 lines
14174 bytes
14174 bytes
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
Technical Details
Message-ID:
<179538224441.3135.6950839726802616846@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368824-linux-kernel-netdev=dewy.ruReferences:
<20261118201250.2075007-2-florian.fainelli@broadcom.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368824-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Date: Sun, 22 Nov 2026 21:17:24 +0000 Organization: Usenet Network Message-ID: <179538224441.3135.6950839726802616846@kernel.org> References: <20261118201250.2075007-2-florian.fainelli@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3724946"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Nab5mTBhCyHQRzZvKhHePFoEkRk= sha256:+CXBMhDV6zcvNGAEq/0CrcLtmFZPVREcmNmlSlKdLdg= sha1:aI+kFiuo3Xejyg4R/CpcXGhsYRU= sha256:Iqi2Z1LQth8PWwqQdHNTqnixxMz/d4IQipl873qBvoM= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 543BE125D83; Mon, 23 Nov 2026 00:17:49 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 59HyBDO8mLxt; Mon, 23 Nov 2026 00:17:45 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-368824-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 523A9125D86; Mon, 23 Nov 2026 00:17:36 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 9EC39292BF; Sun, 22 Nov 2026 21:17:32 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1795382246; b=tJBKG6CqjmxYDJIzga+/5J/AAYXhKl3Lusg+sBnb28xRRSKe8kX7LM9vnaZ5tCG/oyVJ T1qNUDk5msnUExNanwbYCuhbf20HHauZspzOZHE17Oazrf2LhyBwwbrQMp6yHkKVMXUOk t5VYHA/aH0aa1KRiiqXI9VXX9cqX9VTGPA6pZ7cV0nJNCjw8HPPnNv3C3RtzXcnFLfqwp tX2j8/wlPt7DmmVxX/bBtBM/wzgSHi8W9gYmx89Qhg6mKs1FP6c1brYX2KsoIyIDRXbJn jqRepMMQe2YUVvtYjydWo3YyaEuNkCw8WlD+LULru9eVYXiL9KGNdR7kCNEFV4EI5/Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795382246; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=wRYkt/8bNJ83BACxmsyULTPzgzoASxC6Ha6Jh0WjC7A=; b=AXEPffPdw6K2KtUkrUgTTuiQHkgTCeZH3bFOZDl09kIMMxeOt8PLNKM1ATX2EOopUnXI vmZT4gx3IzdGRGpvcEklZQF+N+MFSv/p0aHJO5ZFSttyk6sWmP9FPXnXJmadgVynjbQZf fkdDfMTPtqXLcIjOI+P0AC0byBavu2Urp8OYjfBXMn0tY0nyQnw1PfEq0/dJ5OOCcnvO9 SuNcQrBllZu+f+Z3afCJUO+1rwfRObzF+xnMomDm+WgJKhuuSmCLNhBmcmADbfiH9wNeB XTeEQQ62ti9StvHeAABDb5CaXHUAu3by9gNEVKMg8xm6mStGrHi+Pk3I2tmBtnhOghw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WIuYE0bU; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C22CE606A337; Sun, 22 Nov 2026 21:17:26 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WIuYE0bU X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795382246; b=P7Wxl6byJkFlvZQaUCgRZ47MlAL4ZSPCvWgMNnPAHj5afWr8/tCFj0MxXOUerOhQE22L Zd07LIocIxNJX6/2Q7/aX9dU2iiBxb6KIbGxSEy6yO510QCbDaQ83YZhkZd+ARcEeLQzO H4/l/8Yo+5ZZzRrtMVMZlvuGzGlqkrqsnqFMIh+4+2Pp4taDYLkK0ovWn8I6vFVgi/lNc x9AXo9f/bwzHeJG0qjbjd1wUDmoszXWdtoQyozBXa6C8m9vkTXO9TbXlhbvBJFE90gH+k cu/y4PZG6NUNfO1fRBeA7uuBQx2tfuaDhmwoh50FYVkZJNBvmYJ9WUg1nlNEQ6rPZNw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795382246; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=wRYkt/8bNJ83BACxmsyULTPzgzoASxC6Ha6Jh0WjC7A=; b=djIljtAJTsGhxpRYWLZekoajM/KDERRdjYwY2v7NDLlCdRC0+vzDaNBPIikzWlyu7ijm FjlxSU9dMLKPDzzE8NxQkMrXEMOgkPhWyBd693DIbTluMzkm/noDdqizx3HPicw7Dxo2q tMe5qec1gVUsaE6Sxv2fWqHjnxRyt1evB/FWietT8dB+rcjTIpYSEJanVVP4LowyIkw2m LztGlsuSGmEkOn6cF+tfUvBrvG8PyVLkKXD3F/hPbOFagRHcUDoIXU4vcJ/F7LDktWhaf 6VtGuPMd4ZVvGDun83a+WF/H9lZDT/O+kjtKWS2cGilhHCQFSae14WITpu5J9DzV3Mg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WIuYE0bU; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E158A606A31A; Sun, 22 Nov 2026 21:17:25 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D50C81F000CA; Sun, 22 Nov 2026 21:17:24 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795382245; bh=wRYkt/8bNJ83BACxmsyULTPzgzoASxC6Ha6Jh0WjC7A=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=WIuYE0bUeVh7j/c1tgbS8K7qmz+PGL4nSuV/JONTuW33K7yFbi2NGfmizYXYOwafi JA+MwHWxErlgc6mrZyIqiGsgfk3I2U4B5VjWTH+vaSi2vvsMZybYLWWhLL/UC/QzHk YlHwcmLGb14znJdpbxCyPXT0kh0Gz/VgpcN9+ThZj1PNL7vPXwYM/SFRyfF8rGuZk6 5OilF8sZ+iWuAd7Us//Utc027aBFPDob3yimedL8MaIghJ+codIQTo1sfC8TFAXwLN 6P/fpcBrLX2vxr43cAR/Em08metddXH4ctFZZe1WF3OxTbEfZ8EGOXczhmuBiMNO9/ 9sXw1OITOSvnw== X-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 X-In-Reply-To: <20261118201250.2075007-2-florian.fainelli@broadcom.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list