From nobody Tue Sep 29 00:36:43 2026 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF02343847E; Fri, 14 Aug 2026 08:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695178; cv=none; b=k5AsMZpCw7bxdPG2hGhurFIkam3Xq17ldcbhINiN8GYcEMSA6XCGC/8zzP2uLHRAGSWTpEoBy1qeTYLOzxp2erGBwot79CAI4vtjSo7bydOnofd3xDEEc/d8viGUMtl4gqy7l1tjSU8MpCJ/n7mugikWcbd9dQpQ3JCQBggF3Xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786695178; c=relaxed/simple; bh=ZVWeD1F6psm4Kaw5gTaTRCWGhsg0lm0QeTch3nBmH4s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=VSLqKUkyTvA7TS9BFzSKNya/ynGrCzjVRNm1hnC+7V7kFxX9oIphs0XpYrn/Kh074oE6NG3fNN5Cl8F+Nbnrc6mC8n3P9jQjyj/EIMgKBUfbcnPMOVy+6M8cfLdhMkgDKsoWB4SLzL+54Q2mA48EZyNRHsm5+mXBzKVrgVYxQxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from localhost.localdomain (unknown [111.196.241.250]) by APP-01 (Coremail) with SMTP id qwCowAAX6+72zX5q_CWfBQ--.5989S2; Fri, 14 Aug 2026 16:12:39 +0800 (CST) From: Pengpeng Hou To: Liam Girdwood , Peter Ujfalusi , Mark Brown Cc: Bard Liao , Ranjani Sridharan , Daniel Baluta , Kai Vehmanen , Pierre-Louis Bossart , Vijendar Mukunda , Jaroslav Kysela , Takashi Iwai , sound-open-firmware@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Pengpeng Hou Subject: [PATCH v2] ASoC: SOF: validate topology volume range before allocation Date: Fri, 14 Aug 2026 16:12:38 +0800 Message-ID: <20260814081238.25434-1-pengpeng@iscas.ac.cn> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qwCowAAX6+72zX5q_CWfBQ--.5989S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCryfAry3AF4kJF1UtFyxXwb_yoW5ZFy7pF s5WrZIgrWrXr43JFnxtw1v9rn3Z3y3GFW7GwsFqw1fZF13Ary8uay5t34ayFWUCryDtr4S kF4Yy3yDXa1qyFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9I14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v26r xl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E 8cxan2IY04v7MxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFV Cjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWl x4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6r yUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j 6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJb IYCTnIWIevJa73UjIFyTuYvjfU5byZUUUUU X-CM-SenderInfo: pshqw1xhqjqxpvfd2hldfou0/ 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 Acked-by: Peter Ujfalusi --- Changes since v1: https://lore.kernel.org/all/20260722041532.14085-1-pengpe= ng@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 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_compo= nent *scomp, struct snd_soc_tplg_mixer_control *mc =3D container_of(hdr, struct snd_soc_tplg_mixer_control, hdr); int tlv[SOF_TLV_ITEMS]; + u32 min, max; unsigned int mask; int ret; =20 @@ -853,6 +854,11 @@ static int sof_control_load_volume(struct snd_soc_comp= onent *scomp, if (le32_to_cpu(mc->num_channels) > SND_SOC_TPLG_MAX_CHAN) return -EINVAL; =20 + min =3D le32_to_cpu(mc->min); + max =3D le32_to_cpu(mc->max); + if (min > max || max >=3D 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_MA= X_CHAN =3D 8, the @@ -863,12 +869,12 @@ static int sof_control_load_volume(struct snd_soc_com= ponent *scomp, kc->info =3D snd_sof_volume_info; =20 scontrol->comp_id =3D sdev->next_comp_id; - scontrol->min_volume_step =3D le32_to_cpu(mc->min); - scontrol->max_volume_step =3D le32_to_cpu(mc->max); + scontrol->min_volume_step =3D min; + scontrol->max_volume_step =3D max; scontrol->num_channels =3D le32_to_cpu(mc->num_channels); =20 - scontrol->max =3D le32_to_cpu(mc->max); - if (le32_to_cpu(mc->max) =3D=3D 1) + scontrol->max =3D max; + if (max =3D=3D 1) goto skip; =20 /* extract tlv data */ @@ -878,7 +884,7 @@ static int sof_control_load_volume(struct snd_soc_compo= nent *scomp, } =20 /* set up volume table */ - ret =3D set_up_volume_table(scontrol, tlv, le32_to_cpu(mc->max) + 1); + ret =3D 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_compo= nent *scomp, return 0; =20 err: - if (le32_to_cpu(mc->max) > 1) + if (max > 1) kfree(scontrol->volume_table); =20 return ret; --=20 2.50.1 (Apple Git-155)