Skip to content

Commit 959fe01

Browse files
rfvirgilbroonie
authored andcommitted
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 <[email protected]> Fixes: f6bc909 ("firmware: cs_dsp: add driver to support firmware loading on Cirrus Logic DSPs") Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 3019b86 commit 959fe01

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
@@ -1444,8 +1444,13 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,
14441444
cs_dsp_dbg(dsp, "%s: timestamp %llu\n", file,
14451445
le64_to_cpu(footer->timestamp));
14461446

1447-
while (pos < firmware->size &&
1448-
sizeof(*region) < firmware->size - pos) {
1447+
while (pos < firmware->size) {
1448+
/* Is there enough data for a complete block header? */
1449+
if (sizeof(*region) > firmware->size - pos) {
1450+
ret = -EOVERFLOW;
1451+
goto out_fw;
1452+
}
1453+
14491454
region = (void *)&(firmware->data[pos]);
14501455
region_name = "Unknown";
14511456
reg = 0;
@@ -2133,8 +2138,13 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware
21332138
pos = le32_to_cpu(hdr->len);
21342139

21352140
blocks = 0;
2136-
while (pos < firmware->size &&
2137-
sizeof(*blk) < firmware->size - pos) {
2141+
while (pos < firmware->size) {
2142+
/* Is there enough data for a complete block header? */
2143+
if (sizeof(*blk) > firmware->size - pos) {
2144+
ret = -EOVERFLOW;
2145+
goto out_fw;
2146+
}
2147+
21382148
blk = (void *)(&firmware->data[pos]);
21392149

21402150
type = le16_to_cpu(blk->type);

0 commit comments

Comments
 (0)