Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] idpf: use-after-free of vport in
  idpf_mac_filter_async_handler() on remove
--

commit 6b177b36cf8b8b2ad682680d9ce0837d77dda78f
Author: guohongyu <[email protected]>

idpf: fix vport_id used as array index in MAC filter async handler

This commit indexes adapter->vport_config[] by vport->idx instead of the
raw vport_id from the virtchnl payload in idpf_mac_filter_async_handler().

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c 
> b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index dac1d9fc4ab12..7870e8f810fa9 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -3781,7 +3781,7 @@ static void idpf_mac_filter_async_handler(void *ctx,
>       if (!vport)
>               goto invalid_payload;
>  
> -     vport_config = adapter->vport_config[le32_to_cpu(ma_list->vport_id)];
> +     vport_config = adapter->vport_config[vport->idx];

[Severity: Medium]
Can dereferencing vport->idx here cause a use-after-free of vport during
driver removal or shutdown?

CPU0                                    CPU1 (mbx_wq)
idpf_remove()
  set_bit(IDPF_REMOVE_IN_PROG, ...)
  idpf_vc_core_deinit()
    queue_delayed_work(..., &mbx_task)
    idpf_deinit_task()
      idpf_vport_dealloc()
                                        idpf_mac_filter_async_handler()
                                          vport = idpf_vid_to_vport(...)
        idpf_vport_rel()
          kfree(vport)
                                          vport->idx  <-- use-after-free
        adapter->vports[i] = NULL;

During removal, idpf_vc_core_deinit() keeps mbx_task running across
idpf_deinit_task() and relies on async callbacks to bail out when
IDPF_REMOVE_IN_PROG is set, as idpf_ptp_get_tx_tstamp_async_handler()
does.  Because idpf_vport_dealloc() frees vport inside idpf_vport_rel()
before clearing adapter->vports[i], and nothing serializes it against
idpf_vid_to_vport(), an arriving MAC filter error reply can obtain a
dangling vport pointer and read vport->idx after vport is freed.

Checking test_bit(IDPF_REMOVE_IN_PROG, adapter->flags) at the start of
idpf_mac_filter_async_handler() would prevent the handler from running
while vports are being torn down.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to