Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/virtio: NULL dereference of virtio_gpu_panic_get_vbuf()
  return in callers
- [Low] drm/virtio: missing Fixes: trailer for commit 6f3d9d0dd335
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] drm/virtio: slab allocation deadlock in
  virtio_gpu_panic_get_vbuf() [1]
--

commit 3cd455d3f4907312dc90888e92ffe07456cc5f36
Author: Syh-Xiong <[email protected]>

> virtio: Handle vbuf allocation failure in panic path
>
> virtio_gpu_panic_get_vbuf() does not check the return value of
> kmem_cache_zalloc(),so a failed allocation is followed by a
> NULL pointer dereference.
>
> Signed-off-by: Syh-Xiong <[email protected]>

[Severity: Low]
Should this bug fix include a Fixes: tag for the commit that added
virtio_gpu_panic_get_vbuf()?

  Fixes: 6f3d9d0dd335 ("drm/virtio: Add drm_panic support")

> diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c 
> b/drivers/gpu/drm/virtio/virtgpu_vq.c
> index d99fb9e326e81..0d7ae44471522 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_vq.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
> @@ -94,6 +94,8 @@ virtio_gpu_panic_get_vbuf(struct virtio_gpu_device *vgdev, 
> int size)
>       struct virtio_gpu_vbuffer *vbuf;
>  
>       vbuf = kmem_cache_zalloc(vgdev->vbufs, GFP_ATOMIC);

[Severity: High]
This problem wasn't introduced by this patch, but calling
kmem_cache_zalloc() from the drm_panic handler can deadlock [1] if
the kernel panics while a slab allocator spinlock is already held, hanging
the system before the panic screen or kdump can run.

> +     if (!vbuf)
> +             return NULL;

[Severity: Medium]
Does returning NULL here still result in an immediate NULL pointer
dereference in the callers?

Its sole caller, virtio_gpu_panic_alloc_cmd_resp(), does not check vbuf
before reading vbuf->buf:

drivers/gpu/drm/virtio/virtgpu_vq.c:virtio_gpu_panic_alloc_cmd_resp() {
        vbuf = virtio_gpu_panic_get_vbuf(vgdev, cmd_size);
        *vbuffer_p = vbuf;
        return (struct virtio_gpu_command *)vbuf->buf;
}

Both callers of virtio_gpu_panic_alloc_cmd_resp(),
virtio_gpu_panic_cmd_resource_flush() and
virtio_gpu_panic_cmd_transfer_to_host_2d(), also pass the returned cmd_p to
memset() and dereference vbuf->objs without checking for NULL.

[1] https://sashiko.dev/#/bug/linux-c6d68f26-60e8-47ae-8a01-6ff4145223a3

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

Reply via email to