Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] misc: fastrpc: unsigned ADSP node bypasses
  is_session_rejected() on attach
- [Medium] misc: fastrpc: double misc_deregister() on
  fastrpc_register_devices() failure
--

commit d18eec61ddce41081d48907710281fa58756b138
Author: Anandu Krishnan E <[email protected]>

misc: fastrpc: expose unsigned PD node for compute-capable ADSP

This commit registers both the secure and non-secure fastrpc device nodes
when an ADSP domain reports FASTRPC_DSP_COMPUTE_LITE in its cached DSP
attributes.

> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 48ded6080ddd6..28d29c768aad7 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c

[ ... ]

> @@ -2647,6 +2664,9 @@ static int fastrpc_register_devices(struct 
> fastrpc_channel_ctx *cctx,
>  
>       switch (cctx->domain_id) {
>       case ADSP_DOMAIN_ID:
> +             if (compute_capable)
> +                     goto unsigned_capable;
> +             fallthrough;

[Severity: High]
Can an untrusted application opening the non-secure /dev/fastrpc-adsp
node on a secure ADSP channel bypass is_session_rejected() and attach to
signed protection domains?

Jumping to unsigned_capable registers a non-secure node (fl->is_secure_dev
is false) on a secure ADSP channel (fl->cctx->secure is true).  While
fastrpc_init_create_process() calls is_session_rejected() to restrict
non-secure nodes to unsigned PD requests, neither
fastrpc_init_create_static_process() nor fastrpc_init_attach() checks
is_session_rejected(fl, false).  Unlike CDSP and GDSP, ADSP populates
cctx->remote_heap_addr, so an unprivileged caller holding an fd to
/dev/fastrpc-adsp can invoke FASTRPC_IOCTL_INIT_CREATE_STATIC,
FASTRPC_IOCTL_INIT_ATTACH, or FASTRPC_IOCTL_INIT_ATTACH_SNS to attach to
the static Audio PD, ROOT_PD, or SENSORS_PD and invoke remote methods in
those privileged PDs.

>       case MDSP_DOMAIN_ID:
>       case SDSP_DOMAIN_ID:
>               /* Unsigned PD offloading is only supported on CDSP and GDSP */
> @@ -2657,6 +2677,7 @@ static int fastrpc_register_devices(struct 
> fastrpc_channel_ctx *cctx,
>               break;
>       case CDSP_DOMAIN_ID:
>       case GDSP_DOMAIN_ID:
> +unsigned_capable:
>               cctx->unsigned_support = true;
>               /* Create both device nodes so that we can allow both Signed 
> and Unsigned PD */
>               err = fastrpc_device_register(rdev, cctx, true, cctx->domain);

[Severity: Medium]
Can a failure when registering the second device node under
unsigned_capable cause a double misc_deregister() on
cctx->secure_fdevice->miscdev?

If the first fastrpc_device_register() succeeds and sets
cctx->secure_fdevice, and the second fastrpc_device_register() for the
non-secure node fails, err_deregister_fdev deregisters
cctx->secure_fdevice->miscdev without clearing cctx->secure_fdevice to
NULL:

drivers/misc/fastrpc.c:fastrpc_register_devices() {
        ...
err_deregister_fdev:
        if (cctx->fdevice)
                misc_deregister(&cctx->fdevice->miscdev);
        if (cctx->secure_fdevice)
                misc_deregister(&cctx->secure_fdevice->miscdev);

        return err;
}

Because fastrpc_register_devices() runs asynchronously in
fastrpc_cap_query_work() after fastrpc_rpmsg_probe() has already returned
0, the rpmsg device remains bound.  When fastrpc_rpmsg_remove() later runs
on channel teardown, it sees cctx->secure_fdevice still non-NULL and calls
misc_deregister(&cctx->secure_fdevice->miscdev) a second time, freeing an
already-freed minor number.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=2

Reply via email to