From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH 08/11] ASoC: imx-audio-rpmsg: Use guard() for spin locks
Date: Fri, 12 Jun 2026 13:46:13 +0000 [thread overview]
Message-ID: <20260612134613.E54D51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612132639.78086-9-phucduc.bui@gmail.com>
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Pre-existing issues:
- [High] The rpmsg callback `imx_audio_rpmsg_cb` can be invoked before probe initialization completes, leading to a NULL pointer dereference on the `rpmsg` variable.
- [High] Spurious or early messages from the M core cause a NULL pointer dereference on the `info` pointer.
- [High] Spurious or early `TX_PERIOD_DONE` / `RX_PERIOD_DONE` messages cause a divide-by-zero panic due to an uninitialized `num_period` divisor.
- [High] Uninitialized callback execution upon receiving early messages causes a kernel crash.
- [High] The callback `imx_audio_rpmsg_cb` can execute concurrently with or after driver removal, resulting in a Use-After-Free of the `info` and `rpmsg_pdev` structures.
- [High] Platform devices are leaked on the error paths of `imx_audio_rpmsg_probe()` due to missing cleanup.
- [Medium] The callback trusts the length of the incoming rpmsg payload without validation, leading to out-of-bounds reads.
--
commit b1578c7b9299ee080ea08b2217771219cd8e93c4
Author: bui duc phuc <phucduc.bui@gmail.com>
ASoC: imx-audio-rpmsg: Use guard() for spin locks
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
> diff --git a/sound/soc/fsl/imx-audio-rpmsg.c b/sound/soc/fsl/imx-audio-rpmsg.c
> index 38aafb8954c76..b55dfbdb45026 100644
> --- a/sound/soc/fsl/imx-audio-rpmsg.c
> +++ b/sound/soc/fsl/imx-audio-rpmsg.c
> @@ -22,7 +22,6 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
> struct rpmsg_r_msg *r_msg = (struct rpmsg_r_msg *)data;
> struct rpmsg_info *info;
> struct rpmsg_msg *msg;
> - unsigned long flags;
>
> if (!rpmsg->rpmsg_pdev)
[Severity: High]
This isn't a bug introduced by this patch, but could this lead to a NULL
pointer dereference?
The rpmsg endpoint is created and the callback registered before the driver's
probe function executes. If the remote core sends an early message, this
callback could run while rpmsg is NULL because dev_set_drvdata() hasn't
happened yet.
Additionally, if imx_audio_rpmsg_remove() unregisters the platform device while
the rpmsg endpoint is still active, could an incoming message execute this
callback and dereference freed memory for rpmsg_pdev and info?
> return 0;
[ ... ]
> @@ -37,21 +36,21 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
> /* TYPE C is notification from M core */
> switch (r_msg->header.cmd) {
> case TX_PERIOD_DONE:
> - spin_lock_irqsave(&info->lock[TX], flags);
> - msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
> - msg->r_msg.param.buffer_tail =
> - r_msg->param.buffer_tail;
> - msg->r_msg.param.buffer_tail %= info->num_period[TX];
> - spin_unlock_irqrestore(&info->lock[TX], flags);
> + scoped_guard(spinlock_irqsave, &info->lock[TX]) {
[Severity: High]
This is a pre-existing issue, but can spurious or early messages cause a NULL
pointer dereference here?
If a message arrives before the child probe completes initialization,
platform_get_drvdata() could return NULL for info, causing scoped_guard() to
dereference a NULL pointer when accessing &info->lock[TX].
> + msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
> + msg->r_msg.param.buffer_tail =
> + r_msg->param.buffer_tail;
> + msg->r_msg.param.buffer_tail %= info->num_period[TX];
[Severity: High]
This isn't a bug introduced by this patch, but does this modulo operation
risk a division-by-zero panic?
If a spurious or early TX_PERIOD_DONE message arrives before the ALSA stream
is prepared, info->num_period[TX] will still be initialized to 0.
> + }
> info->callback[TX](info->callback_param[TX]);
[Severity: High]
This is a pre-existing issue, but could this unconditionally execute an
uninitialized function pointer?
If an early message arrives before the ALSA stream starts, info->callback[TX]
might be NULL, triggering a kernel panic.
[ ... ]
There are a few other pre-existing issues in this file that might be worth
looking into:
[Severity: Medium]
This is a pre-existing issue, but does the callback trust the length of the
incoming rpmsg payload without validation?
In imx_audio_rpmsg_cb() for MSG_TYPE_B:
memcpy(&info->r_msg, r_msg, sizeof(struct rpmsg_r_msg));
The callback casts data to struct rpmsg_r_msg * but doesn't validate that
len >= sizeof(struct rpmsg_r_msg). If the remote peer sends a smaller payload,
this results in an out-of-bounds read from the IPC buffer.
[Severity: High]
This isn't a bug introduced by this patch, but are platform devices leaked on
the error paths of imx_audio_rpmsg_probe()?
If platform_device_register_data() for data->rpmsg_pdev fails, the code records
the error but unconditionally proceeds to register data->card_pdev. If the
latter succeeds, the function returns the error from the first failure, leaving
card_pdev permanently registered. Conversely, if rpmsg_pdev succeeds but
card_pdev fails, it returns without unregistering rpmsg_pdev.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260612132639.78086-1-phucduc.bui@gmail.com?part=8
next prev parent reply other threads:[~2026-06-12 13:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 13:26 [PATCH 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
2026-06-12 13:26 ` [PATCH 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
2026-06-12 13:38 ` sashiko-bot
2026-06-12 13:26 ` [PATCH 02/11] ASoC: fsl_audmix: " phucduc.bui
2026-06-12 13:26 ` [PATCH 03/11] ASoC: fsl_easrc: " phucduc.bui
2026-06-12 13:36 ` sashiko-bot
2026-06-12 13:26 ` [PATCH 04/11] ASoC: fsl_esai: " phucduc.bui
2026-06-12 13:26 ` [PATCH 05/11] ASoC: fsl_spdif: " phucduc.bui
2026-06-12 13:38 ` sashiko-bot
2026-06-12 13:26 ` [PATCH 06/11] ASoC: fsl_ssi: Use guard() for mutex locks phucduc.bui
2026-06-12 13:26 ` [PATCH 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
2026-06-12 13:37 ` sashiko-bot
2026-06-12 13:26 ` [PATCH 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
2026-06-12 13:46 ` sashiko-bot [this message]
2026-06-12 13:26 ` [PATCH 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
2026-06-12 13:42 ` sashiko-bot
2026-06-12 13:26 ` [PATCH 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
2026-06-12 13:44 ` sashiko-bot
2026-06-12 13:26 ` [PATCH 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks phucduc.bui
2026-06-12 13:42 ` sashiko-bot
2026-06-12 15:05 ` Mark Brown
2026-06-12 21:42 ` Bui Duc Phuc
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=20260612134613.E54D51F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.