Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1367afa

Browse files
Lai Jiangshansuryasaimadhu
authored andcommitted
x86/entry: Use the correct fence macro after swapgs in kernel CR3
The commit c758907 ("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: c758907 ("x86/entry/64: Remove unneeded kernel CR3 switching") Signed-off-by: Lai Jiangshan <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent c07e455 commit 1367afa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

arch/x86/entry/entry_64.S

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,6 @@ SYM_CODE_START_LOCAL(error_entry)
987987
pushq %r12
988988
ret
989989

990-
.Lerror_entry_done_lfence:
991-
FENCE_SWAPGS_KERNEL_ENTRY
992-
.Lerror_entry_done:
993-
ret
994-
995990
/*
996991
* There are two places in the kernel that can potentially fault with
997992
* usergs. Handle them here. B stepping K8s sometimes report a
@@ -1014,8 +1009,14 @@ SYM_CODE_START_LOCAL(error_entry)
10141009
* .Lgs_change's error handler with kernel gsbase.
10151010
*/
10161011
SWAPGS
1017-
FENCE_SWAPGS_USER_ENTRY
1018-
jmp .Lerror_entry_done
1012+
1013+
/*
1014+
* Issue an LFENCE to prevent GS speculation, regardless of whether it is a
1015+
* kernel or user gsbase.
1016+
*/
1017+
.Lerror_entry_done_lfence:
1018+
FENCE_SWAPGS_KERNEL_ENTRY
1019+
ret
10191020

10201021
.Lbstep_iret:
10211022
/* Fix truncated RIP */

0 commit comments

Comments
 (0)