Intel Wired LAN Driver Updates 2026-11-25 (idpf)
Subsystems (4)
Tony Nguyen
maintainerYuho Choi fixes memory leak of IRQ name in failure path; also returns -ENOMEM if name allocation fails.
Tian Xun Ng fixes shutdown and removal races by ignoring Tx timestamp and link events during teardown and keeping the mailbox active long enough to disable and remove vports.
Emil Tantilov resolves PTP use-after-free issues by introducing rxq_grps_lock to serialize rsrc->rxq_grps transitions against the worker and correcting unwind ordering during initialization failure.
The following are changes since commit 7ed616970b652ae76d99a01b468588e491021648:
mptcp: gate diag sequence counters on CAP_NET_ADMIN
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue 200GbE
Emil Tantilov (2):
idpf: fix use-after-free in the PTP auxiliary worker
idpf: release PTP before freeing vports on the init task error path
Tian Xun Ng (3):
idpf: ignore Tx timestamp replies once removal has started
idpf: ignore link events once removal has started
idpf: keep the mailbox up while tearing down vports on shutdown
Yuho Choi (1):
idpf: Fix vport IRQ name leak on request failure
drivers/net/ethernet/intel/idpf/idpf.h | 10 ++- drivers/net/ethernet/intel/idpf/idpf_lib.c | 12 +++- drivers/net/ethernet/intel/idpf/idpf_main.c | 11 +++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 16 ++++- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 68 ++++++++++++++----- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 49 +++++++++++-- .../net/ethernet/intel/idpf/idpf_virtchnl.h | 1 + .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 3 +- 8 files changed, 142 insertions(+), 28 deletions(-)
Signature · 1 line
2.47.1
Tony Nguyen
maintainerPATCH 1/6 idpf: Fix vport IRQ name leak on request failure
From: Yuho Choi <[email protected]>
idpf_vport_intr_req_irq() allocates a name for each vector IRQ before calling request_irq(). On success, the name is released later through kfree(free_irq()), but when request_irq() fails, the error path only unwinds the previous vectors and the name for the failed one is leaked.
Free the allocated name on the request_irq() failure path, as done for the mailbox IRQ in commit 9bff30482c10 ("idpf: Fix mailbox IRQ name leak on request failure"). While at it, fail with -ENOMEM when the name cannot be allocated instead of requesting the IRQ without a name.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5 -0
@@ -4132,12 +4132,17 @@ static int idpf_vport_intr_req_irq(struct idpf_vport *vport, name =kasprintf (GFP_KERNEL ,"%s-%s-%s-%d" , drv_name, if_name, vec_name, vector); +if (!name) { + err = -ENOMEM ; + goto free_q_irqs; + } err =request_irq (irq_num, idpf_vport_intr_clean_queues,0 , name, q_vector);if (err) {netdev_err (vport->netdev,"Request_irq failed, error: %d\n" , err); +kfree (name); goto free_q_irqs; }
Signature · 1 line
2.47.1
Tony Nguyen
maintainerPATCH 2/6 idpf: ignore Tx timestamp replies once removal has started
In reply to Tony NguyenFrom: Tian Xun Ng <[email protected]>
On remove, idpf_vc_core_deinit() keeps the virtchnl transaction manager up until the vports have been torn down, so mbx_task keeps processing replies while idpf_ptp_release() frees the Tx timestamp trackers. An async VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP reply handled in that window reaches idpf_ptp_get_tx_tstamp_async_handler(), which reads vport->tx_tstamp_caps and takes its lock after idpf_ptp_release_vport_tstamp() may already have freed it.
Once IDPF_REMOVE_IN_PROG is set, wait for a mailbox task that may be running a callback before releasing anything, and make the Tx timestamp callback return when the bit is set. Matched replies to synchronous transactions are not affected, so the vport teardown still receives them; mbx_task is requeued straight away for that.
The last patch of this series sets IDPF_REMOVE_IN_PROG on shutdown too, which would otherwise expose shutdown to the same window.
--- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 12 +++++++++++- drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +11 -1
@@ -3262,8 +3262,18 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)/* Avoid transaction timeouts when called during reset */ remove_in_prog =test_bit (IDPF_REMOVE_IN_PROG , adapter->flags); -if (!remove_in_prog) +if (!remove_in_prog) {libie_ctlq_xn_shutdown (adapter->xnm); + }else { +/* The transaction manager stays up for the teardown below, so +* async replies can still arrive. Wait for a mailbox task that +* may be running an async callback; callbacks that run later +* see IDPF_REMOVE_IN_PROG and leave the state released below +* alone. +*/ +cancel_delayed_work_sync (&adapter->mbx_task); +queue_delayed_work (adapter->mbx_wq, &adapter->mbx_task,0 ); + }idpf_ptp_release (adapter);idpf_deinit_task (adapter);
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +2 -1
@@ -550,7 +550,8 @@ idpf_ptp_get_tx_tstamp_async_handler(void *ctx, struct kvec *mem, int status)u16 num_latches;u32 vport_id; -if (status) +/* The Tx timestamp trackers are released on remove and shutdown */ +if (status ||test_bit (IDPF_REMOVE_IN_PROG , adapter->flags))return ; recv_tx_tstamp_msg = mem->iov_base;
Signature · 1 line
2.47.1
Tony Nguyen
maintainerPATCH 3/6 idpf: ignore link events once removal has started
In reply to Tony NguyenFrom: Tian Xun Ng <[email protected]>
mbx_task keeps handling mailbox events while idpf_deinit_task() releases the vports: it requeues itself, or is queued from the mailbox interrupt, until idpf_vc_core_deinit() cancels it once the vports are gone. A VIRTCHNL2_EVENT_LINK_CHANGE event handled in that window looks its vport up in adapter->vports[] without a lock, and idpf_vport_dealloc() releases the netdev and frees the vport before it clears that slot, so idpf_handle_event_link() can follow a NULL netdev pointer or use the freed vport.
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. Shutdown has the same window today; the last patch of this series sets the bit there as well. The window also remains on a hard reset, which tears the vports down without setting the bit; that path is not changed here.
--- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +4 -0
@@ -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 ; + 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",
Signature · 1 line
2.47.1
[email protected]
AI reviewRe: [PATCH net 3/6] idpf: ignore link events once removal has started
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…
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.
Quoted 4 lines
Make
idpf_handle_event_link()return onceIDPF_REMOVE_IN_PROGis set. The previous patch waits for a runningmbx_taskafter 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.
[ ... ]
Quoted 2 lines
Fixes 02cbfba1add5 ("idpf: add ethtool callbacks")
[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: [email protected] # needs ...".
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c static void idpf_handle_event_link(struct idpf_adapter *adapter, · line 47
Quoted 12 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +4
-0@@ -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.
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c static void idpf_handle_event_link(struct idpf_adapter *adapter, · line 50
Quoted 3 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +0
-0vport =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)];
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125225145.4126333-1-anthony.l.nguyen%40intel.com
Tony Nguyen
maintainerPATCH 4/6 idpf: keep the mailbox up while tearing down vports on shutdown
In reply to Tony NguyenFrom: Tian Xun Ng <[email protected]>
Since commit 4c9106f4906a ("idpf: fix adapter NULL pointer dereference on reboot"), idpf_shutdown() calls idpf_vc_core_deinit() directly instead of idpf_remove(), so IDPF_REMOVE_IN_PROG is not set on shutdown. idpf_vc_core_deinit() uses that flag to decide when to shut the virtchnl transaction manager down. Without it, libie_ctlq_xn_shutdown() runs before idpf_deinit_task() tears the vports down, so every message sent during that teardown (disable vport, disable queues, destroy vport) fails at once, and the device is never told that the vports are gone.
A reset should clear that state, but on the system where this was found the device kept the queues enabled across a warm reboot. The first queue reconfiguration in the next kernel (udev setting the MTU) sends VIRTCHNL2_OP_DEL_QUEUES, and the device then writes SW_MARKER TX completions to the previous kernel's completion rings. With the IOMMU translating, those writes fault about 19 s into every such boot:
arm-smmu-v3 arm-smmu-v3.12.auto: event: F_TRANSLATION client: 0006:01:00.0 sid: 0x30100 ssid: 0x0 iova: 0x3ef60840 ipa: 0x0
In IOMMU pass-through mode they corrupt pages the new kernel has reused.
Set IDPF_REMOVE_IN_PROG at the start of idpf_shutdown(), as idpf_remove() does, so that the event task cannot be requeued and the vports are destroyed while the mailbox is still up; the first two patches keep the Tx timestamp callback and the link event handler away from the state released on the way. So that an unresponsive control plane does not hold up a reboot for long, cap each transaction sent during the teardown at 500 ms instead of 60 s, through a new adapter->vc_xn_timeout_ms, and fail later synchronous ones at once after the first one times out. If the SW marker of one disabled Tx queue does not arrive, the remaining queues of that vport do not wait for theirs, but the mailbox messages that follow are still sent: the device has just answered DISABLE_QUEUES. A control plane that dies at that point costs one marker timeout per vport and one mailbox timeout. The statistics task stops sending once IDPF_REMOVE_IN_PROG is set. A request it already has waiting, or a reset already running in the event task, keeps its own timeouts, as bounding those would need support in libie. If the function has already been reset, for instance a VF whose PF went down first, idpf_is_reset_detected() fails the messages without waiting.
Tested on two arm64 (64K pages) servers, each with two idpf PFs, with this series backported to a 6.17 kernel and the IOMMU translating: 20 warm reboots without a fault. Each PF's teardown took about 1.2 s for six mailbox transactions, with all 64 Tx queue markers received; the slowest transaction, VIRTCHNL2_OP_DEALLOC_VECTORS, took about 300 ms. With the first Tx queue marker treated as missing, the other 63 queues did not wait, all six transactions still completed, the teardown took about 2 s per PF, and 3 of 3 warm reboots were clean. With the driver made to skip sending the teardown messages, every reboot faulted again.
--- drivers/net/ethernet/intel/idpf/idpf.h | 5 ++- drivers/net/ethernet/intel/idpf/idpf_lib.c | 3 ++ drivers/net/ethernet/intel/idpf/idpf_main.c | 11 +++++++ .../net/ethernet/intel/idpf/idpf_virtchnl.c | 33 ++++++++++++++++--- .../net/ethernet/intel/idpf/idpf_virtchnl.h | 1 + 5 files changed, 47 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +4 -1
@@ -85,7 +85,7 @@ enum idpf_state {* @IDPF_HR_FUNC_RESET: Hard reset when TxRx timeout * @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW * @IDPF_HR_RESET_IN_PROG: Reset in progress -* @IDPF_REMOVE_IN_PROG: Driver remove in progress +* @IDPF_REMOVE_IN_PROG: Driver remove or shutdown in progress * @IDPF_MB_INTR_MODE: Mailbox in interrupt mode * @IDPF_VC_CORE_INIT: virtchnl core has been init * @IDPF_FLAGS_NBITS: Must be last
@@ -635,6 +635,8 @@ struct idpf_edt_caps_ilog2 {* @asq: Send control queue info * @arq: Receive control queue info * @xnm: Xn transaction manager +* @vc_xn_timeout_ms: Upper bound for each Xn transaction timeout, shortened +* on shutdown and set to 0 once a shortened one timed out * @num_avail_msix: Available number of MSIX vectors * @num_msix_entries: Number of entries in MSIX table * @msix_entries: MSIX table
@@ -695,6 +697,7 @@ struct idpf_adapter {struct libie_ctlq_info *asq;struct libie_ctlq_info *arq;struct libie_ctlq_xn_manager *xnm; +u32 vc_xn_timeout_ms;u16 num_avail_msix;u16 num_msix_entries;struct msix_entry *msix_entries;
drivers/net/ethernet/intel/idpf/idpf_lib.c +3 -0
@@ -1377,6 +1377,9 @@ void idpf_statistics_task(struct work_struct *work)for (i =0 ; i < adapter->max_vports; i++) {struct idpf_vport *vport = adapter->vports[i]; +if (test_bit (IDPF_REMOVE_IN_PROG , adapter->flags)) +return ; +if (vport && !test_bit (IDPF_HR_RESET_IN_PROG , adapter->flags))idpf_send_get_stats_msg (netdev_priv (vport->netdev), &vport->port_stats);
drivers/net/ethernet/intel/idpf/idpf_main.c +11 -0
@@ -194,8 +194,18 @@ static void idpf_shutdown(struct pci_dev *pdev) {struct idpf_adapter *adapter =pci_get_drvdata (pdev); +/* As in idpf_remove(): keep the event task from being requeued, and +* destroy the vports while the mailbox is still up. +*/ +set_bit (IDPF_REMOVE_IN_PROG , adapter->flags);cancel_delayed_work_sync (&adapter->serv_task);cancel_delayed_work_sync (&adapter->vc_event_task); + +/* Bound the teardown transactions started from here on, so that an +* unresponsive control plane costs a single timeout. A reset or a +* transaction that is already running keeps its own timeouts. +*/ +WRITE_ONCE (adapter->vc_xn_timeout_ms,IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC );idpf_vc_core_deinit (adapter);idpf_deinit_dflt_mbx (adapter);
@@ -267,6 +277,7 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) adapter->req_rx_splitq = true; adapter->pdev = pdev; + adapter->vc_xn_timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC ; err =idpf_dev_init (adapter, ent);if (err) {
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +28 -5
@@ -195,20 +195,32 @@ static void idpf_prepare_ptp_mb_msg(struct idpf_adapter *adapter, u32 op,* Cleanup the mailbox queue entries of the previously sent message to * unmap and release the buffer. * +* The transaction timeout is capped at adapter->vc_xn_timeout_ms. Once a +* synchronous transaction with a shortened timeout times out, later ones +* fail at once instead of waiting again. +* * Return: 0 if the request was successful, -%EBUSY if reset is detected -* or Tx control queue is full, other negative error code on failure. +* or Tx control queue is full, -%ETIMEDOUT if a shortened transaction +* already timed out, other negative error code on failure. */ int idpf_send_mb_msg (struct idpf_adapter *adapter,struct libie_ctlq_xn_send_params *xn_params,void *send_buf,size_t send_buf_size) { +u32 timeout_ms =READ_ONCE (adapter->vc_xn_timeout_ms);struct libie_ctlq_msg ctlq_msg = {}; +int err =0 ; -if (idpf_is_reset_detected (adapter)) { +if (idpf_is_reset_detected (adapter)) + err = -EBUSY ; +else if (!timeout_ms) + err = -ETIMEDOUT ; + +if (err) {if (!libie_cp_can_send_onstack (send_buf_size))kfree (send_buf); -return -EBUSY ; +return err; }idpf_prepare_ptp_mb_msg (adapter, xn_params->chnl_opcode, &ctlq_msg);
@@ -219,10 +231,15 @@ int idpf_send_mb_msg(struct idpf_adapter *adapter, xn_params->xnm = adapter->xnm; xn_params->ctlq = xn_params->ctlq ? xn_params->ctlq : adapter->asq; xn_params->rel_tx_buf = kfree; + xn_params->timeout_ms =min_t (u64, xn_params->timeout_ms, timeout_ms);idpf_mb_clean (xn_params->ctlq, false); -return libie_ctlq_xn_send (xn_params); + err =libie_ctlq_xn_send (xn_params); +if (err == -ETIMEDOUT && timeout_ms <IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC ) +WRITE_ONCE (adapter->vc_xn_timeout_ms,0 ); + +return err; }/**
@@ -372,6 +389,11 @@ static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs)struct net_device *netdev;struct idpf_tx_queue *txq;bool markers_rcvd = true; +bool wait_all; + +/* On shutdown, once one marker is missing, don't wait for the rest */ + wait_all =READ_ONCE (qs->adapter->vc_xn_timeout_ms) >= +IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC ;for (u32 i =0 ; i < qs->num; i++) {switch (qs->qs[i].type) {
@@ -381,7 +403,8 @@ static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs) netdev = txq->netdev;idpf_queue_set (SW_MARKER , txq); -idpf_wait_for_sw_marker_completion (txq); +if (markers_rcvd || wait_all) +idpf_wait_for_sw_marker_completion (txq); markers_rcvd &= !idpf_queue_has (SW_MARKER , txq);break ;default :
drivers/net/ethernet/intel/idpf/idpf_virtchnl.h +1 -0
@@ -7,6 +7,7 @@#include <linux/net/intel/virtchnl2.h> #define IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC (60 * 1000) +#define IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC 500struct idpf_adapter ;struct idpf_netdev_priv ;
Signature · 1 line
2.47.1
[email protected]
AI reviewRe: [PATCH net 4/6] idpf: keep the mailbox up while tearing down vports on shutdown
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · Low: 2
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 fix still misses its target when the control plane is slow but alive.
- [Medium] During shutdown, idpf_wait_for_marker_event_set() computes wait_all as false, because vc_xn_timeout_ms is 500 or 0, below…
- [Medium] The 500 ms cap and the sticky zero apply to the whole adapter, but idpf_shutdown() shortens the timeout before every other mailbox…
- [Medium] The shutdown path can now free the mailbox rings while a control-plane reply is still pending, and the mailbox queues stay…
- [Low] The new kernel-doc for idpf_send_mb_msg() in drivers/net/ethernet/intel/idpf/idpf_virtchnl.c says -ETIMEDOUT is…
- [Low] The struct idpf_adapter kernel-doc for @vc_xn_timeout_ms (drivers/net/ethernet/intel/idpf/idpf.h) says the field is "set to 0…
--
idpf: keep the mailbox up while tearing down vports on shutdown
This patch sets IDPF_REMOVE_IN_PROG at the start of idpf_shutdown(). The vports are then torn down while the virtchnl transaction manager is still up, so the device is told to disable and destroy them before reboot. Each teardown transaction is capped at 500 ms through a new adapter->vc_xn_timeout_ms, later synchronous sends fail at once after a capped one times out, and after one SW marker is missed the remaining marker waits of that vport are skipped.
Quoted 4 lines
drivers/net/ethernet/intel/idpf/idpf.h +0
-0
[ ... ]
drivers/net/ethernet/intel/idpf/idpf.h struct idpf_edt_caps_ilog2 { · line 639
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf.h +2
-0@@ -635,6 +635,8 @@ struct idpf_edt_caps_ilog2 {* @asq: Send control queue info * @arq: Receive control queue info * @xnm: Xn transaction manager +* @vc_xn_timeout_ms: Upper bound for each Xn transaction timeout, shortened +* on shutdown and set to 0 once a shortened one timed out
[Severity: Low]
This isn't a bug, but is this description accurate for async transactions?
The only code that writes 0 is in idpf_send_mb_msg(), and it runs only when the synchronous libie_ctlq_xn_send() returns -ETIMEDOUT.
Async transactions with resp_cb set also get the shortened cap through min_t(). Examples are the MAC filter, promiscuous and PTP Tx timestamp async handlers. For those, libie_ctlq_xn_send() returns 0 right after posting. Their timeout is reported later through resp_cb, which never touches vc_xn_timeout_ms.
The idpf_send_mb_msg() kernel-doc says "synchronous". Should this one say it too?
[ ... ]
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_main.c +2
-0@@ -194,8 +194,18 @@ static void idpf_shutdown(struct pci_dev *pdev) {struct idpf_adapter *adapter =pci_get_drvdata (pdev); +/* As in idpf_remove(): keep the event task from being requeued, and +* destroy the vports while the mailbox is still up.
drivers/net/ethernet/intel/idpf/idpf_main.c static void idpf_shutdown(struct pci_dev *pdev) · line 208
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_main.c +8
-0+*/ +set_bit (IDPF_REMOVE_IN_PROG , adapter->flags);cancel_delayed_work_sync (&adapter->serv_task);cancel_delayed_work_sync (&adapter->vc_event_task); + +/* Bound the teardown transactions started from here on, so that an +* unresponsive control plane costs a single timeout. A reset or a +* transaction that is already running keeps its own timeouts. +*/ +WRITE_ONCE (adapter->vc_xn_timeout_ms,IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC );
[Severity: Medium]
Can a transaction that has nothing to do with the teardown pick up the 500 ms cap here and latch vc_xn_timeout_ms to 0?
Only serv_task and vc_event_task are cancelled before this write. init_task and stats_task are cancelled later, inside idpf_deinit_task():
idpf_deinit_task() {
cancel_delayed_work_sync(&adapter->init_task);
...
cancel_delayed_work_sync(&adapter->stats_task);
...
}idpf_init_task() never checks IDPF_REMOVE_IN_PROG. Any message it sends in this window, such as idpf_send_create_vport_msg(), gets the 500 ms cap.
In idpf_statistics_task(), the new test_bit(IDPF_REMOVE_IN_PROG) check and the READ_ONCE(adapter->vc_xn_timeout_ms) in idpf_send_mb_msg() are separate reads. A worker can pass the bit check before set_bit() and then read the timeout after this WRITE_ONCE(). That GET_STATS is then sent with the 500 ms cap.
If either of these times out, idpf_send_mb_msg() writes 0. Once cancel_delayed_work_sync() returns in idpf_deinit_task(), every vport teardown message (DISABLE_VPORT, DISABLE_QUEUES, DEL_QUEUES, DESTROY_VPORT) then fails at once and nothing is sent.
The commit message says "A request it already has waiting ... keeps its own timeouts". Does that also hold for a stats worker that is past the flag check but has not read the timeout yet? What about init_task, which has no flag check at all?
drivers/net/ethernet/intel/idpf/idpf_main.c static void idpf_shutdown(struct pci_dev *pdev) · line 210
Quoted 2 lines
drivers/net/ethernet/intel/idpf/idpf_main.c +0
-0idpf_vc_core_deinit (adapter);idpf_deinit_dflt_mbx (adapter);
[Severity: Medium]
Can the mailbox rings be freed here while the control plane still owes a reply, with the mailbox queues still enabled in hardware?
Before this patch, libie_ctlq_xn_shutdown() ran first on shutdown, so no teardown message was ever posted. Now the messages are posted with a 500 ms cap, and once one times out the rest fail right away. The code then reaches idpf_deinit_dflt_mbx() almost at once:
idpf_deinit_dflt_mbx() {
...
if (adapter->xnm) {
libie_ctlq_xn_shutdown(adapter->xnm);
idpf_mb_clean(adapter->asq, true);
libie_ctlq_xn_deinit(adapter->xnm, &adapter->ctlq_ctx);
}
...
}libie_ctlq_xn_deinit()->libie_ctlq_deinit()->libie_ctlq_remove()-> libie_ctlq_dealloc_ring_res() frees the ARQ and ASQ descriptor rings and the ARQ buffers.
Nothing in libie/controlq.c ever clears the len/enable or base address registers; libie_ctlq_init_regs() is the only place that writes them. idpf_remove() calls trigger_reset(adapter, IDPF_HR_FUNC_RESET) before idpf_deinit_dflt_mbx(), but idpf_shutdown() does not.
If the reply to the timed-out request arrives late, could the device write a descriptor and payload into the freed ARQ memory, or read a freed ASQ send buffer?
Quoted 1 line
[ ... ]
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +0
-0@@ -195,20 +195,32 @@ static void idpf_prepare_ptp_mb_msg(struct idpf_adapter *adapter, u32 op,* Cleanup the mailbox queue entries of the previously sent message to
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c static void idpf_prepare_ptp_mb_msg(struct idpf_adapter *adapter, u32 op, · line 204
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +6
-1* unmap and release the buffer. * +* The transaction timeout is capped at adapter->vc_xn_timeout_ms. Once a +* synchronous transaction with a shortened timeout times out, later ones +* fail at once instead of waiting again. +* * Return: 0 if the request was successful, -%EBUSY if reset is detected -* or Tx control queue is full, other negative error code on failure. +* or Tx control queue is full, -%ETIMEDOUT if a shortened transaction +* already timed out, other negative error code on failure.
[Severity: Low]
This isn't a bug, but this text ties -ETIMEDOUT only to the early-fail case where nothing is sent.
The function also passes back -ETIMEDOUT from libie_ctlq_xn_send() when the transaction it just sent gets no reply in time. That can happen with any timeout, including the default 60 s.
Should the doc mention both meanings, "message never sent" and "message sent, no reply"?
Quoted 22 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +9
-2*/ int idpf_send_mb_msg (struct idpf_adapter *adapter,struct libie_ctlq_xn_send_params *xn_params,void *send_buf,size_t send_buf_size) { +u32 timeout_ms =READ_ONCE (adapter->vc_xn_timeout_ms);struct libie_ctlq_msg ctlq_msg = {}; +int err =0 ; -if (idpf_is_reset_detected (adapter)) { +if (idpf_is_reset_detected (adapter)) + err = -EBUSY ; +else if (!timeout_ms) + err = -ETIMEDOUT ; + +if (err) {if (!libie_cp_can_send_onstack (send_buf_size))kfree (send_buf); -return -EBUSY ; +return err; }
[ ... ]
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c int idpf_send_mb_msg(struct idpf_adapter *adapter, · line 240
Quoted 12 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +4
-1@@ -219,10 +231,15 @@ int idpf_send_mb_msg(struct idpf_adapter *adapter, xn_params->xnm = adapter->xnm; xn_params->ctlq = xn_params->ctlq ? xn_params->ctlq : adapter->asq; xn_params->rel_tx_buf = kfree; + xn_params->timeout_ms =min_t (u64, xn_params->timeout_ms, timeout_ms);idpf_mb_clean (xn_params->ctlq, false); -return libie_ctlq_xn_send (xn_params); + err =libie_ctlq_xn_send (xn_params); +if (err == -ETIMEDOUT && timeout_ms <IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC ) +WRITE_ONCE (adapter->vc_xn_timeout_ms,0 );
[Severity: High]
Can a control plane that is slow but still alive leave the device in the same state this commit sets out to fix?
The first synchronous transaction that takes longer than 500 ms during shutdown sets vc_xn_timeout_ms to 0 for good. From then on, every idpf_send_mb_msg() takes the new early return above. Nothing is posted to the ASQ, nothing is logged, and nothing resets the value.
idpf_vport_stop() ignores these return values and frees the rings anyway:
idpf_vport_stop() {
...
idpf_send_disable_vport_msg(adapter, vport_id);
idpf_send_disable_queues_msg(vport);
idpf_send_map_unmap_queue_vector_msg(adapter, rsrc, vport_id, false);
...
idpf_vport_queues_rel(vport, rsrc);
...
}idpf_deinit_task() tears the vports down one after another. A single timeout on an early vport, for example on DISABLE_VPORT, also suppresses DISABLE_QUEUES, DEL_QUEUES and DESTROY_VPORT for that vport, plus the whole teardown of every later vport. The device keeps those queues enabled over freed rings.
If DISABLE_QUEUES itself is the one that times out, idpf_send_disable_queues_msg() returns before the marker wait:
err = idpf_send_ena_dis_queues_msg(vport->adapter, &vport->dflt_qv_rsrc, vport->vport_id, false); if (err) return err; return idpf_wait_for_marker_event(vport);
The rings are then freed while the CP may still be processing the request and writing markers into them.
The commit message measures the slowest transaction (DEALLOC_VECTORS) at about 300 ms on an idle system, against the 500 ms cap. It accepts an incomplete teardown only for a control plane that dies.
Would a larger cap, a cap that does not stick at 0, or an overall time budget for the teardown avoid this?
Quoted 18 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +7
-0+ +return err; }/** @@ -372,6 +389,11 @@ static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs)struct net_device *netdev;struct idpf_tx_queue *txq;bool markers_rcvd = true; +bool wait_all; + +/* On shutdown, once one marker is missing, don't wait for the rest */ + wait_all =READ_ONCE (qs->adapter->vc_xn_timeout_ms) >= +IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC ;for (u32 i =0 ; i < qs->num; i++) {switch (qs->qs[i].type) {
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs) · line 407
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +2
-1@@ -381,7 +403,8 @@ static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs) netdev = txq->netdev;idpf_queue_set (SW_MARKER , txq); -idpf_wait_for_sw_marker_completion (txq); +if (markers_rcvd || wait_all) +idpf_wait_for_sw_marker_completion (txq);
[Severity: Medium]
What happens to markers that are late rather than lost on the queues that are skipped here?
During shutdown, wait_all is false for the whole teardown, because vc_xn_timeout_ms is 500 or 0. Once one Tx queue misses its IDPF_WAIT_FOR_MARKER_TIMEO window, the remaining Tx queues of the vport are never polled. Their SW_MARKER bits stay set and their completion queues are not drained.
idpf_vport_stop() then carries on and frees the completion rings, while DESTROY_VPORT is sent only later from idpf_vport_rel():
idpf_vport_intr_deinit(vport, rsrc); idpf_xdp_rxq_info_deinit_all(rsrc); idpf_vport_queues_rel(vport, rsrc);
Before this patch, each queue got its own wait, so markers that arrived up to N times the marker timeout late were still consumed before the rings were freed.
If a remaining marker arrives late on a completion queue other than the one that was polled, can the device write it into a completion ring that has already been freed? The commit message describes the shortcut as intended, but it does not cover late markers.
Quoted 3 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +0
-0markers_rcvd &= !idpf_queue_has (SW_MARKER , txq);break ;default :
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125225145.4126333-1-anthony.l.nguyen%40intel.com
Tony Nguyen
maintainerPATCH 5/6 idpf: fix use-after-free in the PTP auxiliary worker
In reply to Tony NguyenFrom: Emil Tantilov <[email protected]>
idpf_ptp_update_cached_phctime() runs from the PTP auxiliary worker and walks the Rx queues of every vport to refresh rxq->cached_phc_time. There is a small window on down that can result in use-after-free, detected by KASAN:
BUG: KASAN: slab-use-after-free in idpf_ptp_update_cached_phctime+0x367/0x4a0 [idpf] Write of size 8 at addr ff11002146c2a4a0 by task ptp3/8084 ... idpf_ptp_update_cached_phctime+0x367/0x4a0 [idpf] idpf_ptp_do_aux_work+0x37/0x50 [idpf] ptp_aux_kworker+0x64/0xd0 kthread_worker_fn+0x289/0xa20 ... Allocated by task 8615 on cpu 5 at 812.655509s: idpf_vport_queues_alloc+0x9e5/0x2580 [idpf] idpf_vport_open.constprop.0+0x12c/0x10f0 [idpf] idpf_open+0x1bb/0x230 [idpf] __dev_open+0x2f5/0x7c0 ... Freed by task 8628 on cpu 10 at 814.925757s: idpf_rxq_group_rel.part.0+0xef/0x5a0 [idpf] idpf_vport_queues_rel+0xaf/0x140 [idpf] idpf_vport_stop+0x49e/0x850 [idpf] idpf_stop+0x6d/0xc0 [idpf] __dev_close_many+0x24c/0x650
The existing rxq_grps test does not help. It is evaluated before the pointer is read again, so the worker can equally run past the kfree() and dereference a NULL rxq_grps with a stale num_rxq_grp.
Add a per vport rxq_grps_lock and use it to serialize every transition of rsrc->rxq_grps against the worker:
- Teardown: idpf_rxq_group_rel() sets rsrc->rxq_grps to NULL under the lock before anything reachable through it is freed. The worker re-reads the pointer under the same lock, so it either sees a live array while the release path is still blocked on the lock, or sees NULL and skips that vport. The frees stay outside the lock.
- Allocation: Build the rxq_grps array privately and publish it to rsrc->rxq_grps under the lock only once every group is complete. The freeing of the group contents moves to idpf_rxq_grps_free(), which takes the array explicitly so the allocation error path can unwind safely.
- Soft reset: idpf_vport_stop() freed rxq_grps and cleared the live vport's copy under rxq_grps_lock. Drop the stale pointer in the clone so the memcpy() below does not republish the freed array to the PTP aux worker before idpf_vport_open() reallocates it. The lock sits past the offsetof(struct idpf_vport, link_up) boundary that idpf_initiate_soft_reset() stops its memcpy() at, next to the wait queues and mutexes that are already kept out of the copy, so a soft reset never byte-copies it. The data it guards, dflt_qv_rsrc, is inside that copied region, which is why the clone has to be cleared rather than relying on the lock alone.
Also, fix the NULL check in idpf_ptp_update_phctime_rxq_grp(). The split queue case took the address of a member before testing it, which can never be NULL, so test the rxq_sets[] entry itself.
--- drivers/net/ethernet/intel/idpf/idpf.h | 5 ++ drivers/net/ethernet/intel/idpf/idpf_lib.c | 6 ++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 16 +++++- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 63 +++++++++++++++------ 4 files changed, 71 insertions(+), 19 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +5 -0
@@ -373,6 +373,8 @@ struct idpf_q_vec_rsrc {* @default_vport: Use this vport if one isn't specified * @crc_enable: Enable CRC insertion offload * @link_up: True if link is up +* @rxq_grps_lock: Serializes every transition of the @dflt_qv_rsrc.rxq_grps +* pointer of a vport against the PTP auxiliary worker * @tx_tstamp_caps: Capabilities negotiated for Tx timestamping * @tstamp_config: The Tx tstamp config * @tstamp_task: Tx timestamping task
@@ -406,6 +408,9 @@ struct idpf_vport {bool crc_enable;bool link_up; +/* Must be past the point idpf_initiate_soft_reset() memcpy()s */ +spinlock_t rxq_grps_lock; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps;struct kernel_hwtstamp_config tstamp_config;struct work_struct tstamp_task;
drivers/net/ethernet/intel/idpf/idpf_lib.c +6 -0
@@ -1295,6 +1295,7 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, vport->compln_clean_budget =IDPF_TX_COMPLQ_CLEAN_BUDGET ; vport->default_vport = adapter->num_alloc_vports <idpf_get_default_vports (adapter); +spin_lock_init (&vport->rxq_grps_lock); rsrc = &vport->dflt_qv_rsrc; rsrc->dev = &adapter->pdev->dev;
@@ -2097,6 +2098,11 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport, }else {set_bit (IDPF_VPORT_DEL_QUEUES , vport->flags);idpf_vport_stop (vport, false); + +/* Drop the stale pointer in the clone, as rxq_grps was freed +* by idpf_vport_stop(). +*/ + new_rsrc->rxq_grps =NULL ; } err = idpf_send_add_queues_msg(adapter, vport_config, new_rsrc,
drivers/net/ethernet/intel/idpf/idpf_ptp.c +13 -3
@@ -348,9 +348,11 @@ idpf_ptp_update_phctime_rxq_grp(const struct idpf_rxq_group *grp, bool split, } }else {for (i =0 ; i < grp->splitq.num_rxq_sets; i++) { +if (!grp->splitq.rxq_sets[i]) +continue ; + rxq = &grp->splitq.rxq_sets[i]->rxq; -if (rxq) -WRITE_ONCE (rxq->cached_phc_time, systime); +WRITE_ONCE (rxq->cached_phc_time, systime); } } }
@@ -387,10 +389,17 @@ static int idpf_ptp_update_cached_phctime(struct idpf_adapter *adapter)struct idpf_q_vec_rsrc *rsrc;bool split; -if (!vport || !vport->dflt_qv_rsrc.rxq_grps) +if (!vport)continue ; rsrc = &vport->dflt_qv_rsrc; + +spin_lock (&vport->rxq_grps_lock); +if (!rsrc->rxq_grps) { +spin_unlock (&vport->rxq_grps_lock); +continue ; + } + split =idpf_is_queue_model_split (rsrc->rxq_model);for (u16 i =0 ; i < rsrc->num_rxq_grp; i++) {
@@ -398,6 +407,7 @@ static int idpf_ptp_update_cached_phctime(struct idpf_adapter *adapter)idpf_ptp_update_phctime_rxq_grp (grp, split, systime); } +spin_unlock (&vport->rxq_grps_lock); }return 0 ;
drivers/net/ethernet/intel/idpf/idpf_txrx.c +47 -16
118 lines not on this page · raw message
Signature · 1 line
2.47.1
[email protected]
AI reviewRe: [PATCH net 5/6] idpf: fix use-after-free in the PTP auxiliary worker
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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] This patch makes idpf leak the top-level Rx queue group array every time a vport is stopped, and also on the allocation error path.
- [Low] idpf: inaccurate Fixes trailer citing 1a49cf814fe1 instead of 494565a74502
--
idpf: fix use-after-free in the PTP auxiliary worker
This patch adds a per-vport rxq_grps_lock that serializes changes to rsrc->rxq_grps against the PTP auxiliary worker. idpf_rxq_group_rel() now clears the pointer under the lock and passes the array to a new idpf_rxq_grps_free() helper. idpf_rxq_group_alloc() now builds the array privately and publishes it at the end. The patch also clears the stale pointer in the soft reset clone and fixes a NULL check in idpf_ptp_update_phctime_rxq_grp().
Quoted 39 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +14
-6@@ -1357,16 +1357,15 @@ static void idpf_rxq_sw_queue_rel(struct idpf_rxq_group *rx_qgrp) }/** -* idpf_rxq_group_rel - Release all resources for rxq groups +* idpf_rxq_grps_free - Free an Rx queue group array and everything in it * @rsrc: pointer to queue and vector resources +* @rxq_grps: group array to free, not reachable through @rsrc any more */ -static void idpf_rxq_group_rel (struct idpf_q_vec_rsrc *rsrc) +static void idpf_rxq_grps_free (struct idpf_q_vec_rsrc *rsrc, +struct idpf_rxq_group *rxq_grps) { -if (!rsrc->rxq_grps) -return ; -for (unsigned int i =0 ; i < rsrc->num_rxq_grp; i++) { -struct idpf_rxq_group *rx_qgrp = &rsrc->rxq_grps[i]; +struct idpf_rxq_group *rx_qgrp = &rxq_grps[i];u16 num_rxq;if (idpf_is_queue_model_split (rsrc->rxq_model)) {@@ -1391,14 +1390,37 @@ static void idpf_rxq_group_rel(struct idpf_q_vec_rsrc *rsrc) rsrc->rxq_grps =NULL ; } +/** +* idpf_rxq_group_rel - Release all resources for rxq groups +* @vport: vport the queue groups belong to +* @rsrc: pointer to queue and vector resources +*/ +static void idpf_rxq_group_rel (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc) +{ +struct idpf_rxq_group *rxq_grps;
drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_rxq_group_rel(struct idpf_q_vec_rsrc *rsrc) · line 1411
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +10
-0+ +if (!rsrc->rxq_grps) +return ; + +spin_lock (&vport->rxq_grps_lock); + rxq_grps = rsrc->rxq_grps; + rsrc->rxq_grps =NULL ; +spin_unlock (&vport->rxq_grps_lock); + +idpf_rxq_grps_free (rsrc, rxq_grps);
[Severity: High]
Does this leak the rxq_grps array?
The last two lines of idpf_rxq_grps_free() are unchanged from the old idpf_rxq_group_rel(). They still free through rsrc, not through the new argument:
drivers/net/ethernet/intel/idpf/idpf_txrx.c:idpf_rxq_grps_free() {
...
kfree(rsrc->rxq_grps);
rsrc->rxq_grps = NULL;
}By the time the helper runs here, rsrc->rxq_grps has already been set to NULL under rxq_grps_lock, so this is kfree(NULL). The helper frees the contents of each group through rxq_grps[i], but the array allocated by kzalloc_objs() is never freed.
This path runs on every interface down, every soft reset (channel, ring, MTU or GRO_HW changes) and every vport dealloc:
idpf_vport_stop()
idpf_vport_queues_rel()
idpf_vport_queue_grp_rel_all()
idpf_rxq_group_rel()
idpf_rxq_grps_free()
The error path in idpf_rxq_group_alloc() seems to have the same problem:
err_alloc:
idpf_rxq_grps_free(rsrc, rxq_grps);
Here rxq_grps was never published to rsrc->rxq_grps, so again only kfree(NULL) runs. The err_out path in idpf_vport_queue_grp_alloc_all() calls idpf_vport_queue_grp_rel_all(), but that does not free it either, because idpf_rxq_group_rel() returns early when rsrc->rxq_grps is NULL.
Also, the helper's rsrc->rxq_grps = NULL store writes the protected pointer without holding rxq_grps_lock. The new @rxq_grps_lock kernel-doc says the lock serializes every transition of that pointer.
The same code is still there at the end of the series (73aecc14293f).
Should idpf_rxq_grps_free() end with kfree(rxq_grps) and leave rsrc->rxq_grps alone?
Quoted 2 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +2
-0+} +
[ ... ]
Quoted 7 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +0
-0@@ -348,9 +348,11 @@ idpf_ptp_update_phctime_rxq_grp(const struct idpf_rxq_group *grp, bool split, } }else {for (i =0 ; i < grp->splitq.num_rxq_sets; i++) {
drivers/net/ethernet/intel/idpf/idpf_ptp.c idpf_ptp_update_phctime_rxq_grp(const struct idpf_rxq_group *grp, bool split, · line 358
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +4
-2+if (!grp->splitq.rxq_sets[i]) +continue ; + rxq = &grp->splitq.rxq_sets[i]->rxq; -if (rxq) -WRITE_ONCE (rxq->cached_phc_time, systime); +WRITE_ONCE (rxq->cached_phc_time, systime); } } }
[Severity: Low]
Is the Fixes tag pointing at the right commit?
As far as I can tell, in 1a49cf814fe1 ("idpf: add Tx timestamp flows") idpf_ptp_update_cached_phctime() only refreshed adapter->ptp->cached_phc_time and adapter->ptp->cached_phc_jiffies. It did not walk the vports and never touched rxq_grps.
The code this patch fixes seems to come from 494565a74502 ("idpf: add support for Rx timestamping"). That commit added the idpf_for_each_vport() loop that reads vport->dflt_qv_rsrc.rxq_grps. It also added idpf_ptp_update_phctime_rxq_grp(), including the always-true test on &grp->splitq.rxq_sets[i]->rxq.
This is going to net and will be picked up for stable. Should the trailer be the following instead?
As it stands, stable trees that carry 1a49cf814fe1 but not the Rx timestamping commit would be told they need this fix. They do not contain the Rx queue walk at all, so the patch would not apply there.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125225145.4126333-1-anthony.l.nguyen%40intel.com
Tony Nguyen
maintainerPATCH 6/6 idpf: release PTP before freeing vports on the init task error path
In reply to Tony NguyenFrom: Emil Tantilov <[email protected]>
Release PTP, which cancels the aux worker, before the unwind frees the vports, matching the idpf_vc_core_deinit() order. Previously it was possible for idpf_ptp_update_cached_phctime() which runs via the PTP auxiliary worker to read a non-NULL but already freed slot, pass its NULL check, and dereference the freed vport. This can happen on driver load, where any vport past the first fails to initialize:
BUG: KASAN: slab-use-after-free in idpf_ptp_update_cached_phctime+0x4ad/0x4d0 [idpf] Read of size 8 at addr ff11002129215050 by task ptp3/10120 ... idpf_ptp_update_cached_phctime+0x4ad/0x4d0 [idpf] idpf_ptp_do_aux_work+0x37/0x50 [idpf] ptp_aux_kworker+0x64/0xd0 kthread_worker_fn+0x289/0xa20 ... Allocated by task 8820 on cpu 32 at 2113.761375s: idpf_init_task+0x321/0x21c0 [idpf]a process_one_work+0x917/0x1940 worker_thread+0x5a5/0xfe0 ... Freed by task 8820 on cpu 32 at 2113.809014s: idpf_vport_dealloc+0x8cf/0x16b0 [idpf] idpf_init_task+0x245/0x21c0 [idpf] process_one_work+0x917/0x1940 worker_thread+0x5a5/0xfe0
The aux worker is armed in idpf_vc_core_init() before idpf_init_task() is queued, so it is live throughout a failing init, leading to the scenario above.
--- drivers/net/ethernet/intel/idpf/idpf_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_lib.c +2 -1
@@ -1769,6 +1769,8 @@ void idpf_init_task(struct work_struct *work)return ; unwind_vports: +idpf_ptp_release (adapter); +if (default_vport) {for (index =0 ; index < adapter->max_vports; index++) {if (adapter->vports[index])
@@ -1782,7 +1784,6 @@ void idpf_init_task(struct work_struct *work)cancel_delayed_work_sync (&adapter->serv_task);cancel_delayed_work_sync (&adapter->mbx_task); } -idpf_ptp_release (adapter);clear_bit (IDPF_HR_RESET_IN_PROG , adapter->flags); }
Signature · 1 line
2.47.1
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
- 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.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.