* [PATCH 0/2] misc: fastrpc: fix session setup and teardown ordering in probe
@ 2026-12-03 5:41 Ekansh Gupta
2026-12-03 5:41 ` [PATCH 1/2] misc: fastrpc: create ADSP duplicate sessions before registering devices Ekansh Gupta
2026-12-03 5:41 ` [PATCH 2/2] misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path Ekansh Gupta
0 siblings, 2 replies; 4+ messages in thread
From: Ekansh Gupta @ 2026-12-03 5:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Arnd Bergmann, Greg Kroah-Hartman,
Vinayak Katoch
Cc: Bharath Kumar, Chenna Kesava Raju, linux-arm-msm, dri-devel,
linux-kernel, Ekansh Gupta
Commit 112dc91edd51 ("misc: fastrpc: move ADSP duplicate session
creation to the driver") and commit 81b3908cf7b9 ("misc: fastrpc:
iterate CB nodes manually instead of of_platform_populate") were
developed against different layouts of fastrpc_rpmsg_probe(). After
both landed in fastrpc for-next, two parts of the probe still reflect
the layout they were written against.
Patch 1 moves the ADSP duplicate session creation ahead of
fastrpc_device_register(), so the session table is complete and unused
before userspace can open the device. In the current order an open()
can fail with all sessions in use, and a duplicate copied from an
already-allocated session is created with used = true and can never be
freed.
Patch 2 switches the probe error path from of_platform_depopulate() to
fastrpc_cb_devices_destroy(), matching the helper that now creates the
CB devices and that fastrpc_rpmsg_remove() already uses, so the
sessions are invalidated under the channel lock before the CB devices
go away.
Both issues exist only in fastrpc for-next, so no stable backport is
needed. Feel free to squash these into the original commits if you
prefer that over applying them on top.
Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
---
Ekansh Gupta (2):
misc: fastrpc: create ADSP duplicate sessions before registering devices
misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path
drivers/misc/fastrpc.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
---
base-commit: 3680d0d62e9c661e228874cab35346ebd79feaf9
change-id: 20261203-fastrpc-probe-ordering-fix-80c72974d916
Best regards,
--
Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] misc: fastrpc: create ADSP duplicate sessions before registering devices
2026-12-03 5:41 [PATCH 0/2] misc: fastrpc: fix session setup and teardown ordering in probe Ekansh Gupta
@ 2026-12-03 5:41 ` Ekansh Gupta
2026-12-03 5:41 ` [PATCH 2/2] misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path Ekansh Gupta
1 sibling, 0 replies; 4+ messages in thread
From: Ekansh Gupta @ 2026-12-03 5:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Arnd Bergmann, Greg Kroah-Hartman,
Vinayak Katoch
Cc: Bharath Kumar, Chenna Kesava Raju, linux-arm-msm, dri-devel,
linux-kernel, Ekansh Gupta
fastrpc_rpmsg_probe() appends the ADSP duplicate sessions at the end of
probe, after fastrpc_device_register() has already exposed the device
nodes to userspace. This leaves a window in which:
- an open() can only be served by the real CB sessions and may fail
with all sessions in use, which is exactly what the duplicate
sessions are meant to avoid;
- the duplicates are memcpy()'d from the last session. If that session
has already been handed out, the copies are created with used = true.
fastrpc_session_free() only clears the flag of the session it is
given, so these copies can never be allocated again.
Create the duplicate sessions right after the CB devices are created
and before any device node is registered, so that the session table is
complete and unused by the time userspace can access it.
While moving the block, drop its local 'flags' declaration, which
shadowed the one already declared at function scope.
Fixes: 112dc91edd51 ("misc: fastrpc: move ADSP duplicate session creation to the driver")
Co-developed-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
---
drivers/misc/fastrpc.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1dcc8602a380..cb0972722e08 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -2792,6 +2792,21 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
if (err)
goto err_free_data;
+ if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
+ struct fastrpc_session_ctx *last_sess;
+ struct fastrpc_session_ctx *dup_sess;
+
+ spin_lock_irqsave(&data->lock, flags);
+ last_sess = &data->session[data->sesscount - 1];
+ for (i = 0; i < FASTRPC_DUP_SESSIONS; i++) {
+ if (data->sesscount >= FASTRPC_MAX_SESSIONS)
+ break;
+ dup_sess = &data->session[data->sesscount++];
+ memcpy(dup_sess, last_sess, sizeof(*dup_sess));
+ }
+ spin_unlock_irqrestore(&data->lock, flags);
+ }
+
switch (domain_id) {
case ADSP_DOMAIN_ID:
case MDSP_DOMAIN_ID:
@@ -2819,22 +2834,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
goto err_depopulate;
}
- if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
- struct fastrpc_session_ctx *last_sess;
- struct fastrpc_session_ctx *dup_sess;
- unsigned long flags;
-
- spin_lock_irqsave(&data->lock, flags);
- last_sess = &data->session[data->sesscount - 1];
- for (i = 0; i < FASTRPC_DUP_SESSIONS; i++) {
- if (data->sesscount >= FASTRPC_MAX_SESSIONS)
- break;
- dup_sess = &data->session[data->sesscount++];
- memcpy(dup_sess, last_sess, sizeof(*dup_sess));
- }
- spin_unlock_irqrestore(&data->lock, flags);
- }
-
return 0;
err_deregister_fdev:
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path
2026-12-03 5:41 [PATCH 0/2] misc: fastrpc: fix session setup and teardown ordering in probe Ekansh Gupta
2026-12-03 5:41 ` [PATCH 1/2] misc: fastrpc: create ADSP duplicate sessions before registering devices Ekansh Gupta
@ 2026-12-03 5:41 ` Ekansh Gupta
2026-12-03 5:59 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Ekansh Gupta @ 2026-12-03 5:41 UTC (permalink / raw)
To: Srinivas Kandagatla, Arnd Bergmann, Greg Kroah-Hartman,
Vinayak Katoch
Cc: Bharath Kumar, Chenna Kesava Raju, linux-arm-msm, dri-devel,
linux-kernel, Ekansh Gupta
Since commit 81b3908cf7b9 ("misc: fastrpc: iterate CB nodes manually
instead of of_platform_populate"), the CB devices are created by
fastrpc_cb_devices_create(), but the probe error path still tears them
down with of_platform_depopulate().
Use fastrpc_cb_devices_destroy(), as fastrpc_rpmsg_remove() already
does, so that the sessions are invalidated under the channel lock
before the CB devices are removed.
Fixes: 81b3908cf7b9 ("misc: fastrpc: iterate CB nodes manually instead of of_platform_populate")
Co-developed-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
---
drivers/misc/fastrpc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index cb0972722e08..ff8a94cc522d 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -2854,7 +2854,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
fastrpc_notify_users(user);
spin_unlock_irqrestore(&data->lock, flags);
- of_platform_depopulate(rdev);
+ fastrpc_cb_devices_destroy(rpdev);
fastrpc_channel_ctx_put(data);
return err;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2] misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path
2026-12-03 5:41 ` [PATCH 2/2] misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path Ekansh Gupta
@ 2026-12-03 5:59 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-03 5:59 UTC (permalink / raw)
To: Ekansh Gupta; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] misc: fastrpc: UAF of CB devices freed by
fastrpc_cb_devices_destroy()
- [Low] misc: fastrpc: commit log misses that of_platform_depopulate()
was a no-op
- [Low] misc: fastrpc: inaccurate commit message and Fixes attribution
--
commit 64e6c11d9bcb9cc1584f86ad076bfec7bd18df7d
Author: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
> misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path
>
> Since commit 81b3908cf7b9 ("misc: fastrpc: iterate CB nodes manually
> instead of of_platform_populate"), the CB devices are created by
> fastrpc_cb_devices_create(), but the probe error path still tears them
> down with of_platform_depopulate().
>
> Use fastrpc_cb_devices_destroy(), as fastrpc_rpmsg_remove() already
> does, so that the sessions are invalidated under the channel lock
> before the CB devices are removed.
[Severity: Low]
Does the commit message understate what this change fixes?
fastrpc_cb_devices_create() creates child devices individually via
of_platform_device_create() and never sets OF_POPULATED_BUS on
rdev->of_node. Because of_platform_depopulate() returns immediately when
OF_POPULATED_BUS is unset, it was a complete no-op that leaked the CB
platform devices and left OF_POPULATED set on their DT nodes, causing
later re-probes to fail with -ENODEV.
In addition, cctx->session[i].valid is only checked in
fastrpc_session_alloc() during fastrpc_device_open(), which
misc_deregister() has already prevented before err_depopulate runs.
> Fixes: 81b3908cf7b9 ("misc: fastrpc: iterate CB nodes manually instead of of_platform_populate")
> Co-developed-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
> Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
[Severity: Low]
Is this Fixes: tag pointing to the right commit?
Commit 81b3908cf7b9 ("misc: fastrpc: iterate CB nodes manually instead of
of_platform_populate") had no err_depopulate label or
of_platform_depopulate() call. Commit 367972113065 ("misc: fastrpc: fix
init ordering race in rpmsg probe") added err_depopulate on a branch that
still used of_platform_populate(), and the mismatch was introduced by the
merge commit 3680d0d62e9c ("Merge branch 'fastrpc-for-v7.5' into
fastrpc-for-next"). If that merge commit is permanent in history, the
commit message and Fixes: tag should reference it instead.
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index cb0972722e083..ff8a94cc522d2 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -2854,7 +2854,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
> fastrpc_notify_users(user);
> spin_unlock_irqrestore(&data->lock, flags);
>
> - of_platform_depopulate(rdev);
> + fastrpc_cb_devices_destroy(rpdev);
> fastrpc_channel_ctx_put(data);
> return err;
[Severity: High]
Can calling fastrpc_cb_devices_destroy() here trigger a use-after-free on
the freed CB struct device?
On CDSP and GDSP, fastrpc_rpmsg_probe() registers secure_fdevice before
fdevice, so userspace can open the first node before the second
fastrpc_device_register() fails and jumps to err_depopulate. Neither
fastrpc_cb_init() nor __fastrpc_buf_alloc() takes a get_device() reference
on the CB device, and clearing session[i].valid only blocks new opens.
CPU0 (probe error path) CPU1 / kworker
fastrpc_rpmsg_probe()
fastrpc_device_register(secure)
fastrpc_device_open()
fl->sctx = &cctx->session[i]
/* allocate buf / submit invoke */
fastrpc_device_register(non-sec) -> fails
misc_deregister(...)
fastrpc_notify_users()
fastrpc_context_schedule_put_work()
fastrpc_cb_devices_destroy()
of_platform_device_destroy()
platform_device_unregister() /* frees CB struct device */
fastrpc_context_put_wq()
fastrpc_buf_free(ctx->buf)
dma_free_coherent(buf->dev, ...)
<-- use-after-free
Because of_platform_depopulate() was previously a no-op, this change
newly exposes the probe error path to freeing the CB platform devices
while scheduled put_work, open fds (e.g. fastrpc_dmabuf_alloc()), and
exported dma-bufs still dereference fl->sctx->dev and buf->dev, causing
kernel memory corruption or a panic. (The same underlying
fastrpc_cb_devices_destroy() issue also affects fastrpc_rpmsg_remove().)
Should sessions and buffers hold a get_device() reference, or should CB
device teardown wait until the last channel context reference is dropped
in fastrpc_channel_ctx_free()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-fastrpc-probe-ordering-fix-v1-0-b5e56e5c895f@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 5:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 5:41 [PATCH 0/2] misc: fastrpc: fix session setup and teardown ordering in probe Ekansh Gupta
2026-12-03 5:41 ` [PATCH 1/2] misc: fastrpc: create ADSP duplicate sessions before registering devices Ekansh Gupta
2026-12-03 5:41 ` [PATCH 2/2] misc: fastrpc: use fastrpc_cb_devices_destroy() in probe error path Ekansh Gupta
2026-12-03 5:59 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox