From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning
Date: Mon, 6 May 2024 20:24:00 -0700 [thread overview]
Message-ID: <20240507032400.gxorrjm3q7mg5cac@treble> (raw)
In-Reply-To: <20240506155537.it.760-kees@kernel.org>
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
prev parent reply other threads:[~2024-05-07 3:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240507032400.gxorrjm3q7mg5cac@treble \
--to=jpoimboe@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).