Skip to content

Commit 2bc84dc

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

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

subsys/llext/llext_load.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ static int llext_count_export_syms(struct llext_loader *ldr, struct llext *ext)
542542
size_t ent_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_entsize;
543543
size_t syms_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_size;
544544
int sym_cnt = syms_size / sizeof(elf_sym_t);
545+
elf_shdr_t *str_region = ldr->sects + LLEXT_MEM_STRTAB;
546+
size_t str_reg_size = str_region->sh_size;
545547
const char *name;
546548
elf_sym_t sym;
547549
int i, ret;
@@ -568,6 +570,12 @@ static int llext_count_export_syms(struct llext_loader *ldr, struct llext *ext)
568570
return ret;
569571
}
570572

573+
if (sym.st_name >= str_reg_size) {
574+
LOG_ERR("Invalid symbol name index %d in symbol %d",
575+
sym.st_name, i);
576+
return -ENOEXEC;
577+
}
578+
571579
uint32_t stt = ELF_ST_TYPE(sym.st_info);
572580
uint32_t stb = ELF_ST_BIND(sym.st_info);
573581
uint32_t sect = sym.st_shndx;

0 commit comments

Comments
 (0)