Skip to content

Commit 497c960

Browse files
committed
smex: bound section name offsets to the string table
Section names are used as offsets into the string table; an out-of-range name offset from a crafted ELF read past the table. Validate every section name offset against the string-table size after loading the sections. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent a12a275 commit 497c960

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

smex/elf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ static int elf_read_sections(struct elf_module *module, bool verbose)
8888
return count > 0 ? -ENODATA : -errno;
8989
}
9090

91+
/* every section name is used as an offset into the string table; make
92+
* sure each stays within it so later "module->strings + name" reads
93+
* cannot run past the table
94+
*/
95+
for (i = 0; i < hdr->shnum; i++) {
96+
if (section[i].name >= section[hdr->shstrndx].size) {
97+
fprintf(stderr, "error: %s section %d name offset %u out of range\n",
98+
module->elf_file, i, section[i].name);
99+
return -ENOEXEC;
100+
}
101+
}
102+
91103
module->bss_index = elf_find_section(module, ".bss");
92104
if (module->bss_index < 0) {
93105
fprintf(stderr, "Can't find .bss section in %s",

0 commit comments

Comments
 (0)