objtool: Validate find symtab in elf_create_rela_section()
PATCH 1/1 objtool: Validate find symtab in elf_create_rela_section()
find_section_by_name() will return NULL if the section is not found. If the symtab section is not found, using the return value of find_section_by_name() directly will cause null pointer dereference. So check the return value from find_section_by_name() when finding symtab section before using the information.
This is reported by Coverity Scan with CID 1445573 as NULL_RETURNS.
Fixes 627fce14809b ("objtool: Add ORC unwind table generation")
Signed-off-by Robertus Diawan Chris <[email protected]>
---
Currently still not sure _when_ symtab section is not found. This is reported by static analysis tool, which can be wrong. I apologize if this turns out to be false positive.
tools/objtool/elf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/objtool/elf.c +8 -2
@@ -1625,7 +1625,7 @@ static int elf_alloc_reloc(struct elf *elf, struct section *rsec)struct section *elf_create_rela_section (struct elf *elf,struct section *sec,unsigned int nr_relocs) { -struct section *rsec; +struct section *rsec, *symtab;char *rsec_name; rsec_name =malloc (strlen (sec->name) +strlen (".rela" ) +1 );
@@ -1654,7 +1654,13 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *sec, } } - rsec->sh.sh_link =find_section_by_name (elf,".symtab" )->idx; + symtab =find_section_by_name (elf,".symtab" ); +if (!symtab) { +ERROR ("can't find .symtab" ); +return NULL ; + } + + rsec->sh.sh_link = symtab->idx; rsec->sh.sh_info = sec->idx; sec->rsec = rsec;
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
Signature · 1 line
2.54.0