🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9376

Re: [PATCH net v2] netfilter: flowtable: flush delete work after final GC

#9376
From: Pablo Neira Ayuso
Date: Sun, 01 Nov 2026 23:11
86 lines
11731 bytes
On Mon, Sep 28, 2026 at 12:32:48AM +0800, Chengfeng Ye wrote:
> nf_flow_table_free() can return while delete work still holds a pointer to
> the flowtable. Its caller can then free the flowtable before the worker
> accesses it, causing a use-after-free.
> 
> nf_flow_offload_del() sets NF_FLOW_HW_DYING only after allocating the work
> item. If this GFP_ATOMIC allocation fails during the first teardown GC
> pass, the flow remains eligible for deletion in the final GC pass inside
> nf_flow_table_offload_flush_cleanup(). That pass runs after the delete
> workqueue has been flushed, so a successful retry queues work which is
> not waited for:
> 
>   teardown worker                         delete worker
>   first GC: work allocation fails
>     NF_FLOW_HW_DYING remains clear
>   flush delete workqueue
>   final GC: allocation succeeds
>     queue FLOW_CLS_DESTROY work
>   destroy rhashtable
>   free flowtable
>                                           access offload->flowtable
> 
> Flush the delete workqueue again after the final GC to complete this work
> before the flowtable can be freed. All flows have already been marked for
> teardown, so this GC pass only queues delete work, and the delete worker
> does not queue further offload work.
> 
> KASAN reported:
> 
>   BUG: KASAN: slab-use-after-free in flow_offload_work_handler+0xbe8/0xe30
>   Read of size 8 at addr ffff888109c9fd98 by task kworker/u16:3/397
>   Workqueue: nf_ft_offload_del flow_offload_work_handler
>   Call Trace:
>    flow_offload_work_handler+0xbe8/0xe30
>    process_one_work+0x63a/0x1070
>    worker_thread+0x45b/0xd10
>   Allocated by task 87:
>    nf_tables_newflowtable+0x5d0/0x22f0
>    nfnetlink_rcv_batch+0x1396/0x1d00
>   Freed by task 11:
>    kfree+0x131/0x3c0
>    nf_tables_trans_destroy_work+0xb26/0xeb0
>    process_one_work+0x63a/0x1070
>   Last potentially related work creation:
>    __queue_work+0x68e/0x1030
>    flow_offload_del+0x74c/0xad0
>    nf_flow_offload_gc_step+0x264/0x8e0
>    nf_flow_table_gc_run+0xcd/0x150
>    nf_flow_table_offload_flush_cleanup+0x5c/0x70
>    nf_flow_table_free+0x280/0x350
>    nf_tables_flowtable_destroy+0x71/0x270

For the record, proposed alternative to this patch:

https://patch.msgid.link/netfilter-devel/20261029230657.302417-1-pablo@netfilter.org/

> Fixes: c921ffe85333 ("netfilter: flowtable: Fix flushing of offloaded flows on free")
> Cc: stable@vger.kernel.org
> Assisted-by: GPT-6-Astra
> Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
> ---
> Changes in v2:
> - Rebase onto current mainline; the independently revalidated one-line fix
>   is unchanged from v1.
> 
> v1: https://lore.kernel.org/r/20260824115829.205118-1-nicoyip.dev@gmail.com/
> 
>  net/netfilter/nf_flow_table_offload.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 6757fd89c1f1..728220ba3882 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -1172,6 +1172,7 @@ void nf_flow_table_offload_flush_cleanup(struct nf_flowtable *flowtable)
>  	if (nf_flowtable_hw_offload(flowtable)) {
>  		flush_workqueue(nf_flow_offload_del_wq);
>  		nf_flow_table_gc_run(flowtable);
> +		flush_workqueue(nf_flow_offload_del_wq);
>  	}
>  }
>  
> -- 
> 2.43.0
> 
Technical Details
Message-ID: <aufHB1HXHtm7rw4M@chamomile>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354363-linux-kernel-netdev=dewy.ru
References: <20260927163248.1002656-1-nicoyip.dev@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354363-linux-kernel-netdev=dewy.ru
From: pablo@netfilter.org (Pablo Neira Ayuso)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] netfilter: flowtable: flush delete work after
 final GC
