All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lyude Paul" <lyude@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/5] drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling
Date: Thu, 30 Jul 2026 20:04:40 +0000	[thread overview]
Message-ID: <20260730200440.B9D451F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730195523.1467423-4-lyude@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Dynamically allocating `struct drm_driver` with `devm_kzalloc` introduces a Use-After-Free vulnerability when the physical device is unbound.

Pre-existing issues:
- [High] The core driver structure `struct nouveau_drm` is allocated with `devm_kzalloc`, leading to a preexisting Use-After-Free when the device is unbound.
--

--- Patch [3]: [PATCH v2 3/5] drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling ---
commit 9eb1e724469599d6b2baf3bcec061d6d7b31c8bc
Author: Lyude Paul <lyude@redhat.com>

drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling

This commit addresses issues with how the nouveau.atomic module parameter is
handled. It replaces shared static drm_driver structures with dynamically
allocated ones using devm_kzalloc to allow safely setting per-device driver
flags.

> diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
> index 5565cf2367aa9..ae489dc1b1943 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_drm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
[ ... ]
> @@ -737,12 +734,18 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
>  		{}
>  	};
>  	struct nouveau_drm *drm;
> +	struct drm_driver *drm_driver;
>  	int ret;
>  
>  	drm = devm_kzalloc(parent, sizeof(*drm), GFP_KERNEL);

[Severity: High]
This is a pre-existing issue, but does allocating struct nouveau_drm with
devm_kzalloc() cause a use-after-free on device unbind?

If a userspace process holds a DRM file descriptor open while the physical
device is unbound via sysfs or hot-unplug, devres will free this memory.
Since the DRM device lifetime is reference-counted and extended by the open
descriptor, subsequent ioctls or the final drm_release() might dereference
the freed memory via dev->dev_private.

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

[Severity: High]
Does allocating drm_driver with devm_kzalloc() introduce a similar
use-after-free vulnerability?

If the device is unbound while a DRM file descriptor is open, devres will
free the drm_driver struct. Since the DRM device outlives the physical
device in this scenario, when userspace eventually closes the file
descriptor, the DRM core cleans up by calling driver hooks (like postclose
or release) through dev->driver, which would now point to freed memory.

Could this be avoided by using the static const struct drm_driver and
modifying the drm->dev->driver_features field instead of allocating a new
driver struct for each device?

> +	if (!drm_driver)
> +		return ERR_PTR(-ENOMEM);
> +	*drm_driver = driver_stub;
> +
>  	drm->nvkm = device;
>  
>  	drm->dev = drm_dev_alloc(drm_driver, parent);
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730195523.1467423-1-lyude@redhat.com?part=3

  reply	other threads:[~2026-07-30 20:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 19:51 [PATCH v2 0/5] drm/nouveau: Enable atomic modesetting by default Lyude Paul
2026-07-30 19:51 ` Lyude Paul
2026-07-30 19:51 ` [PATCH v2 1/5] drm/nouveau: Fix cleanup bug in nouveau_drm_device_new() Lyude Paul
2026-07-30 19:51   ` Lyude Paul
2026-07-30 20:13   ` sashiko-bot
2026-07-30 19:51 ` [PATCH v2 2/5] drm/nouveau: Print the nouveau.atomic parameter in nouveau_display_options() Lyude Paul
2026-07-30 19:51   ` Lyude Paul
2026-07-30 19:51 ` [PATCH v2 3/5] drm/nouveau: Fix drm_driver struct/nouveau.atomic parameter handling Lyude Paul
2026-07-30 19:51   ` Lyude Paul
2026-07-30 20:04   ` sashiko-bot [this message]
2026-07-30 19:51 ` [PATCH v2 4/5] drm/nouveau/kms: Only allow enabling atomic modesetting on nv50+ Lyude Paul
2026-07-30 19:51   ` Lyude Paul
2026-07-30 20:10   ` sashiko-bot
2026-07-30 19:51 ` [PATCH v2 5/5] drm/nouveau/kms/nv50-: Enable atomic modesetting by default Lyude Paul
2026-07-30 19:51   ` Lyude Paul

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=20260730200440.B9D451F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lyude@redhat.com \
    --cc=sashiko-reviews@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 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.