All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio: Handle vbuf allocation failure in panic path
@ 2026-12-02 13:41 Syh-Xiong
  2026-12-02 13:53 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Syh-Xiong @ 2026-12-02 13:41 UTC (permalink / raw)
  To: airlied
  Cc: kraxel, dmitry.osipenko, gurchetansingh, olvaffe,
	maarten.lankhorst, mripard, tzimmermann, simona, dri-devel,
	virtualization, Syh-Xiong

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 <1850029304@qq.com>
---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index d99fb9e326e8..0d7ae4447152 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);
+	if (!vbuf)
+		return NULL;
 
 	vbuf->buf = (void *)vbuf + sizeof(*vbuf);
 	vbuf->size = size;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] virtio: Handle vbuf allocation failure in panic path
  2026-12-02 13:41 [PATCH] virtio: Handle vbuf allocation failure in panic path Syh-Xiong
@ 2026-12-02 13:53 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 13:53 UTC (permalink / raw)
  To: Syh-Xiong; +Cc: dri-devel, virtualization, Michael S. Tsirkin, Eugenio Perez

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 <1850029304@qq.com>

> 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 <1850029304@qq.com>

[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/tencent_108E6BD0C2683FCD678A1B68C99A5CFFF806@qq.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 13:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:41 [PATCH] virtio: Handle vbuf allocation failure in panic path Syh-Xiong
2026-12-02 13:53 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.