drm/virtio: reject mappable HOST3D blobs without host-visible memory
Subsystems (5)
PATCH 1/1 drm/virtio: reject mappable HOST3D blobs without host-visible memory
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.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +5 -0
@@ -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;
Signature · 1 line
2.43.7
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 24 lines
virtio_gpu_resource_create_blob_ioctl()->verify_blob()validates blob flags, memory type, context and alignment, but never checksVIRTGPU_BLOB_FLAG_USE_MAPPABLEagainstvgdev->has_host_visible.For
blob_mem==VIRTGPU_BLOB_MEM_HOST3Dthe blob is created viavirtio_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 thecreate_blobcommand issued whenvirtio_gpu_vram_map()returns-EINVAL, and the cleanup callsvirtio_gpu_vram_free(), which is a no-op whilebo->createdis 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_GUESTandVIRTGPU_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 onvirtio_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.
Quoted 5 lines
This issue was discovered by Tencent CodeBuddy Security.
Fixes 16845c5d5409 ("drm/virtio: implement blob resources: implement vram object")Signed-off-by Henry Martin <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Dmitry Osipenko
maintainerQuoted 4 lines · Henry Martin
virtio_gpu_resource_create_blob_ioctl()->verify_blob()validates blob flags, memory type, context and alignment, but never checksVIRTGPU_BLOB_FLAG_USE_MAPPABLEagainstvgdev->has_host_visible.
Quoted 8 lines
For
blob_mem==VIRTGPU_BLOB_MEM_HOST3Dthe blob is created viavirtio_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 thecreate_blobcommand issued whenvirtio_gpu_vram_map()returns-EINVAL, and the cleanup callsvirtio_gpu_vram_free(), which is a no-op whilebo->createdis 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?
Signature · 2 lines
Best regards, Dmitry
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
Quoted 22 lines · Dmitry Osipenko <[email protected]> 于2026年10月11日周日 04:19写道:
Quoted 4 lines · Henry Martin
virtio_gpu_resource_create_blob_ioctl()->verify_blob()validates blob flags, memory type, context and alignment, but never checksVIRTGPU_BLOB_FLAG_USE_MAPPABLEagainstvgdev->has_host_visible.Quoted 8 lines
For
blob_mem==VIRTGPU_BLOB_MEM_HOST3Dthe blob is created viavirtio_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 thecreate_blobcommand issued whenvirtio_gpu_vram_map()returns-EINVAL, and the cleanup callsvirtio_gpu_vram_free(), which is a no-op whilebo->createdis still false (the host response has not been processed yet). Every such
virtio_gpu_cmd_resource_create_blob()is invoked beforevirtio_gpu_vram_map()invirtio_gpu_vram_create(), hencebo->createdis always true, how come it's false?--
Best regards,
Dmitry