From: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: vkoul@kernel.org, perex@perex.cz, tiwai@suse.com,
pierre-louis.bossart@linux.dev, linux-sound@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 1/4] ALSA: compress: fix buffer leak on repeated SET_PARAMS
Date: Thu, 8 Oct 2026 10:54:13 +0300 [thread overview]
Message-ID: <4fb417d8-94c3-473f-95bc-8d15b7c98654@linux.intel.com> (raw)
In-Reply-To: <878q49obcu.wl-tiwai@suse.de>
On 07/10/2026 17:04, Takashi Iwai wrote:
> On Wed, 07 Oct 2026 15:25:06 +0200,
> Peter Ujfalusi wrote:
>>
>> snd_compr_allocate_buffer() unconditionally overwrites
>> stream->runtime->buffer with a freshly kmalloc'd buffer whenever the
>> driver has no ops->copy and no preallocated dma_buffer_p. SET_PARAMS
>> is permitted repeatedly while the stream is in the OPEN state, so a
>> local process can loop SNDRV_COMPRESS_SET_PARAMS and leak the
>> previous buffer on every call, exhausting kernel memory.
>>
>> Free any framework-owned buffer before replacing it, mirroring the
>> ownership check already used in snd_compr_free().
>>
>> Fixes: b21c60a4edd2 ("ALSA: core: add support for compress_offload")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
>> ---
>> sound/core/compress_offload.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
>> index 7c397b1c9231..c0ed76e1c844 100644
>> --- a/sound/core/compress_offload.c
>> +++ b/sound/core/compress_offload.c
>> @@ -613,6 +613,10 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
>> return -ENOMEM;
>> }
>>
>> + /* a prior SET_PARAMS may have left a framework-owned buffer behind */
>> + if (!stream->runtime->dma_buffer_p)
>> + kfree(stream->runtime->buffer);
>> +
>
> I'd rather put to the else block above (or even better, if
> (stream->runtime->dma_buffer_p) block above that point).
>
> The code is specific to that condition, after all.
Yes, that is true, but then we would also need to add additional check
in there and free only if the allocation succeeded.
I think that would somehow be a bit more convoluted to grasp at once
--
Péter
next prev parent reply other threads:[~2026-10-08 7:53 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 [this message]
2026-10-07 14:08 ` Vinod Koul
2026-10-07 13:25 ` [PATCH 2/4] ALSA: compress: reject buffer geometry change on gapless next_track Peter Ujfalusi
2026-10-07 14:12 ` 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=4fb417d8-94c3-473f-95bc-8d15b7c98654@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=tiwai@suse.de \
--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