🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20287

Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY

#20287
From: Pablo Neira Ayuso
Date: Sat, 21 Nov 2026 23:23
84 lines
12310 bytes
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
> 
> 
Technical Details
Message-ID: <awIoBL3Rz5GbNs1l@chamomile>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368521-linux-kernel-netdev=dewy.ru
References: <20261118201250.2075007-1-florian.fainelli@broadcom.com> <20261118201250.2075007-2-florian.fainelli@broadcom.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368521-linux-kernel-netdev=dewy.ru
From: pablo@netfilter.org (Pablo Neira Ayuso)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work
 after DESTROY
Date: Sun, 22 Nov 2026 00:23:48 +0100
Organization: Usenet Network
Message-ID: <awIoBL3Rz5GbNs1l@chamomile>
References: <20261118201250.2075007-1-florian.fainelli@broadcom.com>
 <20261118201250.2075007-2-florian.fainelli@broadcom.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Info: usenet.network;
	logging-data="3520884"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NRuVgsvCGGeAuHIqSIr8KOi9Z5s= sha256:YsR6+7fAys4VK06DhGqIaIqW5dS6q4etzwiFFI+S9Ik=
	sha1:LJH8fI3E0GXPxdlvW1JGHHMMr8A= sha256:LEJJMBKwnEcHbHmT3Ewr/ZHJpT618VRPenJSlrBcNt4=
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 0585F115C34; Sun, 22 Nov 2026 02:24:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, URIBL_BLOCKED=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 HPGUIf1ztuRK;
	Sun, 22 Nov 2026 02:24:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368521-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 05923115C25; Sun, 22 Nov 2026 02:23:58 +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 7F4DB36474; Sat, 21 Nov 2026 23:23:55 +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=1795303434;
	b=u8VnAy/V3PaFruwB1yZe+HIdxbnNvd+iNibkp0i1li7PnwjVOdGgYZRTqNz/XUo1Hmim
	 5dN8WZHLNCOBpM6gPbH00FRnuv8OGsm9/OPKOA92Uz7yeN4L/SaDBInFLi+vS5LANZnXy
	 1NrDm6uuV8nK8ADgNtWk5XIaDVQRIj8fcJTvdTlw8yXWjD39l4+HJ0jMDXhxyaUViM1La
	 vyBKDC5amfgix9knROTruqXrBAtvq0zVZz4ZRmciP1nptkvRDrKp4qicfQv3TVkw0yKlg
	 mpLewBuAkn0CzRkjDTEye8oYW3CHxs2B0uTSI4ZP+Can7YKz+MZ0Oh2J2z9Gq1BtRZg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795303434;
	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:In-Reply-To;
	bh=fiedK0LMLpg949+WbK0ZI33jcOksdkyv7tc4RWl8y2A=;
	b=B91yFvAOE/heLhrC3GUgGme4I8Qh5Dn2CUrokazapLznXkL6mHFcald66XQD32NAzTen
	 XcTGK5SHRUI8HXBA/b4D8c7VVI8C8kC0qWbsNyhyzg3UsdqSU0lUBl89o0iL1Bn9zPuKw
	 TfgKtEqkdLXrGMOEa0Uo7uzGqV2PT3B6q4xIh4d/fc5UXtvDIb7WwfgYvH0fgZSXxw+fe
	 uogN4vj2niNLO3CeubUwJsMtTDmzAx2pYxbT4N2p6zvF62x3mfPkGwjIZU89W65pt6RXN
	 Xa2Gl8Co7duhKi/1KUi5a3DpnYo+Ysz6jrVccTjOVanlLkqGfp7h/vn1EadKVmf+Fww==
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=Mjx+VZY6;
	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 55893606A33E;
	Sat, 21 Nov 2026 23:23:54 +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=Mjx+VZY6
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=1795303433;
	b=CJer7Vo6w+cVO3mjimKaGkxqq24FbzVG8xTRqLoUXy4gOEwK5LpCl/3ogG0TOcWLoYoZ
	 jc75E4sdLWHvWS4y4eqvLeYuq1IzinNq046bv07BiVktDGHxGg5k4t/IY+sIdTrVmiKKe
	 NQfEtWV3/bh5NWpt0XsGMdfdEIwzVB2NEZGWV5t0wIQ/gg4mzE+Ya2vtaA0v19215iBdY
	 5HGCo+0A+kDZU918H6lUs46EJ/fphDymkmQExXyOwIQjI1xiIjI0tSYhYKpVP+Y99h+NV
	 QA/zQinI7CC+4pDU29ze+Anb5Nh0f6iSYyr1YEVjHoCMt3bMOPG9mAbB33NLzuYyqgQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795303433;
	h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:MIME-Version:Content-Type:Content-Disposition:
	 In-Reply-To:X-Spam-Status:X-Spam-Checker-Version;
	bh=fiedK0LMLpg949+WbK0ZI33jcOksdkyv7tc4RWl8y2A=;
	b=mZnpf2sJHN/BLHjN8L8Xw5IJHRi0K2okhcg/xrStlttF0zJTU9nD+OMG4olZRtghuR4Q
	 OwV72FFLxrPDXffQ9h9L2lkoyoa6Rl/1DTlysuV/hqrHc91u0UMYVHZ6RVonVB2Et+dK1
	 OXTjZJTR7+JS4eDzZPejGOrHr6z56fBa55HLw3b1A9gU/yOq9Y/gd6a3V+1y1RmXizEFo
	 PWRvlhaCBGF3Ja3QX77eUzOvPeLUqu36uDtOhuNWb16/NLqxaUJ1jZp4eWJAmHi3rLSxJ
	 AVtDlLLjhmyAyVxzQWFEMcD/ohvvv5Pvjp+poAGvYAD+UG/Wmd1nsjMSG6QBO8+FauQ==
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=Mjx+VZY6;
	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))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id EF5C6606A320;
	Sat, 21 Nov 2026 23:23:52 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF5C6606A320
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=1795303430;
	bh=fiedK0LMLpg949+WbK0ZI33jcOksdkyv7tc4RWl8y2A=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To:From;
	b=Mjx+VZY6SWzg/KaoyDuuSmFdlq4sBo+hlSCL36KiOWf6n2mE/5L9B6niEydtAleOl
	 EsRkJSahZ9cBoBznJ++9fso4zUqu6BZ/iqjMSKsfZKJ1GWhCAoQ5hPy9vEM2UV29wE
	 16ONdISWmn/t6imvu/MYuKesEBeB7+o85WN37KlfeInE7FyGz4m03DjvqkiAe8IdYW
	 9DmMOUDGQDjR5Q7oWjyo9qM8ThXajcpQgc4Z86OSyD1asAKrFyR4VdhvnMK5pXBYml
	 OT30tEid/wmyGpU0rX2a7BLC91sgzqJlnyp1PbpaKW/mqbVBbYyj0LnUDUei+luow8
	 QttcYlDqqSZqQ==
X-Received: from netfilter.org (mail-agni [217.70.190.124])
	by mail.netfilter.org (Postfix) with UTF8SMTPSA id 82C126005F;
	Sun, 22 Nov 2026 00:23:50 +0100 (CET)
X-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>
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: <20261118201250.2075007-2-florian.fainelli@broadcom.com>