* [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
@ 2026-11-22 0:05 Falconet3
2026-11-22 0:49 ` Jens Axboe
2026-11-22 10:49 ` Falconet3
0 siblings, 2 replies; 4+ messages in thread
From: Falconet3 @ 2026-11-22 0:05 UTC (permalink / raw)
To: sumit.semwal@linaro.org, christian.koenig@amd.com
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, axboe@kernel.dk,
io-uring@vger.kernel.org, asml.silence@gmail.com,
linux-kernel@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 89 bytes --]
(leak of ctx + dmabuf ref on the WARN_ON_ONCE path, new file in v7.4-rc1, patch attached)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-dma-buf-fix-leak-in-dma_buf_io_ctx_create-WARN-path.patch --]
[-- Type: text/x-patch; name=0002-dma-buf-fix-leak-in-dma_buf_io_ctx_create-WARN-path.patch, Size: 1957 bytes --]
From: Falconet3 <Falconet3@proton.me>
Date: Sat, 21 Nov 2026 21:05:00 +0000
Subject: [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
The file drivers/dma-buf/dma-buf-io.c (and the io_uring dmabuf regbuf
feature on top of it) is new in v7.4-rc1. In dma_buf_io_ctx_create(),
the error path of init_dma_buf_io_ctx() correctly does
kfree(ctx) + dma_buf_put(dmabuf) (dma-buf-io.c:178-182), but the
WARN_ON_ONCE() path right below it returns -EINVAL without freeing
either (dma-buf-io.c:184-188):
if (WARN_ON_ONCE(!ctx->dev_ops || ...))
return -EINVAL; /* leaks ctx and the get_dma_buf() ref */
Reachable from userspace via io_uring buffer registration
(IORING_REGISTER_BUF / rsrc update with IO_REGBUF_TYPE_DMABUF,
io_uring/dma-buf.c -> dma_buf_io_ctx_create()) whenever an importer's
init_dma_buf_io_ctx() succeeds but leaves dev_ops incomplete:
kernel memory + dma-buf reference leak (DoS-grade).
Affects v7.4-rc1..v7.4-rc3 only; the file does not exist in v7.3.5.
Fix was verified with git apply --check against v7.4-rc3; not
build-tested and no reproducer available in this environment.
Fixes: FILL-IN-SHA ("dma-buf: introduce ... file I/O ...")
Assisted-by: LLM Mistral Vibe
Signed-off-by: Falconet3 <Falconet3@proton.me>
---
drivers/dma-buf/dma-buf-io.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/dma-buf/dma-buf-io.c b/drivers/dma-buf/dma-buf-io.c
index 0000000..0000000 100644
--- a/drivers/dma-buf/dma-buf-io.c
+++ b/drivers/dma-buf/dma-buf-io.c
@@ -179,13 +179,16 @@ int dma_buf_io_ctx_create(struct file *file,
kfree(ctx);
dma_buf_put(dmabuf);
return ret;
}
if (WARN_ON_ONCE(!ctx->dev_ops ||
!ctx->dev_ops->map ||
!ctx->dev_ops->unmap ||
- !ctx->dev_ops->release))
- return -EINVAL;
+ !ctx->dev_ops->release)) {
+ kfree(ctx);
+ dma_buf_put(dmabuf);
+ return -EINVAL;
+ }
*out_ctx = ctx;
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
2026-11-22 0:05 [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path Falconet3
@ 2026-11-22 0:49 ` Jens Axboe
2026-11-22 10:49 ` Falconet3
1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-11-22 0:49 UTC (permalink / raw)
To: Falconet3, sumit.semwal@linaro.org, christian.koenig@amd.com
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, io-uring@vger.kernel.org,
asml.silence@gmail.com, linux-kernel@vger.kernel.org
On 11/21/26 5:05 PM, Falconet3 wrote:
> (leak of ctx + dmabuf ref on the WARN_ON_ONCE path, new file in v7.4-rc1, patch attached)
Please see how patches are usually sent - not a huge deal, attachments can
be applied, it's just a lot more inconvenient than a properly sent
patch as you can't comment on it in email. The bigger issue is your
From and Signed-off-by - that needs to be a real identify, not some
leet handle.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
2026-11-22 0:05 [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path Falconet3
2026-11-22 0:49 ` Jens Axboe
@ 2026-11-22 10:49 ` Falconet3
2026-11-23 13:42 ` Pavel Begunkov
1 sibling, 1 reply; 4+ messages in thread
From: Falconet3 @ 2026-11-22 10:49 UTC (permalink / raw)
To: sumit.semwal@linaro.org, christian.koenig@amd.com
Cc: linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
dri-devel@lists.freedesktop.org, axboe@kernel.dk,
io-uring@vger.kernel.org, asml.silence@gmail.com,
linux-kernel@vger.kernel.org
Withdrawing this patch. Apologies for the noise.
The WARN_ON_ONCE() path in dma_buf_io_ctx_create() is not reachable with
in-tree code: the only in-tree implementation, nvme_init_io_ctx_locked(),
installs all of dev_ops (map/unmap/release) before it returns 0.
And on the only path where it could ever fire — an importer violating the
contract — freeing ctx directly is not safe: init_dma_buf_io_ctx() has
already attached ctx to the dmabuf and linked it into the importer's
tracking, so kfree() + dma_buf_put() leaves dangling pointers and turns an
unreachable leak into a potential use-after-free. Since dev_ops->release
may itself be one of the missing callbacks, the core has no safe generic
cleanup on that path.
Thanks,
Falconet3
Em domingo, 22 de novembro de 2026 às 00:05, Falconet3 <Falconet3@proton.me> escreveu:
> (leak of ctx + dmabuf ref on the WARN_ON_ONCE path, new file in v7.4-rc1, patch attached)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
2026-11-22 10:49 ` Falconet3
@ 2026-11-23 13:42 ` Pavel Begunkov
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2026-11-23 13:42 UTC (permalink / raw)
To: Falconet3, sumit.semwal@linaro.org, christian.koenig@amd.com
Cc: linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
dri-devel@lists.freedesktop.org, axboe@kernel.dk,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
On 11/22/26 10:49, Falconet3 wrote:
> Withdrawing this patch. Apologies for the noise.
>
> The WARN_ON_ONCE() path in dma_buf_io_ctx_create() is not reachable with
> in-tree code: the only in-tree implementation, nvme_init_io_ctx_locked(),
> installs all of dev_ops (map/unmap/release) before it returns 0.
Right, it's a warning for the same exact reason, and cleanup considerations
for it are different as well.
> And on the only path where it could ever fire — an importer violating the
> contract — freeing ctx directly is not safe: init_dma_buf_io_ctx() has
> already attached ctx to the dmabuf and linked it into the importer's
> tracking, so kfree() + dma_buf_put() leaves dangling pointers and turns an
> unreachable leak into a potential use-after-free. Since dev_ops->release
> may itself be one of the missing callbacks, the core has no safe generic
> cleanup on that path.
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 13:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 0:05 [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path Falconet3
2026-11-22 0:49 ` Jens Axboe
2026-11-22 10:49 ` Falconet3
2026-11-23 13:42 ` Pavel Begunkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox