Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 2 related pre-existing issues it does not
introduce:
- [Critical] idpf: double free of vport->txqs in
  idpf_initiate_soft_reset() [1]
- [Critical] idpf: use-after-free in
  idpf_ptp_get_txq_tstamp_capability() [2]
--

commit 1bdbc7bd2b7486c90a1b74658932d35032195933
Author: Stan Iliev <[email protected]>

idpf: psp: add psp work and tx key insertion completion

This commit adds delayed work to send queued PSP key deletion requests and
implements completion handling, timeout recovery, and quiescing for
asynchronous TX key insertion requests.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c 
> b/drivers/net/ethernet/intel/idpf/idpf_lib.c
> index 062753a62f593..18d484c1a2cad 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c
[ ... ]
> @@ -1882,6 +1888,11 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,
>       if (!new_vport)
>               return -ENOMEM;
>  
> +     /* No PSP packet is sent while the queues are reallocated, the PSP
> +      * work is queued again below
> +      */
> +     idpf_cancel_psp_work(adapter);
> +
>       /* This purposely avoids copying the end of the struct because it
>        * contains wait_queues and mutexes and other stuff we don't want to
>        * mess with. Nothing below should use those variables from new_vport
> @@ -1970,6 +1981,7 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,
>  
>  free_vport:
>       kfree(new_vport);
> +     idpf_queue_psp_work(adapter);
>  
>       if (reset_cause == IDPF_SR_MTU_CHANGE)
>               idpf_idc_vdev_mtu_event(vport->vdev_info,

[Severity: Critical]
This problem wasn't introduced by this patch, but can
idpf_initiate_soft_reset() cause a double free of vport->txqs [1]?

After copying vport into new_vport, idpf_vport_stop() calls
idpf_vport_queues_rel(), which frees vport->txqs and sets it to NULL, while
only new_rsrc->rxq_grps is cleared in the clone:

drivers/net/ethernet/intel/idpf/idpf_lib.c:idpf_initiate_soft_reset() {
        ...
        memcpy(new_vport, vport, offsetof(struct idpf_vport, link_up));
        ...
        } else {
                set_bit(IDPF_VPORT_DEL_QUEUES, vport->flags);
                idpf_vport_stop(vport, false);

                /* Drop the stale pointer in the clone, as rxq_grps was freed
                 * by idpf_vport_stop().
                 */
                new_rsrc->rxq_grps = NULL;
        }
        ...
        memcpy(vport, new_vport, offsetof(struct idpf_vport, link_up));
        ...
}

The second memcpy() writes the freed vport->txqs pointer from new_vport
back into vport.  If idpf_set_real_num_queues() or idpf_vport_open() fails
before reallocating the queues, the dangling vport->txqs pointer remains in
vport and is freed a second time when idpf_vport_queues_alloc() later fails
into idpf_vport_queues_rel().

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c 
> b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index 90fe5212095df..bff3b0f46113e 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -3281,6 +3281,9 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)
>       if (remove_in_prog)
>               libie_ctlq_xn_shutdown(adapter->xnm);
>  
> +     /* The mailbox transactions were shut down in both cases */
> +     idpf_psp_quiesce(adapter);
> +
>       cancel_delayed_work_sync(&adapter->serv_task);
>       cancel_delayed_work_sync(&adapter->mbx_task);

[Severity: Critical]
This problem wasn't introduced by this patch, but can
idpf_ptp_get_txq_tstamp_capability() trigger a use-after-free on
txq->cached_tstamp_caps during teardown [2]?

In idpf_vc_core_deinit(), idpf_ptp_release() frees vport->tx_tstamp_caps
before idpf_deinit_task() stops the vports and netdevs, while
txq->cached_tstamp_caps on active TX queues still points to it:

CPU0                                  CPU1
idpf_vc_core_deinit()
  idpf_ptp_release()
    idpf_ptp_release_vport_tstamp()
      kfree(vport->tx_tstamp_caps)
                                      idpf_tx_start()
                                        ...
                                          idpf_ptp_get_txq_tstamp_capability()
                                            txq->cached_tstamp_caps->access
                                              <-- use-after-free
  idpf_deinit_task()

[1] https://sashiko.dev/#/bug/linux-2cb96bfd-fe1d-4dd4-ba7f-97cce6b47ab6
[2] https://sashiko.dev/#/bug/linux-6f8f8f90-94e3-4193-85dc-3ce7d6f00653

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

Reply via email to