Commit 86e2d14b authored by Cezary Rojewski's avatar Cezary Rojewski Committed by Mark Brown

ASoC: topology: Add header payload_size verification

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: default avatarCezary Rojewski <cezary.rojewski@intel.com>
Link: https://lore.kernel.org/r/20211015161257.27052-3-cezary.rojewski@intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 7db53c21
...@@ -2438,6 +2438,7 @@ static int soc_tplg_manifest_load(struct soc_tplg *tplg, ...@@ -2438,6 +2438,7 @@ static int soc_tplg_manifest_load(struct soc_tplg *tplg,
_manifest = manifest; _manifest = manifest;
} else { } else {
abi_match = false; abi_match = false;
ret = manifest_new_ver(tplg, manifest, &_manifest); ret = manifest_new_ver(tplg, manifest, &_manifest);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -2468,6 +2469,14 @@ static int soc_valid_header(struct soc_tplg *tplg, ...@@ -2468,6 +2469,14 @@ static int soc_valid_header(struct soc_tplg *tplg,
return -EINVAL; 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 */ /* big endian firmware objects not supported atm */
if (le32_to_cpu(hdr->magic) == SOC_TPLG_MAGIC_BIG_ENDIAN) { if (le32_to_cpu(hdr->magic) == SOC_TPLG_MAGIC_BIG_ENDIAN) {
dev_err(tplg->dev, dev_err(tplg->dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment