dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory
@ 2026-10-10  8:10 Henry Martin
  2026-10-10  8:25 ` sashiko-bot
  2026-10-10 20:19 ` Dmitry Osipenko
  0 siblings, 2 replies; 4+ messages in thread
From: Henry Martin @ 2026-10-10  8:10 UTC (permalink / raw)
  To: David Airlie, Dmitry Osipenko, Gerd Hoffmann, Chia-I Wu,
	Gurchetan Singh, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Simona Vetter, Junrui Luo
  Cc: dri-devel, virtualization, linux-kernel, Henry Martin, stable

virtio_gpu_resource_create_blob_ioctl() -> verify_blob() validates
blob flags, memory type, context and alignment, but never checks
VIRTGPU_BLOB_FLAG_USE_MAPPABLE against vgdev->has_host_visible.

For blob_mem == VIRTGPU_BLOB_MEM_HOST3D the blob is created via
virtio_gpu_vram_create(), and on a device without host-visible
memory (plain virtio-gpu-pci,blob=on with no hostmem) the failure
comes too late: the GEM object has been allocated, a host resource
id taken and the create_blob command issued when
virtio_gpu_vram_map() returns -EINVAL, and the cleanup calls
virtio_gpu_vram_free(), which is a no-op while bo->created is still
false (the host response has not been processed yet).  Every such
blob creation permanently leaks the vram object and its resource
id; /dev/dri/renderD* is reachable by unprivileged users.

Guest-backed blobs (VIRTGPU_BLOB_MEM_GUEST and
VIRTGPU_BLOB_MEM_HOST3D_GUEST) mmap through the shmem path and do
not need host-visible memory, so only the HOST3D case is rejected.

