From: Murali Krishna <muralikrishna2444b@gmail.com>
To: rene@renesp.com.br
Cc: srini@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de,
ekansh.gupta@oss.qualcomm.com, anandu.e@oss.qualcomm.com,
linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
Murali Krishna <muralikrishna2444b@gmail.com>
Subject: Re: [PATCH] misc: fastrpc: fix fastrpc_user leak on abnormal process exit
Date: Tue, 24 Nov 2026 19:52:23 +0530 [thread overview]
Message-ID: <20261124142229.88456-1-muralikrishna2444b@gmail.com> (raw)
In-Reply-To: <20261124122011.2912030-1-rene@renesp.com.br>
On Tue, 24 Nov 2026 13:20:11 +0100, Renê de Souza Pinto wrote:
> 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.
I am new to this driver, so please treat the below as observations
rather than a review. I read the context lifetime in char-misc-next
(917fcbf03) and it does appear to support your description:
- fastrpc_context_alloc() takes fastrpc_channel_ctx_get(cctx) and
fastrpc_user_get(user), links the context onto fl->pending, and
kref_init()s the context.
- fastrpc_invoke_send() takes a second context reference for the DSP,
released by put_work from fastrpc_rpmsg_callback(), or immediately
if rpmsg_send() fails.
- fastrpc_internal_invoke() unlinks the context and drops the first
reference in its bail path, but only when err is neither
-ERESTARTSYS nor -ETIMEDOUT.
- fastrpc_context_free() never touches fl->pending; it ends with
fastrpc_user_put(fl) and fastrpc_channel_ctx_put(cctx).
fl->pending is referenced in only four places in the file: the
INIT_LIST_HEAD() in fastrpc_device_open(), the list_add_tail() in
fastrpc_context_alloc(), the drain loop in fastrpc_user_free(), and
fastrpc_notify_users(), which sets -EPIPE and completes waiters but
neither unlinks nor drops a reference.
So for an interrupted or timed out invoke the first reference is never
dropped, and the only other place that drops it is the drain loop in
fastrpc_user_free(), which cannot run while any context still holds a
reference on fl. That matches the cycle you describe.
Two things I was unsure about.
First, this looks like it overlaps with Anandu Krishnan E's series,
now at v4:
https://lore.kernel.org/linux-arm-msm/20261117-interrupted-invoke-v4-v4-0-2320a8a7eda2@oss.qualcomm.com/
I see you have Anandu on Cc, so this may already be understood, but as
the two fix the same leak in different places it would help to know
which is meant to land.
> 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.
Second, about the symptom in your test report. If a context is still
waiting for the DSP, the put added here only drops the first reference;
the DSP reference keeps the context alive, so fastrpc_map_put() on its
maps runs later, from fastrpc_context_free(). The maps are attached to
the session device (dma_buf_attach(map->buf, sess->dev) in
fastrpc_map_create()) and the attachment is only torn down in
fastrpc_free_map(). fastrpc_session_free() runs immediately after your
loop and only sets session->used = false, so the context bank becomes
available to the next process while those attachments are, as far as I
can tell, still in place.
Does fastrpc_release_current_dsp_process() above guarantee the DSP has
drained everything by this point, so that case cannot occur in
practice? If not, the window you are aiming at would seem to remain for
genuinely in-flight contexts.
> + list_for_each_entry_safe(ctx, n, &orphans, node) {
> + list_del_init(&ctx->node);
> + fastrpc_context_put(ctx);
> + }
Very minor: after list_splice_init() the entries are already off
fl->pending, and list_for_each_entry_safe() does not need them removed,
so the list_del_init() looks redundant.
For what it is worth, the patch applies cleanly to char-misc-next at
917fcbf03 and builds there on x86_64 with COMPILE_TEST=y under W=1 C=1,
with no new warnings from either gcc or sparse against the unpatched
file. I have no Qualcomm hardware, so none of it is runtime tested and
I could not reproduce your leak; the rest is from reading the code.
Thanks,
Murali Krishna
next prev parent reply other threads:[~2026-11-24 14:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:20 [PATCH] misc: fastrpc: fix fastrpc_user leak on abnormal process exit Renê de Souza Pinto
2026-11-24 12:36 ` sashiko-bot
2026-11-24 14:22 ` Murali Krishna [this message]
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=20261124142229.88456-1-muralikrishna2444b@gmail.com \
--to=muralikrishna2444b@gmail.com \
--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=rene@renesp.com.br \
--cc=srini@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.