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 <[email protected]>

> 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 <[email protected]>
> Signed-off-by: Vinayak Katoch <[email protected]>
> Signed-off-by: Ekansh Gupta <[email protected]>

[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-b5e56e5c8...@oss.qualcomm.com?part=2

Reply via email to