dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pavel Begunkov" <asml.silence@gmail.com>
Cc: media-ci@linuxtv.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 13/13] io_uring/rsrc: add dmabuf backed registered buffers
Date: Mon, 28 Sep 2026 14:03:59 +0000	[thread overview]
Message-ID: <20260928140359.884F61F000FF@smtp.kernel.org> (raw)
In-Reply-To: <f51f95d2e5e2f8c0c4fe0e17364b2b333b6e6cd6.1790602223.git.asml.silence@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] io_uring: UAF of dmabuf map on async I/O reissue with partial progress
- [High] io_uring: UAF of driver module due to fput() race in io_release_reg_dmabuf()
--

commit 72563100c98fb5b83c9261811926c28b98fe4b8b
Author: Pavel Begunkov <asml.silence@gmail.com>

io_uring/rsrc: add dmabuf backed registered buffers

This commit introduces support for dmabuf-backed registered buffers, allowing
users to register a dmabuf file descriptor and a target file. Direct I/O
requests can then be issued against the target file using standard io_uring
fixed read/write opcodes.

> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 6e4fe70b316f0..535cc94a1421f 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c

[ ... ]

> +static void io_release_reg_dmabuf(void *priv)
> +{
> +	struct io_regbuf_dma *db = priv;
> +
> +	fput(db->target_file);
> +	dma_buf_io_ctx_release(db->ctx);

[Severity: High]
Could this sequence create a race condition with module unloading?

If fput() is called during process exit (PF_EXITING), it might schedule
delayed_fput_work on the system workqueue. A concurrent worker thread could
execute __fput(), dropping the final module reference of
target_file->f_op->owner.

If that happens, and the original thread then proceeds to call
dma_buf_io_ctx_release(db->ctx) which invokes ctx->dev_ops->release(ctx),
would this execute unmapped memory if the target module is unloaded in the
interim?

> +	kfree(db);
> +}

[ ... ]

> diff --git a/io_uring/rw.c b/io_uring/rw.c
> index 755166e90746e..9867ae2905e31 100644
> --- a/io_uring/rw.c
> +++ b/io_uring/rw.c
> @@ -367,8 +367,8 @@ static int io_init_rw_fixed(struct io_kiocb *req, unsigned int issue_flags,
>  	if (io->bytes_done)
>  		return 0;

[Severity: High]
Does this early return leave a dangling pointer in the iterator if the
request is being reissued after partial progress?

If an async I/O request on a dmabuf-backed fixed buffer makes partial
progress (io->bytes_done > 0) but then completes asynchronously with
-EAGAIN, it appears io_complete_rw() unconditionally calls
io_req_drop_dmabuf(), dropping the map reference.

When the request is caught and requeued to io-wq (because
__io_complete_rw_common() marks it with REQ_F_REISSUE), returning
early here bypasses io_import_dmabuf(). Would the iterator then retain
a dangling pointer to the previously freed map, leading to a
use-after-free when the block layer processes the remaining bytes?

>  
> -	ret = io_import_reg_buf(req, &io->iter, rw->addr, rw->len, ddir,
> -				issue_flags);
> +	ret = __io_import_reg_buf(req, &io->iter, rw->addr, rw->len, ddir,
> +				  issue_flags, IO_REGBUF_IMPORT_ALLOW_DMABUF);
>  	iov_iter_save_state(&io->iter, &io->iter_state);
>  	return ret;
>  }

[ ... ]

> @@ -583,6 +583,8 @@ static void io_complete_rw(struct kiocb *kiocb, long res)
>  	struct io_rw *rw = container_of(kiocb, struct io_rw, kiocb);
>  	struct io_kiocb *req = cmd_to_io_kiocb(rw);
>  
> +	io_req_drop_dmabuf(req);

[Severity: High]
Is it safe to unconditionally drop the dmabuf map here before checking if
the request will be reissued?

If this request made partial progress but completes with -EAGAIN,
__io_complete_rw_common() will see the result and set REQ_F_REISSUE.
Since io_req_drop_dmabuf() has already dropped the map, would the
reissued request in io-wq end up with a dangling map reference if
io_init_rw_fixed() skips re-importing it?

> +
>  	/* ring owner may block in freeze_super() before task_work runs */
>  	if (kiocb->ki_flags & IOCB_WRITE)
>  		io_req_end_write(req);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790602223.git.asml.silence@gmail.com?part=13

      reply	other threads:[~2026-09-28 14:04 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 13:32 [PATCH v7 00/13] Add dmabuf read/write via io_uring Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 01/13] dma-buf: introduce initial file I/O infrastructure Pavel Begunkov
2026-09-28 13:46   ` sashiko-bot
2026-09-29 16:12   ` Christophe JAILLET
2026-09-28 13:32 ` [PATCH v7 02/13] iov_iter: add iterator type for dmabuf maps Pavel Begunkov
2026-09-28 13:49   ` sashiko-bot
     [not found]   ` <20261005091008.GA10727@lst.de>
2026-10-05 11:44     ` Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 03/13] block: always adjust bi_offset on bio_advance_iter Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 04/13] block: introduce dma map backed bio type Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 05/13] block: add dma-buf support for raw bdev Pavel Begunkov
2026-09-28 13:46   ` sashiko-bot
     [not found]   ` <20261005091111.GB10727@lst.de>
2026-10-05 11:43     ` Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 06/13] nvme-pci: implement dma-buf backed requests Pavel Begunkov
2026-09-28 14:02   ` sashiko-bot
2026-09-28 14:41     ` Pavel Begunkov
2026-09-29 15:45   ` Christophe JAILLET
2026-09-30 10:09     ` Pavel Begunkov
     [not found]   ` <20261005091554.GD10727@lst.de>
2026-10-05 11:45     ` Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 07/13] nvme-pci: rename nvme_pci_sgl_set_data to nvme_pci_dma_iter_set_sgl Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 08/13] nvme-pci: add SGL support for the dmabuf path Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 09/13] io_uring/rsrc: introduce buf registration structure Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 10/13] io_uring/rsrc: extend buffer update Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 11/13] io_uring/rsrc: add uncloneable regbuf flag Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 12/13] io_uring/rsrc: add regbuf import flags Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 13/13] io_uring/rsrc: add dmabuf backed registered buffers Pavel Begunkov
2026-09-28 14:03   ` 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=20260928140359.884F61F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=asml.silence@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=media-ci@linuxtv.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