drm/virtio: fix 0-byte blob ZERO_SIZE_PTR, GEM leak, and context_init rollback
Subsystems (4)
PATCH 1/1 drm/virtio: fix 0-byte blob ZERO_SIZE_PTR, GEM leak, and context_init rollback
Fix multiple issues in virtio-gpu VRAM mapping, blob creation, and context initialization:
1. In virtio_gpu_vram_mmap(), set vram->map_state = STATE_ERR if deferred virtio_gpu_vram_map() fails so callers do not treat an unmapped VRAM node as valid.
2. In verify_blob(), reject rc_blob->size == 0 or size values that wrap PAGE_ALIGN() to prevent kvmalloc_array(0, ...) from returning ZERO_SIZE_PTR.
3. In virtio_gpu_gem_create(), virtio_gpu_resource_create_ioctl(), and virtio_gpu_resource_create_blob_ioctl(), use drm_gem_object_put() instead of drm_gem_object_release() on error so the BO's free callback is properly invoked.
4. In virtio_gpu_context_init_ioctl(), stage context parameters into local variables and only commit them to vfpriv after all parameters and ring_idx_mask have been validated.
---
drivers/gpu/drm/virtio/virtgpu_gem.c +1 -1
@@ -45,7 +45,7 @@ static int virtio_gpu_gem_create(struct drm_file *file, ret =drm_gem_handle_create (file, &obj->base.base, &handle);if (ret) { -drm_gem_object_release (&obj->base.base); +drm_gem_object_put (&obj->base.base);return ret; }
drivers/gpu/drm/virtio/virtgpu_ioctl.c +40 -16
136 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vram.c +5 -2
@@ -248,7 +248,10 @@ void virtio_gpu_vram_map_deferred(struct virtio_gpu_object_vram *vram)return ;mutex_lock (&map_lock); -if (!drm_mm_node_allocated (&vram->vram_node)) -virtio_gpu_vram_map (&vram->base); +if (!drm_mm_node_allocated (&vram->vram_node)) { + vram->map_state =STATE_INITIALIZING ; +if (virtio_gpu_vram_map (&vram->base)) + vram->map_state =STATE_ERR ; + }mutex_unlock (&map_lock); }
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines
Fix multiple issues in virtio-gpu VRAM mapping, blob creation, and context initialization:
1. In
virtio_gpu_vram_mmap(), setvram->map_state=STATE_ERRif deferredvirtio_gpu_vram_map()fails so callers do not treat an unmapped VRAM node as valid.
2. Inverify_blob(), rejectrc_blob->size== 0 or size values that wrapPAGE_ALIGN()to preventkvmalloc_array(0, ...)from returningZERO_SIZE_PTR.
3. Invirtio_gpu_gem_create(),virtio_gpu_resource_create_ioctl(), andvirtio_gpu_resource_create_blob_ioctl(), usedrm_gem_object_put()instead ofdrm_gem_object_release()on error so the BO's free callback is properly invoked.
4. Invirtio_gpu_context_init_ioctl(), stage context parameters into local variables and only commit them to vfpriv after all parameters andring_idx_maskhave been validated.
Quoted 4 lines
Fixes 16845c5d5409 ("drm/virtio: implement blob resources: implement vram object")Fixes 85c83ea915ed ("drm/virtio: implement context init: allocate an array of fence contexts")Assisted-by LLMSigned-off-by Hui Peng <[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 17 lines · Hui Peng
Fix multiple issues in virtio-gpu VRAM mapping, blob creation, and context initialization:
1. In
virtio_gpu_vram_mmap(), setvram->map_state=STATE_ERRif deferredvirtio_gpu_vram_map()fails so callers do not treat an unmapped VRAM node as valid.
2. Inverify_blob(), rejectrc_blob->size== 0 or size values that wrapPAGE_ALIGN()to preventkvmalloc_array(0, ...)from returningZERO_SIZE_PTR.
3. Invirtio_gpu_gem_create(),virtio_gpu_resource_create_ioctl(), andvirtio_gpu_resource_create_blob_ioctl(), usedrm_gem_object_put()instead ofdrm_gem_object_release()on error so the BO's free callback is properly invoked.
4. Invirtio_gpu_context_init_ioctl(), stage context parameters into local variables and only commit them to vfpriv after all parameters andring_idx_maskhave been validated.
Quoted 5 lines
Fixes 16845c5d5409 ("drm/virtio: implement blob resources: implement vram object")Fixes 85c83ea915ed ("drm/virtio: implement context init: allocate an array of fence contexts")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>---
Please split this patch to have one fix per one patch and make a v2. The same for your other patch.
Signature · 2 lines
Best regards, Dmitry