Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] Dynamically allocating `struct drm_driver` with `devm_kzalloc` creates 
a Use-After-Free on device unbind.
--

--- Patch [4]: [PATCH v2 4/5] drm/nouveau/kms: Only allow enabling atomic 
modesetting on nv50+ ---
commit 5c23d4459a380de49a6e089b9ca550a380ff5d97
Author: Lyude Paul <[email protected]>

drm/nouveau/kms: Only allow enabling atomic modesetting on nv50+

Atomic modesetting support was never added for pre-nv50 chipsets, so make
sure we don't allow it to be forced on. Additionally, print a small warning
when it's not supported.

> diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c 
> b/drivers/gpu/drm/nouveau/nouveau_drm.c
> index ae489dc1b1943..33f60f5d4d9f3 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_drm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
> @@ -770,8 +770,12 @@ nouveau_drm_device_new(struct device *parent, struct 
> nvkm_device *device)
>               goto done;
>       }
>  
> -     if (nouveau_atomic)
> -             drm_driver->driver_features |= DRIVER_ATOMIC;
> +     if (nouveau_atomic) {
> +             if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
> +                     drm_driver->driver_features |= DRIVER_ATOMIC;

[Severity: High]
Earlier in nouveau_drm_device_new(), drm_driver is dynamically allocated
with devm_kzalloc():

        drm_driver = devm_kzalloc(parent, sizeof(*drm_driver), GFP_KERNEL);
        if (!drm_driver)
                return ERR_PTR(-ENOMEM);

Can this create a use-after-free on device unbind?

If userspace opens the DRM device node, it takes a reference on the
drm_device object. If the PCI device is hot-unplugged or manually unbound,
devres cleanup frees the drm_driver (along with nouveau_drm).

Later, when userspace closes the DRM file descriptor, drm_release() calls
drm_dev_needs_global_mutex() which evaluates dev->driver->driver_features,
and eventually executes dev->driver->postclose(), dereferencing the freed
memory.

> +             else
> +                     NV_WARN(drm, "Atomic modesetting not supported (needs 
> nv50+)\n");
> +     }
>  
>       ret = nvif_device_map(&drm->device);
>       if (ret) {

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

Reply via email to