Skip to content

Commit 6b63cf4

Browse files
committed
rimage: bound extended manifest header read to the section
The extended-manifest validator copied a fixed header from an offset that could leave fewer than a header's worth of bytes, reading past the section. Require a whole header to remain before the copy. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent e8c1ff9 commit 6b63cf4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

tools/rimage/src/ext_manifest.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ static int ext_man_validate(uint32_t section_size, const void *section_data)
6969

7070
/* copy each head to local struct to omit memory align issues */
7171
while (offset < section_size) {
72+
/* make sure a whole header remains before copying it out */
73+
if (offset + sizeof(head) > section_size) {
74+
fprintf(stderr,
75+
"error: extended manifest header straddles section end\n");
76+
return -EINVAL;
77+
}
7278
memcpy(&head, &sbuf[offset], sizeof(head));
7379
fprintf(stdout, "Extended manifest found module, type: 0x%04X size: 0x%04X (%4d) offset: 0x%04X\n",
7480
head.type, head.elem_size, head.elem_size, offset);
@@ -150,10 +156,12 @@ int ext_man_write(struct image *image)
150156
/* validate metadata section */
151157
ret = ext_man_validate(ext_man->full_size - ext_man->header_size,
152158
(char *)ext_man + ext_man->header_size);
153-
if (ret) {
154-
ret = -errno;
159+
if (ret)
160+
/* ext_man_validate() already returns a negative errno; do not
161+
* overwrite it with -errno, which is not set on validation
162+
* failure and would mask the error
163+
*/
155164
goto out;
156-
}
157165

158166
/* write extended metadata to file */
159167
count = fwrite(ext_man, 1, ext_man->full_size, image->out_ext_man_fd);

0 commit comments

Comments
 (0)