[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMj1kXHNvPdgG+OKX6UB70oTzzbvovfvDhSH73vAj-q7G03c5Q@mail.gmail.com>
Date: Wed, 16 Jul 2025 20:26:55 +1000
From: Ard Biesheuvel <ardb@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Ard Biesheuvel <ardb+git@...gle.com>, linux-kernel@...r.kernel.org,
linux-efi@...r.kernel.org, x86@...nel.org, Borislav Petkov <bp@...en8.de>,
Ingo Molnar <mingo@...nel.org>, Kevin Loughlin <kevinloughlin@...gle.com>,
Tom Lendacky <thomas.lendacky@....com>, Josh Poimboeuf <jpoimboe@...nel.org>,
Nikunj A Dadhania <nikunj@....com>
Subject: Re: [PATCH v5 15/22] objtool: Add action to check for absence of
absolute relocations
On Wed, 16 Jul 2025 at 19:54, Peter Zijlstra <peterz@...radead.org> wrote:
>
> On Wed, Jul 16, 2025 at 05:18:30AM +0200, Ard Biesheuvel wrote:
> > index d967ac001498..5d1d38404892 100644
> > --- a/tools/objtool/check.c
> > +++ b/tools/objtool/check.c
> > @@ -4643,6 +4643,39 @@ static void disas_warned_funcs(struct objtool_file *file)
> > disas_funcs(funcs);
> > }
> >
> > +static int check_abs_references(struct objtool_file *file)
> > +{
> > + struct section *sec;
> > + struct reloc *reloc;
> > + int ret = 0;
> > +
> > + for_each_sec(file, sec) {
> > + /* absolute references in non-loadable sections are fine */
> > + if (!(sec->sh.sh_flags & SHF_ALLOC))
> > + continue;
> > +
> > + /* section must have an associated .rela section */
> > + if (!sec->rsec)
> > + continue;
> > +
> > + /*
> > + * Special case for compiler generated metadata that is not
> > + * consumed until after boot.
> > + */
> > + if (!strcmp(sec->name, "__patchable_function_entries"))
> > + continue;
> > +
> > + for_each_reloc(sec->rsec, reloc) {
> > + if (reloc_type(reloc) == R_ABS64) {
>
> This should probably also check R_ABS32. Yes, your current only user is
> x86_64 so R_ABS64 covers things, but we're getting more and more archs
> using objtool. No reason this check shouldn't also work on PPC32 for
> example.
>
Yeah, I was unsure about this.
This check is sufficient to ensure that PIC code is not emitted with,
e.g., global variables with absolute addresses, etc. So the R_ABS64
check here is only a check whether any relocations of the native
pointer size are present (but no R_ABS_NATIVE exists at this point)
For robustness, we should actually check for all absolute relocations
here, including R_X86_64_32S, which is not abstracted into a R_ABSxx
type for objtool.
So perhaps this needs an arch hook where x86_64 can implement it as
bool arch_is_abs_reloc(reloc)
{
switch (reloc_type(reloc)) {
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_64:
return true;
}
return false;
}
and the default just compares against R_ABS32 / R_ABS64 depending on
the word size?
Powered by blists - more mailing lists