From: "Renê de Souza Pinto" <rene@renesp.com.br>
To: srini@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de
Cc: ekansh.gupta@oss.qualcomm.com, anandu.e@oss.qualcomm.com,
linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
stable@vger.kernel.org,
"Renê de Souza Pinto" <rene@renesp.com.br>
Subject: [PATCH] misc: fastrpc: fix fastrpc_user leak on abnormal process exit
Date: Tue, 24 Nov 2026 13:20:11 +0100 [thread overview]
Message-ID: <20261124122011.2912030-1-rene@renesp.com.br> (raw)
Since commit e85eb5feca8e ("misc: fastrpc: fix use-after-free of
fastrpc_user in workqueue context"), each invoke context holds a
reference on its fastrpc_user, while contexts left on the pending list
(interrupted or timed out invocations) are only freed by
fastrpc_user_free(). When a process dies with invocations in flight,
this cycle leaks the user with all its maps and buffers. As the session
is given back at release, the next process can get the same SMMU
context bank with its IOVA space still in use and fail to map its
buffers.
No thread can be in an ioctl on the file at release time, so drop the
references of the pending contexts there. A context still waiting for
the DSP response is freed when it arrives.
Fixes: e85eb5feca8e ("misc: fastrpc: fix use-after-free of fastrpc_user in workqueue context")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
---
Tested on a Qualcomm IQ-8275 EVK (QCS8275) with a 6.18-based kernel:
a llama.cpp process using the CDSP was killed while invocations were in
flight. Without the fix its ~1.8 GB of buffers stayed attached to its
context bank, and the next process, given the same context bank, failed
to map its own ("failed to map buffer"), leaking more memory on every
retry. With the fix the buffers are released at close and the next
process works. On mainline this is only build-tested (arm64, W=1).
drivers/misc/fastrpc.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index cdc2627bdaf2..09a2963d72f9 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1725,7 +1725,9 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
{
struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data;
struct fastrpc_channel_ctx *cctx = fl->cctx;
+ struct fastrpc_invoke_ctx *ctx, *n;
unsigned long flags;
+ LIST_HEAD(orphans);
fastrpc_release_current_dsp_process(fl);
@@ -1733,6 +1735,20 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
list_del(&fl->user);
spin_unlock_irqrestore(&cctx->lock, flags);
+ /*
+ * Pending (interrupted or timed out) contexts can't be resumed anymore
+ * and each holds a reference on the user: release them here to avoid
+ * a cycle.
+ */
+ spin_lock(&fl->lock);
+ list_splice_init(&fl->pending, &orphans);
+ spin_unlock(&fl->lock);
+
+ list_for_each_entry_safe(ctx, n, &orphans, node) {
+ list_del_init(&ctx->node);
+ fastrpc_context_put(ctx);
+ }
+
fastrpc_session_free(cctx, fl->sctx);
file->private_data = NULL;
/* Release the reference taken in fastrpc_device_open */
--
2.53.0
next reply other threads:[~2026-11-24 12:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:20 Renê de Souza Pinto [this message]
2026-11-24 12:36 ` [PATCH] misc: fastrpc: fix fastrpc_user leak on abnormal process exit sashiko-bot
2026-11-24 14:22 ` Murali Krishna
2026-11-24 14:37 ` Renê
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=20261124122011.2912030-1-rene@renesp.com.br \
--to=rene@renesp.com.br \
--cc=anandu.e@oss.qualcomm.com \
--cc=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=ekansh.gupta@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=srini@kernel.org \
--cc=stable@vger.kernel.org \
/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 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.