Skip to content

Commit 4589f19

Browse files
author
Ingo Molnar
committed
Merge branch 'x86/bugs' into x86/core, to pick up pending changes before dependent patches
Merge in pending alternatives patching infrastructure changes, before applying more patches. Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents 03c11eb + 4461438 commit 4589f19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+288
-268
lines changed

Documentation/admin-guide/hw-vuln/spectre.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ Spectre variant 2
473473
-mindirect-branch=thunk-extern -mindirect-branch-register options.
474474
If the kernel is compiled with a Clang compiler, the compiler needs
475475
to support -mretpoline-external-thunk option. The kernel config
476-
CONFIG_RETPOLINE needs to be turned on, and the CPU needs to run with
477-
the latest updated microcode.
476+
CONFIG_MITIGATION_RETPOLINE needs to be turned on, and the CPU needs
477+
to run with the latest updated microcode.
478478

479479
On Intel Skylake-era systems the mitigation covers most, but not all,
480480
cases. See :ref:`[3] <spec_ref3>` for more details.
@@ -609,8 +609,8 @@ kernel command line.
609609
Selecting 'on' will, and 'auto' may, choose a
610610
mitigation method at run time according to the
611611
CPU, the available microcode, the setting of the
612-
CONFIG_RETPOLINE configuration option, and the
613-
compiler with which the kernel was built.
612+
CONFIG_MITIGATION_RETPOLINE configuration option,
613+
and the compiler with which the kernel was built.
614614

615615
Selecting 'on' will also enable the mitigation
616616
against user space to user space task attacks.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6027,8 +6027,8 @@
60276027
Selecting 'on' will, and 'auto' may, choose a
60286028
mitigation method at run time according to the
60296029
CPU, the available microcode, the setting of the
6030-
CONFIG_RETPOLINE configuration option, and the
6031-
compiler with which the kernel was built.
6030+
CONFIG_MITIGATION_RETPOLINE configuration option,
6031+
and the compiler with which the kernel was built.
60326032

60336033
Selecting 'on' will also enable the mitigation
60346034
against user space to user space task attacks.

Documentation/arch/x86/pti.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ comments in pti.c).
2626

2727
This approach helps to ensure that side-channel attacks leveraging
2828
the paging structures do not function when PTI is enabled. It can be
29-
enabled by setting CONFIG_PAGE_TABLE_ISOLATION=y at compile time.
30-
Once enabled at compile-time, it can be disabled at boot with the
31-
'nopti' or 'pti=' kernel parameters (see kernel-parameters.txt).
29+
enabled by setting CONFIG_MITIGATION_PAGE_TABLE_ISOLATION=y at compile
30+
time. Once enabled at compile-time, it can be disabled at boot with
31+
the 'nopti' or 'pti=' kernel parameters (see kernel-parameters.txt).
3232

3333
Page Table Management
3434
=====================

arch/x86/Kconfig

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,12 +2477,12 @@ config CALL_PADDING
24772477

24782478
config FINEIBT
24792479
def_bool y
2480-
depends on X86_KERNEL_IBT && CFI_CLANG && RETPOLINE
2480+
depends on X86_KERNEL_IBT && CFI_CLANG && MITIGATION_RETPOLINE
24812481
select CALL_PADDING
24822482

24832483
config HAVE_CALL_THUNKS
24842484
def_bool y
2485-
depends on CC_HAS_ENTRY_PADDING && RETHUNK && OBJTOOL
2485+
depends on CC_HAS_ENTRY_PADDING && MITIGATION_RETHUNK && OBJTOOL
24862486

24872487
config CALL_THUNKS
24882488
def_bool n
@@ -2504,7 +2504,7 @@ menuconfig SPECULATION_MITIGATIONS
25042504

25052505
if SPECULATION_MITIGATIONS
25062506

2507-
config PAGE_TABLE_ISOLATION
2507+
config MITIGATION_PAGE_TABLE_ISOLATION
25082508
bool "Remove the kernel mapping in user mode"
25092509
default y
25102510
depends on (X86_64 || X86_PAE)
@@ -2515,7 +2515,7 @@ config PAGE_TABLE_ISOLATION
25152515

25162516
See Documentation/arch/x86/pti.rst for more details.
25172517

2518-
config RETPOLINE
2518+
config MITIGATION_RETPOLINE
25192519
bool "Avoid speculative indirect branches in kernel"
25202520
select OBJTOOL if HAVE_OBJTOOL
25212521
default y
@@ -2525,9 +2525,9 @@ config RETPOLINE
25252525
branches. Requires a compiler with -mindirect-branch=thunk-extern
25262526
support for full protection. The kernel may run slower.
25272527

2528-
config RETHUNK
2528+
config MITIGATION_RETHUNK
25292529
bool "Enable return-thunks"
2530-
depends on RETPOLINE && CC_HAS_RETURN_THUNK
2530+
depends on MITIGATION_RETPOLINE && CC_HAS_RETURN_THUNK
25312531
select OBJTOOL if HAVE_OBJTOOL
25322532
default y if X86_64
25332533
help
@@ -2536,14 +2536,14 @@ config RETHUNK
25362536
Requires a compiler with -mfunction-return=thunk-extern
25372537
support for full protection. The kernel may run slower.
25382538

2539-
config CPU_UNRET_ENTRY
2539+
config MITIGATION_UNRET_ENTRY
25402540
bool "Enable UNRET on kernel entry"
2541-
depends on CPU_SUP_AMD && RETHUNK && X86_64
2541+
depends on CPU_SUP_AMD && MITIGATION_RETHUNK && X86_64
25422542
default y
25432543
help
25442544
Compile the kernel with support for the retbleed=unret mitigation.
25452545

2546-
config CALL_DEPTH_TRACKING
2546+
config MITIGATION_CALL_DEPTH_TRACKING
25472547
bool "Mitigate RSB underflow with call depth tracking"
25482548
depends on CPU_SUP_INTEL && HAVE_CALL_THUNKS
25492549
select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
@@ -2563,7 +2563,7 @@ config CALL_DEPTH_TRACKING
25632563

25642564
config CALL_THUNKS_DEBUG
25652565
bool "Enable call thunks and call depth tracking debugging"
2566-
depends on CALL_DEPTH_TRACKING
2566+
depends on MITIGATION_CALL_DEPTH_TRACKING
25672567
select FUNCTION_ALIGNMENT_32B
25682568
default n
25692569
help
@@ -2574,14 +2574,14 @@ config CALL_THUNKS_DEBUG
25742574
Only enable this when you are debugging call thunks as this
25752575
creates a noticeable runtime overhead. If unsure say N.
25762576

2577-
config CPU_IBPB_ENTRY
2577+
config MITIGATION_IBPB_ENTRY
25782578
bool "Enable IBPB on kernel entry"
25792579
depends on CPU_SUP_AMD && X86_64
25802580
default y
25812581
help
25822582
Compile the kernel with support for the retbleed=ibpb mitigation.
25832583

2584-
config CPU_IBRS_ENTRY
2584+
config MITIGATION_IBRS_ENTRY
25852585
bool "Enable IBRS on kernel entry"
25862586
depends on CPU_SUP_INTEL && X86_64
25872587
default y
@@ -2590,14 +2590,14 @@ config CPU_IBRS_ENTRY
25902590
This mitigates both spectre_v2 and retbleed at great cost to
25912591
performance.
25922592

2593-
config CPU_SRSO
2593+
config MITIGATION_SRSO
25942594
bool "Mitigate speculative RAS overflow on AMD"
2595-
depends on CPU_SUP_AMD && X86_64 && RETHUNK
2595+
depends on CPU_SUP_AMD && X86_64 && MITIGATION_RETHUNK
25962596
default y
25972597
help
25982598
Enable the SRSO mitigation needed on AMD Zen1-4 machines.
25992599

2600-
config SLS
2600+
config MITIGATION_SLS
26012601
bool "Mitigate Straight-Line-Speculation"
26022602
depends on CC_HAS_SLS && X86_64
26032603
select OBJTOOL if HAVE_OBJTOOL
@@ -2607,7 +2607,7 @@ config SLS
26072607
against straight line speculation. The kernel image might be slightly
26082608
larger.
26092609

2610-
config GDS_FORCE_MITIGATION
2610+
config MITIGATION_GDS_FORCE
26112611
bool "Force GDS Mitigation"
26122612
depends on CPU_SUP_INTEL
26132613
default n

arch/x86/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RETPOLINE_VDSO_CFLAGS := -mretpoline
2222
endif
2323
RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix)
2424

25-
ifdef CONFIG_RETHUNK
25+
ifdef CONFIG_MITIGATION_RETHUNK
2626
RETHUNK_CFLAGS := -mfunction-return=thunk-extern
2727
RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS)
2828
endif
@@ -192,7 +192,7 @@ KBUILD_CFLAGS += -Wno-sign-compare
192192
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
193193

194194
# Avoid indirect branches in kernel to deal with Spectre
195-
ifdef CONFIG_RETPOLINE
195+
ifdef CONFIG_MITIGATION_RETPOLINE
196196
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS)
197197
# Additionally, avoid generating expensive indirect jumps which
198198
# are subject to retpolines for small number of switch cases.
@@ -205,7 +205,7 @@ ifdef CONFIG_RETPOLINE
205205
endif
206206
endif
207207

208-
ifdef CONFIG_SLS
208+
ifdef CONFIG_MITIGATION_SLS
209209
KBUILD_CFLAGS += -mharden-sls=all
210210
endif
211211

@@ -301,7 +301,7 @@ vdso-install-$(CONFIG_IA32_EMULATION) += arch/x86/entry/vdso/vdso32.so.dbg
301301

302302
archprepare: checkbin
303303
checkbin:
304-
ifdef CONFIG_RETPOLINE
304+
ifdef CONFIG_MITIGATION_RETPOLINE
305305
ifeq ($(RETPOLINE_CFLAGS),)
306306
@echo "You are building kernel with non-retpoline compiler." >&2
307307
@echo "Please update your compiler." >&2

arch/x86/boot/compressed/ident_map_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* Copyright (C) 2016 Kees Cook
99
*/
1010

11-
/* No PAGE_TABLE_ISOLATION support needed either: */
12-
#undef CONFIG_PAGE_TABLE_ISOLATION
11+
/* No MITIGATION_PAGE_TABLE_ISOLATION support needed either: */
12+
#undef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
1313

1414
#include "error.h"
1515
#include "misc.h"

arch/x86/configs/i386_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CONFIG_EFI_STUB=y
4242
CONFIG_HZ_1000=y
4343
CONFIG_KEXEC=y
4444
CONFIG_CRASH_DUMP=y
45-
# CONFIG_RETHUNK is not set
45+
# CONFIG_MITIGATION_RETHUNK is not set
4646
CONFIG_HIBERNATION=y
4747
CONFIG_PM_DEBUG=y
4848
CONFIG_PM_TRACE_RTC=y

arch/x86/entry/calling.h

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ For 32-bit we have the following conventions - kernel is built with
142142
.endif
143143
.endm
144144

145-
#ifdef CONFIG_PAGE_TABLE_ISOLATION
145+
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
146146

147147
/*
148-
* PAGE_TABLE_ISOLATION PGDs are 8k. Flip bit 12 to switch between the two
148+
* MITIGATION_PAGE_TABLE_ISOLATION PGDs are 8k. Flip bit 12 to switch between the two
149149
* halves:
150150
*/
151151
#define PTI_USER_PGTABLE_BIT PAGE_SHIFT
@@ -160,7 +160,7 @@ For 32-bit we have the following conventions - kernel is built with
160160

161161
.macro ADJUST_KERNEL_CR3 reg:req
162162
ALTERNATIVE "", "SET_NOFLUSH_BIT \reg", X86_FEATURE_PCID
163-
/* Clear PCID and "PAGE_TABLE_ISOLATION bit", point CR3 at kernel pagetables: */
163+
/* Clear PCID and "MITIGATION_PAGE_TABLE_ISOLATION bit", point CR3 at kernel pagetables: */
164164
andq $(~PTI_USER_PGTABLE_AND_PCID_MASK), \reg
165165
.endm
166166

@@ -275,7 +275,7 @@ For 32-bit we have the following conventions - kernel is built with
275275
.Lend_\@:
276276
.endm
277277

278-
#else /* CONFIG_PAGE_TABLE_ISOLATION=n: */
278+
#else /* CONFIG_MITIGATION_PAGE_TABLE_ISOLATION=n: */
279279

280280
.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
281281
.endm
@@ -303,7 +303,7 @@ For 32-bit we have the following conventions - kernel is built with
303303
* Assumes x86_spec_ctrl_{base,current} to have SPEC_CTRL_IBRS set.
304304
*/
305305
.macro IBRS_ENTER save_reg
306-
#ifdef CONFIG_CPU_IBRS_ENTRY
306+
#ifdef CONFIG_MITIGATION_IBRS_ENTRY
307307
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS
308308
movl $MSR_IA32_SPEC_CTRL, %ecx
309309

