* [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy
@ 2026-12-04 13:06 Guangshuo Li
2026-12-04 13:13 ` netdev-bot+sinfo
2026-12-05 13:23 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: Guangshuo Li @ 2026-12-04 13:06 UTC (permalink / raw)
To: alex.austin, andy.moreton
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, alexanderduyck,
weiwan, hannes, netdev, linux-net-drivers, linux-kernel
Channel cloning copies the NAPI thread pointer without acquiring a
reference. If threaded NAPI is disabled by an earlier thread creation
failure, a later cloned channel can retain that old pointer. Removing
the old channels then leaves it pointing to a stopped thread.
Clear the thread pointer before initializing the copied NAPI context.
This issue was found by our static analysis tool under development.
Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/net/ethernet/sfc/falcon/efx.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/sfc/falcon/efx.c b/drivers/net/ethernet/sfc/falcon/efx.c
index 0c197b448645..d4431b706475 100644
--- a/drivers/net/ethernet/sfc/falcon/efx.c
+++ b/drivers/net/ethernet/sfc/falcon/efx.c
@@ -466,6 +466,7 @@ ef4_copy_channel(const struct ef4_channel *old_channel)
INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
channel->napi_str.napi_id = 0;
channel->napi_str.state = 0;
+ channel->napi_str.thread = NULL;
memset(&channel->eventq, 0, sizeof(channel->eventq));
for (j = 0; j < EF4_TXQ_TYPES; j++) {
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy
2026-12-04 13:06 [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy Guangshuo Li
@ 2026-12-04 13:13 ` netdev-bot+sinfo
2026-12-05 13:23 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 13:13 UTC (permalink / raw)
To: Guangshuo Li
Cc: alex.austin, andy.moreton, andrew+netdev, davem, edumazet, kuba,
pabeni, alexanderduyck, weiwan, hannes, netdev, linux-net-drivers,
linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy
2026-12-04 13:06 [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy Guangshuo Li
2026-12-04 13:13 ` netdev-bot+sinfo
@ 2026-12-05 13:23 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 13:23 UTC (permalink / raw)
To: liguangshuo
Cc: alex.austin, andy.moreton, andrew+netdev, davem, edumazet, kuba,
pabeni, alexanderduyck, weiwan, hannes, netdev, linux-net-drivers,
linux-kernel
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 fixes the falcon helper but leaves the same bug in the
other two sfc channel-clone helpers.
- [Low] The commit message understates both the trigger and the impact.
--
sfc: falcon: Fix potential stale NAPI thread references on channel copy
This patch clears napi_str.thread in ef4_copy_channel(). A cloned falcon
channel then no longer inherits the NAPI kthread pointer of the channel it
was copied from. Without the change, removing the old channels stops that
thread while the clone still points at it.
> Channel cloning copies the NAPI thread pointer without acquiring a
> reference. If threaded NAPI is disabled by an earlier thread creation
> failure, a later cloned channel can retain that old pointer. Removing
> the old channels then leaves it pointing to a stopped thread.
[Severity: Low]
Is an earlier thread creation failure the only way to trigger this?
netdev_nl_napi_set_config() calls napi_set_threaded() on a single NAPI.
For drivers registered with netif_napi_add(), napi->config is NULL. Only
napi->thread gets set, and dev->threaded stays DISABLED.
A later ethtool -G then copies the pointer into the clone.
netif_napi_add_weight_locked() does not overwrite it, because
napi_get_threaded_config() falls back to dev->threaded:
net/core/dev.c:netif_napi_add_weight_locked() {
...
if (napi_get_threaded_config(dev, napi))
if (napi_kthread_create(napi))
dev->threaded = NETDEV_NAPI_THREADED_DISABLED;
...
}
__netif_napi_del_locked() on the old NAPI then calls kthread_stop(), and
the task can be freed.
At that point the clone holds a pointer to a freed task_struct, not just
to a stopped thread. These paths dereference it later:
- __netif_napi_del_locked() calls kthread_stop() on it.
- napi_set_threaded() and netif_set_threaded() skip thread creation and
set THREADED.
- netdev_nl_napi_fill_one() calls task_pid_nr_ns() on it.
Could the commit message describe this as a use-after-free? A netlink
napi-set followed by ethtool -G reaches it without any allocation failure.
> diff --git a/drivers/net/ethernet/sfc/falcon/efx.c b/drivers/net/ethernet/sfc/falcon/efx.c
> index 0c197b4486458..d4431b7064754 100644
> --- a/drivers/net/ethernet/sfc/falcon/efx.c
> +++ b/drivers/net/ethernet/sfc/falcon/efx.c
> @@ -466,6 +466,7 @@ ef4_copy_channel(const struct ef4_channel *old_channel)
> INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
> channel->napi_str.napi_id = 0;
> channel->napi_str.state = 0;
> + channel->napi_str.thread = NULL;
> memset(&channel->eventq, 0, sizeof(channel->eventq));
[Severity: High]
Two other helpers have the same code. Do they need this change too?
- efx_copy_channel() in drivers/net/ethernet/sfc/efx_channels.c
- efx_copy_channel() in drivers/net/ethernet/sfc/siena/efx_channels.c
Both do the same struct copy and reset only these fields:
drivers/net/ethernet/sfc/efx_channels.c:efx_copy_channel() {
...
*channel = *old_channel;
channel->napi_dev = NULL;
INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
channel->napi_str.napi_id = 0;
channel->napi_str.state = 0;
memset(&channel->eventq, 0, sizeof(channel->eventq));
...
}
So napi_str.thread is still copied from the old channel. The sfc version
is used by the default channel type and by the PTP channel type
(.copy = efx_copy_channel in ptp.c).
efx_realloc_channels() and efx_siena_realloc_channels() appear to follow
the same sequence as falcon:
ethtool -G
efx_realloc_channels()
efx_copy_channel() <- clone keeps old napi_str.thread
netif_napi_add() on clone <- pointer is not overwritten when
napi_get_threaded_config() is false
efx_fini_napi_channel(old)
netif_napi_del()
__netif_napi_del_locked()
kthread_stop(napi->thread)
After this, the new channel's NAPI holds a pointer to a freed
task_struct:
- The next ethtool -G, or driver removal, calls kthread_stop() on it
again.
- netif_set_threaded() sees a non-NULL pointer and skips
napi_kthread_create(), so NAPI scheduling wakes the freed task.
- napi_enable_locked() sets NAPIF_STATE_THREADED when
n->dev->threaded && n->thread.
- netdev_nl_napi_fill_one() calls task_pid_nr_ns() on it.
Two paths reach this. One is the earlier kthread creation failure the
commit message describes. The other is a netlink napi-set with
threaded=enabled followed by ethtool -G.
All three helpers share the same Fixes: tag. Should this patch also cover
the sfc and siena helpers, or come with companion patches for them?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204130610.2419077-1-liguangshuo%40mail.sdu.edu.cn
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-05 13:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 13:06 [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy Guangshuo Li
2026-12-04 13:13 ` netdev-bot+sinfo
2026-12-05 13:23 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox