Skip to content

Commit 4c16908

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 4c16908

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/library_manager/lib_manager.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,21 @@ static enum buildinfo_mod_type lib_manager_get_module_type(const struct sof_man_
574574
if (module_is_llext(mod))
575575
return MOD_TYPE_LLEXT;
576576

577+
/*
578+
* build_info is derived from a manifest-supplied file_offset; bound it
579+
* against the library image size before dereferencing so a crafted
580+
* offset cannot read outside the library buffer.
581+
*/
582+
{
583+
const size_t lib_size = (size_t)desc->header.preload_page_count * PAGE_SZ;
584+
const uint32_t text_off = mod->segment[SOF_MAN_SEGMENT_TEXT].file_offset;
585+
586+
if (text_off > lib_size || lib_size - text_off < sizeof(*build_info)) {
587+
tr_err(&lib_manager_tr, "Invalid TEXT file_offset %u", text_off);
588+
return MOD_TYPE_INVALID;
589+
}
590+
}
591+
577592
tr_info(&lib_manager_tr, "Module API version: %u.%u.%u, format: 0x%x",
578593
build_info->api_version_number.fields.major,
579594
build_info->api_version_number.fields.middle,

0 commit comments

Comments
 (0)