dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anandu Krishnan E" <anandu.e@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 2/3] misc: fastrpc: drop the DSP-response reference on channel removal
Date: Tue, 17 Nov 2026 09:55:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-218551@kernel.org> (raw)
In-Reply-To: <20261117-interrupted-invoke-v4-v4-2-2320a8a7eda2@oss.qualcomm.com>

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 <anandu.e@oss.qualcomm.com>

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

  reply	other threads:[~2026-11-17  9:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:39 [PATCH v4 0/3] misc: fastrpc: fix context leak and hang on signal-interrupted invoke Anandu Krishnan E
2026-11-17  9:39 ` [PATCH v4 1/3] misc: fastrpc: remove dead context drain in fastrpc_user_free() Anandu Krishnan E
2026-11-17  9:52   ` sashiko-bot
2026-11-17 15:35   ` Ekansh Gupta
2026-11-17  9:39 ` [PATCH v4 2/3] misc: fastrpc: drop the DSP-response reference on channel removal Anandu Krishnan E
2026-11-17  9:55   ` sashiko-bot [this message]
2026-11-17 15:49   ` Ekansh Gupta
2026-11-17  9:39 ` [PATCH v4 3/3] misc: fastrpc: fix context leak and hang on signal-interrupted invoke Anandu Krishnan E
2026-11-17 10:05   ` sashiko-bot

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=sashiko-outbox-218551@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anandu.e@oss.qualcomm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox