๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16820

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

#16820
From: Pablo Neira Ayuso
Date: Sun, 15 Nov 2026 23:12
175 lines
15105 bytes
Hi,

On Sat, Nov 14, 2026 at 03:23:38AM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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 patch only partly closes the packet-path refresh race.
> - [Low] The commit fixes a race found by an automated reporter ('Sashiko
>   reports...') but carries no Fixes:, Reported-by: or Closes: tag.
> 
> --
> 
> netfilter: flowtable: do not hw offload flows in teardown state
> 
> This commit makes nf_flow_offload_refresh() check NF_FLOW_TEARDOWN again
> after NF_FLOW_PENDING has been acquired. The goal is to stop the packet
> path from queueing a hardware refresh for a flow that is going away. It
> relies on GC skipping flows that have NF_FLOW_PENDING set, which came in
> with commit 7c549fb7eecd.
> 
> > Sashiko reports that refreshing hw offload from packet path is racy
> > since the flow might be already going away.
> >
> > 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]
> This isn't a bug, but should this have Fixes:, Reported-by: and Closes:
> tags for the report?
> 
> The fix only works on trees where nf_flow_offload_gc_step() already skips
> flows with NF_FLOW_PENDING set:
> 
> 	if (test_bit(NF_FLOW_PENDING, &flow->flags))
> 		return;
> 
> That check came from commit 7c549fb7eecd. A stable backport to a tree
> without that commit would leave the race open.
> 
> Could the message record this dependency? Could it also state the
> consequence, which is offload work queued on a flow that GC frees, i.e. a
> possible use-after-free?
> 
> > 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]
> Does this close the race for flows that are only in the NF_FLOW_CLOSING
> state?

This patch is intended to address the TEARDOWN race only as described.

> GC also sends a hardware DESTROY for a CLOSING flow while TEARDOWN is
> still clear. This happens in nf_flow_offload_gc_step():
> 
> 	} else if (test_bit(NF_FLOW_CLOSING, &flow->flags) &&
> 		   test_bit(NF_FLOW_HW, &flow->flags) &&
> 		   !test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
> 		nf_flow_offload_del(flow_table, flow);
> 
> On the packet path, flow_offload_refresh() is the only place that tests
> CLOSING, and it does so before PENDING is taken:
> 
> 	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);
> 
> Could this sequence happen?
> 
> CPU B (packet path)
> flow_offload_refresh()
>   sees CLOSING == 0 and NF_FLOW_HW set
>   <stalls before test_and_set_bit(NF_FLOW_PENDING)>
> 
> CPU A
> nf_flow_state_check() on FIN/RST
>   sets NF_FLOW_CLOSING

It seems CPU A is also on packet path. Two TCP packets of the same
flow going through different CPUs is unlikely to happen. This also
assumes preemptible softirq, ie. PREEMPT_RT.

I will have closer look to search for possible issues with the CLOSING
state but that this patch is specifically aiming at the TEARDOWN state
only.

> GC
> nf_flow_offload_gc_step()
>   nf_flow_offload_del()
>     takes PENDING, sets NF_FLOW_HW_DYING, queues DESTROY
> flow_offload_work_del()
>   removes the rule, sets NF_FLOW_HW_DEAD
>   PENDING is cleared
> 
> CPU B resumes
> nf_flow_offload_refresh()
>   nf_flow_offload_work_alloc() wins PENDING
>   test_bit(NF_FLOW_TEARDOWN) == 0
>   flow_offload_queue_work() with FLOW_CLS_REPLACE
> 
> flow_offload_work_add() does not check NF_FLOW_HW_DYING or
> NF_FLOW_HW_DEAD. It installs the hardware rule again and sets
> IPS_HW_OFFLOAD_BIT.
> 
> Nothing clears HW_DYING or HW_DEAD after that. When the flow later
> expires, the teardown branch in nf_flow_offload_gc_step() goes straight
> to flow_offload_del() and sends no new DESTROY:
> 
> 		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);
> 
> Would the re-installed rule then stay in the driver and hardware after
> the flow and its conntrack entry are freed? Its cookie is the address of
> the freed tuple, so a new flow allocated at the same address could
> collide with it.
> 
> There seems to be a worse interleaving as well:
> 
> 1. GC reads PENDING == 0 at the top of nf_flow_offload_gc_step().
> 2. CPU B wins PENDING and reads TEARDOWN == 0.
> 3. GC calls flow_offload_teardown(). HW_DYING and HW_DEAD are already set
>    from the CLOSING DESTROY, so GC frees the flow through
>    flow_offload_del() without taking PENDING.
>
> Can the queued REPLACE work then run on a flow that was freed via
> call_rcu()?
> 
> The window is narrow. It still looks reachable on PREEMPT_RT, where
> softirq is preemptible, or under vCPU preemption. The FIN/RST that starts
> it comes from the network.

