Skip to content

Commit

Permalink
ASoC: topology: Add header payload_size verification
Browse files Browse the repository at this point in the history
Add sanity check to make sure the data is read within file boundary.
Helps in situations where file is only partially copied or malformed.

Signed-off-by: Cezary Rojewski <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
crojewsk-intel authored and broonie committed Oct 29, 2021
1 parent 7db53c2 commit 86e2d14
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sound/soc/soc-topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,7 @@ static int soc_tplg_manifest_load(struct soc_tplg *tplg,
_manifest = manifest;
} else {
abi_match = false;

ret = manifest_new_ver(tplg, manifest, &_manifest);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -2468,6 +2469,14 @@ static int soc_valid_header(struct soc_tplg *tplg,
return -EINVAL;
}

if (soc_tplg_get_hdr_offset(tplg) + hdr->payload_size >= tplg->fw->size) {
dev_err(tplg->dev,
"ASoC: invalid header of type %d at offset %ld payload_size %d\n",
le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg),
hdr->payload_size);
return -EINVAL;
}

/* big endian firmware objects not supported atm */
if (le32_to_cpu(hdr->magic) == SOC_TPLG_MAGIC_BIG_ENDIAN) {
dev_err(tplg->dev,
Expand Down

0 comments on commit 86e2d14

Please sign in to comment.