Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] drm/virtio: do not enforce blob_alignment in cross-domain contexts
@ 2026-10-06  0:34 Val Packett
  2026-10-06  0:53 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Val Packett @ 2026-10-06  0:34 UTC (permalink / raw)
  To: David Airlie, Gerd Hoffmann, Dmitry Osipenko, Gurchetan Singh,
	Chia-I Wu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Simona Vetter, Sergio Lopez
  Cc: Val Packett, dri-devel, virtualization, linux-kernel

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.

Fixes: 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")
Signed-off-by: Val Packett <val@invisiblethingslab.com>
---

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(+)

diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
index 01a5f17cb22b..d493f04b9993 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -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;
 
-- 
2.55.0


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

* Re: [PATCH] drm/virtio: do not enforce blob_alignment in cross-domain contexts
  2026-10-06  0:34 [PATCH] drm/virtio: do not enforce blob_alignment in cross-domain contexts Val Packett
@ 2026-10-06  0:53 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-06  0:53 UTC (permalink / raw)
  To: Val Packett; +Cc: virtualization, dri-devel, Michael S. Tsirkin, Eugenio Perez

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 <val@invisiblethingslab.com>
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.

> diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> @@ -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.

>  	    !IS_ALIGNED(params->size, vgdev->blob_alignment))
>  		return -EINVAL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261006004044.2242154-1-val@invisiblethingslab.com?part=1

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

end of thread, other threads:[~2026-10-06  0:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-06  0:34 [PATCH] drm/virtio: do not enforce blob_alignment in cross-domain contexts Val Packett
2026-10-06  0:53 ` sashiko-bot

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