From: Stefan Ghetu <stefan.ghetu@nxp.com>
To: Shengjiu Wang <shengjiu.wang@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-sound@vger.kernel.org
Cc: daniel.baluta@nxp.com, Stefan Ghetu <stefan.ghetu@nxp.com>,
Xiubo Li <Xiubo.Lee@gmail.com>,
Fabio Estevam <festevam@gmail.com>,
Nicolin Chen <nicoleotsuka@gmail.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] ASoC: fsl_asrc_m2m: fix out-of-bounds write when draining
Date: Tue, 10 Nov 2026 14:07:39 +0200 [thread overview]
Message-ID: <20261110120743.6301-2-stefan.ghetu@nxp.com> (raw)
In-Reply-To: <20261110120743.6301-1-stefan.ghetu@nxp.com>
asrc_read_last_fifo() checks the FIFO fill level, a number of frames,
against a length in bytes, and ignores the frames already drained by
previous iterations of its retry loop. With an output length close to
the 512 KiB buffer size, which userspace controls through the task input
size and formats, the drain writes past the end of the output buffer:
312 bytes for 10 channels of S24_LE with 8 frames left in the FIFO.
8-bit formats are also stored as 3 bytes per sample.
Check the space needed by all drained frames in bytes, and add a 1-byte
path for 8-bit formats.
Fixes: 24a01710f627 ("ASoC: fsl_asrc_m2m: Add memory to memory function")
Signed-off-by: Stefan Ghetu <stefan.ghetu@nxp.com>
---
sound/soc/fsl/fsl_asrc_m2m.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/sound/soc/fsl/fsl_asrc_m2m.c b/sound/soc/fsl/fsl_asrc_m2m.c
index 58101ce07c9f..cadfebb12e7c 100644
--- a/sound/soc/fsl/fsl_asrc_m2m.c
+++ b/sound/soc/fsl/fsl_asrc_m2m.c
@@ -53,21 +53,26 @@ static void asrc_read_last_fifo(struct fsl_asrc_pair *pair, void *dma_vaddr, u32
{
struct fsl_asrc *asrc = pair->asrc;
enum asrc_pair_index index = pair->index;
- u32 i, reg, size, t_size = 0, width;
+ u32 i, reg, size, t_size = 0, width, frame_bytes;
u32 *reg32 = NULL;
u16 *reg16 = NULL;
u8 *reg24 = NULL;
+ u8 *reg8 = NULL;
width = snd_pcm_format_physical_width(pair->sample_format[OUT]);
if (width == 32)
reg32 = dma_vaddr + *length;
else if (width == 16)
reg16 = dma_vaddr + *length;
+ else if (width == 8)
+ reg8 = dma_vaddr + *length;
else
reg24 = dma_vaddr + *length;
+
+ frame_bytes = pair->channels * width / 8;
retry:
size = asrc->get_output_fifo_size(pair);
- if (size + *length > ASRC_M2M_BUFFER_SIZE)
+ if (*length + (t_size + size) * frame_bytes > ASRC_M2M_BUFFER_SIZE)
goto end;
for (i = 0; i < size * pair->channels; i++) {
@@ -76,6 +81,8 @@ static void asrc_read_last_fifo(struct fsl_asrc_pair *pair, void *dma_vaddr, u32
*reg32++ = reg;
} else if (reg16) {
*reg16++ = (u16)reg;
+ } else if (reg8) {
+ *reg8++ = (u8)reg;
} else {
*reg24++ = (u8)reg;
*reg24++ = (u8)(reg >> 8);
@@ -89,12 +96,7 @@ static void asrc_read_last_fifo(struct fsl_asrc_pair *pair, void *dma_vaddr, u32
goto retry;
end:
/* Update payload length */
- if (reg32)
- *length += t_size * pair->channels * 4;
- else if (reg16)
- *length += t_size * pair->channels * 2;
- else
- *length += t_size * pair->channels * 3;
+ *length += t_size * frame_bytes;
}
/* config dma channel */
--
2.53.0
next prev parent reply other threads:[~2026-11-10 12:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 12:07 [PATCH 0/5] ASoC: fsl_asrc/fsl_easrc: fix memory safety issues Stefan Ghetu
2026-11-10 12:07 ` Stefan Ghetu [this message]
2026-11-10 12:07 ` [PATCH 2/5] ASoC: fsl_asrc: fix pair ownership on repeated or failed Stefan Ghetu
2026-11-10 12:07 ` [PATCH 3/5] ASoC: fsl_asrc_dma: release DMA channels on repeated Stefan Ghetu
2026-11-10 12:07 ` [PATCH 4/5] ASoC: fsl_easrc: fix context ownership " Stefan Ghetu
2026-11-10 12:07 ` [PATCH 5/5] ASoC: fsl_asrc_m2m: allow only one task at a time per Stefan Ghetu
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=20261110120743.6301-2-stefan.ghetu@nxp.com \
--to=stefan.ghetu@nxp.com \
--cc=Xiubo.Lee@gmail.com \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=festevam@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=nicoleotsuka@gmail.com \
--cc=perex@perex.cz \
--cc=shengjiu.wang@gmail.com \
--cc=tiwai@suse.com \
/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
all inboxes | Powered by JetHome®