Skip to contentSkip to conversation

ice: fix use-after-free in dynamic port cleanup

PATCH In review [email protected] 4 participants 5 messages Jul 14 – Sep 28

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: fix use-after-free in dynamic port cleanup

From: Xuanqiang Luo <[email protected]>

ice_dealloc_dynamic_port() uses dyn_port->vsi->idx to erase the dynamic port from pf->dyn_ports. However, it frees the VSI before reading the index for the erase, resulting in a use-after-free.

Follow the reverse of the allocation order in ice_alloc_dynamic_port() by erasing the xarray entry before freeing the VSI.

Fixes eda69d654c7e ("ice: add basic devlink subfunctions support")
---
 drivers/net/ethernet/intel/ice/devlink/port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/port.c +1 -1
index 2a2e56777f9f7..3ede246490027 100644
@@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
 
 	xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
 	ice_eswitch_detach_sf(pf, dyn_port);
-	ice_vsi_free(dyn_port->vsi);
 	xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
+	ice_vsi_free(dyn_port->vsi);
 	kfree(dyn_port);
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On 14.07.2026 08:39, [email protected] wrote:

From: Xuanqiang Luo <[email protected]>

ice_dealloc_dynamic_port() uses dyn_port->vsi->idx to erase the dynamic port from pf->dyn_ports. However, it frees the VSI before reading the index for the erase, resulting in a use-after-free.

Quoted 6 lines

Follow the reverse of the allocation order in ice_alloc_dynamic_port() by erasing the xarray entry before freeing the VSI.

Fixes eda69d654c7e ("ice: add basic devlink subfunctions support")

Thank you!
I wonder how such a glaring issue survived in the codebase for so long. Perhaps ice_vsi_free() exited early for some reason.

Quoted 18 lines
---
 drivers/net/ethernet/intel/ice/devlink/port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/port.c +1 -1
index 2a2e56777f9f7..3ede246490027 100644
@@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
 
 	xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
 	ice_eswitch_detach_sf(pf, dyn_port);
-	ice_vsi_free(dyn_port->vsi);
 	xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
+	ice_vsi_free(dyn_port->vsi);
 	kfree(dyn_port);
 }
 
#2 lore raw
Quoted 10 lines · Marcin Szycik
Quoted 9 lines · On 14.07.2026 08:39,[email protected] wrote:

From: Xuanqiang Luo<[email protected]>

ice_dealloc_dynamic_port() uses dyn_port->vsi->idx to erase the dynamic port from pf->dyn_ports. However, it frees the VSI before reading the index for the erase, resulting in a use-after-free.

Follow the reverse of the allocation order in ice_alloc_dynamic_port() by erasing the xarray entry before freeing the VSI.

Quoted 8 lines
Quoted 3 lines
Fixes eda69d654c7e ("ice: add basic devlink subfunctions support")

Thank you!
I wonder how such a glaring issue survived in the codebase for so long. Perhaps ice_vsi_free() exited early for some reason.

Thanks for the review!

Hard to say—maybe the window is quite small and the freed slab still holds the old idx most of the time, so nothing obvious shows up.

Quoted 18 lines
Quoted 18 lines
---
  drivers/net/ethernet/intel/ice/devlink/port.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/port.c +1 -1
index 2a2e56777f9f7..3ede246490027 100644
@@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
 
  	xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
  	ice_eswitch_detach_sf(pf, dyn_port);
-	ice_vsi_free(dyn_port->vsi);
  	xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
+	ice_vsi_free(dyn_port->vsi);
  	kfree(dyn_port);
  }
 
Tested-by
#3 lore raw
Quoted 55 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of luoxuanqiang
Sent: Wednesday, July 15, 2026 4:59 AM
To: Marcin Szycik <[email protected]>; intel-wired- [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; Samudrala, Sridhar <[email protected]>; Drewek, Wojciech <[email protected]>; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; Xuanqiang Luo <[email protected]>; [email protected]
Subject: Re: [Intel-wired-lan] [PATCH iwl-net v1] ice: fix use-after-free in dynamic port cleanup

Quoted 10 lines · Marcin Szycik
Quoted 9 lines · On 14.07.2026 08:39,[email protected] wrote:

From: Xuanqiang Luo<[email protected]>

ice_dealloc_dynamic_port() uses dyn_port->vsi->idx to erase the dynamic port from pf->dyn_ports. However, it frees the VSI before reading the index for the erase, resulting in a use-after-free.

Follow the reverse of the allocation order in ice_alloc_dynamic_port() by erasing the xarray entry before freeing the VSI.

Quoted 8 lines
Quoted 3 lines
Fixes eda69d654c7e ("ice: add basic devlink subfunctions support")

Thank you!
I wonder how such a glaring issue survived in the codebase for so long. Perhaps ice_vsi_free() exited early for some reason.

Thanks for the review!

Hard to say—maybe the window is quite small and the freed slab still holds the old idx most of the time, so nothing obvious shows up.

Quoted 12 lines
Quoted 12 lines
---
  drivers/net/ethernet/intel/ice/devlink/port.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/port.c +0 -0
index 2a2e56777f9f7..3ede246490027 100644
@@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct
 ice_dynamic_port *dyn_port)
 
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ice/devlink/port.c static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port) · line 596

Quoted 8 lines
drivers/net/ethernet/intel/ice/devlink/port.c +1 -1
  	xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
  	ice_eswitch_detach_sf(pf, dyn_port);
-	ice_vsi_free(dyn_port->vsi);
  	xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
+	ice_vsi_free(dyn_port->vsi);
  	kfree(dyn_port);
  }
Reviewed-by on v1 1/1
#4 lore raw
In reply to [email protected]
Quoted 50 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of [email protected]
Sent: Tuesday, July 14, 2026 8:40 AM
To: [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; Samudrala, Sridhar <[email protected]>; Drewek, Wojciech <[email protected]>; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; Xuanqiang Luo <[email protected]>; [email protected]
Subject: [Intel-wired-lan] [PATCH iwl-net v1] ice: fix use-after-free in dynamic port cleanup

From: Xuanqiang Luo <[email protected]>

ice_dealloc_dynamic_port() uses dyn_port->vsi->idx to erase the dynamic port from pf->dyn_ports. However, it frees the VSI before reading the index for the erase, resulting in a use-after-free.

Follow the reverse of the allocation order in ice_alloc_dynamic_port() by erasing the xarray entry before freeing the VSI.

Fixes eda69d654c7e ("ice: add basic devlink subfunctions support")
---
 drivers/net/ethernet/intel/ice/devlink/port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/port.c +1 -2
index 2a2e56777f9f7..3ede246490027 100644
@@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct
 ice_dynamic_port *dyn_port)
 
 	xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
 	ice_eswitch_detach_sf(pf, dyn_port);
-	ice_vsi_free(dyn_port->vsi);
 	xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
+	ice_vsi_free(dyn_port->vsi);
 	kfree(dyn_port);
 }
 
--
Quoted 1 line

2.43.0