🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9094

[PATCH net v3 1/2] sfc: fix use-after-free of filter_work in efx_realloc_channels()

#9094
From: Sicong Huang
Date: Sat, 31 Oct 2026 06:38
139 lines
13661 bytes
With CONFIG_RFS_ACCEL, efx_poll() queues the per-channel aRFS expiry
work. The work also re-arms itself every 30 seconds so that filters
can expire even when the channel receives no more NAPI polls.

efx_realloc_channels(), called by ethtool -G, copies the channels and
frees the old structures without cancelling their filter_work. A queued
or running expiry callback can therefore access the freed channel and
re-arm a timer in freed memory. The work lifetime problem dates back to
the introduction of asynchronous filter operations; the later periodic
re-arm makes it possible even without recent receive activity.

Introduce efx_free_channel() to cancel filter_work synchronously before
freeing its channel. Use it for ring reallocation and final channel
teardown, keeping this requirement inside the deallocation helper.

The copied channels retain the installed filters but start with an idle
filter_work. Re-arm expiry on the channels that still have filters at
the common reallocation exit, so expiry continues without another NAPI
poll. This also covers allocation failure and probe rollback, when the
original channels remain in use. Apply the same changes to Siena.

Identified by code inspection. The missing expiry re-arm was pointed
out by Sashiko review and Paolo Abeni. Neither the issue nor the fix
has been tested on hardware.
Compile-tested on x86_64 with CONFIG_RFS_ACCEL enabled and disabled.

Fixes: 3af0f34290f6 ("sfc: replace asynchronous filter operations")
Link: https://lore.kernel.org/netdev/179310908138.3134.11515982039281965575@kernel.org/
Signed-off-by: Sicong Huang <congei42@163.com>
---
 drivers/net/ethernet/sfc/efx_channels.c       | 23 +++++++++++++++++--
 drivers/net/ethernet/sfc/siena/efx_channels.c | 23 +++++++++++++++++--
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/sfc/efx_channels.c b/drivers/net/ethernet/sfc/efx_channels.c
index f4dc3f3f4416..44943345fa87 100644
--- a/drivers/net/ethernet/sfc/efx_channels.c
+++ b/drivers/net/ethernet/sfc/efx_channels.c
@@ -561,6 +561,14 @@ static struct efx_channel *efx_alloc_channel(struct efx_nic *efx, int i)
 	return channel;
 }
 
+static void efx_free_channel(struct efx_channel *channel)
+{
+#ifdef CONFIG_RFS_ACCEL
+	cancel_delayed_work_sync(&channel->filter_work);
+#endif
+	kfree(channel);
+}
+
 int efx_init_channels(struct efx_nic *efx)
 {
 	unsigned int i;
@@ -589,7 +597,7 @@ void efx_fini_channels(struct efx_nic *efx)
 
 	for (i = 0; i < EFX_MAX_CHANNELS; i++)
 		if (efx->channel[i]) {
-			kfree(efx->channel[i]);
+			efx_free_channel(efx->channel[i]);
 			efx->channel[i] = NULL;
 		}
 }
@@ -898,10 +906,21 @@ int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
 		if (channel && channel->type->copy) {
 			efx_fini_napi_channel(channel);
 			efx_remove_channel(channel);
-			kfree(channel);
+			efx_free_channel(channel);
 		}
 	}
 
+#ifdef CONFIG_RFS_ACCEL
+	/* Re-arm the expiry work on the channels now in use: the copies on
+	 * success, the originals after a rollback.  The copies inherit the
+	 * aRFS filters, so they must inherit the expiry too, or a channel
+	 * that gets no further NAPI polls would never expire its filters.
+	 */
+	efx_for_each_channel(channel, efx)
+		if (channel->rfs_filter_count)
+			schedule_delayed_work(&channel->filter_work, 30 * HZ);
+#endif
+
 	efx->ptp_data = ptp_data;
 	rc2 = efx_soft_enable_interrupts(efx);
 	if (rc2) {
diff --git a/drivers/net/ethernet/sfc/siena/efx_channels.c b/drivers/net/ethernet/sfc/siena/efx_channels.c
index 1fc343598771..388bef4be468 100644
--- a/drivers/net/ethernet/sfc/siena/efx_channels.c
+++ b/drivers/net/ethernet/sfc/siena/efx_channels.c
@@ -563,6 +563,14 @@ static struct efx_channel *efx_alloc_channel(struct efx_nic *efx, int i)
 	return channel;
 }
 
