Skip to content

Commit 3a4c1cf

Browse files
committed
rimage: bound module manifest count from input
The number of module manifests packed in a section came from the input file and drove writes into the fixed-size module descriptor array. Reject a count above the maximum before the write loop. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 6d28bea commit 3a4c1cf

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/rimage/src/manifest.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,18 @@ static int man_module_create_reloc(struct image *image, struct manifest_module *
534534
return -ENOEXEC;
535535
}
536536

537+
/*
538+
* n_mod comes from the (potentially untrusted) ELF and each manifest
539+
* consumes a sof_man_module descriptor slot written into fw_image.
540+
* Bound it so a crafted .module section cannot overflow the manifest.
541+
*/
542+
if (n_mod > MAX_MODULES) {
543+
fprintf(stderr, "error: too many module manifests (%u > %u) in '.module' section.\n",
544+
n_mod, MAX_MODULES);
545+
elf_section_free(&section);
546+
return -ENOEXEC;
547+
}
548+
537549
unsigned int i;
538550

539551
for (i = 0, sof_mod = section.data; i < n_mod; i++, sof_mod++) {

0 commit comments

Comments
 (0)