From: Baul Lee <baul.lee@xbow.com>
To: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Baul Lee <baul.lee@xbow.com>
Subject: [PATCH] drm/gem-dma: fix double GEM object put on the mmap error path
Date: Wed, 5 Aug 2026 21:44:42 +0900 [thread overview]
Message-ID: <20260805124442.57426-1-baul.lee@xbow.com> (raw)
drm_gem_dma_mmap() drops a GEM reference when the DMA mapping fails:
if (ret)
drm_gem_vm_close(vma);
drm_gem_vm_close() puts vma->vm_private_data. drm_gem_mmap_obj() has
already pointed that at the object, and puts it again when the callback
returns an error:
drm_gem_object_get(obj);
vma->vm_private_data = obj;
...
ret = obj->funcs->mmap(obj, vma);
if (ret)
goto err_drm_gem_object_put;
One get, two puts: a failing dma_mmap_wc() or dma_mmap_pages() underflows
the reference count and can free the object while the caller still holds
it.
The callee does not own that reference. drm_gem_shmem_mmap() returns the
error and leaves the put to the caller, and both callers do it,
drm_gem_mmap_obj() as above and drm_gem_prime_mmap() from its own error
path. Drop the call.
It was harmless until commit f49a51bfdc8e ("drm/shme-helpers: Fix
dma_buf_mmap forwarding bug") moved the vm_private_data assignment ahead
of the callback; before that the field was still NULL when the callback
ran and drm_gem_vm_close() put nothing.
exynos_drm_gem_mmap() and __tegra_gem_mmap() have the same error path.
Fixes: f49a51bfdc8e ("drm/shme-helpers: Fix dma_buf_mmap forwarding bug")
Cc: stable@vger.kernel.org
Signed-off-by: Baul Lee <baul.lee@xbow.com>
---
drivers/gpu/drm/drm_gem_dma_helper.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c
index 1c00a71ab3c9..a34561efd1ae 100644
--- a/drivers/gpu/drm/drm_gem_dma_helper.c
+++ b/drivers/gpu/drm/drm_gem_dma_helper.c
@@ -550,8 +550,6 @@ int drm_gem_dma_mmap(struct drm_gem_dma_object *dma_obj, struct vm_area_struct *
dma_obj->vaddr, dma_obj->dma_addr,
vma->vm_end - vma->vm_start);
}
- if (ret)
- drm_gem_vm_close(vma);
return ret;
}
--
2.50.1 (Apple Git-155)
next reply other threads:[~2026-08-05 12:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 12:44 Baul Lee [this message]
2026-08-05 13:07 ` [PATCH] drm/gem-dma: fix double GEM object put on the mmap error path sashiko-bot
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=20260805124442.57426-1-baul.lee@xbow.com \
--to=baul.lee@xbow.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=tzimmermann@suse.de \
/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.