* [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:11 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 6+ 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] 6+ 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:11 ` sashiko-bot
2026-11-22 0:49 ` Jens Axboe
2026-11-22 10:49 ` Falconet3
2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-22 0:11 UTC (permalink / raw)
To: Falconet3; +Cc: dri-devel@lists.freedesktop.org, media-ci
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] dma-buf: use-after-free on WARN_ON_ONCE path in
dma_buf_io_ctx_create()
- [Low] dma-buf: malformed Fixes trailer and scratch notes in commit
message
--
commit e9d30f7c9b6146d91fac7e600ae7718d7d49f057
Author: Falconet3 <Falconet3@proton.me>
> dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
>
> (leak of ctx + dmabuf ref on the WARN_ON_ONCE path, new file in v7.4-rc1, patch attached)
>
> 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>
[Severity: Low]
The Fixes trailer is still a placeholder and should be:
Fixes: 0d3120db2cbe ("dma-buf: introduce initial file I/O infrastructure")
Also, the submission scratch notes at the top and bottom should be dropped
from the changelog, and the claim that this path is reachable from
userspace is inaccurate because the only in-tree init_dma_buf_io_ctx()
implementation (nvme_init_io_ctx_locked()) populates all three callbacks in
nvme_dma_buf_io_ops.
> diff --git a/drivers/dma-buf/dma-buf-io.c b/drivers/dma-buf/dma-buf-io.c
> index 8440151de8600..d4d37e109a7e4 100644
> --- a/drivers/dma-buf/dma-buf-io.c
> +++ b/drivers/dma-buf/dma-buf-io.c
> @@ -184,8 +184,11 @@ int dma_buf_io_ctx_create(struct file *file,
> if (WARN_ON_ONCE(!ctx->dev_ops ||
> !ctx->dev_ops->map ||
> !ctx->dev_ops->unmap ||
> - !ctx->dev_ops->release))
> + !ctx->dev_ops->release)) {
> + kfree(ctx);
> + dma_buf_put(dmabuf);
> return -EINVAL;
> + }
>
> *out_ctx = ctx;
> return 0;
[Severity: Medium]
Can freeing ctx and dropping its dmabuf reference here cause a
use-after-free once file->f_op->init_dma_buf_io_ctx() has succeeded?
When init_dma_buf_io_ctx() returns 0, the importer has already attached ctx
to dmabuf and linked it into importer tracking lists:
drivers/nvme/host/pci-dmabuf.c:nvme_init_io_ctx_locked() {
...
attach = dma_buf_dynamic_attach(ctx->dmabuf, ctrl->dev,
&nvme_dmabuf_importer_ops, ctx);
...
list_add(&nvme_ctx->list, &buf_list->ctxs);
nvme_ctx->attach = attach;
nvme_ctx->base = ctx;
...
}
As in dma_buf_io_ctx_release(), ctx->dev_ops->release(ctx) must run before
dma_buf_put() and kfree(ctx) to detach the importer and remove ctx from its
tracking list. Freeing ctx directly without detaching leaves dangling
pointers in attach->importer_priv and nvme_ctx->base, causing a
use-after-free on subsequent mapping invalidation or controller teardown in
__nvme_pci_remove_dmabuf().
--
Sashiko AI review · https://sashiko.dev/#/patchset/2xySoxkTOy_cwwTsVb3MjcYIN2J0LJftOab-bhMICCuE_LxaBfqRKUCBOrBQQpQeTBzizv3ci1RqJH09_VL9RbAFk9n8dvQO9YaWIoIT7tE=@proton.me?part=1
^ permalink raw reply [flat|nested] 6+ 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:11 ` sashiko-bot
@ 2026-11-22 0:49 ` Jens Axboe
2026-11-22 10:49 ` Falconet3
2 siblings, 0 replies; 6+ 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] 6+ 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:11 ` sashiko-bot
2026-11-22 0:49 ` Jens Axboe
@ 2026-11-22 10:49 ` Falconet3
2026-11-23 13:42 ` Pavel Begunkov
2 siblings, 1 reply; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread
* [PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path
@ 2026-11-22 0:03 Falconet3
0 siblings, 0 replies; 6+ messages in thread
From: Falconet3 @ 2026-11-22 0:03 UTC (permalink / raw)
To: sumit.semwal@linaro.org, christian.koenig@amd.com
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org
leak of ctx + dmabuf ref on the WARN_ON_ONCE path, new file in v7.4-rc1, patch attached)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-23 13:43 UTC | newest]
Thread overview: 6+ 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:11 ` sashiko-bot
2026-11-22 0:49 ` Jens Axboe
2026-11-22 10:49 ` Falconet3
2026-11-23 13:42 ` Pavel Begunkov
-- strict thread matches above, loose matches on Subject: below --
2026-11-22 0:03 Falconet3
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.