Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Honglei Huang" <honghuan@amd.com>
Cc: dri-devel@lists.freedesktop.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	virtualization@lists.linux.dev,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v7 4/4] drm/virtio: wire blob ioctl creation to userptr objects
Date: Fri, 18 Sep 2026 02:23:16 +0000	[thread overview]
Message-ID: <20260918022316.795CC1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260918021154.1432154-5-honghuan@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] drm/virtio: PRIME export of RDONLY userptr allows writable DMA mapping
--

commit 5d368a790c7066062061e9164c64d6e00b653f96
Author: Honglei Huang <honghuan@amd.com>
Subject: drm/virtio: wire blob ioctl creation to userptr objects

This commit integrates userptr support into the virtio GPU blob resource
creation ioctl. It adds userptr flags to the allowed mask, handles userptr
verification, and calls virtio_gpu_userptr_create() when requested.

> diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> index 3d8e4ccdb7c1f..6d38483f5fd61 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> @@ -36,7 +36,9 @@
>  
>  #define VIRTGPU_BLOB_FLAG_USE_MASK (VIRTGPU_BLOB_FLAG_USE_MAPPABLE | \
>  				    VIRTGPU_BLOB_FLAG_USE_SHAREABLE | \
> -				    VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE)
> +				    VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE | \
> +				    VIRTGPU_BLOB_FLAG_USE_USERPTR | \
> +				    VIRTGPU_BLOB_FLAG_USERPTR_RDONLY)

[Severity: Critical]
By exposing VIRTGPU_BLOB_FLAG_USERPTR_RDONLY to userspace, does this allow an
unprivileged local user to bypass write protection on read-only pages via
PRIME export?

Looking at virtio_gpu_userptr_funcs in
drivers/gpu/drm/virtio/virtgpu_userptr.c, .export is exposed for userptr
objects:

drivers/gpu/drm/virtio/virtgpu_userptr.c:
static const struct drm_gem_object_funcs virtio_gpu_userptr_funcs = {
	.open = virtio_gpu_gem_object_open,
	.close = virtio_gpu_gem_object_close,
	.free = virtio_gpu_userptr_free,
	.export = virtgpu_gem_prime_export,
	.get_sg_table = virtio_gpu_userptr_get_sg_table,
};

And in virtio_gpu_userptr_get_pages() within the same file, it only pins with
FOLL_WRITE if read-only is not set:

drivers/gpu/drm/virtio/virtgpu_userptr.c:virtio_gpu_userptr_get_pages()
	if (!(userptr->flags & VIRTGPU_BLOB_FLAG_USERPTR_RDONLY))
		flag |= FOLL_WRITE;

If a user maps a read-only file into memory, creates a virtgpu blob resource
using VIRTGPU_BLOB_FLAG_USE_USERPTR and VIRTGPU_BLOB_FLAG_USERPTR_RDONLY, and
then exports it via DRM_IOCTL_PRIME_HANDLE_TO_FD while requesting DRM_RDWR,
does this allow the user to import this dma-buf into another device and
perform DMA writes to it?

This appears to circumvent the read-only pinning constraints when the resulting
sg_table is shared via PRIME and modified by an unaware importer, potentially
leading to arbitrary code execution or local privilege escalation.

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260918021154.1432154-1-honghuan@amd.com?part=4

      reply	other threads:[~2026-09-18  2:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  2:11 [PATCH v7 0/4] virtio-gpu: Add userptr support for compute workloads Honglei Huang
2026-09-18  2:11 ` [PATCH v7 1/4] drm/virtio-gpu: Add VIRTIO_GPU_CAPSET_ROCM capability Honglei Huang
2026-09-18  2:16   ` sashiko-bot
2026-09-18  2:11 ` [PATCH v7 2/4] drm/virtgpu api: add blob userptr resource Honglei Huang
2026-09-18  2:19   ` sashiko-bot
2026-09-18  2:11 ` [PATCH v7 3/4] drm/virtio: implement userptr support for zero-copy memory access Honglei Huang
2026-09-18  2:29   ` sashiko-bot
2026-09-18  2:11 ` [PATCH v7 4/4] drm/virtio: wire blob ioctl creation to userptr objects Honglei Huang
2026-09-18  2:23   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918022316.795CC1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eperezma@redhat.com \
    --cc=honghuan@amd.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox