History

x86/entry: Use the correct fence macro after swapgs in kernel CR3

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. ]

Lai Jiangshan committed 4 years ago

Commit 1367afa1 parent c07e4551 file · +8 −7Browse files

Unified · Split

arch/x86/entry/entry_64.S+8−7
@@ -987,11 +987,6 @@ SYM_CODE_START_LOCAL(error_entry) · 986 unmodified lines
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) · 16 unmodified lines
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 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t