All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ke Sun" <sunke@kylinos.cn>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v6 10/10] drm/tyr: add BO-related ioctls
Date: Mon, 09 Nov 2026 01:05:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-204278@kernel.org> (raw)
In-Reply-To: <20261109-tyr-ioctls-v6-10-b2896bf2b3c9@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/tyr: slab-out-of-bounds access in bo_mmap_offset() on
  imported or dumb BOs
- [Medium] drm/tyr: NO_MMAP buffer objects remain mappable via mmap()
  and PRIME
--

commit 31c4893f869db54a6627810d48273b6077efa3af
Author: Alvin Sun <alvin.sun@linux.dev>

drm/tyr: add BO-related ioctls

This commit implements the PANTHOR_BO_CREATE and PANTHOR_BO_MMAP_OFFSET
ioctls for allocating GEM buffer objects and retrieving their mmap offsets.

> diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs
> index b982e8db2c4c1..f99bb2992d87a 100644
> --- a/drivers/gpu/drm/tyr/file.rs
> +++ b/drivers/gpu/drm/tyr/file.rs

[ ... ]

> +    pub(crate) fn bo_mmap_offset(
> +        ddev: &TyrDrmDevice<Registered>,
> +        _reg_data: &TyrDrmRegistrationData<'_>,
> +        bommap: &mut uapi::drm_panthor_bo_mmap_offset,
> +        file: &TyrDrmFile,
> +    ) -> Result<u32> {
> +        if bommap.pad != 0 {
> +            dev_dbg!(
> +                ddev.as_ref(),
> +                "BO mmap offset pad not zero: {}\n",
> +                bommap.pad
> +            );
> +            return Err(EINVAL);
> +        }
> +
> +        let bo = crate::gem::lookup_handle(file, bommap.handle).inspect_err(|_| {
> +            dev_dbg!(ddev.as_ref(), "Invalid BO mmap handle: {}\n", bommap.handle);
> +        })?;

[Severity: High]
Can passing a PRIME-imported or dumb-buffer handle to bo_mmap_offset() read
past the end of the GEM object allocation when bo.flags() is called below?

rust/kernel/drm/gem/shmem.rs:Object::ALLOC_OPS {
    ...
        gem_create_object: None,
    ...
        gem_prime_import_sg_table: Some(bindings::drm_gem_shmem_prime_import_sg_table),
        dumb_create: Some(bindings::drm_gem_shmem_dumb_create),
    ...
}

Because gem_create_object is None while gem_prime_import_sg_table and
dumb_create are wired up, DRM_IOCTL_PRIME_FD_TO_HANDLE (or
DRM_IOCTL_MODE_CREATE_DUMB) calls __drm_gem_shmem_create() and allocates a
bare struct drm_gem_shmem_object rather than a gem::shmem::Object<BoData>.
lookup_handle() casts that pointer to gem::shmem::Object<BoData>, so calling
bo.flags() reads self.inner.flags out of bounds in the slab allocation.

> +        if bo.flags() & uapi::drm_panthor_bo_flags_DRM_PANTHOR_BO_NO_MMAP != 0 {
> +            dev_dbg!(ddev.as_ref(), "BO mmap offset on NO_MMAP object\n");
> +            return Err(EPERM);
> +        }

[Severity: Medium]
Can userspace still CPU-map a DRM_PANTHOR_BO_NO_MMAP buffer object despite
this check?

In bo_create(), new_object() calls __drm_gem_shmem_init(), which allocates
the object's VMA offset via drm_gem_create_mmap_offset(), and
bo.create_handle() authorizes that offset for the file via
drm_vma_node_allow().  Because gem::shmem::Object<BoData>::VTABLE sets mmap
directly to drm_gem_shmem_object_mmap() without inspecting BoData::flags,
userspace can export a DRM_PANTHOR_BO_NO_MMAP handle with
DRM_IOCTL_PRIME_HANDLE_TO_FD and mmap() the returned dma-buf fd (or mmap()
the DRM fd directly using the pre-allocated VMA offset).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109-tyr-ioctls-v6-0-b2896bf2b3c9@kylinos.cn?part=10

      reply	other threads:[~2026-11-09  1:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  0:36 [PATCH v6 00/10] drm/tyr: add VM and BO ioctl support Ke Sun via B4 Relay
2026-11-09  0:36 ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 01/10] rust: sizes: add SZ_4G constant Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 02/10] rust: task: add task_size() Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 03/10] rust: sync: arc: relax `ForeignOwnable` for `Arc<T>` Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 04/10] drm/tyr: add per-file VM pool Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:48   ` sashiko-bot
2026-11-09  0:36 ` [PATCH v6 05/10] drm/tyr: add user and MCU VM specifications Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 06/10] drm/tyr: add BO creation and lookup helpers Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 07/10] drm/tyr: add VM-related ioctls Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  1:01   ` sashiko-bot
2026-11-09  0:36 ` [PATCH v6 08/10] rust: device: expose the device DMA attribute Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  0:36 ` [PATCH v6 09/10] drm/tyr: support write-combine BO mappings Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  1:10   ` sashiko-bot
2026-11-09  0:36 ` [PATCH v6 10/10] drm/tyr: add BO-related ioctls Ke Sun via B4 Relay
2026-11-09  0:36   ` Ke Sun
2026-11-09  1:05   ` 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=sashiko-outbox-204278@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sunke@kylinos.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.