Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: compress: Fix task creation error unwind
@ 2026-06-15 13:37 Cássio Gabriel
  2026-06-17  9:04 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Cássio Gabriel @ 2026-06-15 13:37 UTC (permalink / raw)
  To: Vinod Koul, Takashi Iwai, Jaroslav Kysela,
	Amadeusz Sławiński
  Cc: linux-sound, linux-kernel, notify, stable, Cássio Gabriel

snd_compr_task_new() allocates the driver task before validating the
returned DMA buffers and reserving file descriptors. When either of
those later steps fails, the core frees its task wrapper and DMA-buffer
references without calling the driver's task_free() callback. Any
driver resources allocated by task_create() are therefore leaked.

The dual-fd allocation path also jumps to cleanup without storing the
negative get_unused_fd_flags() result in retval. Since retval still
contains the successful task_create() return value, TASK_CREATE can
incorrectly report success although the task was discarded.

Preserve the fd allocation errors and call task_free() when failure
occurs after a successful task_create() callback.

Fixes: 04177158cf98 ("ALSA: compress_offload: introduce accel operation mode")
Fixes: 3d3f43fab4cf ("ALSA: compress_offload: improve file descriptors installation for dma-buf")
Cc: stable@vger.kernel.org
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
---
base-commit: 419f8dc84429d67db48393ffe6aa420ea38064e0
---
 sound/core/compress_offload.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index fd63d219bf86..ea699491f0c3 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -1083,15 +1083,18 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_
 	   file descriptors are allocated before fd_install() */
 	if (!task->input || !task->input->file || !task->output || !task->output->file) {
 		retval = -EINVAL;
-		goto cleanup;
+		goto free_driver_task;
 	}
 	fd_i = get_unused_fd_flags(O_WRONLY|O_CLOEXEC);
-	if (fd_i < 0)
-		goto cleanup;
+	if (fd_i < 0) {
+		retval = fd_i;
+		goto free_driver_task;
+	}
 	fd_o = get_unused_fd_flags(O_RDONLY|O_CLOEXEC);
 	if (fd_o < 0) {
+		retval = fd_o;
 		put_unused_fd(fd_i);
-		goto cleanup;
+		goto free_driver_task;
 	}
 	/* keep dmabuf reference until freed with task free ioctl */
 	get_dma_buf(task->input);
@@ -1103,6 +1106,8 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_
 	list_add_tail(&task->list, &stream->runtime->tasks);
 	stream->runtime->total_tasks++;
 	return 0;
+free_driver_task:
+	stream->ops->task_free(stream, task);
 cleanup:
 	snd_compr_task_free(task);
 	return retval;




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

* Re: [PATCH] ALSA: compress: Fix task creation error unwind
  2026-06-15 13:37 [PATCH] ALSA: compress: Fix task creation error unwind Cássio Gabriel
@ 2026-06-17  9:04 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-06-17  9:04 UTC (permalink / raw)
  To: Cássio Gabriel
  Cc: Vinod Koul, Takashi Iwai, Jaroslav Kysela,
	Amadeusz Sławiński, linux-sound, linux-kernel, notify,
	stable

On Mon, 15 Jun 2026 15:37:26 +0200,
Cássio Gabriel wrote:
> 
> snd_compr_task_new() allocates the driver task before validating the
> returned DMA buffers and reserving file descriptors. When either of
> those later steps fails, the core frees its task wrapper and DMA-buffer
> references without calling the driver's task_free() callback. Any
> driver resources allocated by task_create() are therefore leaked.
> 
> The dual-fd allocation path also jumps to cleanup without storing the
> negative get_unused_fd_flags() result in retval. Since retval still
> contains the successful task_create() return value, TASK_CREATE can
> incorrectly report success although the task was discarded.
> 
> Preserve the fd allocation errors and call task_free() when failure
> occurs after a successful task_create() callback.
> 
> Fixes: 04177158cf98 ("ALSA: compress_offload: introduce accel operation mode")
> Fixes: 3d3f43fab4cf ("ALSA: compress_offload: improve file descriptors installation for dma-buf")
> Cc: stable@vger.kernel.org
> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>

Applied now.  Thanks.


Takashi

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

end of thread, other threads:[~2026-06-17  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15 13:37 [PATCH] ALSA: compress: Fix task creation error unwind Cássio Gabriel
2026-06-17  9:04 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox