From: Alexander Lobakin <alobakin@pm.me>
To: Sami Tolvanen <samitolvanen@google.com>
Cc: Alexander Lobakin <alobakin@pm.me>,
Peter Zijlstra <peterz@infradead.org>,
Borislav Petkov <bp@alien8.de>, X86 ML <x86@kernel.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
andrew.cooper3@citrix.com, LKML <linux-kernel@vger.kernel.org>,
alexei.starovoitov@gmail.com,
Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: [PATCH 4/9] x86/alternative: Implement .retpoline_sites support
Date: Tue, 19 Oct 2021 18:00:22 +0000 [thread overview]
Message-ID: <20211019175336.169584-1-alobakin@pm.me> (raw)
In-Reply-To: <CABCJKudtYwFtYPAES_Y1uU1TYrApf0D054H8soJo2J_Mx51wkg@mail.gmail.com>
From: Sami Tolvanen <samitolvanen@google.com>
Date: Tue, 19 Oct 2021 08:37:14 -0700
> On Tue, Oct 19, 2021 at 3:17 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> >
> > + Sami
> >
> > (Sami, for context:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=objtool/core
> >
> > which contains the following code:
> >
> > + void (*target)(void);
> > + int reg, i = 0;
> > +
> > + target = addr + insn->length + insn->immediate.value;
> > + reg = (target - &__x86_indirect_thunk_rax) /
> > + (&__x86_indirect_thunk_rcx - &__x86_indirect_thunk_rax);
> > +
> > + if (WARN_ON_ONCE(reg & ~0xf))
> > + return -1;
> >
> > which blows up something fierce on clang-cfi)
> >
> > On Tue, Oct 19, 2021 at 09:47:26AM +0000, Alexander Lobakin wrote:
> >
> > > Oh okay, it's because of ClangCFI:
> > >
> > > SMP alternatives: You were looking for __typeid__ZTSFvvE_global_addr+0x370/0x1410 at 0xffffffffa523cd60,>
> > > SMP alternatives: rax is __typeid__ZTSFvvE_global_addr+0x360/0x1410 at 0xffffffffa523cd50
> > >
> > > Sorry for confusing, seems like it's a side effect of using it on
> > > Clang 12 while the original series supports only 13+. I'll double
> > > check and let know if find something.
> >
> > I'm thinking CFI will totally screw this up regardless, seeing how a
> > function pointer is taken, and the CFI magicks will turn that into one
> > of those weird trampolines instead of the actual symbol.
> >
> > The compiler could of course deduce that these addresses are never
> > called and don't escape the function, and therefore doesn't need to do
> > the CFI transformation on then, but I'm guessing it isn't quite that
> > clever.
>
> Yes, it's unfortunately not that clever.
>
> > Also doing CFI on retpoline thunks seems 'weird', they have a very
> > particular calling convention, excplicitly very much not the standard C
> > one. Can't we mark them using asmlinkage or something to tell the
> > compiler to politely 'bugger off' or somesuch ;-)
>
> I confirmed that using an opaque type for the thunk declaration fixes
> this issue with CFI. It also makes it obvious that these are not
> callable from C code.
Oh, glad we caught this then, much thanks y'all!
> Sami
Thanks,
Al
next prev parent reply other threads:[~2021-10-19 18:00 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 12:22 [PATCH 0/9] x86: Rewrite the retpoline rewrite logic Peter Zijlstra
2021-10-13 12:22 ` [PATCH 1/9] objtool,x86: Replace alternatives with .retpoline_sites Peter Zijlstra
2021-10-13 13:29 ` Borislav Petkov
2021-10-13 20:11 ` Josh Poimboeuf
2021-10-14 15:43 ` Peter Zijlstra
2021-10-13 12:22 ` [PATCH 2/9] x86/retpoline: Remove unused replacement symbols Peter Zijlstra
2021-10-13 12:22 ` [PATCH 3/9] x86/asm: Fix register order Peter Zijlstra
2021-10-13 20:15 ` Josh Poimboeuf
2021-10-13 12:22 ` [PATCH 4/9] x86/alternative: Implement .retpoline_sites support Peter Zijlstra
2021-10-13 14:38 ` Andrew Cooper
2021-10-13 15:12 ` Peter Zijlstra
2021-10-13 17:11 ` Andrew Cooper
2021-10-14 10:05 ` Peter Zijlstra
2021-10-13 20:39 ` Josh Poimboeuf
2021-10-13 21:20 ` Peter Zijlstra
2021-10-13 21:49 ` Josh Poimboeuf
2021-10-13 21:52 ` Josh Poimboeuf
2021-10-13 22:10 ` Peter Zijlstra
2021-10-13 22:47 ` Andrew Cooper
2021-10-13 20:52 ` Josh Poimboeuf
2021-10-13 21:00 ` Peter Zijlstra
2021-10-19 11:37 ` Peter Zijlstra
2021-10-19 16:46 ` Josh Poimboeuf
2021-10-19 16:49 ` Josh Poimboeuf
2021-10-20 8:25 ` Peter Zijlstra
2021-10-20 8:30 ` Peter Zijlstra
2021-10-13 21:11 ` Josh Poimboeuf
2021-10-13 21:43 ` Peter Zijlstra
2021-10-13 22:05 ` Josh Poimboeuf
2021-10-13 22:14 ` Peter Zijlstra
2021-10-15 14:24 ` Borislav Petkov
2021-10-15 16:56 ` Peter Zijlstra
2021-10-18 23:06 ` Alexander Lobakin
2021-10-19 0:25 ` Alexander Lobakin
2021-10-19 9:47 ` Alexander Lobakin
2021-10-19 10:16 ` Peter Zijlstra
2021-10-19 15:37 ` Sami Tolvanen
2021-10-19 18:00 ` Alexander Lobakin [this message]
2021-10-19 9:40 ` Peter Zijlstra
2021-10-19 10:02 ` Peter Zijlstra
2021-10-13 12:22 ` [PATCH 5/9] x86/alternative: Handle Jcc __x86_indirect_thunk_\reg Peter Zijlstra
2021-10-13 20:11 ` Nick Desaulniers
2021-10-13 21:08 ` Peter Zijlstra
2021-10-13 12:22 ` [PATCH 6/9] x86/alternative: Try inline spectre_v2=retpoline,amd Peter Zijlstra
2021-10-13 12:22 ` [PATCH 7/9] x86/alternative: Add debug prints to apply_retpolines() Peter Zijlstra
2021-10-13 12:22 ` [PATCH 8/9] x86,bugs: Unconditionally allow spectre_v2=retpoline,amd Peter Zijlstra
2021-10-13 12:22 ` [PATCH 9/9] bpf,x86: Respect X86_FEATURE_RETPOLINE* Peter Zijlstra
2021-10-13 21:06 ` Josh Poimboeuf
2021-10-13 21:54 ` Peter Zijlstra
2021-10-14 9:46 ` Peter Zijlstra
2021-10-14 9:48 ` Peter Zijlstra
2021-10-20 7:34 ` Peter Zijlstra
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=20211019175336.169584-1-alobakin@pm.me \
--to=alobakin@pm.me \
--cc=alexei.starovoitov@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=samitolvanen@google.com \
--cc=x86@kernel.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 NNTP newsgroup(s).