Commit 036d28db1818a ("drm/virtio: release the GEM object on
virtio_gpu_vram_create() errors") fixed the sibling error paths but
missed this one.  Reject the impossible combination at ioctl entry,
making the failure mode unreachable.

This issue was discovered by Tencent CodeBuddy Security.

Cc: stable@vger.kernel.org
Fixes: 16845c5d5409 ("drm/virtio: implement blob resources: implement vram object")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
index 81e70a12b3569..e3edade4a62dd 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -533,6 +533,11 @@ static int verify_blob(struct virtio_gpu_device *vgdev,
 			return -EINVAL;
 	}
 
+	if ((rc_blob->blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE) &&
+	    rc_blob->blob_mem == VIRTGPU_BLOB_MEM_HOST3D &&
+	    !vgdev->has_host_visible)
+		return -EINVAL;
+
 	params->blob_mem = rc_blob->blob_mem;
 	params->size = rc_blob->size;
 	params->blob = true;
-- 
2.43.7

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

* Re: [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory
  2026-10-10  8:10 [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory Henry Martin
@ 2026-10-10  8:25 ` sashiko-bot
  2026-10-10 20:19 ` Dmitry Osipenko
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-10-10  8:25 UTC (permalink / raw)
  To: Henry Martin; +Cc: dri-devel, Michael S. Tsirkin, virtualization, Eugenio Perez

> virtio_gpu_resource_create_blob_ioctl() -> verify_blob() validates
> blob flags, memory type, context and alignment, but never checks
> VIRTGPU_BLOB_FLAG_USE_MAPPABLE against vgdev->has_host_visible.
> 
> For blob_mem == VIRTGPU_BLOB_MEM_HOST3D the blob is created via
> virtio_gpu_vram_create(), and on a device without host-visible
> memory (plain virtio-gpu-pci,blob=on with no hostmem) the failure
> comes too late: the GEM object has been allocated, a host resource
> id taken and the create_blob command issued when
> virtio_gpu_vram_map() returns -EINVAL, and the cleanup calls
> virtio_gpu_vram_free(), which is a no-op while bo->created is still
> false (the host response has not been processed yet).  Every such
> blob creation permanently leaks the vram object and its resource
> id; /dev/dri/renderD* is reachable by unprivileged users.
> 
> Guest-backed blobs (VIRTGPU_BLOB_MEM_GUEST and
> VIRTGPU_BLOB_MEM_HOST3D_GUEST) mmap through the shmem path and do
> not need host-visible memory, so only the HOST3D case is rejected.
> 
> Commit 036d28db1818a ("drm/virtio: release the GEM object on
> virtio_gpu_vram_create() errors") fixed the sibling error paths but
> missed this one.  Reject the impossible combination at ioctl entry,
> making the failure mode unreachable.
> 
> This issue was discovered by Tencent CodeBuddy Security.
> 
> Cc: stable@vger.kernel.org
> Fixes: 16845c5d5409 ("drm/virtio: implement blob resources: implement vram object")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261010081059.3096312-1-bsdhenrymartin@gmail.com?part=1


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

* Re: [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory
  2026-10-10  8:10 [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory Henry Martin
  2026-10-10  8:25 ` sashiko-bot
@ 2026-10-10 20:19 ` Dmitry Osipenko
  2026-10-11  4:24   ` henry martin
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Osipenko @ 2026-10-10 20:19 UTC (permalink / raw)
  To: Henry Martin, David Airlie, Gerd Hoffmann, Chia-I Wu,
	Gurchetan Singh, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Simona Vetter, Junrui Luo
  Cc: dri-devel, virtualization, linux-kernel, stable

On 10/10/26 11:10, Henry Martin wrote:
> virtio_gpu_resource_create_blob_ioctl() -> verify_blob() validates
> blob flags, memory type, context and alignment, but never checks
> VIRTGPU_BLOB_FLAG_USE_MAPPABLE against vgdev->has_host_visible.
> 
> For blob_mem == VIRTGPU_BLOB_MEM_HOST3D the blob is created via
> virtio_gpu_vram_create(), and on a device without host-visible
> memory (plain virtio-gpu-pci,blob=on with no hostmem) the failure
> comes too late: the GEM object has been allocated, a host resource
> id taken and the create_blob command issued when
> virtio_gpu_vram_map() returns -EINVAL, and the cleanup calls
> virtio_gpu_vram_free(), which is a no-op while bo->created is still
> false (the host response has not been processed yet).  Every such

virtio_gpu_cmd_resource_create_blob() is invoked before
virtio_gpu_vram_map() in virtio_gpu_vram_create(), hence bo->created is
always true, how come it's false?

-- 
Best regards,
Dmitry

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

* Re: [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory
  2026-10-10 20:19 ` Dmitry Osipenko
@ 2026-10-11  4:24   ` henry martin
  0 siblings, 0 replies; 4+ messages in thread
From: henry martin @ 2026-10-11  4:24 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: David Airlie, Gerd Hoffmann, Chia-I Wu, Gurchetan Singh,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Simona Vetter, Junrui Luo, dri-devel, virtualization,
	linux-kernel, stable

Hi Dmitry,

You're right, thanks for catching this.  bo->created is set
synchronously in virtio_gpu_cmd_resource_create_blob(), so the
unmap/unref completion chain (cmd_unref_cb -> cleanup_object)
releases everything once the host acks.  The leak I described does
not exist - please drop the patch.

Sorry for the noise.

Regards,
Henry

Dmitry Osipenko <dmitry.osipenko@collabora.com> 于2026年10月11日周日 04:19写道:
>
> On 10/10/26 11:10, Henry Martin wrote:
> > virtio_gpu_resource_create_blob_ioctl() -> verify_blob() validates
> > blob flags, memory type, context and alignment, but never checks
> > VIRTGPU_BLOB_FLAG_USE_MAPPABLE against vgdev->has_host_visible.
> >
> > For blob_mem == VIRTGPU_BLOB_MEM_HOST3D the blob is created via
> > virtio_gpu_vram_create(), and on a device without host-visible
> > memory (plain virtio-gpu-pci,blob=on with no hostmem) the failure
> > comes too late: the GEM object has been allocated, a host resource
> > id taken and the create_blob command issued when
> > virtio_gpu_vram_map() returns -EINVAL, and the cleanup calls
> > virtio_gpu_vram_free(), which is a no-op while bo->created is still
> > false (the host response has not been processed yet).  Every such
>
> virtio_gpu_cmd_resource_create_blob() is invoked before
> virtio_gpu_vram_map() in virtio_gpu_vram_create(), hence bo->created is
> always true, how come it's false?
>
> --
> Best regards,
> Dmitry

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

end of thread, other threads:[~2026-10-11  4:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-10  8:10 [PATCH] drm/virtio: reject mappable HOST3D blobs without host-visible memory Henry Martin
2026-10-10  8:25 ` sashiko-bot
2026-10-10 20:19 ` Dmitry Osipenko
2026-10-11  4:24   ` henry martin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox