diff mbox series

ASoC: SOF: Add some bounds checking to firmware data

Message ID 5593d147-058c-4de3-a6f5-540ecb96f6f8@moroto.mountain (mailing list archive)
State Accepted
Commit 98f681b0f84cfc3a1d83287b77697679e0398306
Headers show
Series ASoC: SOF: Add some bounds checking to firmware data | expand

Commit Message

Dan Carpenter Feb. 9, 2024, 1:02 p.m. UTC
Smatch complains about "head->full_size - head->header_size" can
underflow.  To some extent, we're always going to have to trust the
firmware a bit.  However, it's easy enough to add a check for negatives,
and let's add a upper bounds check as well.

Fixes: d2458baa799f ("ASoC: SOF: ipc3-loader: Implement firmware parsing and loading")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 sound/soc/sof/ipc3-loader.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Mark Brown Feb. 14, 2024, 3:44 p.m. UTC | #1
On Fri, 09 Feb 2024 16:02:16 +0300, Dan Carpenter wrote:
> Smatch complains about "head->full_size - head->header_size" can
> underflow.  To some extent, we're always going to have to trust the
> firmware a bit.  However, it's easy enough to add a check for negatives,
> and let's add a upper bounds check as well.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: SOF: Add some bounds checking to firmware data
      commit: 98f681b0f84cfc3a1d83287b77697679e0398306

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/sound/soc/sof/ipc3-loader.c b/sound/soc/sof/ipc3-loader.c
index 28218766d211..6e3ef0672110 100644
--- a/sound/soc/sof/ipc3-loader.c
+++ b/sound/soc/sof/ipc3-loader.c
@@ -148,6 +148,8 @@  static size_t sof_ipc3_fw_parse_ext_man(struct snd_sof_dev *sdev)
 
 	head = (struct sof_ext_man_header *)fw->data;
 	remaining = head->full_size - head->header_size;
+	if (remaining < 0 || remaining > sdev->basefw.fw->size)
+		return -EINVAL;
 	ext_man_size = ipc3_fw_ext_man_size(sdev, fw);
 
 	/* Assert firmware starts with extended manifest */