From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796476996; b=Hnp+IvWNLEumN00+looVsiPp2S9Q3nVgw8p3tNVem31ulFXqnwlI5SJaNCnv8LG4PDHu ZBvhhkVHnJw29ye1eyrTPX1BpXvaE1GvY1j+3rM68fyUiPP4KfkJmBVviCJt54jFZIV/n AH5/RGd6gJlr/zpJsYVukCBZsFo93YT++sk2oO1yaCpZLtyyGyn1VFF8zPEEhN9n07qwp c8E5sp+Jm++N03eDVfZurID1odo9/j0LMiPcWpRthhYpjqqoLOPJvsFExqZI3OhqTvk4m Rrqp48f/lNIA9W5Pjtr4ob51JO+fkeSG2MoXb7jM6Axww9gzbWbgg5i+smflU7P975Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796476996; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=umY/gBdFwR2pIVsocwZTY/QXPSwayRe2zPqZtw40OZU=; b=0txolgUdnBoflJ7TfZBcXy9YoVNzSzyLWU9EW4PLZGDa6Fv70k8iAFKgKwJtSi30O+kk 33H+LXYEkYXudsVmAC4HmJ3rpz4O7xNY1MFIlnD21cHffGf1B3zT5g3qUPynbjy9y5TMR K7ERnX+iJNv5fme7ARLj+gZkRLxtEekNLUZ3acaYYIuncf3DIIBXFpJ5TvhfuOdEAxKAH R0LCbo/+IpTqslc8yW5D6FlC3E/S+kokIUxd3q53Ock1cUAZ1/Uvlvcf/9MeWQtoMcKcX WDjHpaFUCFy8zw4wR7gFVQdQwg7cJ3KHd1zEO7VPB4RTyPNwT9tJI5MSapVPaZhFhvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lnYW8eyM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 ESMTPS id 8F2EB606A338; Sat, 5 Dec 2026 13:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lnYW8eyM Received: by smtp.kernel.org (Postfix) with ESMTPSA id B24061F0092B; Sat, 5 Dec 2026 13:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796476996; bh=umY/gBdFwR2pIVsocwZTY/QXPSwayRe2zPqZtw40OZU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=lnYW8eyMSzwxGEZXua24+18rI0D2OCa5lQUFD5frXq5Fo1skRMXelkJAnmUG2FZSn Fyxk6ZFVMtrHMd5uF7B2Wg9B5QpRM7PpeE08AzneVBVyoXACoXwPQj2GESX3e3dVe5 sx2Re4UOflvnIdQU+J/sawiRXzN7A60espKxtzEZBJMdF19uty36DkPXs6oqrVa9xG dNXnMBMpDvBtvloWyE0o72yKvE/c4DHW4y+UkgTywgklyv33taImY624NWKCq8ODqy KWyfhtmh8JXcWluzNrWPK95s5XkKMpENmgwh5ikcwmrxQdJhY53dkv+B5+vCx8EIjT CK9o+SGcx1XPw== Subject: Re: [PATCH net] sfc: falcon: Fix potential stale NAPI thread references on channel copy From: netdev-bot+sashiko@kernel.org To: liguangshuo@mail.sdu.edu.cn Cc: alex.austin@amd.com, andy.moreton@amd.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, alexanderduyck@fb.com, weiwan@google.com, hannes@stressinduktion.org, netdev@vger.kernel.org, linux-net-drivers@amd.com, linux-kernel@vger.kernel.org Date: Sat, 05 Dec 2026 13:23:15 +0000 Message-ID: <179647699531.3146.16235073420230238974@kernel.org> In-Reply-To: <20261204130610.2419077-1-liguangshuo@mail.sdu.edu.cn> References: <20261204130610.2419077-1-liguangshuo@mail.sdu.edu.cn> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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