All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Seojin An" <love09010224@uos.ac.kr>
Cc: dri-devel@lists.freedesktop.org, virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] drm/virtio: bound execbuffer commands to control queue size
Date: Thu, 26 Nov 2026 08:22:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-235004@kernel.org> (raw)
In-Reply-To: <20261126080044.2898223-1-love09010224@uos.ac.kr>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/virtio: UAF of ctrlq.vq in virtio_gpu_execbuffer_ioctl()
  on unplug
--

commit 03e41369bd07f481a8b25bccdf4ab65b96d730a3
Author: Seojin An <love09010224@uos.ac.kr>

drm/virtio: bound execbuffer commands to control queue size

This commit rejects execbuffer commands whose page count plus the request and
response descriptors exceeds the control virtqueue size.

> diff --git a/drivers/gpu/drm/virtio/virtgpu_submit.c b/drivers/gpu/drm/virtio/virtgpu_submit.c
> index 6580ece658704..9aff7f8d5195f 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
> @@ -482,6 +482,8 @@ int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
>  	u64 fence_ctx = vgdev->fence_drv.context;
>  	struct drm_virtgpu_execbuffer *exbuf = data;
>  	struct virtio_gpu_submit submit;
> +	u64 command_sgs;
> +	unsigned int max_sgs;
>  	u32 ring_idx = 0;
>  	int ret = -EINVAL;
>  
> @@ -491,6 +493,17 @@ int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
>  	if (exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS)
>  		return ret;
>  
> +	/*
> +	 * The command contributes one SG entry per vmalloc page in addition
> +	 * to the fixed request and response entries.  Virtio requires both
> +	 * direct and indirect descriptor chains to fit the device queue.
> +	 * Reject oversized commands before copying or queueing them.
> +	 */
> +	max_sgs = virtqueue_get_vring_size(vgdev->ctrlq.vq);
> +	command_sgs = DIV_ROUND_UP((u64)exbuf->size, PAGE_SIZE);
> +	if (max_sgs < 2 || command_sgs > max_sgs - 2)
> +		return -E2BIG;
> +
>  	if (exbuf->flags & VIRTGPU_EXECBUF_RING_IDX) {
>  		if (exbuf->ring_idx >= vfpriv->num_rings)
>  			return ret;

[Severity: Medium]
Can virtqueue_get_vring_size() dereference vgdev->ctrlq.vq after it has been
freed on device unplug?

drm_ioctl_kernel() checks drm_dev_is_unplugged(), which enters and immediately
exits its SRCU section before calling virtio_gpu_execbuffer_ioctl().  Because
other virtqueue paths such as virtio_gpu_queue_ctrl_sgs() guard vgdev->ctrlq.vq
with drm_dev_enter(), an in-flight ioctl can race with virtio_gpu_remove():

CPU0                                  CPU1
drm_ioctl_kernel()
  drm_dev_is_unplugged()
                                      virtio_gpu_remove()
                                        drm_dev_unplug()
                                        virtio_gpu_deinit()
                                          del_vqs()
                                            kfree(vq)
  virtio_gpu_execbuffer_ioctl()
    virtqueue_get_vring_size(ctrlq.vq)  <-- use-after-free

Guarding the virtqueue_get_vring_size() call with drm_dev_enter() and
drm_dev_exit() would prevent this race.

[Severity: High]
This problem wasn't introduced by this patch, but virtio_gpu_cmd_submit() has
a void return type and drops errors from [1]
virtio_gpu_queue_fenced_ctrl_buffer().

When queueing fails due to memory pressure or device unplug,
virtio_gpu_fence_emit() is never called and the fence stays at seqno 0, yet
virtio_gpu_execbuffer_ioctl() continues to virtio_gpu_install_out_fence_fd()
and exports the uninitialized fence to userspace.  Any client waiting on that
fence file descriptor hangs indefinitely, and checking the fence triggers
WARN_ON_ONCE(f->seqno == 0) in virtio_gpu_fence_signaled().

[1] https://sashiko.dev/#/bug/linux-c280d0dd-d017-4ef7-a36a-c0606306f02c

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126080044.2898223-1-love09010224@uos.ac.kr?part=1

  reply	other threads:[~2026-11-26  8:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  8:00 [PATCH] drm/virtio: bound execbuffer commands to control queue size Seojin An
2026-11-26  8:22 ` sashiko-bot [this message]
2026-11-26 14:38   ` [PATCH v2] " Seojin An
2026-11-26 14:47     ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-235004@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eperezma@redhat.com \
    --cc=love09010224@uos.ac.kr \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.