dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guangshuo Li" <lgs201920130244@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/tegra: Finalize GEM object on initialization failure
Date: Tue, 14 Jul 2026 13:33:52 +0000	[thread overview]
Message-ID: <20260714133352.B8B131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714131923.1575860-1-lgs201920130244@gmail.com>

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

Pre-existing issues:
- [High] A racing userspace thread can trigger a use-after-free by guessing the GEM handle during creation, leading to premature object destruction.
--

--- Patch [1]: [PATCH] drm/tegra: Finalize GEM object on initialization failure ---
commit dfc541dc5f8719918460cc54c0dfa389b27272fd
Author: Guangshuo Li <lgs201920130244@gmail.com>

drm/tegra: Finalize GEM object on initialization failure

The commit introduces a call to drm_gem_private_object_fini() on the failure 
path of drm_gem_object_init() inside tegra_bo_alloc_object() before freeing
the buffer object, ensuring proper cleanup of the partially initialized GEM
object.

> diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c
> index ace3e5a805cf7..9ce8ecf1a2335 100644
> --- a/drivers/gpu/drm/tegra/gem.c
> +++ b/drivers/gpu/drm/tegra/gem.c
> @@ -312,8 +312,10 @@ static struct tegra_bo *tegra_bo_alloc_object(struct drm_device *drm,
>  	size = round_up(size, PAGE_SIZE);
>  
>  	err = drm_gem_object_init(drm, &bo->gem, size);
> -	if (err < 0)
> +	if (err < 0) {
> +		drm_gem_private_object_fini(&bo->gem);
>  		goto free;
> +	}
>  
>  	err = drm_gem_create_mmap_offset(&bo->gem);
>  	if (err < 0)

[Severity: High]
This is a pre-existing issue, but while reviewing this area of the code
I noticed a potential use-after-free in the related
tegra_bo_create_with_handle() function.

If drm_gem_handle_create() fails, the error path unconditionally calls
tegra_bo_free_object():

drivers/gpu/drm/tegra/gem.c:tegra_bo_create_with_handle() {
	...
	err = drm_gem_handle_create(file, &bo->gem, handle);
	if (err) {
		tegra_bo_free_object(&bo->gem);
		return ERR_PTR(err);
	}
	...
}

Inside drm_gem_handle_create(), the handle is inserted into the IDR before
secondary operations like drm_vma_node_allow() are checked. If that check
fails, the handle is removed.

During the brief window where the handle is in the IDR, could a racing
userspace thread guess the handle and issue an ioctl (like
DRM_IOCTL_GEM_CLOSE) to look up the object and increment its refcount?

If that happens and tegra_bo_create_with_handle() receives the error, it
appears to ignore the elevated refcount and unconditionally free the object
by calling tegra_bo_free_object(). When the racing thread later calls
drm_gem_object_put(), does this result in dereferencing freed memory?

Would it be safer to use drm_gem_object_put() instead of directly calling
tegra_bo_free_object() here so that the object is only freed when the
racing thread drops its reference?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714131923.1575860-1-lgs201920130244@gmail.com?part=1

  reply	other threads:[~2026-07-14 13:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 13:19 [PATCH] drm/tegra: Finalize GEM object on initialization failure Guangshuo Li
2026-07-14 13:33 ` sashiko-bot [this message]
2026-07-15  5:54 ` Mikko Perttunen

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=20260714133352.B8B131F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lgs201920130244@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox