From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & spin locks
Date: Mon, 15 Jun 2026 09:59:03 +0000 [thread overview]
Message-ID: <20260615095904.00F2D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260615093824.115751-10-phucduc.bui@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Non-synchronous timer cancellation (`timer_delete()`) and improper teardown order allow race conditions and use-after-free.
- [High] Unvalidated remote processor command index allows out-of-bounds array write.
- [High] Workqueue destroyed before ALSA component unregistration leads to Use-After-Free.
--
commit fb7a6469268cda085459a69bd6a9d37338ef0a42
Author: bui duc phuc <phucduc.bui@gmail.com>
ASoC: fsl_rpmsg: Use guard() for mutex & spin locks
Clean up the code using guard() for mutex & spin locks.
Merely code refactoring, and no behavior change.
> diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c
> index 031e5272215d4..7210393dfa5d9 100644
> --- a/sound/soc/fsl/imx-pcm-rpmsg.c
> +++ b/sound/soc/fsl/imx-pcm-rpmsg.c
[ ... ]
> @@ -71,7 +67,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
> if (!ret) {
> dev_err(&rpdev->dev, "rpmsg_send cmd %d timeout!\n",
> msg->s_msg.header.cmd);
> - mutex_unlock(&info->msg_lock);
> return -ETIMEDOUT;
> }
[Severity: High]
This is a pre-existing issue, but can this out-of-bounds write occur here?
Looking at the code just below this in imx_rpmsg_pcm_send_message():
memcpy(&msg->r_msg, &info->r_msg, sizeof(struct rpmsg_r_msg));
memcpy(&info->msg[msg->r_msg.header.cmd].r_msg,
&msg->r_msg, sizeof(struct rpmsg_r_msg));
The msg->r_msg.header.cmd field comes from the remote processor and is used
directly as an array index for info->msg. Since cmd is an 8-bit unsigned
integer, and the array bounds are likely smaller, a compromised remote
processor could send a command ID up to 255.
Does this allow an out-of-bounds write that corrupts adjacent heap
structures like the workqueue pointer?
[ ... ]
> @@ -681,10 +672,10 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
> info->send_message(&work_of_rpmsg->msg, info);
>
> /* update read index */
> - spin_lock_irqsave(&info->wq_lock, flags);
> - info->work_read_index++;
> - info->work_read_index %= WORK_MAX_NUM;
> - spin_unlock_irqrestore(&info->wq_lock, flags);
> + scoped_guard(spinlock_irqsave, &info->wq_lock) {
> + info->work_read_index++;
> + info->work_read_index %= WORK_MAX_NUM;
> + }
> }
[Severity: High]
This is a pre-existing issue, but does using timer_delete() instead of
timer_delete_sync() or timer_shutdown_sync() allow the timer callback
to execute after teardown?
In imx_rpmsg_pcm_close() and imx_rpmsg_terminate_all():
timer_delete(&info->stream_timer[substream->stream].timer);
This non-synchronous deletion means the timer callback might continue
executing concurrently. In imx_rpmsg_pcm_close(), timer_delete() is called
after flush_workqueue(), so a late timer callback could queue new work
after the stream is supposedly closed.
Additionally, imx_rpmsg_pcm_remove() does not appear to stop timers
before devres frees the info structure, potentially leading to a
use-after-free if a timer is still pending.
[Severity: High]
This isn't a bug introduced by this patch, but does the current cleanup
order in imx_rpmsg_pcm_remove() cause a use-after-free?
The driver registers the component using devm_snd_soc_register_component()
in imx_rpmsg_pcm_probe(), which relies on devres for cleanup. However, the
workqueue is explicitly destroyed in imx_rpmsg_pcm_remove():
static void imx_rpmsg_pcm_remove(struct platform_device *pdev)
{
...
if (info->rpmsg_wq)
destroy_workqueue(info->rpmsg_wq);
}
Since devres runs after the remove callback returns, the component
remains active while the workqueue is already destroyed. If a stream
is closed during this window, imx_rpmsg_pcm_close() will call
flush_workqueue(info->rpmsg_wq) on the destroyed workqueue.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=9
next prev parent reply other threads:[~2026-06-15 9:59 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
2026-06-15 9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
2026-06-15 9:51 ` sashiko-bot
2026-06-15 14:18 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 02/11] ASoC: fsl_audmix: " phucduc.bui
2026-06-15 14:30 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 03/11] ASoC: fsl_easrc: " phucduc.bui
2026-06-15 9:48 ` sashiko-bot
2026-06-15 14:24 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 04/11] ASoC: fsl_esai: " phucduc.bui
2026-06-15 9:52 ` sashiko-bot
2026-06-15 14:15 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 05/11] ASoC: fsl_spdif: " phucduc.bui
2026-06-15 9:52 ` sashiko-bot
2026-06-15 14:17 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks phucduc.bui
2026-06-15 14:25 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
2026-06-15 9:49 ` sashiko-bot
2026-06-15 14:19 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
2026-06-15 9:51 ` sashiko-bot
2026-06-15 14:17 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
2026-06-15 9:59 ` sashiko-bot [this message]
2026-06-15 14:12 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
2026-06-15 9:57 ` sashiko-bot
2026-06-15 14:14 ` Frank Li
2026-06-15 9:38 ` [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks phucduc.bui
2026-06-15 14:26 ` Frank Li
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=20260615095904.00F2D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=phucduc.bui@gmail.com \
--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