* [PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning
@ 2024-05-06 15:55 Kees Cook
2024-05-07 3:24 ` Josh Poimboeuf
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2024-05-06 15:55 UTC (permalink / raw)
To: Josh Poimboeuf; +Cc: Kees Cook, Peter Zijlstra, linux-kernel, linux-hardening
While tracking down issues with LKDTM's .rodata "function", I found
the warning from elf_init_reloc_text_sym() to be unhelpful because it
wasn't clear which calling path it was coming from. Report the sec->name
and rephrase the warning a bit. Additionally check for NULL sym->name,
which may happen.
Before:
vmlinux.o: warning: objtool: bad call to elf_init_reloc_text_sym() for data symbol .rodata
After:
vmlinux.o: warning: objtool: .cfi_sites: unexpected reference to non-executable symbol '.rodata'
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
v1: https://lore.kernel.org/lkml/20240430235106.work.680-kees@kernel.org/
---
tools/objtool/elf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 3d27983dc908..b38cedd4fd55 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -891,8 +891,8 @@ struct reloc *elf_init_reloc_text_sym(struct elf *elf, struct section *sec,
int addend = insn_off;
if (!(insn_sec->sh.sh_flags & SHF_EXECINSTR)) {
- WARN("bad call to %s() for data symbol %s",
- __func__, sym->name);
+ WARN("%s: unexpected reference to non-executable symbol '%s'",
+ sec->name, sym->name ?: "<unknown>");
return NULL;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning
2024-05-06 15:55 [PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning Kees Cook
@ 2024-05-07 3:24 ` Josh Poimboeuf
0 siblings, 0 replies; 2+ messages in thread
From: Josh Poimboeuf @ 2024-05-07 3:24 UTC (permalink / raw)
To: Kees Cook; +Cc: Peter Zijlstra, linux-kernel, linux-hardening
On Mon, May 06, 2024 at 08:55:54AM -0700, Kees Cook wrote:
> While tracking down issues with LKDTM's .rodata "function", I found
> the warning from elf_init_reloc_text_sym() to be unhelpful because it
> wasn't clear which calling path it was coming from. Report the sec->name
> and rephrase the warning a bit. Additionally check for NULL sym->name,
> which may happen.
Hm, as far as I know sym->name shouldn't ever be NULL.
Though, looking at this code again I'm realizing that 'sym' could be
NULL because it refers to the symbol for the function's *section* rather
than for the function itself. And sometimes the toolchain doesn't
generate symbols for some sections, if they're not referenced anywhere.
(Note the code immediately below your patch actually makes a section
symbol if it doesn't exist.)
But also, this warning doesn't even need the section's symbol. It can
just get the name from the section directly (insn_sec->name). And it
would probably also be useful to print the offset (insn_off), like
".rodata+0x1234".
Though, even better, we have an offstr() helper which can pretty-print
the name of the function or variable, if one exists at that address.
tl;dr, does the following work?
WARN("%s: unexpected reference to non-executable '%s'",
sec->name, offstr(insn_sec, insn_off));
--
Josh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-07 3:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 15:55 [PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning Kees Cook
2024-05-07 3:24 ` Josh Poimboeuf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.