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, 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 3/6] idpf: ignore link events once removal has started
Date: Thu, 26 Nov 2026 23:40:11 +0000 [thread overview]
Message-ID: <179573641139.3135.13380331474083412807@kernel.org> (raw)
In-Reply-To: <20261125225145.4126333-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] The new IDPF_REMOVE_IN_PROG test in idpf_handle_event_link()
(idpf_virtchnl.c:45) only works together with the…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
leaves the same vport-lifetime race open on two other teardown paths,…
- [High] This problem wasn't introduced by this patch, but
idpf_handle_event_link() can see a vport whose netdev pointer is not…
- [High] This problem wasn't introduced by this patch, but
idpf_handle_event_link() does an unlocked check-then-act on…
--
idpf: ignore link events once removal has started
This patch makes idpf_handle_event_link() return early once
IDPF_REMOVE_IN_PROG is set. During remove, mbx_task can handle a
VIRTCHNL2_EVENT_LINK_CHANGE while idpf_vport_dealloc() is freeing the
vport, and the early return keeps that event from using it. It depends on
an earlier patch in the series that waits for a running mbx_task after
the bit is set.
> Make idpf_handle_event_link() return once IDPF_REMOVE_IN_PROG is set.
> The previous patch waits for a running mbx_task after the bit is set and
> before anything is released, so on remove a link event is either handled
> before the vports are torn down or ignored.
[ ... ]
> Fixes: 02cbfba1add5 ("idpf: add ethtool callbacks")
> Cc: stable@vger.kernel.org
[Severity: Low]
Could the prerequisite be named by subject or SHA here, instead of "The
previous patch"?
The new check only closes the window together with this pair in the
remove_in_prog branch of idpf_vc_core_deinit():
} else {
...
cancel_delayed_work_sync(&adapter->mbx_task);
queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0);
}
Without that wait, an mbx_task that passed test_bit() just before
idpf_remove() set the bit can still be inside the handler when
idpf_deinit_task()->idpf_vport_dealloc() frees the vport.
The pair comes from "idpf: ignore Tx timestamp replies once removal has
started". That patch has Fixes: 1a49cf814fe1 ("idpf: add Tx timestamp
flows"). This patch has Fixes: 02cbfba1add5, which is much older.
Stable trees that have 02cbfba1add5 but not 1a49cf814fe1 could pick up
this patch by its Fixes: tag and miss the prerequisite. The prerequisite
also has no PTP code to apply against in those trees. They would get a
smaller race window rather than a fix.
Would a dependency note on the Cc: stable line help here? For example,
"Cc: stable@vger.kernel.org # needs ...".
> 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: High]
This isn't a bug introduced by this patch, but the same vport lifetime
race is still open on two teardown paths that never set
IDPF_REMOVE_IN_PROG. It is still there at the end of the series.
idpf_vport_dealloc() frees the vport through idpf_vport_rel(), which ends
in kfree(vport), before it clears the slot:
idpf_vport_rel(vport);
adapter->vports[i] = NULL;
adapter->vport_ids[i] is never cleared.
That means this call chain can return the freed vport:
idpf_mbx_task()->libie_ctlq_xn_recv()->idpf_recv_event_msg()->
idpf_handle_event_link()->idpf_vid_to_vport()
The handler then loads vport->netdev from the freed vport, writes
np->link_speed_mbps through that pointer, and writes vport->link_up into
freed memory.
The first path is hard reset. idpf_vc_event_task() does:
func_reset:
if (adapter->xnm)
libie_ctlq_xn_shutdown(adapter->xnm);
drv_load:
set_bit(IDPF_HR_RESET_IN_PROG, adapter->flags);
idpf_init_hard_reset(adapter);
With remove_in_prog false, idpf_vc_core_deinit() only calls
libie_ctlq_xn_shutdown(). That does not stop event delivery, because
libie_ctlq_xn_recv() still passes unmatched messages to
idpf_recv_event_msg().
mbx_task is only cancelled after idpf_deinit_task() has freed the vports:
idpf_ptp_release(adapter);
idpf_deinit_task(adapter);
...
cancel_delayed_work_sync(&adapter->serv_task);
cancel_delayed_work_sync(&adapter->mbx_task);
The second path is the error unwind in idpf_init_task(). The commit
message doesn't mention it:
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);
}
Here mbx_task is cancelled only after the vports are freed, and only on
driver load. The KASAN report in the last patch of this series shows
that this init failure window is real for the PTP worker.
On both paths IDPF_HR_RESET_IN_PROG is set. idpf_decfg_netdev() is
therefore skipped, and vport->netdev is not cleared before the free.
Can a link change event that arrives between idpf_vid_to_vport() and
adapter->vports[i] = NULL cause a use-after-free on these paths?
The new comment ("The vports are released on remove and shutdown") also
leaves these paths out.
> vport = idpf_vid_to_vport(adapter, le32_to_cpu(v2e->vport_id));
> 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, not one introduced by this patch. Can
idpf_handle_event_link() see a vport whose netdev pointer is not set yet?
idpf_vport_alloc() publishes the zeroed vport:
/* fill vport slot in the adapter struct */
adapter->vports[idx] = vport;
adapter->vport_ids[idx] = idpf_get_vport_id(vport);
vport->netdev is only assigned later, in idpf_cfg_netdev(). That happens
after idpf_check_supported_desc_ids() and, on first load, after
alloc_etherdev_mqs(), which may sleep.
mbx_task is already running at that point, because idpf_vc_core_init()
queues it before init_task.
A link event for the new vport_id in that window passes both early
returns. The handler then does:
np = netdev_priv(vport->netdev);
np->link_speed_mbps = le32_to_cpu(v2e->link_speed);
With a NULL netdev, this write goes to a near-NULL address in mbx_task
context. The same window opens again on every hard reset re-init.
The error path in idpf_cfg_netdev() also calls free_netdev(vport->netdev)
and then sets vport->netdev = NULL while the vport is still published.
That leaves a short use-after-free window as well.
[Severity: High]
This is another pre-existing issue that this patch does not introduce.
Further down in idpf_handle_event_link(), the IDPF_VPORT_UP test is an
unlocked check-then-act:
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() resets link_up and frees the queues before it clears
the bit:
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);
mbx_task holds neither rtnl nor vport_ctrl_lock. It keeps processing
events in this window, because the stop path needs it for its own
mailbox replies.
A link-up event in this window sees vport->link_up != link_status and
IDPF_VPORT_UP still set. It then restarts the Tx queues and the carrier.
In the soft reset path the netdev stays running, and the qdisc stays
active because linkwatch needs rtnl. That path is
idpf_initiate_soft_reset(), called from ethtool set_channels and
set_ringparam and from ndo_change_mtu.
idpf_vport_queues_rel() frees vport->txqs and sets it to NULL. Could the
next transmit reach this line in idpf_tx_start() after that, and before
idpf_vport_open() reallocates the queues?
tx_q = vport->txqs[skb_get_queue_mapping(skb)];
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125225145.4126333-1-anthony.l.nguyen%40intel.com
next prev parent reply other threads:[~2026-11-26 23:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 22:51 [PATCH net 0/6][pull request] Intel Wired LAN Driver Updates 2026-11-25 (idpf) Tony Nguyen
2026-11-25 22:51 ` [PATCH net 1/6] idpf: Fix vport IRQ name leak on request failure Tony Nguyen
2026-11-25 22:51 ` [PATCH net 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen
2026-11-25 22:51 ` [PATCH net 3/6] idpf: ignore link events " Tony Nguyen
2026-11-26 23:40 ` netdev-bot+sashiko [this message]
2026-11-25 22:51 ` [PATCH net 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen
2026-11-26 23:40 ` netdev-bot+sashiko
2026-11-25 22:51 ` [PATCH net 5/6] idpf: fix use-after-free in the PTP auxiliary worker Tony Nguyen
2026-11-26 23:40 ` netdev-bot+sashiko
2026-11-25 22:51 ` [PATCH net 6/6] idpf: release PTP before freeing vports on the init task error path Tony Nguyen
2026-11-25 22:58 ` [PATCH net 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=179573641139.3135.13380331474083412807@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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox