Skip to contentSkip to conversation

ice: fix double free in ice_sf_eth_activate() error path

PATCH In review Guangshuo Li 2 participants 2 messages Mar 19 – Mar 20

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

PATCH v2 1/1 ice: fix double free in ice_sf_eth_activate() error path

When auxiliary_device_add() fails, ice_sf_eth_activate() jumps to aux_dev_uninit and calls auxiliary_device_uninit(&sf_dev->adev).

The device release callback ice_sf_dev_release() frees sf_dev, but the current error path falls through to sf_dev_free and calls kfree(sf_dev) again, causing a double free.

Keep kfree(sf_dev) for the auxiliary_device_init() failure path, but avoid falling through to sf_dev_free after auxiliary_device_uninit().

Fixes 13acc5c4cdbe ("ice: subfunction activation and base devlink ops")

---
v2:
- replace goto xa_erase with return err after auxiliary_device_uninit()
- avoid xa_erase() in the auxiliary_device_uninit() path since it is already done in ice_sf_dev_release()

 drivers/net/ethernet/intel/ice/ice_sf_eth.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/ice/ice_sf_eth.c +2 -0
index 1a2c94375ca7..f7266d036815 100644
@@ -305,6 +305,8 @@ ice_sf_eth_activate(struct ice_dynamic_port *dyn_port,
 
 aux_dev_uninit:
 	auxiliary_device_uninit(&sf_dev->adev);
+	return err;
+
 sf_dev_free:
 	kfree(sf_dev);
 xa_erase:
Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 14 lines · Guangshuo Li

When auxiliary_device_add() fails, ice_sf_eth_activate() jumps to aux_dev_uninit and calls auxiliary_device_uninit(&sf_dev->adev).

The device release callback ice_sf_dev_release() frees sf_dev, but the current error path falls through to sf_dev_free and calls kfree(sf_dev) again, causing a double free.

Keep kfree(sf_dev) for the auxiliary_device_init() failure path, but avoid falling through to sf_dev_free after auxiliary_device_uninit().

Fixes 13acc5c4cdbe ("ice: subfunction activation and base devlink ops")
Quoted 5 lines

---
v2:
- replace goto xa_erase with return err after auxiliary_device_uninit()
- avoid xa_erase() in the auxiliary_device_uninit() path since it is already done in ice_sf_dev_release()