Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/virtio: out-of-bounds user page pinning in verify_blob() on
  size ALIGN()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] drm/virtio: silent blob size truncation in verify_blob()
  [1]
--

commit 47f959d0cfefd215bffd18078894e965cea40441
Author: Honglei Huang <[email protected]>

drm/virtio: wire blob ioctl creation to userptr objects

This commit wires the blob resource creation ioctl to userptr objects, adds
support for the VIRTIO_GPU_F_BLOB_READONLY feature, and adjusts blob size and
userptr alignment handling.

> diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c 
> b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> index 81e70a12b3569..454d0e9a7d59d 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c

[ ... ]

> @@ -538,10 +565,16 @@ static int verify_blob(struct virtio_gpu_device *vgdev,
>       params->blob = true;
>       params->blob_flags = rc_blob->blob_flags;
>       params->blob_hints = rc_blob->blob_hints;
> +     params->userptr = rc_blob->userptr;

[Severity: Critical]
This problem wasn't introduced by this patch, but does assigning the 64-bit
rc_blob->size to params->size just above this [1] silently truncate
blob sizes over 4 GB on 32-bit architectures?

params->size is an unsigned long, so on 32-bit systems the upper 32 bits of
rc_blob->size are discarded before alignment checks, allocation, and host
command submission, allocating a smaller buffer than userspace requested.

> -     if (vgdev->has_blob_alignment &&
> -         !IS_ALIGNED(params->size, vgdev->blob_alignment))
> -             return -EINVAL;
> +     if (vgdev->has_blob_alignment) {
> +             params->size = ALIGN(params->size,
> +                                  max_t(uint32_t, vgdev->blob_alignment,
> +                                        PAGE_SIZE));
> +
> +             if (!IS_ALIGNED(params->userptr, vgdev->blob_alignment))
> +                     return -EINVAL;
> +     }
>  
>       return 0;
>  }

[Severity: High]
When params->userptr is non-zero and vgdev->blob_alignment is larger than
PAGE_SIZE, can rounding params->size up to vgdev->blob_alignment cause
virtio_gpu_userptr_create() to pin guest pages past the end of the
user-supplied buffer?

Unlike shmem or VRAM blobs that allocate new backing storage of params->size,
virtio_gpu_userptr_init() sets userptr->npages = params->size >> PAGE_SHIFT
and virtio_gpu_userptr_get_pages() pins that many pages from current->mm
starting at userptr->start.  If userspace passes a userptr buffer whose size
is not a multiple of vgdev->blob_alignment, the extra pages past
rc_blob->userptr + rc_blob->size either fail in pin_user_pages_fast() with
-EFAULT or pin and export unrelated pages from an adjacent VMA to the host
device.

[1] https://sashiko.dev/#/bug/linux-20577b57-1c85-44eb-8080-3e8c4e2bce2a

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=4

Reply via email to