[PATCH] dma-buf: fix leak of ctx and dmabuf reference in dma_buf_io_ctx_create() WARN path

From: Falconet3

Date: Sat Nov 21 2026 - 19:05:35 EST


(leak of ctx + dmabuf ref on the WARN_ON_ONCE path, new file in v7.4-rc1, patch attached)From: Falconet3 <Falconet3@xxxxxxxxx>
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@xxxxxxxxx>
---
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