From: sashiko-bot@kernel.org
To: "Linmao Li" <lilinmao@kylinos.cn>
Cc: linux-amlogic@lists.infradead.org, neil.armstrong@linaro.org
Subject: Re: [PATCH] ASoC: meson: Keep link pointers valid on realloc failure
Date: Thu, 16 Jul 2026 10:25:44 +0000 [thread overview]
Message-ID: <20260716102544.8B7681F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260716100939.1381759-1-lilinmao@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unbinding the device causes a use-after-free because `meson_card_remove` frees `card->dai_link` manually before the devres callbacks unregister the card.
--
--- Patch [1]: [PATCH] ASoC: meson: Keep link pointers valid on realloc failure ---
commit 677ad75f5fb5a578b984e744f26d24b961c89685
Author: Linmao Li <lilinmao@kylinos.cn>
ASoC: meson: Keep link pointers valid on realloc failure
This commit fixes a potential use-after-free and double free in the error
path of meson_card_reallocate_links(). It updates the card->dai_link
pointer immediately after the first successful krealloc(), ensuring the
cleanup path can safely free the memory if the second krealloc() fails.
> diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c
> index cdb759b466ad4..38c1b2ae227ff 100644
> --- a/sound/soc/meson/meson-card-utils.c
> +++ b/sound/soc/meson/meson-card-utils.c
> @@ -52,19 +52,18 @@ int meson_card_reallocate_links(struct snd_soc_card *card,
> if (!links)
> goto err_links;
>
> + priv->card.dai_link = links;
> +
> ldata = krealloc(priv->link_data,
> num_links * sizeof(*priv->link_data),
> GFP_KERNEL | __GFP_ZERO);
> if (!ldata)
> - goto err_ldata;
> + goto err_links;
>
> - priv->card.dai_link = links;
> priv->link_data = ldata;
> priv->card.num_links = num_links;
> return 0;
>
> -err_ldata:
> - kfree(links);
> err_links:
> dev_err(priv->card.dev, "failed to allocate links\n");
> return -ENOMEM;
[Severity: High]
This isn't a bug introduced by this patch, but does unbinding the device
cause a use-after-free because meson_card_remove() frees card->dai_link
manually before the devres callbacks unregister the card?
When the driver is unbound, the driver core calls meson_card_remove(), which
calls meson_card_clean_references() to free the links:
sound/soc/meson/meson-card-utils.c:meson_card_clean_references() {
...
kfree(card->dai_link);
...
}
Only after .remove returns does the driver core run devres callbacks, which
includes unregistering the card via devm_snd_soc_register_card's cleanup
handler.
The ASoC unregister path iterates over all PCM runtimes and dereferences
rtd->dai_link, which points directly to elements of the already freed
card->dai_link array.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716100939.1381759-1-lilinmao@kylinos.cn?part=1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2026-07-16 10:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 10:09 Linmao Li
2026-07-16 10:25 ` sashiko-bot [this message]
2026-07-16 14:26 ` Jerome Brunet
2026-07-16 14:13 ` Jerome Brunet
2026-07-17 1:24 ` [PATCH v2] " Linmao Li
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=20260716102544.8B7681F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lilinmao@kylinos.cn \
--cc=linux-amlogic@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=sashiko-reviews@lists.linux.dev \
/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