Date: Mon, 2 Nov 2026 00:11:03 +0100
Organization: Usenet Network
Message-ID: <aufHB1HXHtm7rw4M@chamomile>
References: <20260927163248.1002656-1-nicoyip.dev@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Info: usenet.network;
	logging-data="2793446"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:rIiZEww8NSajoClg5n54x2cjZ4M= sha256:293tdpjucQ5pzOo4U8ZezQ8cEiqPgmsIoeIs1HqDeGo=
	sha1:dxh/QBN+/F4DVUM9hPUQdORoGT0= sha256:HwhSPVsF2nQEBJpUg3YINYepiQ7yQXJ1eC1MPXYIiCA=
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 08A6511401C; Mon,  2 Nov 2026 02:12:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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.25,
	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 hiRYCaL-ruAG;
	Mon,  2 Nov 2026 02:12:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354363-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 31D97C72C6; Mon,  2 Nov 2026 02:11:52 +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 933E62A8D2; Sun,  1 Nov 2026 23:11:20 +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=1793574680;
	b=IvcfFSgTEN+6FliGTQDDC387ZAhrzrIzu0atz1+aCFql2DvWt+3yE15BMQM7YLP7Zm3Q
	 CReyWKZjLuKdRsgcFgf0MCKZLl+3cwjZg/ckaabGCzbojMiRXr+7smPtSgjaWx1gMAz1f
	 bp7KL8M72EPQJk8dg9/egHNm/8d2pgYGTZ+dFiWWW+WP4R3Qh34rWmeFstOnEC9P1AbZv
	 8R0DBTGL7K9Sha4VwcwLQ1LdbVwaiL2LgWfEE6GxgTnlPZLj0kNu4y8cpfj2tM1iUJFR2
	 HD7G+o+jHOVw+uzflVThZW5swyJt7QA9tMTs2HbYxhRq2uJZhXXHV38xXtQEolfTAqA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793574680;
	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=pP4TSECHhZx0zxl/HEDYPKq8T0EGn/TF0YTD8IQWiug=;
	b=ekZktuVhtuleYVRlJFyDH6lQVMVrluAHLNbVSyaoOaAkvLEakltRCaESOuni3sjPvZkw
	 id+JAcjBsUaA/JHOCysRZa5yDU6PNV7Lh0TuyqOqviAeyga7COxRoGo6h1iEbv8Jkeasz
	 hBcBiM8psO9qu3NmbPKye2HNGuc79NLAl3KIJ5lPtNaLLHvI5Sh7enatvueGsQBxs83Zg
	 wybi01Pv3mt7RSsZR+//zdu3fuZXWFQ4Y9y/+7NnXPH5GDEST0ydin6BW0z+5X0TDKbc2
	 3F90qLhwLvCzrr3IszOi1QQddXrjcfzFuTPWoxMl3cBBXz8TsGYvFVMYKE9DcoR/leg==
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=Kby+au8r;
	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 63AE2606A32C;
	Sun,  1 Nov 2026 23:11:20 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=netfilter.org header.i=@netfilter.org header.a=rsa-sha256 header.s=2025 header.b=Kby+au8r
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=1793574669;
	b=l/1fkSEBe/GZnz+xVP/Z856O7dgQ79zLBOfg16m/jrGLXpGqPmuNGKAHTqIZ3qfn31uQ
	 PVNT56gGgDOkLAeh+QqZM1CFLMID0nZuXaHnKQhL/sgRKfyAayhl8abzd7ssuor5S7NwI
	 ZrZhS4Mp07rahm5ZuKl8CUUZ1EgvZseglEr46vmGkhPV97SHjUIKPpX9kF9boA8eYA86X
	 5jk/BLq39gnOhBJwAyUXHVFywfK3NZ79PTHD9mmmRrkvAN/V6XzFY69a/Y94iQnUBGdGi
	 iq6X/4GNR+Ekc6D5tQdqvXlv8JNw2SGCpvbA/lLIXGlMG6pAUji8ky2hVhDq7ASCwAg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793574669;
	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=pP4TSECHhZx0zxl/HEDYPKq8T0EGn/TF0YTD8IQWiug=;
	b=i7+kEilQyxTmVvNEcydYJvd/Lru9d61XIRUTFVd4P5Qg5VhrEkTGNej3OfFogaIG55Ba
	 OscZcizFanH0lWCgwFGOdFmMMn941sJvEWL3vqh6tNY1UTBiVf069wdRJg07dFyPrHiTB
	 MZp4EP8+aQfRWxbss8UmA6897NMHi/+WVTm0a9tCwIGsexNgNmafel29qO2DGMfg5AWLH
	 sXlbrcavxYcCt+KEKLse2Hhz1mQIuLGKjB0VN3nhNOAV6VkrJjKeKiwX+S9tuuqYAQ4qP
	 CWndk0GMcR9va1NgLQW+CgqWmew6p2x/nv9weWi0/i+s/bN0qS16gIL5tWzfiMPT2dg==
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=Kby+au8r;
	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 A6398606A324;
	Sun,  1 Nov 2026 23:11:08 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A6398606A324
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=1793574666;
	bh=pP4TSECHhZx0zxl/HEDYPKq8T0EGn/TF0YTD8IQWiug=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To:From;
	b=Kby+au8rk/2gDQQrwaEaUYRsa3sad14btpmCw5JdLOy6c8YuLhSPmxt9BOqC23Gs/
	 0pkG1xXBnLWsDLuZNFuDt3mV6pmTJzJWx1Vm9NG3OpgudaKJ4Y/xG7yeJQr+/uBMuk
	 C7JJQ8DV+UijEAUPu4z+c9G/vHyyhmoW5WWzOLrYGuGVJQ+ehI4AXrIVn3dI3QX1FL
	 xnw9FhWv8G+5El+tNfN98wXyBlGm3CbuFm5oWuL+/M1kd9qQyVar5lyFOS4MkRBFt2
	 42l2GGz1oOkA/SfJtak0gOyyxVQn+ZRowKY/dfo6u+Xwkk7V3MqB7D3vwTWfkN0BWd
	 jJQztauMwGqVQ==
X-Received: from netfilter.org (mail-agni [217.70.190.124])
	by mail.netfilter.org (Postfix) with UTF8SMTPSA id 0A8D460058;
	Mon,  2 Nov 2026 00:11:06 +0100 (CET)
X-Cc: Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@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: <20260927163248.1002656-1-nicoyip.dev@gmail.com>