Skip to content

Commit ed62cc6

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 f0c7938 commit ed62cc6

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
@@ -85,6 +85,18 @@ static int elf_read_sections(struct elf_module *module, bool verbose)
8585
return count > 0 ? -ENODATA : -errno;
8686
}
8787

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

0 commit comments

Comments
 (0)