Skip to contentSkip to conversation

ASoC: topology: Fix bounds check for widget private data

PATCH New Naveed Khan 1 participant 1 message Jun 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: topology: Fix bounds check for widget private data

soc_tplg_dapm_widget_elems_load() validates that a DAPM widget fits within the topology firmware buffer before parsing it. The check for the widget header correctly accounts for sizeof(*widget):

	if (soc_tplg_get_offset(tplg) + sizeof(*widget) >= tplg->fw->size)

but the subsequent check for the widget's private data only adds priv.size:

	if (soc_tplg_get_offset(tplg) + le32_to_cpu(widget->priv.size) >=
	    tplg->fw->size)

The private data is located after the widget header, and soc_tplg_dapm_widget_create() advances tplg->pos by sizeof(struct snd_soc_tplg_dapm_widget) + priv.size accordingly. Since the check omits the header size, a topology blob whose priv.size satisfies

	offset + priv.size < fw->size

but

	offset + sizeof(*widget) + priv.size >= fw->size

passes validation and leaves tplg->pos pointing past the end of the firmware buffer. When the widget declares one or more kcontrols, the following read of control_hdr->type dereferences memory up to sizeof(struct snd_soc_tplg_dapm_widget) bytes beyond the allocation, an out-of-bounds read whose length is controlled by the (firmware supplied) topology data.

Include sizeof(*widget) in the private data bounds check, matching the widget header check above.

---

sound/soc/soc-topology.c +2 -1
index 35cbe29d22..3f8bdacc3a 100644
@@ -1290,7 +1290,8 @@ static int soc_tplg_dapm_widget_elems_load(struct soc_tplg *tplg,
 		}
 
 		/* check if widget private data fits within topology file */
-		if (soc_tplg_get_offset(tplg) + le32_to_cpu(widget->priv.size) >= tplg->fw->size) {
+		if (soc_tplg_get_offset(tplg) + sizeof(*widget) +
+		    le32_to_cpu(widget->priv.size) >= tplg->fw->size) {
 			dev_err(tplg->dev, "ASoC: invalid widget private data size\n");
 			return -EINVAL;
 		}
Signature · 1 line
2.52.0