Skip to content

Commit ef41cc1

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 b0e1da3 commit ef41cc1

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tools/rimage/src/manifest.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,20 @@ 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 the cumulative count across all input modules (this ELF adds
541+
* n_mod to the running output_mod_cfg_count) so a crafted .module
542+
* section cannot overflow the fixed manifest descriptor array.
543+
*/
544+
if (modules->output_mod_cfg_count + n_mod > MAX_MODULES) {
545+
fprintf(stderr, "error: too many module manifests (%u + %u > %u).\n",
546+
modules->output_mod_cfg_count, n_mod, MAX_MODULES);
547+
elf_section_free(&section);
548+
return -ENOEXEC;
549+
}
550+
537551
unsigned int i;
538552

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

0 commit comments

Comments
 (0)