Skip to content

Commit fe868b4

Browse files
GoodLuck612anguy11
authored andcommitted
ice: Fix memory leak in ice_set_ringparam()
In ice_set_ringparam, tx_rings and xdp_rings are allocated before rx_rings. If the allocation of rx_rings fails, the code jumps to the done label leaking both tx_rings and xdp_rings. Furthermore, if the setup of an individual Rx ring fails during the loop, the code jumps to the free_tx label which releases tx_rings but leaks xdp_rings. Fix this by introducing a free_xdp label and updating the error paths to ensure both xdp_rings and tx_rings are properly freed if rx_rings allocation or setup fails. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: fcea6f3 ("ice: Add stats and ethtool support") Fixes: efc2214 ("ice: Add support for XDP") Signed-off-by: Zilin Guan <[email protected]> Reviewed-by: Paul Menzel <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Tested-by: Rinitha S <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent fb4903b commit fe868b4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/net/ethernet/intel/ice/ice_ethtool.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,7 +3332,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
33323332
rx_rings = kzalloc_objs(*rx_rings, vsi->num_rxq);
33333333
if (!rx_rings) {
33343334
err = -ENOMEM;
3335-
goto done;
3335+
goto free_xdp;
33363336
}
33373337

33383338
ice_for_each_rxq(vsi, i) {
@@ -3359,7 +3359,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
33593359
}
33603360
kfree(rx_rings);
33613361
err = -ENOMEM;
3362-
goto free_tx;
3362+
goto free_xdp;
33633363
}
33643364
}
33653365

@@ -3411,6 +3411,13 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
34113411
}
34123412
goto done;
34133413

3414+
free_xdp:
3415+
if (xdp_rings) {
3416+
ice_for_each_xdp_txq(vsi, i)
3417+
ice_free_tx_ring(&xdp_rings[i]);
3418+
kfree(xdp_rings);
3419+
}
3420+
34143421
free_tx:
34153422
/* error cleanup if the Rx allocations failed after getting Tx */
34163423
if (tx_rings) {

0 commit comments

Comments
 (0)