From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381952; b=Fjkj5dzteux69j24cynH76WqetQQqHBexIRIUwW8ufjmbKV6JbIYximPQs5s7CI8NEN+ 4fSIolYLJfz7XkgHX2y4K7ap5HdSQKUFjeDeGA+3bKYYp+2L84L8gf4TClBX1glSFLJVJ VGQqre3C+IOh0IKhnO0kJtOkQGKWR8Jew1BB7LjE5nk1Lj5Ke5ZosWye8xEDjp0mFyUgF kzgFBOKGq1qUv7xAgIvYCYGsbg7NFXCVGyAL+AlGZDqgLp+VyoQUfmWFZ6rj9iEGA6UuF 6lgvwJ2FunnbzOQY25brp9AcsBq+Kox/7yYYOC+ShCpRPZppHfc3vQFdBzOvzYIGHnw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381952; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=PkiYKjMBGFpjYihQ5b6urNr2Y+UrCkS7qykWtStRiQQ=; b=X7heoM5juE1f1cIoE8yB+CXODqUDVBKbcGGBBo5rL0tpzQ5YtErvK9Os4tZpGc6awZr4 BTIFiRb1eoAAw+/4NAstIlb9ATr0qdslKJ/HPPrR6mH6fyt90RVJE/JP9IZ5qqye+PVQy EUHyQmzq2ibMosvxuAnOEuhwHxLJKG2bpwC2r/p7vtIBGVYOSnHbz96b/vnzKc4pMQgmw Oj7FuT3V/o08c2QfCnwiurvJvcGOm3r0k59VSO+O9mfhvSLESB5PdQxngXO2KApN8xpIY VojJcq+7Irl4mFgqiDuy1uC5gPQONsln3WPVx/RQalPlKWwDFqm2+BBassh6ZG36j4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=j1dJX+LG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9834606A32C; Fri, 4 Dec 2026 10:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=j1dJX+LG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 757981F000C2; Fri, 4 Dec 2026 10:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381952; bh=PkiYKjMBGFpjYihQ5b6urNr2Y+UrCkS7qykWtStRiQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j1dJX+LG9+hQusXnnz2MVaGGSr1FMcC1r+QvEUV4npsnWJvhUpDOydSy2yDnMYP/7 ivS+NEItI/iwM7IwMpvUkz6dhpzXWPgy0kHpZ5IH2pioUKcLfNngL5oXQ3uI4i9t2N h4eHIq/a9Mu3fdczMFTwT8r/FNEnnKjylVr8EUhY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stefan Ghetu , Shengjiu Wang , Mark Brown , Sasha Levin Subject: [PATCH 6.18 245/703] ASoC: fsl_asrc_m2m: fix out-of-bounds write when draining the output FIFO Date: Fri, 4 Dec 2026 19:02:24 +0900 Message-ID: <20261204100634.319048932@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stefan Ghetu [ Upstream commit 6b3f779dcac4ea16e232019b68650395ad55f5a2 ] 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. Check the space needed by all drained frames in bytes. Fixes: 24a01710f627 ("ASoC: fsl_asrc_m2m: Add memory to memory function") Signed-off-by: Stefan Ghetu Reviewed-by: Shengjiu Wang Link: https://patch.msgid.link/20261116093751.138455-2-stefan.ghetu@nxp.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/fsl/fsl_asrc_m2m.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sound/soc/fsl/fsl_asrc_m2m.c b/sound/soc/fsl/fsl_asrc_m2m.c index a94ecb40f9e02..181aefa9be8f2 100644 --- a/sound/soc/fsl/fsl_asrc_m2m.c +++ b/sound/soc/fsl/fsl_asrc_m2m.c @@ -53,21 +53,27 @@ 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, sample_bytes, frame_bytes; u32 *reg32 = NULL; u16 *reg16 = NULL; u8 *reg24 = NULL; width = snd_pcm_format_physical_width(pair->sample_format[OUT]); - if (width == 32) + if (width == 32) { reg32 = dma_vaddr + *length; - else if (width == 16) + sample_bytes = 4; + } else if (width == 16) { reg16 = dma_vaddr + *length; - else + sample_bytes = 2; + } else { reg24 = dma_vaddr + *length; + sample_bytes = 3; + } + + frame_bytes = pair->channels * sample_bytes; 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++) { @@ -89,12 +95,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