Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
To: vkoul@kernel.org, perex@perex.cz, tiwai@suse.com
Cc: pierre-louis.bossart@linux.dev, linux-sound@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 2/4] ALSA: compress: reject buffer geometry change on gapless next_track
Date: Wed,  7 Oct 2026 16:25:07 +0300	[thread overview]
Message-ID: <20261007132509.18237-3-peter.ujfalusi@linux.intel.com> (raw)
In-Reply-To: <20261007132509.18237-1-peter.ujfalusi@linux.intel.com>

snd_compr_set_params() is invoked from the gapless next_track
re-entry path, which calls snd_compr_allocate_buffer() again and lets
buffer_size change while total_bytes_available and
total_bytes_transferred still hold values computed for the previous
buffer. snd_compr_calc_avail() then derives an avail/count value from
those stale counters against the new buffer_size, and
snd_compr_write_data() copy_from_user()s that many bytes into the
new, potentially smaller buffer, overflowing it with user-controlled
length and content.

Reject a next_track SET_PARAMS that changes the buffer geometry
instead of reallocating, since total_bytes_available/transferred are
only valid for the buffer sized during the initial SET_PARAMS.

Fixes: 9727b490e543 ("ALSA: compress: add support for gapless playback")
Cc: stable@vger.kernel.org
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
 sound/core/compress_offload.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index c0ed76e1c844..e1cc34ba2c2c 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -673,9 +673,20 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 		if (retval)
 			return retval;
 
-		retval = snd_compr_allocate_buffer(stream, params);
-		if (retval)
-			return -ENOMEM;
+		if (stream->next_track) {
+			/*
+			 * total_bytes_available/transferred still refer to the
+			 * buffer allocated for the current track; the geometry
+			 * must not change underneath them.
+			 */
+			if (params->buffer.fragment_size != stream->runtime->fragment_size ||
+			    params->buffer.fragments != stream->runtime->fragments)
+				return -EINVAL;
+		} else {
+			retval = snd_compr_allocate_buffer(stream, params);
+			if (retval)
+				return -ENOMEM;
+		}
 
 		retval = stream->ops->set_params(stream, params);
 		if (retval)
-- 
2.56.0


  parent reply	other threads:[~2026-10-07 13:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 13:25 [PATCH 0/4] ALSA: compress: fix buffer handling and state validation Peter Ujfalusi
2026-10-07 13:25 ` [PATCH 1/4] ALSA: compress: fix buffer leak on repeated SET_PARAMS Peter Ujfalusi
2026-10-07 14:04   ` Takashi Iwai
2026-10-07 14:10     ` Vinod Koul
2026-10-07 14:25       ` Péter Ujfalusi
2026-10-07 14:37         ` Vinod Koul
2026-10-08  6:25           ` Péter Ujfalusi
2026-10-08  7:57             ` Péter Ujfalusi
2026-10-08  7:54     ` Péter Ujfalusi
2026-10-07 14:08   ` Vinod Koul
2026-10-07 13:25 ` Peter Ujfalusi [this message]
2026-10-07 14:12   ` [PATCH 2/4] ALSA: compress: reject buffer geometry change on gapless next_track Vinod Koul
2026-10-07 13:25 ` [PATCH 3/4] ALSA: compress: add missing OPEN-state gate to SET_METADATA Peter Ujfalusi
2026-10-07 14:12   ` Vinod Koul
2026-10-07 13:25 ` [PATCH 4/4] ALSA: compress: reject restarting an ACTIVE task via origin_seqno Peter Ujfalusi
2026-10-07 14:14   ` Vinod Koul

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=20261007132509.18237-3-peter.ujfalusi@linux.intel.com \
    --to=peter.ujfalusi@linux.intel.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=vkoul@kernel.org \
    /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