FAILED: patch "[PATCH] ALSA: compress: fix buffer leak on failed SET_PARAMS" failed to apply to 5.10-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x fbc74ca9fbf7e0b8f6872ccac62f9f4a1f3b5e53
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From fbc74ca9fbf7e0b8f6872ccac62f9f4a1f3b5e53 Mon Sep 17 00:00:00 2001
From: Peter Ujfalusi <[email protected]>
Date: Mon, 19 Oct 2026 17:45:30 +0300
Subject: [PATCH] ALSA: compress: fix buffer leak on failed SET_PARAMS
When the driver has neither ops->copy nor a preallocated dma_buffer_p, snd_compr_allocate_buffer() kmallocs runtime->buffer. If ops->set_params() then rejects the parameters, SET_PARAMS fails, the stream stays in the OPEN state and keeps the buffer. The next SET_PARAMS allocates a new buffer and overwrites the pointer, so repeated SET_PARAMS calls with parameters that the driver rejects leak one buffer per call.
Release the framework-owned buffer when ops->set_params() fails on an OPEN stream, so that a failed SET_PARAMS leaves no buffer behind and the buffer is allocated only once per successful setup. Use the same ownership check as snd_compr_free().
--- sound/core/compress_offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/core/compress_offload.c +8 -1
@@ -702,8 +702,15 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)return -ENOMEM ; retval = stream->ops->set_params (stream, params); -if (retval) +if (retval) { +/* the stream stays OPEN: drop the buffer of the rejected setup */ +if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN && + !stream->runtime->dma_buffer_p) { +kfree (stream->runtime->buffer); + stream->runtime->buffer =NULL ; + }return retval; + }if (stream->next_track)return retval;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 ALSA: compress: fix buffer leak on failed SET_PARAMS
From: Peter Ujfalusi <[email protected]>
[ Upstream commit fbc74ca9fbf7e0b8f6872ccac62f9f4a1f3b5e53 ]
When the driver has neither ops->copy nor a preallocated dma_buffer_p, snd_compr_allocate_buffer() kmallocs runtime->buffer. If ops->set_params() then rejects the parameters, SET_PARAMS fails, the stream stays in the OPEN state and keeps the buffer. The next SET_PARAMS allocates a new buffer and overwrites the pointer, so repeated SET_PARAMS calls with parameters that the driver rejects leak one buffer per call.
Release the framework-owned buffer when ops->set_params() fails on an OPEN stream, so that a failed SET_PARAMS leaves no buffer behind and the buffer is allocated only once per successful setup. Use the same ownership check as snd_compr_free().
--- sound/core/compress_offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/core/compress_offload.c +8 -1
@@ -602,8 +602,15 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) } retval = stream->ops->set_params (stream, params); -if (retval) +if (retval) { +/* the stream stays OPEN: drop the buffer of the rejected setup */ +if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN && + !stream->runtime->dma_buffer_p) { +kfree (stream->runtime->buffer); + stream->runtime->buffer =NULL ; + } goto out; + } stream->metadata_set = false; stream->next_track = false;
Signature · 1 line
2.53.0