Skip to content

Commit 475ddac

Browse files
committed
lib_manager: bound build info offset to the library size
The build info pointer was derived from a manifest-supplied text segment offset without bounds, so a crafted manifest could read outside the library buffer. Validate the offset against the library image size before dereferencing and fail the module type lookup otherwise. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 3f7738d commit 475ddac

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/library_manager/lib_manager.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,26 @@ static enum buildinfo_mod_type lib_manager_get_module_type(const struct sof_man_
567567
const struct sof_module_api_build_info *const build_info =
568568
(const struct sof_module_api_build_info *)((const char *)desc -
569569
SOF_MAN_ELF_TEXT_OFFSET + mod->segment[SOF_MAN_SEGMENT_TEXT].file_offset);
570+
const size_t lib_size = (size_t)desc->header.preload_page_count * PAGE_SZ;
571+
const uint32_t text_off = mod->segment[SOF_MAN_SEGMENT_TEXT].file_offset;
570572

571573
/*
572574
* llext modules store build info structure in separate section which is not accessible now.
573575
*/
574576
if (module_is_llext(mod))
575577
return MOD_TYPE_LLEXT;
576578

579+
/*
580+
* build_info is derived from a manifest-supplied file_offset; bound it
581+
* against the library image size before dereferencing so a crafted
582+
* offset cannot read outside the library buffer.
583+
*/
584+
if (text_off > lib_size || lib_size - text_off < sizeof(*build_info)) {
585+
tr_err(&lib_manager_tr, "Invalid TEXT file_offset %u, lib_size %zu",
586+
text_off, lib_size);
587+
return MOD_TYPE_INVALID;
588+
}
589+
577590
tr_info(&lib_manager_tr, "Module API version: %u.%u.%u, format: 0x%x",
578591
build_info->api_version_number.fields.major,
579592
build_info->api_version_number.fields.middle,

0 commit comments

Comments
 (0)