mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sicong Huang <congei42@163.com>
To: netdev@vger.kernel.org
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
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	[thread overview]
Message-ID: <20261031063823.876645-2-congei42@163.com> (raw)
In-Reply-To: <20261031063823.876645-1-congei42@163.com>

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


  reply	other threads:[~2026-10-31  6:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  6:38 [PATCH net v3 0/2] sfc: fix use-after-free of aRFS work on ring resize Sicong Huang
2026-10-31  6:38 ` Sicong Huang [this message]
2026-11-01  6:41   ` [PATCH net v3 1/2] sfc: fix use-after-free of filter_work in efx_realloc_channels() netdev-bot+sashiko
2026-10-31  6:38 ` [PATCH net v3 2/2] sfc: quiesce aRFS work before copying channels " Sicong Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261031063823.876645-2-congei42@163.com \
    --to=congei42@163.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-net-drivers@amd.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®