A follow up patch could possibly discard refreshing entries for
fin/rst packets, but this is unrelated to this patch.

> NF_FLOW_HW_DYING is set while PENDING is held, and it is published before
> PENDING is cleared. Would re-checking NF_FLOW_HW_DYING (and/or
> NF_FLOW_CLOSING) here, after PENDING is acquired, cover every state in
> which GC has already issued the DESTROY?
> 
> Later patches in the series don't appear to change
> nf_flow_offload_refresh() or flow_offload_refresh().
> 
> -- 
> Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113031251.2437074-2-pablo%40netfilter.org
Technical Details
Message-ID: <avo8doGLhLtsvSIV@chamomile>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363906-linux-kernel-netdev=dewy.ru
References: <20261113031251.2437074-2-pablo@netfilter.org> <179462661878.2199510.10033227088688888386@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363906-linux-kernel-netdev=dewy.ru
From: pablo@netfilter.org (Pablo Neira Ayuso)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 01/15] netfilter: flowtable: do not hw offload
 flows in teardown state
Date: Mon, 16 Nov 2026 00:12:54 +0100
Organization: Usenet Network
Message-ID: <avo8doGLhLtsvSIV@chamomile>
References: <20261113031251.2437074-2-pablo@netfilter.org>
 <179462661878.2199510.10033227088688888386@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1925089"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tPJBU/k8gnLQJ1nfIKHcNkXiV0I= sha256:zjepBhHW6Op04xPe06GGnnmCN6E0lBA1z2YtEN5HHdk=
	sha1:ugdh15/ql02h/6zdWsPsBKioAHs= sha256:76nK1qL5qM60UcDi7kll11yUKLglcpDzSjldJgyoVDw=