+static void efx_free_channel(struct efx_channel *channel)
+{
+#ifdef CONFIG_RFS_ACCEL
+	cancel_delayed_work_sync(&channel->filter_work);
+#endif
+	kfree(channel);
+}
+
 int efx_siena_init_channels(struct efx_nic *efx)
 {
 	unsigned int i;
@@ -591,7 +599,7 @@ void efx_siena_fini_channels(struct efx_nic *efx)
 
 	for (i = 0; i < EFX_MAX_CHANNELS; i++)
 		if (efx->channel[i]) {
-			kfree(efx->channel[i]);
+			efx_free_channel(efx->channel[i]);
 			efx->channel[i] = NULL;
 		}
 }
@@ -932,10 +940,21 @@ int efx_siena_realloc_channels(struct efx_nic *efx, u32 rxq_entries,
 		if (channel && channel->type->copy) {
 			efx_fini_napi_channel(channel);
 			efx_siena_remove_channel(channel);
-			kfree(channel);
+			efx_free_channel(channel);
 		}
 	}
 
+#ifdef CONFIG_RFS_ACCEL
+	/* Re-arm the expiry work on the channels now in use: the copies on
+	 * success, the originals after a rollback.  The copies inherit the
+	 * aRFS filters, so they must inherit the expiry too, or a channel
+	 * that gets no further NAPI polls would never expire its filters.
+	 */
+	efx_for_each_channel(channel, efx)
+		if (channel->rfs_filter_count)
+			schedule_delayed_work(&channel->filter_work, 30 * HZ);
+#endif
+
 	rc2 = efx_soft_enable_interrupts(efx);
 	if (rc2) {
 		rc = rc ? rc : rc2;
-- 
2.34.1
Technical Details
Message-ID: <20261031063823.876645-2-congei42@163.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354035-linux-kernel-netdev=dewy.ru
References: <20261031063823.876645-1-congei42@163.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-354035-linux-kernel-netdev=dewy.ru
From: congei42@163.com (Sicong Huang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 1/2] sfc: fix use-after-free of filter_work in efx_realloc_channels()
Date: Sat, 31 Oct 2026 14:38:22 +0800
Organization: Usenet Network
Message-ID: <20261031063823.876645-2-congei42@163.com>
References: <20261031063823.876645-1-congei42@163.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2394417"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VQMSz0P2Ci3amKszAisDOWidbXE= sha256:bKm2+ejs45Rc08uC/CVJPEyvNfnZ0jdYXex8gMH17sM=
	sha1:VwQzIlliDxS2keX9aMHEUg0wcdE= sha256:jQR3D25lUWAg2nz82vl1vbT7KDS+/bkuvqFllWVWc7g=
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 B3505125CB7; Sat, 31 Oct 2026 09:39:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.047
X-Spam-Status: No, score=-3.047 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, 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, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=163.com
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 C-bD6GxyC9xg;
	Sat, 31 Oct 2026 09:39:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354035-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E4AB4125CB0; Sat, 31 Oct 2026 09:39:21 +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 0E2A42A136; Sat, 31 Oct 2026 06:39:13 +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=1793428752;
	b=cw7Dl+ZF24RU509cGnKMy3PyGbZKSP1T4RrBh2fsbtepEfvHB3fvDOHATVyjeYZb217x
	 yTPwxzfyWkXXglYQGuCZPECpsMa37Dh9KH04rufaVzQ1V9hLlQf+be6m1icQ86Xc5e3Ae
	 LnLSCe0FDcxEcgIdc656fdML7ce5b0GJJfYbwHIO8A7fyYdCrTZ9g+As2zOZ2NB0NlP/k
	 GQSKJBn1YoOhK1mcw5VIxpLIBSnIRkcaw1WFH4HQuTv3XkFGFvn7ihIxxvLU38YWEURfl
	 CP1iMWDfuZr3OifVMxb2gFKuBgA6sm/zg0/86cGTSkUiPfduWArin7t9HGyGEnjx5Eg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793428752;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=LYnyOHvC5Bif32h/JnLdLhaS59dZvHk6unATAY9XyAA=;
	b=VdCHTdhcC2oDf18JxwJMjdaTfHjBG54fQIS6bC7LgMd0sN6YohKz2SzgTkFsfzF0Wj9N
	 m11nBx+ElgYznVERykmjUvxDGhNlZx/BOXVt3lWdfdctlFm9nbPJGFJm7vdul/uzxWUX2
	 Nbsbhazbhr91holuU28hH71+ZbfT0PLDVeEe/Ubs+FhjGbk/IVFIUXi4pHAFN284TNjbv
	 KFNneB3jRQjg/wLgXR2pfOILh5pFC28g+EVGGVO4BW6GlpkxBm2xBQExvBboPYah0fe4o
	 b4OryVIKyXaWsULh+rE73dpIalMkZy8TxbZGB4sJPK8l4xB89OGmxn2kOt8yx/1eudA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=fx7xmGB+;
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	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 D2276606A329;
	Sat, 31 Oct 2026 06:39:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=fx7xmGB+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.3
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793428746;
	b=SQicW/82a/mx+mjwv1y+oMSOBKa7t2WotPJP5cztugxCltxsmsE+0ldB/kYMpChV5tAX
	 wc/ZLXNQZlZqa0ZYFczaGeAsIFjADv6MVjN1j/F1NTRyvtwZdSkMYjwGhEJVAKVmEBN+a
	 nTCFWvrdT3Cv79QxxhcyZE9Tp0SMkYY+Txdl9ov6Ko3ky/FIpodz4OIyu14p+gmgQvksd
	 MVfTR2ll89nFX/X5qHxSot57A/l4fgqvhHEkD5YocKPV2FPatD4+l+eo/91/XNjzKe5BS
	 +keNYpQ1kcLaqVTX5d3ojWxQYTORz7m/8LI+lm6bnZLn+XWPmTEcd4+cp2eJsjPXL+Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793428746;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-Id:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=LYnyOHvC5Bif32h/JnLdLhaS59dZvHk6unATAY9XyAA=;
	b=s9Zc5I4mKcjDOm7S8BWBn3dSPpVMH5YtrGndylm3g2A47LZmOdU0ESKr2AChCA0VMPTj
	 CohLdBbzC7MmV8tZYcrN/Xn4st1jNEeHm14Bqz6B2rvFpFM5PpFF6VdiChD2arpCP047l
	 hk2viUFeWBejgD8v6cMyfKrRdqgXE592GokSnhlXjgR3W5NY7AtLUoW0C+znVWLIb4K0B
	 DfhteoQ8x5NY7cGOthUS7/dWuE78GyOkV7/GRaXrL11AETcexhnAOgqMbXMFe8V3LAyxu
	 L9JuZm/ZCBeLM9ladmtMEe5I+ohXx7gjxbbTTK7TV0ZkUGg5HNLwKgDa5H0tzVHH8Pw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=fx7xmGB+;
	arc=none smtp.remote-ip=117.135.210.3
X-Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3])
	(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 ESMTPS id D2931606A31A;
	Sat, 31 Oct 2026 06:39:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2931606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;
	s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=LY
	nyOHvC5Bif32h/JnLdLhaS59dZvHk6unATAY9XyAA=; b=fx7xmGB+h1Y14brqia
	yMnrqjD/hkC8JUgj4FSxa6g3dOjv0nq4/C1qft3pg4By/PXrBSGjYn07ATftfkJE
	t8CFCurqa45d5IPCZdlnqkGLP3/tpCKxPI7ohaM4WJhcDADLjXkZNObtKpU7yS9P
	banVDofU4kesvbFUmjLco7hgU=
X-Received: from flipped.. (unknown [])
	by gzga-smtp-mtada-g1-0 (Coremail) with SMTP id _____wDXv9jfjOVqDwKbDg--.29841S3;
	Sat, 31 Oct 2026 14:38:26 +0800 (CST)
X-Cc: ecree.xilinx@gmail.com,
	andrew+netdev@lunn.ch,
	davem@davemloft.net,
	edumazet@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	kees@kernel.org,
	linux-net-drivers@amd.com,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.34.1
X-In-Reply-To: <20261031063823.876645-1-congei42@163.com>
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-CM-TRANSID: _____wDXv9jfjOVqDwKbDg--.29841S3
X-Coremail-Antispam: 1Uf129KBjvJXoW3Xr1xCry5GrWDXrW8ur1rJFb_yoW7WF15pF
	W5t3yjvr45XF9xG3Z7Jw4kAa15Jw48G34jgryDtw1rZwn8ArnxCrsYq34Ygr4DtrWxAr4a
	vr4Yvr48W3Z8J3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jemhrUUUUU=
X-CM-SenderInfo: 5frqwvrlusqiywtou0bp/xtbC0wJvYmrljOIftAAA3W