🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17533

Re: [PATCH net-next 01/13] netfilter: flowtable: do not hw offload flows in teardown state

#17533
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 00:22
156 lines
13716 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 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
Technical Details
Message-ID: <179487496421.3136.13242797618262399074@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.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-364848-linux-kernel-netdev=dewy.ru
References: <20261116001612.2806263-2-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.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-364848-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179487496421.3136.13242797618262399074@kernel.org>
References: <20261116001612.2806263-2-pablo@netfilter.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2202459"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:1uc1CQFx/LisF9KMyL1sIpoB4ew= sha256:qIswLbqJgA/MGx1IVCt8EXqJerIrplbBPz+X2cx1BKs=
	sha1:k6J92FOC22p0F+ZxZG3bQxSTjro= sha256:p3cNJJdAwRP8JKIjEW8HouWxrY/8iuQW3i5UqyT7bx0=
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 C8D55114DD8; Tue, 17 Nov 2026 03:23:08 +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 L_1Fu1GgeOq1;
	Tue, 17 Nov 2026 03:23:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364848-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 82E52114DD6; Tue, 17 Nov 2026 03:22:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id AFCE62DEC9; Tue, 17 Nov 2026 00:22:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794874966;
	b=RBxg/cR0tUYOhA4FqZvCzvbIodxPMsI6Brwqb3UE8A0kqvPLtKg7kAu+V4XuUBoCwJjQ
	 oUl28b250yHm6qaxbwiNhj1szo1Tv6vgMnSujfaFabwiVXJvteDM4ReyJXr4yumfLkLWL
	 hkwWRGlkxg58M/mRnYf+KUzMMC2i5wPFOw60QlfDazrBFPXrmo2NTfEo2PsAy/gRZGTVG
	 ZLA7XQBBuq09MpynvWwNnfK+0uC8SxgQtNjogX24kSV5xTNnvmT4tdnyXWACTjsDl7L0K
	 ZNz4PQw8bi+ZQlsHT4CQ+3uPop73GvjXvXrGkgCzN+QKbn3e925AMaYdQqX/ilJMZAA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794874966;
	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=TA8pVBNu8nx+baK0cXowkwFgcToksZ44AVyEJH19w9I=;
	b=iBhDeg1dBOr4g/zY2qxZaZpgcoDxrWXJLsRlQsyXOULhzf4CFTem6Tr9BigXFTz9oR/v
	 GFntNK5O3G1KQRGdozEpYDaAU+wtPRTlPx0PVga2MGQPosiiXxqVHNNF3A4GDu4nPNgPU
	 hQ7HuoUXtvYkZhjRv/kx+5Kp/doSSOMq/+srOyZFc1Md3CaHNsEGkxHfT6IK9fskCGsMY
	 4n6r7UcS6PzwuEPGLpb+ay4BAI9FymEwfykUs9HOqhRLwEdVU7B/TlfnX+b2kJQdhKTZM
	 SHRmAFP48q7LLy7gYcOH5vZDzwJorqWZ5fjmEco+/QMXunltVMN8bxO9Vyd/E69XuPg==
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=irloyEoC;
	arc=pass header.oldest-pass=0 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 34D36606A338;
	Tue, 17 Nov 2026 00:22:46 +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=irloyEoC
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=1794874965;
	b=ARGzofHTQMWCmEHzbjdXE7OgIcvqbht4k+T6qUfaGrMsi4aXlkP3kFTg3/QkJqlNhcsn
	 UQDCRQ0qznaTv3ziSn7npYWirypHMNP8yW4JjLhEsdHHLcXqAFVd3Hi704Y4rhHdZ3fu8
	 MbgFa0AT3Q/AbOvR3f+8CHM7NyHWVN1xJfCGu7QbHtYNheGtCgBF2N5EnMLX9bCo4hdoK
	 S7nuNorDsozCp78TWBnxBb3gPfj8nxQX7Sw6FbxBqWeDdUpP4dHoWc9VhBpKVxcKdmzBg
	 d42Ha847yYXHmjBMUPp5PPvBiln3/qtqxSeM6TjXZYBg/CRaZUYmGEZpx8UXdOzmpGw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794874965;
	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=TA8pVBNu8nx+baK0cXowkwFgcToksZ44AVyEJH19w9I=;
	b=g/x4CXYcCCODvbwgT2Dnw/EpU5N9bLAjzqDMP6WhLO6suRto3mdTjdx2WVtn9c5pLFfS
	 HkerONQf4HzKhbZoojdFCaPFQ6IV7x593Owie3W2xR3MdtX+jTKOi1+gsrAUBuU79ggm+
	 v6PgFza23wzEVGKZVaaMG9D9H5pFGj0YfOPKWnm1r9I4gu/1BKyaCBG1w9QAzBw48U8dA
	 CXYAThq0wkFQRy/K3l5o3v7s+qvkB6woQ7QyKV4IK0WyAdCRdOiYCBz9p+nep63CiVIlO
	 8X+Gzu51Res5F6YM/JrL1qzNZ79pkkpoG7DRbvt2NDbea5/4VgFewvnIALUGxt4hpjQ==
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=irloyEoC;
	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 55964606A323;
	Tue, 17 Nov 2026 00:22:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A65051F000C4;
	Tue, 17 Nov 2026 00:22:44 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794874965;
	bh=TA8pVBNu8nx+baK0cXowkwFgcToksZ44AVyEJH19w9I=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=irloyEoCW/Gb35zEeK2u45KqK7neb5aO4nb4FSS447jhm1WB82KXYBMpo9/v0MZrA
	 Jfj0KQ67c/zKD4b3fxFHeCGbD7My0lzh1Itd5/gJAZwdIQ5sAcLnsl8YqAUdiuarYA
	 fCP237nh0Zu16Ctx1hXH0PcH2ptpiNC5jFC6MJBw+wL5raRDhP/yfMl68guzKG5g9G
	 kxs1qIfUB75adHBLtK5iJaH26k8O08ICUNhRK5Ji3Cga22LF6gI5B7Nf/Mw3xc1C73
	 dn4jxIzm7RaBWAEBuReKc0JQGQj980aB0QxKSU+9Tky1SrxQ4VgpsESsifN6HibbHX
	 4tXMgdyhsqQaA==
X-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
X-In-Reply-To: <20261116001612.2806263-2-pablo@netfilter.org>
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