dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] misc: fastrpc: fix fastrpc_user leak on abnormal process exit
       [not found] <20261124122011.2912030-1-rene@renesp.com.br>
@ 2026-11-24 12:36 ` sashiko-bot
  0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-11-24 12:36 UTC (permalink / raw)
  To: Renê de Souza Pinto; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] misc: fastrpc: premature fastrpc_session_free() before
  fastrpc_user_free()
- [Low] misc: fastrpc: dead fl->pending cleanup loop left in
  fastrpc_user_free()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] misc: fastrpc: memory leak of handle maps in
  fastrpc_context_free() [1]
--

commit de1f1f214d7656b3f51116b41f6e566209ceb0a7
Author: Renê de Souza Pinto <rene@renesp.com.br>

misc: fastrpc: fix fastrpc_user leak on abnormal process exit

This commit drains fl->pending in fastrpc_device_release() and drops each
pending invoke context's reference so that the reference cycle between
fastrpc_invoke_ctx and fastrpc_user is broken when a file descriptor is
closed.

> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 9e760f68bcaf2..05271beaf821c 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -1734,7 +1734,9 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
>  {
>  	struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data;
>  	struct fastrpc_channel_ctx *cctx = fl->cctx;
> +	struct fastrpc_invoke_ctx *ctx, *n;
>  	unsigned long flags;
> +	LIST_HEAD(orphans);
>  
>  	fastrpc_release_current_dsp_process(fl);
>  
> @@ -1742,6 +1744,20 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
>  	list_del(&fl->user);
>  	spin_unlock_irqrestore(&cctx->lock, flags);
>  
> +	/*
> +	 * Pending (interrupted or timed out) contexts can't be resumed anymore
> +	 * and each holds a reference on the user: release them here to avoid
> +	 * a cycle.
> +	 */
> +	spin_lock(&fl->lock);
> +	list_splice_init(&fl->pending, &orphans);
> +	spin_unlock(&fl->lock);
> +
> +	list_for_each_entry_safe(ctx, n, &orphans, node) {
> +		list_del_init(&ctx->node);
> +		fastrpc_context_put(ctx);
> +	}

[Severity: Low]
Now that fastrpc_device_release() drains fl->pending and every context on
fl->pending holds a reference on fl until fastrpc_context_free(),
fl->pending is always empty when fastrpc_user_free() runs.  Should the
duplicate fl->pending loop in fastrpc_user_free() and the forward
declaration of fastrpc_context_put() be removed?

[Severity: High]
This problem wasn't introduced by this patch, but can
fastrpc_context_free() leak handle maps [1] when an invocation fails
early or is aborted here before fastrpc_put_args() runs?

fastrpc_create_maps() populates ctx->maps up to ctx->nscalars, attaching
handle maps at indices ctx->nbufs through ctx->nscalars - 1 via
fastrpc_map_attach(), but fastrpc_context_free() only releases entries up
to ctx->nbufs:

drivers/misc/fastrpc.c:fastrpc_context_free() {
	...
	for (i = 0; i < ctx->nbufs; i++)
		fastrpc_map_put(ctx->maps[i]);
	...
}

When the invocation never reaches fastrpc_put_args(), those handle map
references and their pinned DMA buffers are never released.

> +
>  	fastrpc_session_free(cctx, fl->sctx);
>  	file->private_data = NULL;
>  	/* Release the reference taken in fastrpc_device_open */

[Severity: Medium]
Can calling fastrpc_session_free() here still hand the session and its
SMMU context bank to a new process before the old process's buffers are
unmapped?

When an orphaned context on fl->pending is still waiting for a DSP
response (or its ctx->put_work work item has not yet run),
fastrpc_context_get() taken in fastrpc_invoke_send() keeps ctx->refcount
above zero until fastrpc_context_put_wq() runs.  Because ctx holds a
reference on fl until fastrpc_context_free(), and commit e85eb5feca8e
("misc: fastrpc: fix use-after-free of fastrpc_user in workqueue context")
moved the teardown of fl->init_mem, fl->maps, and fl->mmaps into
fastrpc_user_free(), marking fl->sctx->used = false in
fastrpc_device_release() allows fastrpc_session_alloc() to reuse the
session while its IOVA space is still occupied by the exiting user's
mappings.  Should fastrpc_session_free() be called in fastrpc_user_free()
after the user's maps and buffers have been freed instead?

[1] https://sashiko.dev/#/bug/linux-9b1d78f7-f355-4424-acce-4fd9aa48eac5

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124122011.2912030-1-rene@renesp.com.br?part=1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-24 12:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261124122011.2912030-1-rene@renesp.com.br>
2026-11-24 12:36 ` [PATCH] misc: fastrpc: fix fastrpc_user leak on abnormal process exit sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox