drm/virtio: do not enforce blob_alignment in cross-domain contexts
Subsystems (4)
PATCH 1/1 drm/virtio: do not enforce blob_alignment in cross-domain contexts
VIRTIO_GPU_F_BLOB_ALIGNMENT is designed for GPU rendering context types, however VIRTIO_GPU_CAPSET_CROSS_DOMAIN is not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.
---
That took its time to be discovered since devices didn't start offering blob_alignment until now e.g. https://github.com/libkrun/libkrun/pull/886
It would also be fine to just revert 47248e0d8264 but I guess this way no one would question why "there's an alignment and we aren't enforcing it"..
Thanks,
~val
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -0
@@ -551,6 +551,8 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_hints = rc_blob->blob_hints;if (vgdev->has_blob_alignment && + (vfpriv->context_init &VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK ) != +VIRTIO_GPU_CAPSET_CROSS_DOMAIN && !IS_ALIGNED (params->size, vgdev->blob_alignment))return -EINVAL ;
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] drm/virtio: NULL pointer dereference in verify_blob() when 3D features are disabled - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] drm/virtio: NULL pointer dereference in verify_blob() when 3D features are disabled
- [Medium] drm/virtio: data race when reading vfpriv->context_init in verify_blob() --
commit e614dba4f51f24b9effac7458783e310e89be777
Author: Val Packett <[email protected]> drm/virtio: do not enforce blob_alignment in cross-domain contexts
The commit prevents enforcing blob_alignment requirements in cross-domain contexts, as resources created there are arbitrary shared system memory files like Wayland keymaps.
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int verify_blob(struct virtio_gpu_device *vgdev, · line 544
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-0@@ -540,6 +540,8 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_hints = rc_blob->blob_hints; if (vgdev->has_blob_alignment && + (vfpriv->context_init & VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK) != + VIRTIO_GPU_CAPSET_CROSS_DOMAIN &&
[Severity: Critical]
If a virtio-gpu device advertises VIRTIO_GPU_F_RESOURCE_BLOB and VIRTIO_GPU_F_BLOB_ALIGNMENT but not VIRTIO_GPU_F_VIRGL, could this cause a NULL pointer dereference?
In this scenario, virtio_gpu_driver_open() returns successfully but leaves file->driver_priv (which is passed as vfpriv) as NULL. When userspace then calls DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB with VIRTGPU_BLOB_MEM_GUEST, verify_blob() is reached without aborting on the has_virgl_3d check.
This newly added code will then unconditionally dereference vfpriv->context_init because vgdev->has_blob_alignment is true, causing a kernel panic. Is there a way to verify vfpriv is not NULL before accessing context_init?
[Severity: Medium]
Does this introduce a data race when reading context_init?
This accesses the lock-protected context_init field without acquiring vfpriv->context_lock. A lockless read of context_init could read a partially written bitmask if updated concurrently, leading to incorrectly enforcing or bypassing blob alignment checks and returning spurious -EINVAL to userspace.
This could happen if userspace calls DRM_IOCTL_VIRTGPU_CONTEXT_INIT and DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB concurrently on the same file descriptor.
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0!IS_ALIGNED(params->size, vgdev->blob_alignment))return -EINVAL ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1