RE: [Intel-wired-lan] [PATCH v3] ice: ice_adapter: release xa entry on adapter allocation failure

From: Loktionov, Aleksandr
Date: Wed Oct 01 2025 - 08:11:32 EST




> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@xxxxxxxxxx> On Behalf
> Of Haotian Zhang
> Sent: Wednesday, October 1, 2025 1:54 PM
> To: Keller, Jacob E <jacob.e.keller@xxxxxxxxx>; Nguyen, Anthony L
> <anthony.l.nguyen@xxxxxxxxx>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@xxxxxxxxx>
> Cc: Andrew Lunn <andrew+netdev@xxxxxxx>; David S . Miller
> <davem@xxxxxxxxxxxxx>; Eric Dumazet <edumazet@xxxxxxxxxx>; Jakub
> Kicinski <kuba@xxxxxxxxxx>; Paolo Abeni <pabeni@xxxxxxxxxx>; intel-
> wired-lan@xxxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; Haotian Zhang <vulab@xxxxxxxxxxx>
> Subject: [Intel-wired-lan] [PATCH v3] ice: ice_adapter: release xa
> entry on adapter allocation failure
>
> When ice_adapter_new() fails, the reserved XArray entry created by
> xa_insert() is not released. This causes subsequent insertions at
> the same index to return -EBUSY, potentially leading to
> NULL pointer dereferences.
>
> Reorder the operations as suggested by Przemek Kitszel:
> 1. Check if adapter already exists (xa_load)
> 2. Reserve the XArray slot (xa_reserve)
> 3. Allocate the adapter (ice_adapter_new)
> 4. Store the adapter (xa_store)
>
> Fixes: 0f0023c649c7 ("ice: do not init struct ice_adapter more times
> than needed")
> Suggested-by: Przemek Kitszel <przemyslaw.kitszel@xxxxxxxxx>
> Suggested-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>
> Signed-off-by: Haotian Zhang <vulab@xxxxxxxxxxx>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@xxxxxxxxx>

>
> ---
> Changes in v3:
> - Reorder xa_load/xa_reserve/ice_adapter_new/xa_store calls as
> suggested by Przemek Kitszel, instead of just adding xa_release().
> Changes in v2:
> - Instead of checking the return value of xa_store(), fix the real
> bug
> where a failed ice_adapter_new() would leave a stale entry in the
> XArray.
> - Use xa_release() to clean up the reserved entry, as suggested by
> Jacob Keller.
> ---

...

> --
> 2.50.1.windows.1