Skip to content

Commit 84f5526

Browse files
niranjanhytibroonie
authored andcommitted
ASoC: tas2783A: Fix issues in firmware parsing
During firmware download, if the size of the firmware is too small, it wrongly assumes the firmware download is successful. If there is size mismatch with chunk's header, invalid memory is accessed. Fix these issues by throwing error during these cases. Fixes: 4cc9bd8 (ASoc: tas2783A: Add soundwire based codec driver) Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/r/202510291226.2R3fbYNh-lkp@intel.com/ Signed-off-by: Niranjan H Y <niranjan.hy@ti.com> Link: https://patch.msgid.link/20251030151637.566-1-niranjan.hy@ti.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1a58d86 commit 84f5526

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

sound/soc/codecs/tas2783-sdw.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,17 @@ static void tas2783_fw_ready(const struct firmware *fmw, void *context)
762762
goto out;
763763
}
764764

765-
mutex_lock(&tas_dev->pde_lock);
766765
img_sz = fmw->size;
767766
buf = fmw->data;
768767
offset += FW_DL_OFFSET;
768+
if (offset >= (img_sz - FW_FL_HDR)) {
769+
dev_err(tas_dev->dev,
770+
"firmware is too small");
771+
ret = -EINVAL;
772+
goto out;
773+
}
774+
775+
mutex_lock(&tas_dev->pde_lock);
769776
while (offset < (img_sz - FW_FL_HDR)) {
770777
memset(&hdr, 0, sizeof(hdr));
771778
offset += read_header(&buf[offset], &hdr);
@@ -776,6 +783,14 @@ static void tas2783_fw_ready(const struct firmware *fmw, void *context)
776783
/* size also includes the header */
777784
file_blk_size = hdr.length - FW_FL_HDR;
778785

786+
/* make sure that enough data is there */
787+
if (offset + file_blk_size > img_sz) {
788+
ret = -EINVAL;
789+
dev_err(tas_dev->dev,
790+
"corrupt firmware file");
791+
break;
792+
}
793+
779794
switch (hdr.file_id) {
780795
case 0:
781796
ret = sdw_nwrite_no_pm(tas_dev->sdw_peripheral,
@@ -808,7 +823,8 @@ static void tas2783_fw_ready(const struct firmware *fmw, void *context)
808823
break;
809824
}
810825
mutex_unlock(&tas_dev->pde_lock);
811-
tas2783_update_calibdata(tas_dev);
826+
if (!ret)
827+
tas2783_update_calibdata(tas_dev);
812828

813829
out:
814830
if (!ret)

0 commit comments

Comments
 (0)