mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jhonraushan <raushan.jhon@gmail.com>
To: Min Ma <mamin506@gmail.com>, Lizhi Hou <lizhi.hou@amd.com>,
	Oded Gabbay <ogabbay@kernel.org>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Jhonraushan <raushan.jhon@gmail.com>
Subject: [PATCH] accel/amdxdna: Fix double drm_gem_object_put() in dma-buf mmap error path
Date: Thu,  2 Jul 2026 12:55:40 +0530	[thread overview]
Message-ID: <20260702072540.2183601-1-raushan.jhon@gmail.com> (raw)

amdxdna_gem_dmabuf_mmap() takes a reference with drm_gem_object_get()
and, on the vm_insert_pages() failure path, jumps to close_vma which
calls vma->vm_ops->close(). For a shmem GEM object vm_ops is
drm_gem_shmem_vm_ops, whose .close (drm_gem_shmem_vm_close ->
drm_gem_vm_close) already drops that reference. Execution then falls
through to put_obj and drops it a second time.

This underflows the GEM object refcount and frees it prematurely while
the dma-buf still references it, leading to a use-after-free.

Return directly after vm_ops->close() instead of falling through to the
extra drm_gem_object_put(), matching the sibling amdxdna_insert_pages()
error path.

Fixes: e486147c912f ("accel/amdxdna: Add BO import and export")
Cc: stable@vger.kernel.org
Signed-off-by: Jhonraushan <raushan.jhon@gmail.com>
---
 drivers/accel/amdxdna/amdxdna_gem.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index 891112c2cddf..3ac8c345b25b 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -526,7 +526,12 @@ static int amdxdna_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struc
 	return 0;
 
 close_vma:
+	/* vm_ops->close() drops the reference taken by drm_gem_object_get()
+	 * above, so return directly instead of falling through to put_obj
+	 * and dropping it a second time.
+	 */
 	vma->vm_ops->close(vma);
+	return ret;
 put_obj:
 	drm_gem_object_put(gobj);
 	return ret;
-- 
2.43.0


             reply	other threads:[~2026-07-02  7:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  7:25 Jhonraushan [this message]
2026-07-02 15:47 ` Lizhi Hou

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=20260702072540.2183601-1-raushan.jhon@gmail.com \
    --to=raushan.jhon@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=mamin506@gmail.com \
    --cc=ogabbay@kernel.org \
    /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

all inboxes | Powered by JetHome®