Skip to content

Commit 823c519

Browse files
edersondisouzakartben
authored andcommitted
subsys/llext: Fail if section name index is outside strings area
Avoid unintended out of bounds accesses. Signed-off-by: Ederson de Souza <[email protected]>
1 parent 2bc84dc commit 823c519

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

subsys/llext/llext_load.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,25 @@ static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext,
744744
return 0;
745745
}
746746

747+
static int llext_validate_sections_name(struct llext_loader *ldr, struct llext *ext)
748+
{
749+
const elf_shdr_t *shstrtab = ldr->sects + LLEXT_MEM_SHSTRTAB;
750+
size_t shstrtab_size = shstrtab->sh_size;
751+
int i;
752+
753+
for (i = 0; i < ext->sect_cnt; i++) {
754+
elf_shdr_t *shdr = ext->sect_hdrs + i;
755+
756+
if (shdr->sh_name >= shstrtab_size) {
757+
LOG_ERR("Invalid section name index %d in section %d",
758+
shdr->sh_name, i);
759+
return -ENOEXEC;
760+
}
761+
}
762+
763+
return 0;
764+
}
765+
747766
/*
748767
* Load a valid ELF as an extension
749768
*/
@@ -790,6 +809,12 @@ int do_llext_load(struct llext_loader *ldr, struct llext *ext,
790809
goto out;
791810
}
792811

812+
ret = llext_validate_sections_name(ldr, ext);
813+
if (ret != 0) {
814+
LOG_ERR("Failed to validate ELF section names, ret %d", ret);
815+
goto out;
816+
}
817+
793818
LOG_DBG("Mapping ELF sections...");
794819
ret = llext_map_sections(ldr, ext, ldr_parm);
795820
if (ret != 0) {

0 commit comments

Comments
 (0)