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
  PRIME/dumb handles
- [Medium] drm/tyr: DRM_PANTHOR_BO_NO_MMAP objects remain CPU-mappable
  via mmap()
--

commit 7d9cd1ac18a4c56e418f19b4899916694572fe8a
Author: Alvin Sun <[email protected]>

drm/tyr: add BO-related ioctls

This commit implements the PANTHOR_BO_CREATE and PANTHOR_BO_MMAP_OFFSET
ioctls for the Tyr DRM driver.

> diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs
> index 8fccb42ab9e56..db57df68449cd 100644
> --- a/drivers/gpu/drm/tyr/file.rs
> +++ b/drivers/gpu/drm/tyr/file.rs
> @@ -242,6 +242,100 @@ pub(crate) fn vm_get_state(
>              Ok(0)
>          })
>      }
> +
> +    pub(crate) fn bo_create(
> +        ddev: &TyrDrmDevice<Registered>,
> +        reg_data: &TyrDrmRegistrationData<'_>,
> +        bocreate: &mut uapi::drm_panthor_bo_create,
> +        file: &TyrDrmFile,
> +    ) -> Result<u32> {

[ ... ]

> +        let bo = crate::gem::lookup_handle(file, 
> bommap.handle).inspect_err(|_| {
> +            dev_dbg!(ddev.as_ref(), "Invalid BO mmap handle: {}\n", 
> bommap.handle);
> +        })?;
> +        if bo.flags() & uapi::drm_panthor_bo_flags_DRM_PANTHOR_BO_NO_MMAP != 
> 0 {

[Severity: High]
Can bo.flags() read past the end of the slab allocation when bommap.handle
comes from DRM_IOCTL_PRIME_FD_TO_HANDLE or DRM_IOCTL_MODE_CREATE_DUMB?

gem::shmem::Object::ALLOC_OPS wires up drm_gem_shmem_prime_import_sg_table
and drm_gem_shmem_dumb_create while leaving gem_create_object as None:

rust/kernel/drm/gem/shmem.rs:<Object<T> as driver::AllocImpl>::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),
}

When gem_create_object is NULL, __drm_gem_shmem_create() allocates only
sizeof(struct drm_gem_shmem_object) rather than gem::shmem::Object<BoData>.
lookup_handle() then casts that bare drm_gem_shmem_object to
&gem::shmem::Object<BoData>, so bo.flags() reads BoData::flags out of
bounds.

> +            dev_dbg!(ddev.as_ref(), "BO mmap offset on NO_MMAP object\n");
> +            return Err(EPERM);
> +        }
> +        bommap.offset = bo.create_mmap_offset().inspect_err(|_| {

[Severity: Medium]
Are DRM_PANTHOR_BO_NO_MMAP buffer objects still CPU-mappable even though
bo_mmap_offset() returns EPERM?

In bo_create(), new_object() calls __drm_gem_shmem_init(), which
unconditionally calls drm_gem_create_mmap_offset(), and bo.create_handle()
calls drm_vma_node_allow() to authorize the file to map that offset.
Because gem::shmem::Object::VTABLE sets mmap to drm_gem_shmem_object_mmap
without checking BoData::flags, userspace can still mmap() a NO_MMAP object
on the DRM fd (or via DRM_IOCTL_PRIME_HANDLE_TO_FD and mmap() on the
dma-buf fd).

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

Reply via email to