* [PATCH RFT] objtool: Validate find symtab in elf_create_rela_section()
@ 2026-04-28 4:30 Robertus Diawan Chris
0 siblings, 0 replies; only message in thread
From: Robertus Diawan Chris @ 2026-04-28 4:30 UTC (permalink / raw)
To: jpoimboe, peterz; +Cc: linux-kernel, linux-kernel-mentees, skhan, me
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 <robertusdchris@gmail.com>
---
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(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index f3df2bde119f..ce7246d3b302 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -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
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-28 4:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 4:30 [PATCH RFT] objtool: Validate find symtab in elf_create_rela_section() Robertus Diawan Chris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox