All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: sprd: validate compress buffer sizes against fixed allocations
@ 2026-08-31 15:13 Tianchu Chen
  2026-08-31 21:40 ` Mark Brown
  2026-09-01 14:07 ` HyeongJun An
  0 siblings, 2 replies; 3+ messages in thread
From: Tianchu Chen @ 2026-08-31 15:13 UTC (permalink / raw)
  To: broonie, baolin.wang, zhang.lyra; +Cc: linux-sound

From: Tianchu Chen <flynnnchen@tencent.com>

sprd_platform_compr_open() allocates the stage 0 IRAM buffer (32K data
area) and the stage 1 DDR buffer (2M data area) with fixed sizes, but
sprd_platform_compr_copy() derives all copy lengths from the user
controlled runtime->fragment_size and the write() count, never
comparing them against the physical buffer sizes. The compress core
only checks fragment_size * fragments for an u32 overflow in
snd_compress_check_input(), so a local user can configure a logical
buffer of up to ~4GB via SNDRV_COMPRESS_SET_PARAMS, far exceeding the
fixed allocations.

A fragment_size larger than the 32K IRAM data area makes the stage 0
copy_from_user() overflow past the IRAM allocation, and a buffer_size
larger than the 2M DDR buffer makes the wrapping copy at the end of
sprd_platform_compr_copy() write fully user controlled data past the
buffer. No SNDRV_PCM_TRIGGER_START is needed, a write() in SETUP
state reaches the copy callback directly.

Reject parameters that do not fit into the fixed buffers in
set_params(), and fix the advertised max fragment size: 128K never
fitted into the 32K IRAM buffer. The caps values may have been carried over
from the qdsp6 driver, which allocates its buffers according to the
advertised maxima, unlike this driver. With 32K as max fragment size
the advertised limits are self-consistent: 32K * 64 = 2M equals the
DDR buffer size.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes: cce1396936ef ("ASoC: sprd: Add Spreadtrum audio compress offload support")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Tianchu Chen <flynnnchen@tencent.com>
---
 sound/soc/sprd/sprd-pcm-compress.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sprd/sprd-pcm-compress.c b/sound/soc/sprd/sprd-pcm-compress.c
index a7d437b49fbf5..e5249924b54d9 100644
--- a/sound/soc/sprd/sprd-pcm-compress.c
+++ b/sound/soc/sprd/sprd-pcm-compress.c
@@ -17,7 +17,7 @@
 
 /* Default values if userspace does not set */
 #define SPRD_COMPR_MIN_FRAGMENT_SIZE	SZ_8K
-#define SPRD_COMPR_MAX_FRAGMENT_SIZE	SZ_128K
+#define SPRD_COMPR_MAX_FRAGMENT_SIZE	SZ_32K
 #define SPRD_COMPR_MIN_NUM_FRAGMENTS	4
 #define SPRD_COMPR_MAX_NUM_FRAGMENTS	64
 
@@ -271,6 +271,19 @@ static int sprd_platform_compr_set_params(struct snd_soc_component *component,
 	struct sprd_compr_params compr_params = { };
 	int ret;
 
+	/*
+	 * The stage 0 IRAM buffer and the stage 1 DDR buffer are allocated
+	 * with fixed sizes at open time, so the requested fragment size and
+	 * fragments must fit into them, otherwise sprd_platform_compr_copy()
+	 * would overflow the buffers. Note the compress core only checks the
+	 * fragment size and fragments against an u32 overflow, not against
+	 * the buffer sizes advertised by get_caps.
+	 */
+	if (params->buffer.fragment_size > SPRD_COMPR_IRAM_BUF_SIZE ||
+	    (u64)params->buffer.fragment_size * params->buffer.fragments >
+	    SPRD_COMPR_AREA_BUF_SIZE)
+		return -EINVAL;
+
 	/*
 	 * Configure the DMA engine 2-stage transfer mode. Channel 1 set as the
 	 * destination channel, and channel 0 set as the source channel, that
-- 
2.51.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: sprd: validate compress buffer sizes against fixed allocations
  2026-08-31 15:13 [PATCH] ASoC: sprd: validate compress buffer sizes against fixed allocations Tianchu Chen
@ 2026-08-31 21:40 ` Mark Brown
  2026-09-01 14:07 ` HyeongJun An
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2026-08-31 21:40 UTC (permalink / raw)
  To: baolin.wang, zhang.lyra, Tianchu Chen; +Cc: linux-sound

On Mon, 31 Aug 2026 15:13:36 +0000, Tianchu Chen wrote:
> ASoC: sprd: validate compress buffer sizes against fixed allocations

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.3

Thanks!

[1/1] ASoC: sprd: validate compress buffer sizes against fixed allocations
      https://git.kernel.org/broonie/sound/c/7a4ce92d150b

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: sprd: validate compress buffer sizes against fixed allocations
  2026-08-31 15:13 [PATCH] ASoC: sprd: validate compress buffer sizes against fixed allocations Tianchu Chen
  2026-08-31 21:40 ` Mark Brown
@ 2026-09-01 14:07 ` HyeongJun An
  1 sibling, 0 replies; 3+ messages in thread
From: HyeongJun An @ 2026-09-01 14:07 UTC (permalink / raw)
  To: tianchu.chen; +Cc: broonie, baolin.wang, zhang.lyra, linux-sound, HyeongJun An

On Mon, Aug 31, 2026 at 03:13:36PM +0000, Tianchu Chen wrote:
> +	if (params->buffer.fragment_size > SPRD_COMPR_IRAM_BUF_SIZE ||
> +	    (u64)params->buffer.fragment_size * params->buffer.fragments >
> +	    SPRD_COMPR_AREA_BUF_SIZE)
> +		return -EINVAL;

I walked the copy path.  Stage 0 writes fragment_size in total and no
more, so '>' against the 32K data area is exact.  '>=' would reject the
32K the comment there calls usual.

Worth saying the overflow is reachable with the driver's own advertised
caps, not just a hostile value.  get_caps reports max_fragment_size 128K
and the core never enforces it.

Reviewed-by: HyeongJun An <sammiee5311@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-01 18:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 15:13 [PATCH] ASoC: sprd: validate compress buffer sizes against fixed allocations Tianchu Chen
2026-08-31 21:40 ` Mark Brown
2026-09-01 14:07 ` HyeongJun An

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.