ASoC: SOF: ipc4-loader: Verify ext manifest magic number
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Tue, 23 Aug 2022 12:42:19 +0000 (15:42 +0300)
committerMark Brown <broonie@kernel.org>
Tue, 23 Aug 2022 18:52:38 +0000 (19:52 +0100)
Firmware image must start with an extended manifest. Add a check to make
sure that the image does contain it.

The magic number (the first u32 of a firmware image if manifest is present)
for an IPC4 image must be 0x31454124 (ASCI "$AE1").

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20220823124219.927-1-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc4-loader.c

index 9fadae8..8bd2132 100644 (file)
@@ -40,6 +40,17 @@ static size_t sof_ipc4_fw_parse_ext_man(struct snd_sof_dev *sdev)
 
        ext_man_hdr = (struct sof_ext_manifest4_hdr *)fw->data;
 
+       /*
+        * At the start of the firmware image we must have an extended manifest.
+        * Verify that the magic number is correct.
+        */
+       if (ext_man_hdr->id != SOF_EXT_MAN4_MAGIC_NUMBER) {
+               dev_err(sdev->dev,
+                       "Unexpected extended manifest magic number: %#x\n",
+                       ext_man_hdr->id);
+               return -EINVAL;
+       }
+
        fw_hdr_offset = ipc4_data->manifest_fw_hdr_offset;
        if (!fw_hdr_offset)
                return -EINVAL;