lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <71f50716-2f8b-432b-970c-9436fa181856@collabora.com>
Date: Thu, 18 Sep 2025 16:37:30 +0200
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
To: Guangshuo Li <lgs201920130244@...il.com>,
 Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
 Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
 Matthias Brugger <matthias.bgg@...il.com>,
 Charles Keepax <ckeepax@...nsource.cirrus.com>,
 Alexandre Mergnat <amergnat@...libre.com>, linux-sound@...r.kernel.org,
 linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
 linux-mediatek@...ts.infradead.org
Cc: stable@...r.kernel.org
Subject: Re: [PATCH] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in
 mt8365_afe_suspend()

Il 18/09/25 16:07, Guangshuo Li ha scritto:
> devm_kcalloc() may fail. mt8365_afe_suspend() uses afe->reg_back_up
> unconditionally after allocation and writes afe->reg_back_up[i], which
> can lead to a NULL pointer dereference under low-memory conditions.
> 
> Add a NULL check and bail out with -ENOMEM, making sure to disable the
> main clock via the existing error path to keep clock state balanced.
> 
> Fixes: e1991d102bc2 ("ASoC: mediatek: mt8365: Add the AFE driver support")
> Cc: stable@...r.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@...il.com>
> ---
>   sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
> index 10793bbe9275..9f398d1249ce 100644
> --- a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
> +++ b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
> @@ -1971,22 +1971,26 @@ static int mt8365_afe_suspend(struct device *dev)
>   {
>   	struct mtk_base_afe *afe = dev_get_drvdata(dev);
>   	struct regmap *regmap = afe->regmap;
> -	int i;
> +	int i, ret = 0;
>   
>   	mt8365_afe_enable_main_clk(afe);
>   
> -	if (!afe->reg_back_up)
> -		afe->reg_back_up =
> -			devm_kcalloc(dev, afe->reg_back_up_list_num,
> -				     sizeof(unsigned int), GFP_KERNEL);
> +	if (!afe->reg_back_up) {
> +		afe->reg_back_up = devm_kcalloc(dev, afe->reg_back_up_list_num,
> +						sizeof(unsigned int), GFP_KERNEL);

Nothing else can fail, so using a label here is unnecessary.

		if (!afe->reg_back_up) {
			mt8365_afe_disable_main_clk(afe);
			return -ENOMEM;
		}

This makes you able to avoid adding a `ret` variable, and also the goto.

Cheers,
Angelo



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