ice: hold a VF reference while creating LAG placeholder VSIs
Subsystems (3)
PATCH 1/1 ice: hold a VF reference while creating LAG placeholder VSIs
When the secondary port of an active-active bond comes up, the driver creates a placeholder VSI for each VF. It walks the VF table with ice_for_each_vf() while holding only pf->lag_mutex. If SR-IOV is disabled during the walk, ice_free_vfs() can remove a VF and drop its last reference while the walk still uses it.
Taking table_lock or vf->cfg_lock here would reverse the lock order used by VF reset, which can hold both locks before taking pf->lag_mutex.
Iterate over VF IDs and look up each VF with ice_get_vf_by_id(). This holds a reference until ice_put_vf(), keeping the VF alive through placeholder VSI setup, even if ice_vsi_setup() sleeps.
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus PCI_IOV, ICE and W=1.
drivers/net/ethernet/intel/ice/ice_lag.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_lag.c +8 -2
@@ -1913,18 +1913,24 @@ static void ice_lag_monitor_act_act(struct ice_lag *lag,struct ice_vsi_cfg_params params = {};struct ice_vsi *nvsi;struct ice_vf *vf; -unsigned int bkt; params.type =ICE_VSI_VF ; params.port_info = event_pf->hw.port_info; params.flags =ICE_VSI_FLAG_INIT ; -ice_for_each_vf (lag->pf, bkt, vf) { +for (u16 vf_id =0 ; + vf_id < lag->pf->vfs.num_supported; + vf_id++) { + vf =ice_get_vf_by_id (lag->pf, vf_id); +if (!vf) +continue ; + params.vf = vf; nvsi =ice_vsi_setup (event_pf, ¶ms);ice_lag_aa_clear_spoof (nvsi); lag->sec_vf[vf->vf_id] = nvsi; +ice_put_vf (vf); } }
base-commit: bf9edda440e747a4a9b351656a395f0b77cc1fef
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] ice: UAF on placeholder VSI nvsi->vf after ice_put_vf() in ice_lag_monitor_act_act() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] ice: UAF on placeholder VSI nvsi->vf after ice_put_vf() in ice_lag_monitor_act_act()
--
commit 78df21de98f414a15f945d5648335b162e30040a
Author: Changyul Lee <[email protected]>
ice: hold a VF reference while creating LAG placeholder VSIs
This commit replaces the ice_for_each_vf() walk in ice_lag_monitor_act_act() with an indexed lookup via ice_get_vf_by_id() and ice_put_vf() so a VF reference is held while creating secondary PF placeholder VSIs.
Quoted 20 lines
drivers/net/ethernet/intel/ice/ice_lag.c +5
-2@@ -1913,18 +1913,24 @@ static void ice_lag_monitor_act_act(struct ice_lag *lag,struct ice_vsi_cfg_params params = {};struct ice_vsi *nvsi;struct ice_vf *vf; -unsigned int bkt; params.type =ICE_VSI_VF ; params.port_info = event_pf->hw.port_info; params.flags =ICE_VSI_FLAG_INIT ; -ice_for_each_vf (lag->pf, bkt, vf) { +for (u16 vf_id =0 ; + vf_id < lag->pf->vfs.num_supported; + vf_id++) { + vf =ice_get_vf_by_id (lag->pf, vf_id); +if (!vf)
drivers/net/ethernet/intel/ice/ice_lag.c static void ice_lag_monitor_act_act(struct ice_lag *lag, · line 1935
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_lag.c +3
-0+continue ; + params.vf = vf; nvsi =ice_vsi_setup (event_pf, ¶ms);ice_lag_aa_clear_spoof (nvsi); lag->sec_vf[vf->vf_id] = nvsi; +ice_put_vf (vf); } }
[Severity: High]
Does dropping the VF reference right after ice_vsi_setup() leave nvsi->vf dangling if SR-IOV is disabled before the bond unlinks?
ice_vsi_setup() copies params.vf into nvsi->vf without taking its own reference, and ice_free_vfs() drops the VF table references and frees struct ice_vf without releasing lag->sec_vf[]. When the bond later unlinks, ice_lag_changeupper_event() calls ice_vsi_release() on lag->sec_vf[i], which dereferences the freed nvsi->vf in ice_vf_is_lldp_ena(vsi->vf) and ice_vsi_delete_from_hw() -> vsi->vf->vf_id.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1