Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] misc: fastrpc: unconditional put_work in fastrpc_notify_users()
  causes UAF
--

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

misc: fastrpc: drop the DSP-response reference on channel removal

This commit schedules ctx->put_work in fastrpc_notify_users() for each
context on user->pending when the rpmsg channel is removed, so the
reference taken for the DSP response is released.

> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index bb0c30419611c..c5c3679f87f6f 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -2835,6 +2835,13 @@ static void fastrpc_notify_users(struct fastrpc_user 
> *user)
>       list_for_each_entry(ctx, &user->pending, node) {
>               ctx->retval = -EPIPE;
>               complete(&ctx->work);
> +             /*
> +              * fastrpc_invoke_send() took a second reference for the
> +              * DSP response that will now never arrive since the
> +              * channel is gone; schedule the matching put the same
> +              * way a real response would via fastrpc_rpmsg_callback().
> +              */
> +             schedule_work(&ctx->put_work);
>       }
>       spin_unlock(&user->lock);
>  }

[Severity: High]
Can scheduling ctx->put_work unconditionally for every entry on
user->pending drop the caller's sole reference and cause a use-after-free
on ctx?

fastrpc_context_alloc() adds ctx->node to user->pending before
fastrpc_get_args() and fastrpc_invoke_send() run, and ctx stays on
user->pending until the bail path of fastrpc_internal_invoke() removes it:

CPU0                              CPU1
fastrpc_internal_invoke()
  ctx = fastrpc_context_alloc()
    list_add_tail(&ctx->node, &user->pending)
    kref_init(&ctx->refcount)
  fastrpc_get_args(kernel, ctx)
                                  fastrpc_rpmsg_remove()
                                    fastrpc_notify_users()
                                      schedule_work(&ctx->put_work)
                                  fastrpc_context_put_wq()
                                    fastrpc_context_free()
                                      kfree(ctx)
  fastrpc_invoke_send(cctx, ...)  <-- use-after-free
  ...
  fastrpc_context_put(ctx)

The same mismatch occurs if rpmsg_send() in fastrpc_invoke_send() fails and
immediately drops the second reference while ctx is still on user->pending.

In addition, fastrpc_rpmsg_callback() schedules ctx->put_work without
removing ctx from user->pending.  If fastrpc_rpmsg_remove() runs after
fastrpc_rpmsg_callback() while the caller is still in fastrpc_put_args()
(or after an earlier -ERESTARTSYS / -ETIMEDOUT bail left ctx on
user->pending), fastrpc_notify_users() schedules ctx->put_work a second
time, freeing ctx while it is still in use or still linked on
user->pending.  A later patch in the series, commit "misc: fastrpc: fix
context leak and hang on signal-interrupted invoke", addresses the
post-callback cases, but the pre-send and failed-send windows remain.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/20261117-interrupted-invoke-v4-v4-0-2320a8a7e...@oss.qualcomm.com?part=2

Reply via email to