Skip to content

Commit 43b0db8

Browse files
committed
firmware: cs_dsp: Return error if block header overflows file
JIRA: https://issues.redhat.com/browse/RHEL-53650 CVE: CVE-2024-42238 commit 959fe01 Author: Richard Fitzgerald <rf@opensource.cirrus.com> Date: Thu Jun 27 15:14:30 2024 +0100 firmware: cs_dsp: Return error if block header overflows file Return an error from cs_dsp_power_up() if a block header is longer than the amount of data left in the file. The previous code in cs_dsp_load() and cs_dsp_load_coeff() would loop while there was enough data left in the file for a valid region. This protected against overrunning the end of the file data, but it didn't abort the file processing with an error. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Fixes: f6bc909 ("firmware: cs_dsp: add driver to support firmware loading on Cirrus Logic DSPs") Link: https://patch.msgid.link/20240627141432.93056-3-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 80852bc commit 43b0db8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/firmware/cirrus/cs_dsp.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,13 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,
15261526
cs_dsp_dbg(dsp, "%s: timestamp %llu\n", file,
15271527
le64_to_cpu(footer->timestamp));
15281528

1529-
while (pos < firmware->size &&
1530-
sizeof(*region) < firmware->size - pos) {
1529+
while (pos < firmware->size) {
1530+
/* Is there enough data for a complete block header? */
1531+
if (sizeof(*region) > firmware->size - pos) {
1532+
ret = -EOVERFLOW;
1533+
goto out_fw;
1534+
}
1535+
15311536
region = (void *)&(firmware->data[pos]);
15321537
region_name = "Unknown";
15331538
reg = 0;
@@ -2215,8 +2220,13 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware
22152220
pos = le32_to_cpu(hdr->len);
22162221

22172222
blocks = 0;
2218-
while (pos < firmware->size &&
2219-
sizeof(*blk) < firmware->size - pos) {
2223+
while (pos < firmware->size) {
2224+
/* Is there enough data for a complete block header? */
2225+
if (sizeof(*blk) > firmware->size - pos) {
2226+
ret = -EOVERFLOW;
2227+
goto out_fw;
2228+
}
2229+
22202230
blk = (void *)(&firmware->data[pos]);
22212231

22222232
type = le16_to_cpu(blk->type);

0 commit comments

Comments
 (0)