Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] drm/etnaviv: dangling pointer in
  etnaviv_flop_reset_ppu_init() [1]
--

commit e39a29696b51cde581759634e80e80a231bf7a60
Author: Christian Gmeiner <[email protected]>

drm/etnaviv: Don't set up a GPU on resume that is not initialized

This commit resets gpu->state to ETNA_GPU_STATE_UNKNOWN when
etnaviv_gpu_init() fails or during etnaviv_gpu_unbind(), and preserves
that state across runtime suspend so uninitialized GPUs are not set up
on resume.

> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c 
> b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
> index 6a4aab75ebba5..2a15ae6135f5e 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
> @@ -951,6 +951,8 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
>       return 0;
>  
>  fail:
> +     /* the GPU is not used, a resume must not set it up */
> +     gpu->state = ETNA_GPU_STATE_UNKNOWN;
>       pm_runtime_mark_last_busy(gpu->dev);
>  pm_put:
>       pm_runtime_put_autosuspend(gpu->dev);

[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure in
etnaviv_flop_reset_ppu_init() during etnaviv_gpu_init() leave a dangling
pointer in priv->flop_reset_data_ppu [1]?

drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c:etnaviv_flop_reset_ppu_init() {
        ...
        int ret = etnaviv_cmdbuf_init(priv->cmdbuf_suballoc,
                                      priv->flop_reset_data_ppu, buffer_size);
        if (ret) {
                kfree(priv->flop_reset_data_ppu);
                return ret;
        }
        ...
}

Because load_gpu() ignores errors from etnaviv_gpu_init() and keeps the
DRM device bound, a subsequent GPU core sees a non-NULL
priv->flop_reset_data_ppu, skips initialization, and dereferences the
freed command buffer in etnaviv_flop_reset_ppu_run() (use-after-free).
On device unbind, etnaviv_unbind() also passes the dangling pointer to
etnaviv_cmdbuf_free() and kfree(), causing a double free.

[1] https://sashiko.dev/#/bug/linux-4d0f1113-6871-425a-a512-96f1b1788e33

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

Reply via email to