All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: imx@lists.linux.dev, Frank.Li@kernel.org,
	wsa+renesas@sang-engineering.com
Subject: Re: [PATCH v2 09/25] ASoC: atmel: atmel-pcm-pdc: Fix atmel_pcm_close() being skipped on rollback
Date: Fri, 16 Oct 2026 04:16:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-173754@kernel.org> (raw)
In-Reply-To: <20261015014324.5569-10-phucduc.bui@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] sound: atmel: Use-after-free and NULL deref in atmel_pcm_hw_free race
--

commit 04962f72fa0bbcac4e1c99626f3cc0f25a8a7762
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: atmel: atmel-pcm-pdc: Fix atmel_pcm_close() being skipped on rollback

This commit fixes an issue where atmel_pcm_close() might be skipped on
rollback. It forces atmel_pcm_open() to explicitly return 0 on success,
as snd_pcm_hw_constraint_integer() can return 1, which causes ASoC to skip
marking the component as opened.

> diff --git a/sound/soc/atmel/atmel-pcm-pdc.c b/sound/soc/atmel/atmel-pcm-pdc.c
> index 374f93fa6e0b0..4cedf2ad934d6 100644
> --- a/sound/soc/atmel/atmel-pcm-pdc.c
> +++ b/sound/soc/atmel/atmel-pcm-pdc.c
> @@ -295,6 +295,13 @@ static int atmel_pcm_open(struct snd_soc_component *component,
>  	}
>  	runtime->private_data = prtd;
>  
> +	/*
> +	 * ASoC only marks the component as opened when .open() returns 0.
> +	 * Since snd_pcm_hw_constraint_integer() may return 1, explicitly
> +	 * return 0 to ensure .close() is not skipped on rollback.
> +	 */
> +	return 0;

[Severity: High]
Could this change expose a race condition during teardown? By ensuring
atmel_pcm_close() executes, it seems we can now hit a use-after-free or
NULL pointer dereference.

When an audio stream is closed, ALSA triggers snd_pcm_drop() followed by
trigger(STOP), which disables the PDC but does not disable SSC interrupts
globally. This is followed by atmel_pcm_hw_free(), which clears the
interrupt handler:

sound/soc/atmel/atmel-pcm-pdc.c:atmel_pcm_hw_free() {
    ...
    prtd->params->dma_intr_handler = NULL;
    ...
}

And finally atmel_pcm_close() is called, which frees the prtd structure:

sound/soc/atmel/atmel-pcm-pdc.c:atmel_pcm_close() {
    ...
    kfree(prtd);
    ...
}

Meanwhile, an interrupt can still fire, and atmel_ssc_interrupt() calls the
handler without synchronization:

sound/soc/atmel/atmel_ssc_dai.c:atmel_ssc_interrupt() {
    ...
    dma_params->dma_intr_handler(ssc_sr, dma_params->substream);
    ...
}

Since there is no synchronize_irq() in the PCM teardown path,
atmel_ssc_interrupt() can race with atmel_pcm_hw_free() and
atmel_pcm_close(). This could lead to a NULL pointer dereference if
dma_intr_handler is evaluated after being cleared, or a use-after-free of
prtd if kfree(prtd) executes while atmel_pcm_dma_irq() is still actively
processing the stream on another CPU.

> +
>   out:
>  	return ret;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015014324.5569-1-phucduc.bui@gmail.com?part=9

  reply	other threads:[~2026-10-16  4:16 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  1:42 [PATCH v2 00/25] ASoC: Fix constraint return value handling phucduc.bui
2026-10-15  1:42 ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 01/25] ASoC: amd: acp: Fix .close() being skipped on rollback phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-16  4:19   ` sashiko-bot
2026-10-16  7:40     ` Bui Duc Phuc
2026-10-15  1:43 ` [PATCH v2 02/25] ASoC: amd: ps: Fix acp63_pdm_dma_close() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 03/25] ASoC: amd: ps: Fix acp63_sdw_dma_close() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 04/25] ASoC: amd: raven: Fix acp3x_dma_close() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-16  4:14   ` sashiko-bot
2026-10-15  1:43 ` [PATCH v2 05/25] ASoC: amd: renoir: Fix acp_pdm_dma_close() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 06/25] ASoC: amd: vangogh: Fix acp5x_dma_close() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 07/25] ASoC: amd: yc: Fix acp6x_pdm_dma_close() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 08/25] ASoC: apple: mca: Ensure the DAI is marked as started on success phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 09/25] ASoC: atmel: atmel-pcm-pdc: Fix atmel_pcm_close() being skipped on rollback phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-16  4:16   ` sashiko-bot [this message]
2026-10-15  1:43 ` [PATCH v2 10/25] ASoC: codecs: cs42l42: Ensure the DAI is marked as started on success phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 11/25] ASoC: codecs: nau8325: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 12/25] ASoC: codecs: nau8540: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 13/25] ASoC: codecs: nau8821: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 14/25] ASoC: codecs: nau8824: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 15/25] ASoC: codecs: nau8825: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 16/25] ASoC: codecs: wm8580: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 17/25] ASoC: codecs: wm8782: " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 18/25] ASoC: imx-pcm-rpmsg: Fix imx_rpmsg_pcm_close() being skipped on rollback phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-16  4:14   ` sashiko-bot
2026-10-15  1:43 ` [PATCH v2 19/25] ASoC: intel: atom: Fix .shutdown() " phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15 10:44   ` Cezary Rojewski
2026-10-15 10:44     ` Cezary Rojewski
2026-10-16  4:12   ` sashiko-bot
2026-10-15  1:43 ` [PATCH v2 20/25] ASoC: renesas: fsi: Ensure the component is marked as opened on success phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  3:55   ` Kuninori Morimoto
2026-10-15  3:55     ` Kuninori Morimoto
2026-10-15  1:43 ` [PATCH v2 21/25] ASoC: renesas: msiof: Remove redundant period constraint phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  3:56   ` Kuninori Morimoto
2026-10-15  3:56     ` Kuninori Morimoto
2026-10-15  1:43 ` [PATCH v2 22/25] ASoC: renesas: rz-ssi: Ensure the component is marked as opened on success phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 23/25] ASoC: renesas: rz-ssi: Remove redundant component open callback phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15  1:43 ` [PATCH v2 24/25] ASoC: rockchip: rk3399_gru_sound: Mark the link as started on success phucduc.bui
2026-10-15  1:43   ` phucduc.bui
2026-10-15 11:12 ` [PATCH v2 00/25] ASoC: Fix constraint return value handling Mark Brown
2026-10-15 11:12   ` Mark Brown
2026-10-16  1:52   ` Bui Duc Phuc
2026-10-16  1:52     ` Bui Duc Phuc
2026-10-16  4:00 ` [PATCH v2 25/25] ASoC: rockchip: rockchip_max98090: Mark the link as started on success phucduc.bui
2026-10-16  4:00   ` phucduc.bui
2026-10-16 10:27   ` Mark Brown
2026-10-16 10:27     ` Mark Brown

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=sashiko-outbox-173754@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=phucduc.bui@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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 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.