lkml.org 
[lkml]   [2021]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.10 106/130] x86/entry: Use the correct fence macro after swapgs in kernel CR3
    Date
    From: Lai Jiangshan <laijs@linux.alibaba.com>

    [ Upstream commit 1367afaa2ee90d1c956dfc224e199fcb3ff3f8cc ]

    The commit

    c75890700455 ("x86/entry/64: Remove unneeded kernel CR3 switching")

    removed a CR3 write in the faulting path of load_gs_index().

    But the path's FENCE_SWAPGS_USER_ENTRY has no fence operation if PTI is
    enabled, see spectre_v1_select_mitigation().

    Rather, it depended on the serializing CR3 write of SWITCH_TO_KERNEL_CR3
    and since it got removed, add a FENCE_SWAPGS_KERNEL_ENTRY call to make
    sure speculation is blocked.

    [ bp: Massage commit message and comment. ]

    Fixes: c75890700455 ("x86/entry/64: Remove unneeded kernel CR3 switching")
    Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20211126101209.8613-3-jiangshanlai@gmail.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    arch/x86/entry/entry_64.S | 15 ++++++++-------
    1 file changed, 8 insertions(+), 7 deletions(-)

    diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
    index f18f3932e971a..a806d68b96990 100644
    --- a/arch/x86/entry/entry_64.S
    +++ b/arch/x86/entry/entry_64.S
    @@ -1035,11 +1035,6 @@ SYM_CODE_START_LOCAL(error_entry)
    pushq %r12
    ret

    -.Lerror_entry_done_lfence:
    - FENCE_SWAPGS_KERNEL_ENTRY
    -.Lerror_entry_done:
    - ret
    -
    /*
    * There are two places in the kernel that can potentially fault with
    * usergs. Handle them here. B stepping K8s sometimes report a
    @@ -1062,8 +1057,14 @@ SYM_CODE_START_LOCAL(error_entry)
    * .Lgs_change's error handler with kernel gsbase.
    */
    SWAPGS
    - FENCE_SWAPGS_USER_ENTRY
    - jmp .Lerror_entry_done
    +
    + /*
    + * Issue an LFENCE to prevent GS speculation, regardless of whether it is a
    + * kernel or user gsbase.
    + */
    +.Lerror_entry_done_lfence:
    + FENCE_SWAPGS_KERNEL_ENTRY
    + ret

    .Lbstep_iret:
    /* Fix truncated RIP */
    --
    2.33.0


    \
     
     \ /
      Last update: 2021-12-06 17:11    [W:4.168 / U:0.064 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site