lkml.org 
[lkml]   [2022]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: [PATCH v2 18/39] x86/ibt: Add IBT feature, MSR and #CP handling
    On Fri, Feb 25, 2022 at 11:51:01AM +0100, Peter Zijlstra wrote:
    > > > +bool ibt_selftest(void)
    > > > +{
    > > > + unsigned long ret;
    > > > +
    > > > + asm ("1: lea 2f(%%rip), %%rax\n\t"
    > > > + ANNOTATE_RETPOLINE_SAFE
    > > > + " jmp *%%rax\n\t"
    > > > + ASM_REACHABLE
    > > > + ANNOTATE_NOENDBR
    > > > + "2: nop\n\t"
    > > > +
    > > > + /* unsigned ibt_selftest_ip = 2b */
    > > > + ".pushsection .rodata,\"a\"\n\t"
    > > > + ".align 8\n\t"
    > > > + ".type ibt_selftest_ip, @object\n\t"
    > > > + ".size ibt_selftest_ip, 8\n\t"
    > > > + "ibt_selftest_ip:\n\t"
    > > > + ".quad 2b\n\t"
    > > > + ".popsection\n\t"
    > >
    > > It's still seems silly to make this variable in asm.
    > >
    > > Also .rodata isn't going to work for CPU hotplug.
    >
    > It's just the IP, that stays invariant. I'm not sure how else to match
    > regs->ip to 2 in #CP.

    Ah, I see what you mean now. Still, it can just reference the code
    label itself without having to allocate storage:

    diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
    index 4806fa0adec7..cfaa05ddd1ec 100644
    --- a/arch/x86/kernel/traps.c
    +++ b/arch/x86/kernel/traps.c
    @@ -225,7 +225,7 @@ static void handle_endbr(struct pt_regs *regs)
    BUG();
    }

    -extern const unsigned long ibt_selftest_ip; /* defined in asm beow */
    +void ibt_selftest_ip(void); /* code label defined in asm below */

    DEFINE_IDTENTRY_ERRORCODE(exc_control_protection)
    {
    @@ -237,7 +237,7 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection)
    if (WARN_ON_ONCE(user_mode(regs) || error_code != 3))
    return;

    - if (unlikely(regs->ip == ibt_selftest_ip)) {
    + if (unlikely(regs->ip == (unsigned long)ibt_selftest_ip)) {
    regs->ax = 0;
    return;
    }
    @@ -249,22 +249,12 @@ bool ibt_selftest(void)
    {
    unsigned long ret;

    - asm ("1: lea 2f(%%rip), %%rax\n\t"
    + asm ("1: lea ibt_selftest_ip(%%rip), %%rax\n\t"
    ANNOTATE_RETPOLINE_SAFE
    " jmp *%%rax\n\t"
    ASM_REACHABLE
    ANNOTATE_NOENDBR
    - "2: nop\n\t"
    -
    - /* unsigned ibt_selftest_ip = 2b */
    - ".pushsection .rodata,\"a\"\n\t"
    - ".align 8\n\t"
    - ".type ibt_selftest_ip, @object\n\t"
    - ".size ibt_selftest_ip, 8\n\t"
    - "ibt_selftest_ip:\n\t"
    - ".quad 2b\n\t"
    - ".popsection\n\t"
    -
    + "ibt_selftest_ip: nop\n\t"
    : "=a" (ret) : : "memory");

    return !ret;
    \
     
     \ /
      Last update: 2022-02-26 00:53    [W:4.074 / U:1.724 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site