@@ -332,7 +332,7 @@ For 32-bit we have the following conventions - kernel is built with
332332
* regs. Must be called after the last RET.
333333
*/
334334
.macro IBRS_EXIT save_reg
335-
#ifdef CONFIG_CPU_IBRS_ENTRY
335+
#ifdef CONFIG_MITIGATION_IBRS_ENTRY
336336
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS
337337
movl $MSR_IA32_SPEC_CTRL, %ecx
338338

@@ -426,3 +426,63 @@ For 32-bit we have the following conventions - kernel is built with
426426
.endm
427427

428428
#endif /* CONFIG_SMP */
429+
430+
#ifdef CONFIG_X86_64
431+
432+
/* rdi: arg1 ... normal C conventions. rax is saved/restored. */
433+
.macro THUNK name, func
434+
SYM_FUNC_START(\name)
435+
pushq %rbp
436+
movq %rsp, %rbp
437+
438+
pushq %rdi
439+
pushq %rsi
440+
pushq %rdx
441+
pushq %rcx
442+
pushq %rax
443+
pushq %r8
444+
pushq %r9
445+
pushq %r10
446+
pushq %r11
447+
448+
call \func
449+
450+
popq %r11
451+
popq %r10
452+
popq %r9
453+
popq %r8
454+
popq %rax
455+
popq %rcx
456+
popq %rdx
457+
popq %rsi
458+
popq %rdi
459+
popq %rbp
460+
RET
461+
SYM_FUNC_END(\name)
462+
_ASM_NOKPROBE(\name)
463+
.endm
464+
465+
#else /* CONFIG_X86_32 */
466+
467+
/* put return address in eax (arg1) */
468+
.macro THUNK name, func, put_ret_addr_in_eax=0
469+
SYM_CODE_START_NOALIGN(\name)
470+
pushl %eax
471+
pushl %ecx
472+
pushl %edx
473+
474+
.if \put_ret_addr_in_eax
475+
/* Place EIP in the arg1 */
476+
movl 3*4(%esp), %eax
477+
.endif
478+
479+
call \func
480+
popl %edx
481+
popl %ecx
482+
popl %eax
483+
RET
484+
_ASM_NOKPROBE(\name)
485+
SYM_CODE_END(\name)
486+
.endm
487+
488+
#endif

arch/x86/entry/entry.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/linkage.h>
88
#include <asm/msr-index.h>
99

10+
#include "calling.h"
11+
1012
.pushsection .noinstr.text, "ax"
1113

1214
SYM_FUNC_START(entry_ibpb)
@@ -20,3 +22,5 @@ SYM_FUNC_END(entry_ibpb)
2022
EXPORT_SYMBOL_GPL(entry_ibpb);
2123

2224
.popsection
25+
26+
THUNK warn_thunk_thunk, __warn_thunk

arch/x86/entry/entry_64.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL)
562562
#ifdef CONFIG_XEN_PV
563563
ALTERNATIVE "", "jmp xenpv_restore_regs_and_return_to_usermode", X86_FEATURE_XENPV
564564
#endif
565-
#ifdef CONFIG_PAGE_TABLE_ISOLATION
565+
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
566566
ALTERNATIVE "", "jmp .Lpti_restore_regs_and_return_to_usermode", X86_FEATURE_PTI
567567
#endif
568568

@@ -578,7 +578,7 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL)
578578
jnz .Lnative_iret
579579
ud2
580580

581-
#ifdef CONFIG_PAGE_TABLE_ISOLATION
581+
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
582582
.Lpti_restore_regs_and_return_to_usermode:
583583
POP_REGS pop_rdi=0
584584

@@ -1096,7 +1096,7 @@ SYM_CODE_END(error_return)
10961096
*
10971097
* Registers:
10981098
* %r14: Used to save/restore the CR3 of the interrupted context
1099-
* when PAGE_TABLE_ISOLATION is in use. Do not clobber.
1099+
* when MITIGATION_PAGE_TABLE_ISOLATION is in use. Do not clobber.
11001100
*/
11011101
SYM_CODE_START(asm_exc_nmi)
11021102
UNWIND_HINT_IRET_ENTRY

0 commit comments

Comments
 (0)