dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Baul Lee" <baul.lee@xbow.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/gem-dma: fix double GEM object put on the mmap error path
Date: Wed, 05 Aug 2026 13:07:41 +0000	[thread overview]
Message-ID: <20260805130742.497EE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805124442.57426-1-baul.lee@xbow.com>

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

Pre-existing issues:
- [High] Double-put causing Use-After-Free and memory leak on mmap paths in exynos_drm_gem_mmap()
--

--- Patch [1]: [PATCH] drm/gem-dma: fix double GEM object put on the mmap error path ---
commit 381f3566395605c2a5479094f795c8569a814b8a
Author: Baul Lee <baul.lee@xbow.com>

drm/gem-dma: fix double GEM object put on the mmap error path

This commit removes drm_gem_vm_close() from the error path of
drm_gem_dma_mmap() to prevent a double-put of the GEM object. The caller
drm_gem_mmap_obj() already drops the reference on error, so the extra
put resulted in an underflow and use-after-free.

> exynos_drm_gem_mmap() and __tegra_gem_mmap() have the same error path.

[Severity: High]
This isn't a bug introduced by this patch, but since the commit message
mentions exynos_drm_gem_mmap() having the same error path, looking at that
function:

drivers/gpu/drm/exynos/exynos_drm_gem.c:exynos_drm_gem_mmap() {
    ...
	ret = exynos_drm_gem_mmap_buffer(exynos_gem, vma);
	if (ret)
		goto err_close_vm;

	return ret;

err_close_vm:
	drm_gem_vm_close(vma);

	return ret;
}

Can this cause a double-put leading to a use-after-free?

When returning an error, this explicitly calls drm_gem_vm_close(vma) which
drops a reference. The caller drm_gem_mmap_obj() will see the error and drop
the reference again, causing a double-put.

[Severity: High]
This is also a pre-existing issue, but looking at the import path earlier in
the same function:

drivers/gpu/drm/exynos/exynos_drm_gem.c:exynos_drm_gem_mmap() {
    ...
	if (obj->import_attach)
		return dma_buf_mmap(obj->dma_buf, vma, 0);
    ...
}

Does this code leak the GEM object?

On success, dma_buf_mmap() replaces vma->vm_ops and vma->vm_private_data
with the exporter's state without dropping the surplus reference acquired
by drm_gem_mmap_obj(). This could cause a memory leak when the VMA is
torn down.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260805124442.57426-1-baul.lee@xbow.com?part=1

      reply	other threads:[~2026-08-05 13:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 12:44 [PATCH] drm/gem-dma: fix double GEM object put on the mmap error path Baul Lee
2026-08-05 13:07 ` 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=20260805130742.497EE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=baul.lee@xbow.com \
    --cc=dri-devel@lists.freedesktop.org \
    --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