All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Daniel Baluta <daniel.baluta@nxp.com>,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
	Vijendar Mukunda <Vijendar.Mukunda@amd.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	sound-open-firmware@alsa-project.org,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ASoC: SOF: validate topology volume range before allocation
Date: Fri, 14 Aug 2026 16:15:45 +0300	[thread overview]
Message-ID: <04b1856e-05e2-450e-a68c-4f9a3455e01e@linux.intel.com> (raw)
In-Reply-To: <20260814081238.25434-1-pengpeng@iscas.ac.cn>



On 14/08/2026 11:12, Pengpeng Hou wrote:
> SOF treats the topology mixer min and max values as non-negative indices
> into its volume table. It stores them in signed fields, allocates max + 1
> entries through an int argument, and later indexes the table with the
> stored range.
> 
> An inverted range is invalid, while a maximum at or above INT_MAX cannot
> be represented safely after the increment or in the signed fields.
> Validate the complete range before storing it or allocating the table.
> 
> Fixes: 311ce4fe7637 ("ASoC: SOF: Add support for loading topologies")
> Assisted-by: Codex:gpt-5
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
> Changes since v1: https://lore.kernel.org/all/20260722041532.14085-1-pengpeng@iscas.ac.cn/
> - validate SOF's non-negative table-index range before signed storage
> - require max + 1 to remain representable by the allocator's int argument
> - rebase on current SOF topology sources

The patch appears to be identical to v1 to my non agent eyes ;)

Acked-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>

> 
> The SOF table-index consumers and allocator conversion were reviewed
> statically; no SOF topology or hardware test was performed.
> 
>  sound/soc/sof/topology.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
> index 42a2d90bb705..31dd7a66a9cf 100644
> --- a/sound/soc/sof/topology.c
> +++ b/sound/soc/sof/topology.c
> @@ -846,6 +846,7 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
>  	struct snd_soc_tplg_mixer_control *mc =
>  		container_of(hdr, struct snd_soc_tplg_mixer_control, hdr);
>  	int tlv[SOF_TLV_ITEMS];
> +	u32 min, max;
>  	unsigned int mask;
>  	int ret;
>  
> @@ -853,6 +854,11 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
>  	if (le32_to_cpu(mc->num_channels) > SND_SOC_TPLG_MAX_CHAN)
>  		return -EINVAL;
>  
> +	min = le32_to_cpu(mc->min);
> +	max = le32_to_cpu(mc->max);
> +	if (min > max || max >= INT_MAX)
> +		return -EINVAL;
> +
>  	/*
>  	 * If control has more than 2 channels we need to override the info. This is because even if
>  	 * ASoC layer has defined topology's max channel count to SND_SOC_TPLG_MAX_CHAN = 8, the
> @@ -863,12 +869,12 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
>  		kc->info = snd_sof_volume_info;
>  
>  	scontrol->comp_id = sdev->next_comp_id;
> -	scontrol->min_volume_step = le32_to_cpu(mc->min);
> -	scontrol->max_volume_step = le32_to_cpu(mc->max);
> +	scontrol->min_volume_step = min;
> +	scontrol->max_volume_step = max;
>  	scontrol->num_channels = le32_to_cpu(mc->num_channels);
>  
> -	scontrol->max = le32_to_cpu(mc->max);
> -	if (le32_to_cpu(mc->max) == 1)
> +	scontrol->max = max;
> +	if (max == 1)
>  		goto skip;
>  
>  	/* extract tlv data */
> @@ -878,7 +884,7 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
>  	}
>  
>  	/* set up volume table */
> -	ret = set_up_volume_table(scontrol, tlv, le32_to_cpu(mc->max) + 1);
> +	ret = set_up_volume_table(scontrol, tlv, max + 1);
>  	if (ret < 0) {
>  		dev_err(scomp->dev, "error: setting up volume table\n");
>  		return ret;
> @@ -911,7 +917,7 @@ static int sof_control_load_volume(struct snd_soc_component *scomp,
>  	return 0;
>  
>  err:
> -	if (le32_to_cpu(mc->max) > 1)
> +	if (max > 1)
>  		kfree(scontrol->volume_table);
>  
>  	return ret;

-- 
Péter


  reply	other threads:[~2026-08-14 13:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14  8:12 [PATCH v2] ASoC: SOF: validate topology volume range before allocation Pengpeng Hou
2026-08-14 13:15 ` Péter Ujfalusi [this message]
2026-08-14 14:28 ` 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=04b1856e-05e2-450e-a68c-4f9a3455e01e@linux.intel.com \
    --to=peter.ujfalusi@linux.intel.com \
    --cc=Vijendar.Mukunda@amd.com \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=pengpeng@iscas.ac.cn \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.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.