* [PATCH] misc: fastrpc: hold fastrpc_user reference for exported dma_buf
@ 2026-12-05 9:58 Gray David
0 siblings, 0 replies; only message in thread
From: Gray David @ 2026-12-05 9:58 UTC (permalink / raw)
To: Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-kernel, stable, Gray David
Buffers exported via FASTRPC_IOCTL_ALLOC_DMA_BUFF (fastrpc_dmabuf_alloc())
keep a pointer to struct fastrpc_user in buf->fl. Both
fastrpc_dma_buf_attach() and fastrpc_release() -> fastrpc_buf_free()
dereference buf->fl->cctx when translating the buffer address via
fastrpc_ipa_to_dma_addr().
However, fastrpc_dmabuf_alloc() does not take a kref reference on fl.
Because the exported dma_buf has an independent lifetime from the FastRPC
device fd, closing /dev/fastrpc-* while the dma_buf fd is still open (or
exiting the process, which closes the lower-numbered device fd first)
causes fastrpc_device_release() to drop the last reference and free fl
via fastrpc_user_free(). Any subsequent fastrpc_dma_buf_attach() or
close(dmabuf_fd) -> fastrpc_release() -> fastrpc_buf_free() then
dereferences the freed fl, triggering a use-after-free / NULL pointer
dereference Oops. Even closing the dma_buf fd immediately before closing
the device fd hits the same bug because fput() defers fastrpc_release()
to the delayed_fput workqueue.
Take a reference with fastrpc_user_get(fl) once dma_buf_export() succeeds,
and release it with fastrpc_user_put(fl) in fastrpc_release() after
fastrpc_buf_free() returns. Error paths after dma_buf_export() call
dma_buf_put(), which invokes fastrpc_release() and drops the reference.
Internal buffers (fl->init_mem and fl->mmaps) are not exported as dma_bufs
and remain freed inside fastrpc_user_free(), avoiding reference cycles.
Analysis and patch drafting were assisted by AI; all changes were
reviewed by the author.
Fixes: 1d94ce8996d7 ("misc: fastrpc: Add support for new DSP IOVA formatting")
Cc: stable@vger.kernel.org
Signed-off-by: Gray David <3059305632@qq.com>
---
drivers/misc/fastrpc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index ca5af64f3..93a358fcc 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -865,8 +865,10 @@ static void fastrpc_unmap_dma_buf(struct dma_buf_attachment *attach,
static void fastrpc_release(struct dma_buf *dmabuf)
{
struct fastrpc_buf *buffer = dmabuf->priv;
+ struct fastrpc_user *fl = buffer->fl;
fastrpc_buf_free(buffer);
+ fastrpc_user_put(fl);
}
static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,
@@ -1931,6 +1933,9 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
return err;
}
+ /* Keep fl alive until fastrpc_release() finishes freeing buffer */
+ fastrpc_user_get(fl);
+
bp.fd = get_unused_fd_flags(O_ACCMODE);
if (bp.fd < 0) {
dma_buf_put(buf->dmabuf);
---
base-commit: 62225881dad6100844bd7ef1b89e30fac9b313c6
change-id: 20261205-fastrpc-dmabuf-uaf-fix-e9fbbd883ee3
Best regards,
--
Gray David <3059305632@qq.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-05 9:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 9:58 [PATCH] misc: fastrpc: hold fastrpc_user reference for exported dma_buf Gray David
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®