From: netdev-bot+sashiko@kernel.org
To: anthony.l.nguyen@intel.com
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@kernel.org, andrew+netdev@lunn.ch, willemb@google.com,
netdev@vger.kernel.org, tianxun.ng@bytedance.com,
oss.patchbox@gmail.com, luckilystar08@gmail.com,
emil.s.tantilov@intel.com, richardcochran@gmail.com,
milena.olech@intel.com, konstantin.ilichev@intel.com,
stable@vger.kernel.org, Samuel.salin@intel.com
Subject: Re: [PATCH net v2 3/6] idpf: ignore link events once removal has started
Date: Sat, 05 Dec 2026 20:47:12 +0000 [thread overview]
Message-ID: <179650363281.3148.9057377963791505666@kernel.org> (raw)
In-Reply-To: <20261204194642.3048406-4-anthony.l.nguyen@intel.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] On remove, the fix only works together with the mbx_task drain
added by the previous patch in the series ("idpf: ignore Tx timestamp…
Pre-existing issues:
- [High] This patch did not introduce the problem: the same link-event
use-after-free stays reachable on teardown paths that do not set…
- [High] This patch did not introduce the problem: a link event can see a
vport before its netdev is set.
- [High] This patch did not introduce the problem:
idpf_handle_event_link() can wake the TX queues of a vport whose…
--
idpf: ignore link events once removal has started
This patch makes idpf_handle_event_link() return early once
IDPF_REMOVE_IN_PROG is set. On remove, it relies on the mbx_task drain
added by the previous patch, so a link event is either handled before the
vports are torn down or ignored. The commit message notes that hard reset
still has the window and that shutdown is handled later in the series.
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index 348c7875134ad..854eb1f1ada4c 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -41,6 +41,10 @@ static void idpf_handle_event_link(struct idpf_adapter *adapter,
> struct idpf_netdev_priv *np;
> struct idpf_vport *vport;
>
> + /* The vports are released on remove and shutdown */
> + if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags))
> + return;
> +
[Severity: Low]
On remove, this check only closes the window when combined with the
mbx_task drain from the previous patch in the series ("idpf: ignore Tx
timestamp replies once removal has started"). That drain is in
idpf_vc_core_deinit():
} else {
...
cancel_delayed_work_sync(&adapter->mbx_task);
queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0);
}
Without the drain, this test_bit() is check-then-act. Suppose an mbx_task
passed the check before idpf_remove() set IDPF_REMOVE_IN_PROG. It can still
be inside idpf_handle_event_link() when
idpf_deinit_task()->idpf_vport_dealloc() frees the vport.
The previous patch has Fixes: 1a49cf814fe1. This patch has
Fixes: 02cbfba1add5 and a plain Cc: stable, with no note about the
prerequisite. Some stable trees have 02cbfba1add5 but not 1a49cf814fe1
(6.12.y, for example). Those trees would not pick up the previous patch,
and its context (idpf_ptp_release()) does not exist there.
In those trees this statement from the commit message would not hold:
"on remove a link event is either handled before the vports are torn
down or ignored"
The race would only be narrowed.
Could the stable tag get a "# depends on" note? Alternatively, the drain
could be split out with a Fixes tag that covers 02cbfba1add5.
> vport = idpf_vid_to_vport(adapter, le32_to_cpu(v2e->vport_id));
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. The
same use-after-free can still happen on teardown paths that never set
IDPF_REMOVE_IN_PROG.
The commit message already mentions hard reset. idpf_init_hard_reset()
calls idpf_vc_core_deinit() with remove_in_prog false. So mbx_task is not
drained before idpf_deinit_task(), and it is only cancelled afterwards:
idpf_ptp_release(adapter);
idpf_deinit_task(adapter);
...
cancel_delayed_work_sync(&adapter->serv_task);
cancel_delayed_work_sync(&adapter->mbx_task);
The commit message does not mention the unwind_vports error path in
idpf_init_task(), which has the same problem. It frees the vports while
mbx_task is live and cancels mbx_task only afterwards:
unwind_vports:
if (default_vport) {
for (index = 0; index < adapter->max_vports; index++) {
if (adapter->vports[index])
idpf_vport_dealloc(adapter->vports[index]);
}
}
...
if (test_and_clear_bit(IDPF_HR_DRV_LOAD, adapter->flags)) {
cancel_delayed_work_sync(&adapter->serv_task);
cancel_delayed_work_sync(&adapter->mbx_task);
}
libie_ctlq_xn_shutdown() does not stop these events. libie_ctlq_xn_recv()
still passes any message that libie_ctlq_xn_process_recv() does not claim
to params->ctlq_msg_handler. So unsolicited VIRTCHNL2_EVENT_LINK_CHANGE
messages keep arriving.
IDPF_HR_RESET_IN_PROG is set on both paths, so idpf_vport_dealloc() skips
idpf_decfg_netdev(). It then frees the vport before clearing its slot:
idpf_vport_rel(vport); <-- kfree(vport)
adapter->vports[i] = NULL;
Can a concurrent link event get the vport from idpf_vid_to_vport() and
then read vport->netdev and read/write vport->link_up after the kfree()?
This could be triggered by a driver-initiated function reset (for example
after a Tx timeout). It could also be triggered by an idpf_init_task()
failure after at least one vport was allocated.
The shutdown part of this is fixed later in the series by "idpf: keep the
mailbox up while tearing down vports on shutdown". That patch sets
IDPF_REMOVE_IN_PROG at the start of idpf_shutdown().
> if (!vport) {
> dev_err_ratelimited(&adapter->pdev->dev, "Failed to find vport_id %d for link event\n",
[Severity: High]
This is also a pre-existing issue and was not introduced by this patch.
Can a link event see a vport before its netdev has been set?
idpf_vport_alloc() publishes the vport with plain stores:
adapter->vports[idx] = vport;
adapter->vport_ids[idx] = idpf_get_vport_id(vport);
vport->netdev is only assigned later, when idpf_init_task() calls
idpf_cfg_netdev():
if (idpf_cfg_netdev(vport))
goto unwind_vports;
At that point mbx_task is already running and IDPF_REMOVE_IN_PROG is
clear. Suppose a VIRTCHNL2_EVENT_LINK_CHANGE for the new vport_id arrives
in that window. idpf_vid_to_vport() returns a vport whose netdev is still
NULL, and idpf_handle_event_link() then does:
np = netdev_priv(vport->netdev);
np->link_speed_mbps = le32_to_cpu(v2e->link_speed);
Would this write through netdev_priv(NULL) and oops?
The window is open on every probe and after every hard reset. On the first
probe it also includes the sleeping alloc_etherdev_mqs().
[Severity: High]
This is another pre-existing race in this handler and was not introduced
by this patch. Can a link event wake the TX queues of a vport while it is
being stopped?
idpf_handle_event_link() runs without rtnl or vport_ctrl_lock and does:
vport->link_up = v2e->link_status;
if (!test_bit(IDPF_VPORT_UP, np->state))
return;
if (vport->link_up) {
netif_tx_start_all_queues(vport->netdev);
netif_carrier_on(vport->netdev);
idpf_vport_stop() clears IDPF_VPORT_UP only after the queues are freed:
vport->link_up = false;
idpf_vport_intr_deinit(vport, rsrc);
idpf_xdp_rxq_info_deinit_all(rsrc);
idpf_vport_queues_rel(vport, rsrc);
idpf_vport_intr_rel(rsrc);
clear_bit(IDPF_VPORT_UP, np->state);
Consider a link-up event handled between the link_up = false store and the
clear_bit(). It would see link_up change and pass the IDPF_VPORT_UP test.
It would then restart all TX queues and turn the carrier on.
On the soft reset path (ethtool -L/-G or an MTU change on an up
interface), the stack can then call idpf_tx_start(), which does:
tx_q = vport->txqs[skb_get_queue_mapping(skb)];
After idpf_vport_queues_rel() that pointer is NULL. After this memcpy() in
idpf_initiate_soft_reset() it is the stale, freed pointer:
memcpy(vport, new_vport, offsetof(struct idpf_vport, link_up));
It stays that way until idpf_vport_open() reallocates the queues.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204194642.3048406-1-anthony.l.nguyen%40intel.com
next prev parent reply other threads:[~2026-12-05 20:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:46 [PATCH net v2 0/6][pull request] Intel Wired LAN Driver Updates 2026-11-25 (idpf) Tony Nguyen
2026-12-04 19:46 ` [PATCH net v2 1/6] idpf: Fix vport IRQ name leak on request failure Tony Nguyen
2026-12-04 19:46 ` [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 3/6] idpf: ignore link events " Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko [this message]
2026-12-04 19:46 ` [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 5/6] idpf: fix use-after-free in the PTP auxiliary worker Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 6/6] idpf: release PTP before freeing vports on the init task error path Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
2026-12-04 19:53 ` [PATCH net v2 0/6][pull request] Intel Wired LAN Driver Updates 2026-11-25 (idpf) netdev-bot+sinfo
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=179650363281.3148.9057377963791505666@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=Samuel.salin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=emil.s.tantilov@intel.com \
--cc=konstantin.ilichev@intel.com \
--cc=kuba@kernel.org \
--cc=luckilystar08@gmail.com \
--cc=milena.olech@intel.com \
--cc=netdev@vger.kernel.org \
--cc=oss.patchbox@gmail.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tianxun.ng@bytedance.com \
--cc=willemb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.