x86/entry: Add a fence for kernel entry SWAPGS in paranoid_entry()
[ Upstream commit c07e45553da1808aa802e9f0ffa8108cfeaf7a17 ] Commit18ec54fdd6
("x86/speculation: Prepare entry code for Spectre v1 swapgs mitigations") added FENCE_SWAPGS_{KERNEL|USER}_ENTRY for conditional SWAPGS. In paranoid_entry(), it uses only FENCE_SWAPGS_KERNEL_ENTRY for both branches. This is because the fence is required for both cases since the CR3 write is conditional even when PTI is enabled. But96b2371413
("x86/entry/64: Switch CR3 before SWAPGS in paranoid entry") changed the order of SWAPGS and the CR3 write. And it missed the needed FENCE_SWAPGS_KERNEL_ENTRY for the user gsbase case. Add it back by changing the branches so that FENCE_SWAPGS_KERNEL_ENTRY can cover both branches. [ bp: Massage, fix typos, remove obsolete comment while at it. ] Fixes:96b2371413
("x86/entry/64: Switch CR3 before SWAPGS in paranoid entry") Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20211126101209.8613-2-jiangshanlai@gmail.com Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
4bbbc9c4f3
commit
92f309c838
@@ -936,6 +936,7 @@ SYM_CODE_START_LOCAL(paranoid_entry)
|
|||||||
.Lparanoid_entry_checkgs:
|
.Lparanoid_entry_checkgs:
|
||||||
/* EBX = 1 -> kernel GSBASE active, no restore required */
|
/* EBX = 1 -> kernel GSBASE active, no restore required */
|
||||||
movl $1, %ebx
|
movl $1, %ebx
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The kernel-enforced convention is a negative GSBASE indicates
|
* The kernel-enforced convention is a negative GSBASE indicates
|
||||||
* a kernel value. No SWAPGS needed on entry and exit.
|
* a kernel value. No SWAPGS needed on entry and exit.
|
||||||
@@ -943,21 +944,14 @@ SYM_CODE_START_LOCAL(paranoid_entry)
|
|||||||
movl $MSR_GS_BASE, %ecx
|
movl $MSR_GS_BASE, %ecx
|
||||||
rdmsr
|
rdmsr
|
||||||
testl %edx, %edx
|
testl %edx, %edx
|
||||||
jns .Lparanoid_entry_swapgs
|
js .Lparanoid_kernel_gsbase
|
||||||
ret
|
|
||||||
|
|
||||||
.Lparanoid_entry_swapgs:
|
|
||||||
swapgs
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The above SAVE_AND_SWITCH_TO_KERNEL_CR3 macro doesn't do an
|
|
||||||
* unconditional CR3 write, even in the PTI case. So do an lfence
|
|
||||||
* to prevent GS speculation, regardless of whether PTI is enabled.
|
|
||||||
*/
|
|
||||||
FENCE_SWAPGS_KERNEL_ENTRY
|
|
||||||
|
|
||||||
/* EBX = 0 -> SWAPGS required on exit */
|
/* EBX = 0 -> SWAPGS required on exit */
|
||||||
xorl %ebx, %ebx
|
xorl %ebx, %ebx
|
||||||
|
swapgs
|
||||||
|
.Lparanoid_kernel_gsbase:
|
||||||
|
|
||||||
|
FENCE_SWAPGS_KERNEL_ENTRY
|
||||||
ret
|
ret
|
||||||
SYM_CODE_END(paranoid_entry)
|
SYM_CODE_END(paranoid_entry)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user