Content-Disposition: inline
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 389F5114A9F; Mon, 16 Nov 2026 02:13:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	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=netfilter.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 kLT5Nn9k1_RK;
	Mon, 16 Nov 2026 02:13:27 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-363906-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=netfilter.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 25960114922; Mon, 16 Nov 2026 02:13:18 +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 C7000269A2; Sun, 15 Nov 2026 23:13:14 +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=1794784394;
	b=k66DK0I8lb2Chq/SDDq9qVV15mSlV3wq0glzEHAjGzXJlkdZ2KA9paFSrd2Xq7cCTyXx
	 3/1AoRj+z0QaVo00JMQ7oAj032Cco2h8MSwV3LdAKL18dC6gUyiVB02H6QQFCsJRG1htX
	 zdGBEgUHWWrMT/PI3VeIb9wUrpGKBthnEjLUecCE51TZYTT3lLI4+8MgGU2eM5zuP8LyF
	 uMglF70cWc0+frUrTWgDofODKDS+OYZIveb6tsVc3B3wK3crgf1uXXLbrblbdwTFxMDB0
	 cMjpT7d6CSPZsddFXeS52oauuSU5Q2cU4I7RvGbyleHd2pc1s92hZzY1t03ZmNEdt4w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794784394;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:Date:
	 From:To:Cc:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To;
	bh=AZvjtH6H70KE39bWF+l9SI/XMWJOGMAp/FHL80ErtWU=;
	b=WoxHv8omibzNIIotmH5C8oYTr6Shi7gzcZdUPzCo9kOxQKUbOrA07PGaI34KgbY17bdI
	 UMr9TnvdQnQNfZtOX069xmppASru+4Cp672o35oO1AFh0MFcx0BFNHq2HEQdpb7EfKfTw
	 mZmKPe+YPUL4NM0I3NvnGMFtulNUIfgvWXfstFpy6U8dHL2gqBw8/tVqPQbH1N7lMc7zV
	 nHhPflzVz1TUvgXoObqn7fmNIvP6rrsWVOb2SGQYHxc8NqfX1ZrHneAZhQzI1gJ2Rb1o3
	 1tXfbiZscdi01Aldw+avPqV5Zr2humvuZ1VizCHa1dFkcNV+aPS5/wiHQszpSj0lzxQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=gUhPa12I;
	dmarc=none header.from=netfilter.org;
	spf=pass smtp.mailfrom=netfilter.org;
	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 1414A606A332;
	Sun, 15 Nov 2026 23:13:14 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=gUhPa12I
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.190.124
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794784388;
	b=xlfOVcVD/EH+EJneaumzjvm1OQCREjFcT/wx+DggM8u9VeNuN3VO/KV27dW/R/1eqeWA
	 UGZshq4510p4kjb4awgiGoQccfJjfTiGM3ivsoGgy2dss987V8h6DuTkX0e0/W3YXvKpN
	 di5Bo6+vt9QK1qvJLrRHrSH75hmRXQ/eQP3VWrzSf+of7APutJ7XUOzlcJ6peCL72D3CB
	 7ipX7oqYO8Ioh1Bo0fXfhYNIHkvqk/3jIqUADDT7Z6IPoSH+bQAPaMlEDmSt3yJ/Af5ta
	 mnvdtnV00rH9Lmn5JfSnOzbTwn+GLgC2Osf0RIFp/bI0hwN37OlLJIR1sh1LFB82/oA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794784388;
	h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To:X-Spam-Status:
	 X-Spam-Checker-Version;
	bh=AZvjtH6H70KE39bWF+l9SI/XMWJOGMAp/FHL80ErtWU=;
	b=Mq34XZfoTZFaHo+SmMldDXHpBTICsmMDM65az+1XQF9/zAHSESJaUv4FwDswJ7q94xh6
	 1mm2hxm6fMZJKryO7BZTUt+2JXR3CLmyE963snR7Tpvo2vIpGquAuMoGt8mw7TuYhvvKK
	 wtx/kd44exLgd662+aA1q1GTBRUZ4semR+CD1eV7WGRbTvdx6Ada29riwB2ybmSoj1ojQ
	 XcwHZnIRG9HYzAoeBOdmyvaHEEwK3sqcdXQR0BYJqIe9j7tlksxxBix8H2zMz+id2/LXn
	 HhzMzk5TJ7Ttec0KfSWUDW/OIl9HsY2MY13m0InRw+wwZQgsz6VaEJYS33qzkrSc3Dg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=netfilter.org;
	spf=pass smtp.mailfrom=netfilter.org;
	dkim=pass header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=gUhPa12I;
	arc=none smtp.remote-ip=217.70.190.124
X-Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id CB3A7606A323;
	Sun, 15 Nov 2026 23:13:06 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CB3A7606A323
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org;
	s=2025; t=1794784378;
	bh=AZvjtH6H70KE39bWF+l9SI/XMWJOGMAp/FHL80ErtWU=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To:From;
	b=gUhPa12IUp4JC2tSOOBn58UOFYI49T/jpnjOjq48fL1MFsGh670gnzRPNKJWR3zDt
	 68XI5rn/ZwKLHTbqh+irmToiDY80AdCs7rOtXQYbmr/zGNG2wZUQa37EoF86cZa/NW
	 uxdLNLBJR+soxumIHhOPeCBpWrBKFZH1OhkmDPuRskUZPdKH7DiNnY6oltFXI/gJZx
	 phvme3WvmTLhxeDUlFMkeDQKomUyndT+On2pDOItAa+jfiZJkCze/79IShUyzem8YM
	 S4jQ8kwODmGX5Qpa2342tDp9kPTnRhg4eWH8Wec/hGDVTzlutOJKQkWi9KmlNtCvlV
	 snlQwcmU6Pmdg==
X-Received: from netfilter.org (mail-agni [217.70.190.124])
	by mail.netfilter.org (Postfix) with UTF8SMTPSA id CE40760060;
	Mon, 16 Nov 2026 00:12:57 +0100 (CET)
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-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
X-In-Reply-To: <179462661878.2199510.10033227088688888386@kernel.org>