Skip to contentSkip to conversation

drm/virtio: add driver_priv validation in virtio_gpu_create_context

PATCH In review Maxim Korotkov 2 participants 2 messages Mar 28, 2024 – Apr 11, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/virtio: add driver_priv validation in virtio_gpu_create_context

The pointer file->driver_priv was dereferenced without checking against NULL, but in the "virtio_gpu_transfer_to_host_ioctl" function it was checked against NULL after calling virtio_gpu_create_context function.

Found by Security Code and Linux Verification Center(linuxtesting.org)

Fixes 72b48ae800da ("drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl")
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
index e4f76f315550..98fe9ad4ed15 100644
@@ -64,6 +64,9 @@ void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file)
 	struct virtio_gpu_device *vgdev = dev->dev_private;
 	struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
 
+	if (!vfpriv)
+		return;
+
 	mutex_lock(&vfpriv->context_lock);
 	if (vfpriv->context_created)
 		goto out_unlock;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 17 lines · Maxim Korotkov

The pointer file->driver_priv was dereferenced without checking against NULL, but in the "virtio_gpu_transfer_to_host_ioctl" function it was checked against NULL after calling virtio_gpu_create_context function.

Found by Security Code and Linux Verification Center(linuxtesting.org)

Fixes 72b48ae800da ("drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl")
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0 -0
index e4f76f315550..98fe9ad4ed15 100644

drivers/gpu/drm/virtio/virtgpu_ioctl.c void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file) · line 72

Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -0
@@ -64,6 +64,9 @@ void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file)
 	struct virtio_gpu_device *vgdev = dev->dev_private;
 	struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
 
+	if (!vfpriv)
+		return;
+
 	mutex_lock(&vfpriv->context_lock);
 	if (vfpriv->context_created)
 		goto out_unlock;

NULL check in virtio_gpu_transfer_to_host_ioctl() is bogus, vfpriv can't be NULL there.

Signature · 2 lines
Best regards,
Dmitry