ASoC: SOF: ipc3: bound firmware-supplied ext header size
Subsystems (3)
PATCH 1/1 ASoC: SOF: ipc3: bound firmware-supplied ext header size
ext_hdr->hdr.size comes straight from firmware and is used unchecked as a read length: too large overflows the PAGE_SIZE heap allocation in ext_data, too small underflows the size_t subtraction (hdr.size - sizeof(*ext_hdr)), producing a read length near SIZE_MAX.
Bound hdr.size to [sizeof(*ext_hdr), PAGE_SIZE] before using it.
--- sound/soc/sof/ipc3.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/soc/sof/ipc3.c +8 -0
@@ -598,6 +598,14 @@ static int ipc3_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 offset) ext_hdr = ext_data;while (ext_hdr->hdr.cmd ==SOF_IPC_FW_READY ) { +/* bound hdr.size to avoid heap overflow/underflow */ +if (ext_hdr->hdr.size <sizeof (*ext_hdr) || + ext_hdr->hdr.size >PAGE_SIZE ) { +dev_err (sdev->dev,"invalid ext data size 0x%x\n" , + ext_hdr->hdr.size); + ret = -EINVAL ; +break ; + }/* read in ext structure */ snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_SRAM, offset + sizeof(*ext_hdr),
Signature · 1 line
2.53.0
Péter Ujfalusi
maintainerQuoted 6 lines · Ștefan Ghețu
ext_hdr->hdr.sizecomes straight from firmware and is used unchecked as a read length: too large overflows thePAGE_SIZEheap allocation inext_data, too small underflows thesize_tsubtraction (hdr.size -sizeof(*ext_hdr)), producing a read length nearSIZE_MAX.Bound hdr.size to [
sizeof(*ext_hdr),PAGE_SIZE] before using it.
We tend to trust the firmware on this.
You would need to compromise the system in so many layers before you could even boot a firmware which is malicious to send deliberately wrong information that this is the least of the issue...
You need to sign the firmware with a key which is accepted by the system (the signing key is secret, even we developers have no access to it). You need root access to deploy the firmware to system.
At this point, there is not really a need to brother with this, you can do anything as root...
And if we are this paranoid, we cannot trust the ext_hdr->hdr.size size either, the attacker can deploy the firmware which would pass this check.
I know, agents flags this (and other similar cases), but we are trying to be realistic.
Quoted 25 lines
Signed-off-by Ștefan Ghețu <[email protected]>--- sound/soc/sof/ipc3.c | 8 ++++++++ 1 file changed, 8 insertions(+)sound/soc/sof/ipc3.c +8
-0@@ -598,6 +598,14 @@ static int ipc3_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 offset) ext_hdr = ext_data;while (ext_hdr->hdr.cmd ==SOF_IPC_FW_READY ) { +/* bound hdr.size to avoid heap overflow/underflow */ +if (ext_hdr->hdr.size <sizeof (*ext_hdr) || + ext_hdr->hdr.size >PAGE_SIZE ) { +dev_err (sdev->dev,"invalid ext data size 0x%x\n" , + ext_hdr->hdr.size); + ret = -EINVAL ; +break ; + }/* read in ext structure */ snd_sof_dsp_block_read(sdev, SOF_FW_BLK_TYPE_SRAM, offset + sizeof(*ext_hdr),
Signature · 1 line
Péter