dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Baineng Shou" <shoubaineng@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] dma-buf: dma-heap: don't publish fd before copy_to_user() succeeds
Date: Sat, 11 Jul 2026 04:29:36 +0000	[thread overview]
Message-ID: <20260711042936.EF5531F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260711041455.3375292-1-shoubaineng@gmail.com>

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

Pre-existing issues:
- [Critical] Pre-existing Use-After-Free in dma_buf_fd() via concurrent close() after fd installation.
--

--- Patch [1]: [PATCH v2] dma-buf: dma-heap: don't publish fd before copy_to_user() succeeds ---
commit a57039a5644f218873e246c9fb9fe2f87ef4dc55
Author: Baineng Shou <shoubaineng@gmail.com>

dma-buf: dma-heap: don't publish fd before copy_to_user() succeeds

DMA_HEAP_IOCTL_ALLOC allocates a dma-buf and installs an fd into the
caller's fd table via dma_buf_fd() -> fd_install() before
dma_heap_ioctl() copies the result back to userspace.

Link: https://lore.kernel.org/dri-devel/175e98de-f414-47d7-81c1-c0fe0a8f7f62@amd.com/

> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 71f37544a5c61..c2f455d028b30 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -799,6 +799,26 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
>  }
>  EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");

[Severity: Critical]
This is a pre-existing issue, but does dma_buf_fd() have a use-after-free
if the file descriptor is closed concurrently?

Looking at dma_buf_fd() just above this diff:

    fd = FD_ADD(flags, dmabuf->file);
    DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);

Once FD_ADD() installs the fd, it becomes visible to userspace. If a
concurrent thread guesses the fd and calls close(fd), the file's
reference count drops to zero, triggering fput() and eventually freeing
the dmabuf structure.

When the original thread continues to DMA_BUF_TRACE(), won't it
dereference the now-freed dmabuf pointer?

[ ... ]

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

      reply	other threads:[~2026-07-11  4:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03  8:09 [PATCH] dma-buf: dma-heap: close installed fd when copy_to_user() fails Baineng Shou
2026-07-03  8:17 ` sashiko-bot
2026-07-03  8:26 ` Christian König
2026-07-10 10:57 ` [PATCH v2] dma-buf: dma-heap: don't publish fd before copy_to_user() succeeds Baineng Shou
2026-07-10 11:06   ` sashiko-bot
2026-07-10 20:20     ` T.J. Mercier
2026-07-11  4:18       ` 寿柏能
2026-07-10 12:33   ` Christian König
2026-07-11  4:14 ` Baineng Shou
2026-07-11  4:29   ` 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=20260711042936.EF5531F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shoubaineng@gmail.com \
    /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