5.10.131-rc1 review
Subsystems (2)
Greg Kroah-Hartman
maintainerPATCH 87/130 x86,static_call: Use alternative RET encoding
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit ee88d363d15617ff50ac24fab0ffec11113b2aeb upstream.
In addition to teaching static_call about the new way to spell 'RET', there is an added complication in that static_call() is allowed to rewrite text before it is known which particular spelling is required.
In order to deal with this; have a static_call specific fixup in the apply_return() 'alternative' patching routine that will rewrite the static_call trampoline to match the definite sequence.
This in turn creates the problem of uniquely identifying static call trampolines. Currently trampolines are 8 bytes, the first 5 being the jmp.d32/ret sequence and the final 3 a byte sequence that spells out 'SCT'.
This sequence is used in __static_call_validate() to ensure it is patching a trampoline and not a random other jmp.d32. That is, false-positives shouldn't be plenty, but aren't a big concern.
OTOH the new __static_call_fixup() must not have false-positives, and 'SCT' decodes to the somewhat weird but semi plausible sequence:
push %rbx
rex.XB push %r12
Additionally, there are SLS concerns with immediate jumps. Combined it seems like a good moment to change the signature to a single 3 byte trap instruction that is unique to this usage and will not ever get generated by accident.
As such, change the signature to: '0x0f, 0xb9, 0xcc', which decodes to:
ud1 %esp, %ecx
--- arch/x86/include/asm/static_call.h | 17 ++++++++++++++++ arch/x86/kernel/alternative.c | 12 +++++++---- arch/x86/kernel/static_call.c | 38 ++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 5 deletions(-)
arch/x86/include/asm/static_call.h +17 -0
@@ -21,6 +21,16 @@* relative displacement across sections. */ +/* +* The trampoline is 8 bytes and of the general form: +* +* jmp.d32 \func +* ud1 %esp, %ecx +* +* That trailing #UD provides both a speculation stop and serves as a unique +* 3 byte signature identifying static call trampolines. Also see tramp_ud[] +* and __static_call_fixup(). +*/ #define __ARCH_DEFINE_STATIC_CALL_TRAMP (name, insns) \ asm(".pushsection .static_call.text, \"ax\" \n" \ ".align 4 \n" \
@@ -34,8 +44,13 @@#define ARCH_DEFINE_STATIC_CALL_TRAMP (name, func) \ __ARCH_DEFINE_STATIC_CALL_TRAMP(name, ".byte 0xe9; .long " #func " - (. + 4)") +#ifdef CONFIG_RETPOLINE +#define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP (name) \ + __ARCH_DEFINE_STATIC_CALL_TRAMP(name, "jmp __x86_return_thunk") +#else #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP (name) \ __ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; int3; nop; nop; nop") +#endif #define ARCH_ADD_TRAMP_KEY (name) \
@@ -44,4 +59,6 @@ ".long " STATIC_CALL_KEY_STR(name) " - . \n" \ ".popsection \n") +extern bool __static_call_fixup (void *tramp,u8 op,void *dest); +#endif /* _ASM_STATIC_CALL_H */
arch/x86/kernel/alternative.c +8 -4
@@ -693,18 +693,22 @@ void __init_or_module noinline apply_rets32 *s;for (s = start; s < end; s++) { -void *addr = (void *)s + *s; +void *dest =NULL , *addr = (void *)s + *s;struct insn insn;int len, ret;u8 bytes[16 ]; -u8 op1; +u8 op; ret =insn_decode_kernel (&insn, addr);if (WARN_ON_ONCE (ret <0 ))continue ; - op1 = insn.opcode.bytes[0 ]; -if (WARN_ON_ONCE (op1 !=JMP32_INSN_OPCODE )) + op = insn.opcode.bytes[0 ]; +if (op ==JMP32_INSN_OPCODE ) + dest = addr + insn.length + insn.immediate.value; + +if (__static_call_fixup (addr, op, dest) || +WARN_ON_ONCE (dest != &__x86_return_thunk))continue ; DPRINTK("return thunk at: %pS (%px) len: %d to: %pS",
arch/x86/kernel/static_call.c +37 -1
@@ -11,6 +11,13 @@ enum insn_type { RET = 3, /* tramp / site cond-tail-call */ }; +/* +* ud1 %esp, %ecx - a 3 byte #UD that is unique to trampolines, chosen such +* that there is no false-positive trampoline identification while also being a +* speculation stop. +*/ +static const u8 tramp_ud[] = {0x0f ,0xb9 ,0xcc }; +static const u8 retinsn[] = {RET_INSN_OPCODE ,0xcc ,0xcc ,0xcc ,0xcc };static void __ref __static_call_transform (void *insn,enum insn_type type,void *func)
@@ -32,7 +39,10 @@ static void __ref __static_call_transforbreak ;case RET : - code = &retinsn; +if (cpu_feature_enabled (X86_FEATURE_RETHUNK )) + code =text_gen_insn (JMP32_INSN_OPCODE , insn, &__x86_return_thunk); +else + code = &retinsn;break ; }
@@ -97,3 +107,29 @@ void arch_static_call_transform(void *simutex_unlock (&text_mutex); }EXPORT_SYMBOL_GPL (arch_static_call_transform); + +#ifdef CONFIG_RETPOLINE +/* +* This is called by apply_returns() to fix up static call trampolines, +* specifically ARCH_DEFINE_STATIC_CALL_NULL_TRAMP which is recorded as +* having a return trampoline. +* +* The problem is that static_call() is available before determining +* X86_FEATURE_RETHUNK and, by implication, running alternatives. +* +* This means that __static_call_transform() above can have overwritten the +* return trampoline and we now need to fix things up to be consistent. +*/ +bool __static_call_fixup (void *tramp,u8 op,void *dest) +{ +if (memcmp (tramp+5 , tramp_ud,3 )) { +/* Not a trampoline site, not our problem. */ +return false; + } + +if (op ==RET_INSN_OPCODE || dest == &__x86_return_thunk) +__static_call_transform (tramp,RET ,NULL ); + +return true; +} +#endif
Greg Kroah-Hartman
maintainerPATCH 88/130 x86/ftrace: Use alternative RET encoding
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 1f001e9da6bbf482311e45e48f53c2bd2179e59c upstream.
Use the return thunk in ftrace trampolines, if needed.
--- arch/x86/kernel/ftrace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/ftrace.c +5 -2
@@ -308,7 +308,7 @@ union ftrace_op_code_union { } __attribute__((packed)); }; -#define RET_SIZE 1 + IS_ENABLED(CONFIG_SLS) +#define RET_SIZE (IS_ENABLED(CONFIG_RETPOLINE) ? 5 : 1 + IS_ENABLED(CONFIG_SLS))static unsigned long create_trampoline (struct ftrace_ops *ops,unsigned int *tramp_size)
@@ -367,7 +367,10 @@ create_trampoline(struct ftrace_ops *ops/* The trampoline ends with ret(q) */ retq = (unsigned long )ftrace_stub; - ret =copy_from_kernel_nofault (ip, (void *)retq,RET_SIZE ); +if (cpu_feature_enabled (X86_FEATURE_RETHUNK )) +memcpy (ip,text_gen_insn (JMP32_INSN_OPCODE , ip, &__x86_return_thunk),JMP32_INSN_SIZE ); +else + ret =copy_from_kernel_nofault (ip, (void *)retq,RET_SIZE );if (WARN_ON (ret <0 )) goto fail;
Greg Kroah-Hartman
maintainerPATCH 89/130 x86/bpf: Use alternative RET encoding
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit d77cfe594ad50e0bf95d457e02ccd578791b2a15 upstream.
Use the return thunk in eBPF generated code, if needed.
--- arch/x86/net/bpf_jit_comp.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +18 -2
@@ -399,6 +399,22 @@ static void emit_indirect_jump(u8 **ppro *pprog = prog; } +static void emit_return (u8 **pprog,u8 *ip) +{ +u8 *prog = *pprog; +int cnt =0 ; + +if (cpu_feature_enabled (X86_FEATURE_RETHUNK )) { +emit_jump (&prog, &__x86_return_thunk, ip); + }else { +EMIT1 (0xC3 );/* ret */ +if (IS_ENABLED (CONFIG_SLS )) +EMIT1 (0xCC );/* int3 */ + } + + *pprog = prog; +} +/* * Generate the following code: *
@@ -1443,7 +1459,7 @@ emit_jmp: ctx->cleanup_addr = proglen;pop_callee_regs (&prog, callee_regs_used);EMIT1 (0xC9 );/* leave */ -EMIT1 (0xC3 );/* ret */ +emit_return (&prog, image + addrs[i -1 ] + (prog - temp));break ;default :
@@ -1884,7 +1900,7 @@ int arch_prepare_bpf_trampoline(struct bif (flags &BPF_TRAMP_F_SKIP_FRAME )/* skip our return address and return to parent */ EMIT4 (0x48 ,0x83 ,0xC4 ,8 );/* add rsp, 8 */ -EMIT1 (0xC3 );/* ret */ +emit_return (&prog, prog);/* Make sure the trampoline generation logic doesn't overflow */ if (WARN_ON_ONCE (prog > (u8 *)image_end -BPF_INSN_SAFETY )) { ret = -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 90/130 x86/kvm: Fix SETcc emulation for return thunks
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit af2e140f34208a5dfb6b7a8ad2d56bda88f0524d upstream.
Prepare the SETcc fastop stuff for when RET can be larger still.
The tricky bit here is that the expressions should not only be constant C expressions, but also absolute GAS expressions. This means no ?: and 'true' is ~0.
Also ensure em_setcc() has the same alignment as the actual FOP_SETCC() ops, this ensures there cannot be an alignment hole between em_setcc() and the first op.
Additionally, add a .skip directive to the FOP_SETCC() macro to fill any remaining space with INT3 traps; however the primary purpose of this directive is to generate AS warnings when the remaining space goes negative. Which is a very good indication the alignment magic went side-ways.
--- arch/x86/kvm/emulate.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
arch/x86/kvm/emulate.c +14 -12
@@ -322,13 +322,15 @@ static int fastop(struct x86_emulate_ctx#define FOP_RET (name) \ __FOP_RET(#name) -#define FOP_START (op) \ +#define __FOP_START (op, align) \ extern void em_##op(struct fastop *fake); \ asm(".pushsection .text, \"ax\" \n\t" \ ".global em_" #op " \n\t" \ - ".align " __stringify(FASTOP_SIZE) " \n\t" \ + ".align " __stringify(align) " \n\t" \ "em_" #op ":\n\t" +#define FOP_START (op) __FOP_START(op, FASTOP_SIZE) +#define FOP_END \ ".popsection")
@@ -432,15 +434,14 @@ static int fastop(struct x86_emulate_ctx/* * Depending on .config the SETcc functions look like: * -* SETcc %al [3 bytes] -* RET [1 byte] -* INT3 [1 byte; CONFIG_SLS] -* -* Which gives possible sizes 4 or 5. When rounded up to the -* next power-of-two alignment they become 4 or 8. +* SETcc %al [3 bytes] +* RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETPOLINE] +* INT3 [1 byte; CONFIG_SLS] */ -#define SETCC_LENGTH (4 + IS_ENABLED(CONFIG_SLS)) -#define SETCC_ALIGN (4 << IS_ENABLED(CONFIG_SLS)) +#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETPOLINE)) + \ + IS_ENABLED(CONFIG_SLS)) +#define SETCC_LENGTH (3 + RET_LENGTH) +#define SETCC_ALIGN (4 << ((SETCC_LENGTH > 4) & 1) << ((SETCC_LENGTH > 8) & 1))static_assert (SETCC_LENGTH <=SETCC_ALIGN );#define FOP_SETCC (op) \
@@ -448,14 +449,15 @@ static_assert(SETCC_LENGTH <= SETCC_ALIG ".type " #op ", @function \n\t" \ #op ": \n\t" \ #op " %al \n\t" \ - __FOP_RET(#op) + __FOP_RET(#op) \ + ".skip " __stringify(SETCC_ALIGN) " - (.-" #op "), 0xcc \n\t" asm(".pushsection .fixup, \"ax\"\n" ".global kvm_fastop_exception \n" "kvm_fastop_exception: xor %esi, %esi; " ASM_RET ".popsection" ); -FOP_START(setcc) +__FOP_START(setcc, SETCC_ALIGN) FOP_SETCC(seto) FOP_SETCC(setno) FOP_SETCC(setc)
Greg Kroah-Hartman
maintainerPATCH 91/130 x86/vsyscall_emu/64: Dont use RET in vsyscall emulation
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 15583e514eb16744b80be85dea0774ece153177d upstream.
This is userspace code and doesn't play by the normal kernel rules.
--- arch/x86/entry/vsyscall/vsyscall_emu_64.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/entry/vsyscall/vsyscall_emu_64.S +6 -3
@@ -19,17 +19,20 @@ __vsyscall_page: mov $__NR_gettimeofday, %rax syscall - RET + ret + int3 .balign 1024, 0xcc mov $__NR_time, %rax syscall - RET + ret + int3 .balign 1024, 0xcc mov $__NR_getcpu, %rax syscall - RET + ret + int3 .balign 4096, 0xcc
Greg Kroah-Hartman
maintainerPATCH 92/130 x86/sev: Avoid using __x86_return_thunk
In reply to Greg Kroah-HartmanFrom: Kim Phillips <[email protected]>
commit 0ee9073000e8791f8b134a8ded31bcc767f7f232 upstream.
Specifically, it's because __enc_copy() encrypts the kernel after being relocated outside the kernel in sme_encrypt_execute(), and the RET macro's jmp offset isn't amended prior to execution.
--- arch/x86/mm/mem_encrypt_boot.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/mm/mem_encrypt_boot.S +6 -2
@@ -65,7 +65,9 @@ SYM_FUNC_START(sme_encrypt_execute) movq %rbp, %rsp /* Restore original stack pointer */ pop %rbp - RET + /* Offset to __x86_return_thunk would be wrong here */ + ret + int3 SYM_FUNC_END(sme_encrypt_execute) SYM_FUNC_START(__enc_copy)
@@ -151,6 +153,8 @@ SYM_FUNC_START(__enc_copy) pop %r12 pop %r15 - RET + /* Offset to __x86_return_thunk would be wrong here */ + ret + int3 .L__enc_copy_end: SYM_FUNC_END(__enc_copy)
Greg Kroah-Hartman
maintainerPATCH 93/130 x86: Use return-thunk in asm code
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit aa3d480315ba6c3025a60958e1981072ea37c3df upstream.
Use the return thunk in asm code. If the thunk isn't needed, it will get patched into a RET instruction during boot by apply_returns().
Since alternatives can't handle relocations outside of the first instruction, putting a 'jmp __x86_return_thunk' in one is not valid, therefore carve out the memmove ERMS path into a separate label and jump to it.
--- arch/x86/entry/vdso/Makefile | 1 + arch/x86/include/asm/linkage.h | 8 ++++++++ arch/x86/lib/memmove_64.S | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-)
arch/x86/entry/vdso/Makefile +1 -0
@@ -91,6 +91,7 @@ endif endif $(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) +$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO # # vDSO code runs in userspace and -pg doesn't help with profiling anyway.
arch/x86/include/asm/linkage.h +8 -0
@@ -18,19 +18,27 @@#define __ALIGN_STR __stringify(__ALIGN)#endif +#if defined(CONFIG_RETPOLINE ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO ) +#define RET jmp __x86_return_thunk +#else /* CONFIG_RETPOLINE */ #ifdef CONFIG_SLS #define RET ret; int3#else #define RET ret#endif +#endif /* CONFIG_RETPOLINE */ #else /* __ASSEMBLY__ */ +#if defined(CONFIG_RETPOLINE ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO ) +#define ASM_RET "jmp __x86_return_thunk\n\t" +#else /* CONFIG_RETPOLINE */ #ifdef CONFIG_SLS #define ASM_RET "ret; int3\n\t"#else #define ASM_RET "ret\n\t"#endif +#endif /* CONFIG_RETPOLINE */ #endif /* __ASSEMBLY__ */
arch/x86/lib/memmove_64.S +6 -1
@@ -40,7 +40,7 @@ SYM_FUNC_START(__memmove) /* FSRM implies ERMS => no length checks, do the copy directly */ .Lmemmove_begin_forward: ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM - ALTERNATIVE "", __stringify(movq %rdx, %rcx; rep movsb; RET), X86_FEATURE_ERMS + ALTERNATIVE "", "jmp .Lmemmove_erms", X86_FEATURE_ERMS /* * movsq instruction have many startup latency
@@ -206,6 +206,11 @@ SYM_FUNC_START(__memmove) movb %r11b, (%rdi) 13: RET + +.Lmemmove_erms: + movq %rdx, %rcx + rep movsb + RET SYM_FUNC_END(__memmove) SYM_FUNC_END_ALIAS(memmove) EXPORT_SYMBOL(__memmove)
Greg Kroah-Hartman
maintainerPATCH 94/130 objtool: Treat .text.__x86.* as noinstr
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 951ddecf435659553ed15a9214e153a3af43a9a1 upstream.
Needed because zen_untrain_ret() will be called from noinstr code.
Also makes sense since the thunks MUST NOT contain instrumentation nor be poked with dynamic instrumentation.
--- tools/objtool/check.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/check.c +2 -1
@@ -366,7 +366,8 @@ static int decode_instructions(struct ob sec->text = true;if (!strcmp (sec->name,".noinstr.text" ) || - !strcmp (sec->name,".entry.text" )) + !strcmp (sec->name,".entry.text" ) || + !strncmp (sec->name,".text.__x86." ,12 )) sec->noinstr = true;for (offset =0 ; offset < sec->len; offset += insn->len) {
Greg Kroah-Hartman
maintainerPATCH 95/130 x86: Add magic AMD return-thunk
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit a149180fbcf336e97ce4eb2cdc13672727feb94d upstream.
Note: needs to be in a section distinct from Retpolines such that the Retpoline RET substitution cannot possibly use immediate jumps.
ORC unwinding for zen_untrain_ret() and __x86_return_thunk() is a little tricky but works due to the fact that zen_untrain_ret() doesn't have any stack ops and as such will emit a single ORC entry at the start (+0x3f).
Meanwhile, unwinding an IP, including the __x86_return_thunk() one (+0x40) will search for the largest ORC entry smaller or equal to the IP, these will find the one ORC entry (+0x3f) and all works.
[ Alexandre: SVM part. ]
[ bp: Build fix, massages. ]
[bwh: Backported to 5.10: SEV-ES is not supported, so drop the change
in arch/x86/kvm/svm/vmenter.S]
--- arch/x86/entry/entry_64.S | 6 ++ arch/x86/entry/entry_64_compat.S | 4 + arch/x86/include/asm/cpufeatures.h | 1 arch/x86/include/asm/disabled-features.h | 3 - arch/x86/include/asm/nospec-branch.h | 17 ++++++++ arch/x86/kernel/vmlinux.lds.S | 2 arch/x86/kvm/svm/vmenter.S | 9 ++++ arch/x86/lib/retpoline.S | 63 +++++++++++++++++++++++++++++-- tools/objtool/check.c | 20 ++++++++- 9 files changed, 117 insertions(+), 8 deletions(-)
arch/x86/entry/entry_64.S +6 -0
@@ -102,6 +102,7 @@ SYM_CODE_START(entry_SYSCALL_64) movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp SYM_INNER_LABEL(entry_SYSCALL_64_safe_stack, SYM_L_GLOBAL) + UNTRAIN_RET /* Construct struct pt_regs on stack */ pushq $__USER_DS /* pt_regs->ss */
@@ -675,6 +676,7 @@ native_irq_return_ldt: pushq %rdi /* Stash user RDI */ swapgs /* to kernel GS */ SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi /* to kernel CR3 */ + UNTRAIN_RET movq PER_CPU_VAR(espfix_waddr), %rdi movq %rax, (0*8)(%rdi) /* user RAX */
@@ -910,6 +912,7 @@ SYM_CODE_START_LOCAL(paranoid_entry) * be retrieved from a kernel internal table. */ SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg=%rax save_reg=%r14 + UNTRAIN_RET /* * Handling GSBASE depends on the availability of FSGSBASE.
@@ -1022,6 +1025,7 @@ SYM_CODE_START_LOCAL(error_entry) FENCE_SWAPGS_USER_ENTRY /* We have user CR3. Change to kernel CR3. */ SWITCH_TO_KERNEL_CR3 scratch_reg=%rax + UNTRAIN_RET .Lerror_entry_from_usermode_after_swapgs: /* Put us onto the real thread stack. */
@@ -1077,6 +1081,7 @@ SYM_CODE_START_LOCAL(error_entry) SWAPGS FENCE_SWAPGS_USER_ENTRY SWITCH_TO_KERNEL_CR3 scratch_reg=%rax + UNTRAIN_RET /* * Pretend that the exception came from user mode: set up pt_regs
@@ -1171,6 +1176,7 @@ SYM_CODE_START(asm_exc_nmi) movq %rsp, %rdx movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp UNWIND_HINT_IRET_REGS base=%rdx offset=8 + UNTRAIN_RET pushq 5*8(%rdx) /* pt_regs->ss */ pushq 4*8(%rdx) /* pt_regs->rsp */ pushq 3*8(%rdx) /* pt_regs->flags */
arch/x86/entry/entry_64_compat.S +4 -0
@@ -14,6 +14,7 @@ #include <asm/irqflags.h> #include <asm/asm.h> #include <asm/smap.h> +#include <asm/nospec-branch.h> #include <linux/linkage.h> #include <linux/err.h>
@@ -71,6 +72,7 @@ SYM_CODE_START(entry_SYSENTER_compat) pushq $__USER32_CS /* pt_regs->cs */ pushq $0 /* pt_regs->ip = 0 (placeholder) */ SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL) + UNTRAIN_RET /* * User tracing code (ptrace or signal handlers) might assume that
@@ -211,6 +213,7 @@ SYM_CODE_START(entry_SYSCALL_compat) movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp SYM_INNER_LABEL(entry_SYSCALL_compat_safe_stack, SYM_L_GLOBAL) + UNTRAIN_RET /* Construct struct pt_regs on stack */ pushq $__USER32_DS /* pt_regs->ss */
@@ -377,6 +380,7 @@ SYM_CODE_START(entry_INT80_compat) pushq (%rdi) /* pt_regs->di */ .Lint80_keep_stack: + UNTRAIN_RET pushq %rsi /* pt_regs->si */ xorl %esi, %esi /* nospec si */ pushq %rdx /* pt_regs->dx */
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -297,6 +297,7 @@#define X86_FEATURE_RETPOLINE (11*32+12)/* "" Generic Retpoline mitigation for Spectre variant 2 */ #define X86_FEATURE_RETPOLINE_LFENCE (11*32+13)/* "" Use LFENCE for Spectre variant 2 */ #define X86_FEATURE_RETHUNK (11*32+14)/* "" Use REturn THUNK */ +#define X86_FEATURE_UNRET (11*32+15)/* "" AMD BTB untrain return */ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX512_BF16 (12*32+ 5)/* AVX512 BFLOAT16 instructions */
arch/x86/include/asm/disabled-features.h +2 -1
@@ -61,7 +61,8 @@#else # define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \ (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)) | \ - (1 << (X86_FEATURE_RETHUNK & 31))) + (1 << (X86_FEATURE_RETHUNK & 31)) | \ + (1 << (X86_FEATURE_UNRET & 31)))#endif /* Force disable because it's broken beyond repair */
arch/x86/include/asm/nospec-branch.h +17 -0
@@ -112,6 +112,22 @@#endif .endm +/* + * Mitigate RETBleed for AMD/Hygon Zen uarch. Requires KERNEL CR3 because the + * return thunk isn't mapped into the userspace tables (then again, AMD + * typically has NO_MELTDOWN). + * + * Doesn't clobber any registers but does require a stable stack. + * + * As such, this must be placed after every *SWITCH_TO_KERNEL_CR3 at a point + * where we have a stack but before any RET instruction. + */ +.macro UNTRAIN_RET +#ifdef CONFIG_RETPOLINE +ALTERNATIVE "" ,"call zen_untrain_ret" ,X86_FEATURE_UNRET +#endif +.endm +#else /* __ASSEMBLY__ */ #define ANNOTATE_RETPOLINE_SAFE \
@@ -121,6 +137,7 @@".popsection\n\t" extern void __x86_return_thunk(void); +extern void zen_untrain_ret (void );#ifdef CONFIG_RETPOLINE
arch/x86/kernel/vmlinux.lds.S +1 -1
@@ -142,7 +142,7 @@ SECTIONS #ifdef CONFIG_RETPOLINE __indirect_thunk_start = .; - *(.text.__x86.indirect_thunk) + *(.text.__x86.*) __indirect_thunk_end = .; #endif } :text =0xcccc
arch/x86/kvm/svm/vmenter.S +9 -0
@@ -129,6 +129,15 @@ SYM_FUNC_START(__svm_vcpu_run) #endif /* + * Mitigate RETBleed for AMD/Hygon Zen uarch. RET should be + * untrained as soon as we exit the VM and are back to the + * kernel. This should be done before re-enabling interrupts + * because interrupt handlers won't sanitize 'ret' if the return is + * from the kernel. + */ + UNTRAIN_RET + + /* * Clear all general purpose registers except RSP and RAX to prevent * speculative use of the guest's values, even those that are reloaded * via the stack. In theory, an L1 cache miss when restoring registers
arch/x86/lib/retpoline.S +60 -3
70 lines not on this page · raw message
tools/objtool/check.c +17 -3
@@ -1082,7 +1082,7 @@ static void add_retpoline_call(struct obannotate_call_site (file, insn, false); } -static void add_return_call (struct objtool_file *file,struct instruction *insn) +static void add_return_call (struct objtool_file *file,struct instruction *insn,bool add) {/* * Return thunk tail calls are really just returns in disguise,
@@ -1092,7 +1092,7 @@ static void add_return_call(struct objto insn->retpoline_safe = true;/* Skip the non-text sections, specially .discard ones */ -if (insn->sec->text) +if (add && insn->sec->text)list_add_tail (&insn->call_node, &file->return_thunk_list); }
@@ -1121,7 +1121,7 @@ static int add_jump_destinations(structadd_retpoline_call (file, insn);continue ; }else if (reloc->sym->return_thunk) { -add_return_call (file, insn); +add_return_call (file, insn, true);continue ; }else if (insn->func) {/* internal or external sibling call (with reloc) */
@@ -1138,6 +1138,7 @@ static int add_jump_destinations(struct insn->jump_dest =find_insn (file, dest_sec, dest_off);if (!insn->jump_dest) { +struct symbol *sym =find_symbol_by_offset (dest_sec, dest_off);/* * This is a special case where an alt instruction
@@ -1147,6 +1148,19 @@ static int add_jump_destinations(structif (!strcmp (insn->sec->name,".altinstr_replacement" ))continue ; +/* +* This is a special case for zen_untrain_ret(). +* It jumps to __x86_return_thunk(), but objtool +* can't find the thunk's starting RET +* instruction, because the RET is also in the +* middle of another instruction. Objtool only +* knows about the outer instruction. +*/ +if (sym && sym->return_thunk) { +add_return_call (file, insn, false); +continue ; + } +WARN_FUNC ("can't find jump dest instruction at %s+0x%lx" , insn->sec, insn->offset, dest_sec->name, dest_off);
Greg Kroah-Hartman
maintainerPATCH 96/130 x86/bugs: Report AMD retbleed vulnerability
In reply to Greg Kroah-HartmanFrom: Alexandre Chartre <[email protected]>
commit 6b80b59b3555706508008f1f127b5412c89c7fd8 upstream.
Report that AMD x86 CPUs are vulnerable to the RETBleed (Arbitrary Speculative Code Execution with Return Instructions) attack.
[peterz: add hygon]
[kim: invert parity; fam15h]
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/bugs.c | 13 +++++++++++++ arch/x86/kernel/cpu/common.c | 19 +++++++++++++++++++ drivers/base/cpu.c | 8 ++++++++ include/linux/cpu.h | 2 ++ 5 files changed, 43 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -426,5 +426,6 @@#define X86_BUG_ITLB_MULTIHIT X86_BUG(23)/* CPU may incur MCE during certain page attribute changes */ #define X86_BUG_SRBDS X86_BUG(24)/* CPU may leak RNG bits if not mitigated */ #define X86_BUG_MMIO_STALE_DATA X86_BUG(25)/* CPU is affected by Processor MMIO Stale Data vulnerabilities */ +#define X86_BUG_RETBLEED X86_BUG(26)/* CPU is affected by RETBleed */ #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/bugs.c +13 -0
@@ -1917,6 +1917,11 @@ static ssize_t srbds_show_state(char *bureturn sprintf (buf,"%s\n" , srbds_strings[srbds_mitigation]); } +static ssize_t retbleed_show_state (char *buf) +{ +return sprintf (buf,"Vulnerable\n" ); +} +static ssize_t cpu_show_common (struct device *dev,struct device_attribute *attr,char *buf,unsigned int bug) {
@@ -1962,6 +1967,9 @@ static ssize_t cpu_show_common(struct decase X86_BUG_MMIO_STALE_DATA :return mmio_stale_data_show_state (buf); +case X86_BUG_RETBLEED : +return retbleed_show_state (buf); +default :break ; }
@@ -2018,4 +2026,9 @@ ssize_t cpu_show_mmio_stale_data(struct {return cpu_show_common (dev, attr, buf,X86_BUG_MMIO_STALE_DATA ); } + +ssize_t cpu_show_retbleed (struct device *dev,struct device_attribute *attr,char *buf) +{ +return cpu_show_common (dev, attr, buf,X86_BUG_RETBLEED ); +}#endif
arch/x86/kernel/cpu/common.c +19 -0
@@ -1092,16 +1092,27 @@ static const __initconst struct x86_cpu_ {} }; +#define VULNBL (vendor, family, model, blacklist) \ + X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, blacklist) +#define VULNBL_INTEL_STEPPINGS (model, steppings, issues) \ X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(INTEL, 6, \ INTEL_FAM6_##model, steppings, \ X86_FEATURE_ANY, issues) +#define VULNBL_AMD (family, blacklist) \ + VULNBL(AMD, family, X86_MODEL_ANY, blacklist) + +#define VULNBL_HYGON (family, blacklist) \ + VULNBL(HYGON, family, X86_MODEL_ANY, blacklist) +#define SRBDS BIT(0)/* CPU is affected by X86_BUG_MMIO_STALE_DATA */ #define MMIO BIT(1)/* CPU is affected by Shared Buffers Data Sampling (SBDS), a variant of X86_BUG_MMIO_STALE_DATA */ #define MMIO_SBDS BIT(2) +/* CPU is affected by RETbleed, speculating where you would not expect it */ +#define RETBLEED BIT(3)static const struct x86_cpu_id cpu_vuln_blacklist[]__initconst = {VULNBL_INTEL_STEPPINGS (IVYBRIDGE ,X86_STEPPING_ANY ,SRBDS ),
@@ -1134,6 +1145,11 @@ static const struct x86_cpu_id cpu_vuln_VULNBL_INTEL_STEPPINGS (ATOM_TREMONT ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS ),VULNBL_INTEL_STEPPINGS (ATOM_TREMONT_D ,X86_STEPPING_ANY ,MMIO ),VULNBL_INTEL_STEPPINGS (ATOM_TREMONT_L ,X86_STEPPINGS (0x0 ,0x0 ),MMIO |MMIO_SBDS ), + +VULNBL_AMD (0x15 ,RETBLEED ), +VULNBL_AMD (0x16 ,RETBLEED ), +VULNBL_AMD (0x17 ,RETBLEED ), + VULNBL_HYGON(0x18, RETBLEED), {} };
@@ -1235,6 +1251,9 @@ static void __init cpu_set_bug_bits(stru !arch_cap_mmio_immune(ia32_cap))setup_force_cpu_bug (X86_BUG_MMIO_STALE_DATA ); +if (cpu_matches (cpu_vuln_blacklist,RETBLEED )) +setup_force_cpu_bug (X86_BUG_RETBLEED ); +if (cpu_matches (cpu_vuln_whitelist,NO_MELTDOWN ))return ;
drivers/base/cpu.c +8 -0
@@ -572,6 +572,12 @@ ssize_t __weak cpu_show_mmio_stale_data(return sysfs_emit (buf,"Not affected\n" ); } +ssize_t __weak cpu_show_retbleed (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"Not affected\n" ); +} + static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
@@ -582,6 +588,7 @@ static DEVICE_ATTR(tsx_async_abort, 0444 static DEVICE_ATTR(itlb_multihit, 0444, cpu_show_itlb_multihit, NULL); static DEVICE_ATTR(srbds, 0444, cpu_show_srbds, NULL); static DEVICE_ATTR(mmio_stale_data, 0444, cpu_show_mmio_stale_data, NULL); +static DEVICE_ATTR(retbleed, 0444, cpu_show_retbleed, NULL);static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr,
@@ -594,6 +601,7 @@ static struct attribute *cpu_root_vulner &dev_attr_itlb_multihit.attr, &dev_attr_srbds.attr, &dev_attr_mmio_stale_data.attr, + &dev_attr_retbleed.attr, NULL };
include/linux/cpu.h +2 -0
@@ -68,6 +68,8 @@ extern ssize_t cpu_show_srbds(struct devextern ssize_t cpu_show_mmio_stale_data (struct device *dev,struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_retbleed (struct device *dev, +struct device_attribute *attr,char *buf); extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata,
Greg Kroah-Hartman
maintainerPATCH 97/130 x86/bugs: Add AMD retbleed= boot parameter
In reply to Greg Kroah-HartmanFrom: Alexandre Chartre <[email protected]>
commit 7fbf47c7ce50b38a64576b150e7011ae73d54669 upstream.
Add the "retbleed=<value>" boot parameter to select a mitigation for RETBleed. Possible values are "off", "auto" and "unret" (JMP2RET mitigation). The default value is "auto".
Currently, "retbleed=auto" will select the unret mitigation on AMD and Hygon and no mitigation on Intel (JMP2RET is not effective on Intel).
[peterz: rebase; add hygon]
[jpoimboe: cleanups]
--- Documentation/admin-guide/kernel-parameters.txt | 15 +++ arch/x86/Kconfig | 3 arch/x86/kernel/cpu/bugs.c | 108 +++++++++++++++++++++++- 3 files changed, 125 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +15 -0
@@ -4656,6 +4656,21 @@ retain_initrd [RAM] Keep initrd memory after extraction + retbleed= [X86] Control mitigation of RETBleed (Arbitrary + Speculative Code Execution with Return Instructions) + vulnerability. + + off - unconditionally disable + auto - automatically select a migitation + unret - force enable untrained return thunks, + only effective on AMD Zen {1,2} + based systems. + + Selecting 'auto' will choose a mitigation method at run + time according to the CPU. + + Not specifying this option is equivalent to retbleed=auto. + rfkill.default_state= 0 "airplane mode". All wifi, bluetooth, wimax, gps, fm, etc. communication is blocked by default.
arch/x86/Kconfig +3 -0
@@ -465,6 +465,9 @@ config RETPOLINE config CC_HAS_SLS def_bool $(cc-option,-mharden-sls=all) +config CC_HAS_RETURN_THUNK + def_bool $(cc-option,-mfunction-return=thunk-extern) + config SLS bool "Mitigate Straight-Line-Speculation" depends on CC_HAS_SLS && X86_64
arch/x86/kernel/cpu/bugs.c +107 -1
132 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 98/130 x86/bugs: Enable STIBP for JMP2RET
In reply to Greg Kroah-HartmanFrom: Kim Phillips <[email protected]>
commit e8ec1b6e08a2102d8755ccb06fa26d540f26a2fa upstream.
For untrained return thunks to be fully effective, STIBP must be enabled or SMT disabled.
--- Documentation/admin-guide/kernel-parameters.txt | 16 ++++-- arch/x86/kernel/cpu/bugs.c | 58 +++++++++++++++++++----- 2 files changed, 57 insertions(+), 17 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +11 -5
@@ -4660,11 +4660,17 @@ Speculative Code Execution with Return Instructions) vulnerability. - off - unconditionally disable - auto - automatically select a migitation - unret - force enable untrained return thunks, - only effective on AMD Zen {1,2} - based systems. + off - no mitigation + auto - automatically select a migitation + auto,nosmt - automatically select a mitigation, + disabling SMT if necessary for + the full mitigation (only on Zen1 + and older without STIBP). + unret - force enable untrained return thunks, + only effective on AMD f15h-f17h + based systems. + unret,nosmt - like unret, will disable SMT when STIBP + is not available. Selecting 'auto' will choose a mitigation method at run time according to the CPU.
arch/x86/kernel/cpu/bugs.c +46 -12
87 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 99/130 x86/bugs: Keep a per-CPU IA32_SPEC_CTRL value
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit caa0ff24d5d0e02abce5e65c3d2b7f20a6617be5 upstream.
Due to TIF_SSBD and TIF_SPEC_IB the actual IA32_SPEC_CTRL value can differ from x86_spec_ctrl_base. As such, keep a per-CPU value reflecting the current task's MSR content.
[jpoimboe: rename]
--- arch/x86/include/asm/nospec-branch.h | 1 + arch/x86/kernel/cpu/bugs.c | 28 +++++++++++++++++++++++----- arch/x86/kernel/process.c | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-)
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -254,6 +254,7 @@ static inline void indirect_branch_predi/* The Intel SPEC CTRL MSR base value cache */ extern u64 x86_spec_ctrl_base; +extern void write_spec_ctrl_current (u64 val);/* * With retpoline, we must use IBRS to restrict branch prediction
arch/x86/kernel/cpu/bugs.c +23 -5
@@ -48,12 +48,30 @@ static void __init taa_select_mitigationstatic void __init mmio_select_mitigation (void );static void __init srbds_select_mitigation (void ); -/* The base value of the SPEC_CTRL MSR that always has to be preserved. */ +/* The base value of the SPEC_CTRL MSR without task-specific bits set */ u64 x86_spec_ctrl_base;EXPORT_SYMBOL_GPL (x86_spec_ctrl_base); + +/* The current value of the SPEC_CTRL MSR with task-specific bits set */ +DEFINE_PER_CPU (u64, x86_spec_ctrl_current); +EXPORT_SYMBOL_GPL (x86_spec_ctrl_current); +static DEFINE_MUTEX (spec_ctrl_mutex);/* +* Keep track of the SPEC_CTRL MSR value for the current task, which may differ +* from x86_spec_ctrl_base due to STIBP/SSB in __speculation_ctrl_update(). +*/ +void write_spec_ctrl_current (u64 val) +{ +if (this_cpu_read (x86_spec_ctrl_current) == val) +return ; + +this_cpu_write (x86_spec_ctrl_current, val); +wrmsrl (MSR_IA32_SPEC_CTRL , val); +} + +/* * The vendor and possibly platform specific bits which can be modified in * x86_spec_ctrl_base. */
@@ -1235,7 +1253,7 @@ static void __init spectre_v2_select_mitif (spectre_v2_in_eibrs_mode (mode)) {/* Force it so VMEXIT will restore correctly */ x86_spec_ctrl_base |=SPEC_CTRL_IBRS ; -wrmsrl (MSR_IA32_SPEC_CTRL , x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base); }switch (mode) {
@@ -1290,7 +1308,7 @@ static void __init spectre_v2_select_mitstatic void update_stibp_msr (void * __unused) { -wrmsrl (MSR_IA32_SPEC_CTRL , x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base); }/* Update x86_spec_ctrl_base in case SMT state changed. */
@@ -1533,7 +1551,7 @@ static enum ssb_mitigation __init __ssb_x86_amd_ssb_disable (); }else { x86_spec_ctrl_base |=SPEC_CTRL_SSBD ; -wrmsrl (MSR_IA32_SPEC_CTRL , x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base); } }
@@ -1751,7 +1769,7 @@ int arch_prctl_spec_ctrl_get(struct taskvoid x86_spec_ctrl_setup_ap (void ) {if (boot_cpu_has (X86_FEATURE_MSR_SPEC_CTRL )) -wrmsrl (MSR_IA32_SPEC_CTRL , x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base);if (ssb_mode ==SPEC_STORE_BYPASS_DISABLE )x86_amd_ssb_disable ();
arch/x86/kernel/process.c +1 -1
@@ -556,7 +556,7 @@ static __always_inline void __speculatio }if (updmsr) -wrmsrl (MSR_IA32_SPEC_CTRL , msr); +write_spec_ctrl_current (msr); }static unsigned long speculation_ctrl_update_tif (struct task_struct *tsk)
Greg Kroah-Hartman
maintainerPATCH 100/130 x86/entry: Add kernel IBRS implementation
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 2dbb887e875b1de3ca8f40ddf26bcfe55798c609 upstream.
Implement Kernel IBRS - currently the only known option to mitigate RSB underflow speculation issues on Skylake hardware.
Note: since IBRS_ENTER requires fuller context established than UNTRAIN_RET, it must be placed after it. However, since UNTRAIN_RET itself implies a RET, it must come after IBRS_ENTER. This means IBRS_ENTER needs to also move UNTRAIN_RET.
Note 2: KERNEL_IBRS is sub-optimal for XenPV.
--- arch/x86/entry/calling.h | 58 +++++++++++++++++++++++++++++++++++++ arch/x86/entry/entry_64.S | 44 ++++++++++++++++++++++++---- arch/x86/entry/entry_64_compat.S | 17 ++++++++-- arch/x86/include/asm/cpufeatures.h | 2 - 4 files changed, 111 insertions(+), 10 deletions(-)
arch/x86/entry/calling.h +58 -0
@@ -6,6 +6,8 @@#include <asm/percpu.h> #include <asm/asm-offsets.h> #include <asm/processor-flags.h> +#include <asm/msr.h> +#include <asm/nospec-branch.h> /*
@@ -309,6 +311,62 @@ For 32-bit we have the following convent#endif /* +* IBRS kernel mitigation for Spectre_v2. +* +* Assumes full context is established (PUSH_REGS, CR3 and GS) and it clobbers +* the regs it uses (AX, CX, DX). Must be called before the first RET +* instruction (NOTE! UNTRAIN_RET includes a RET instruction) +* +* The optional argument is used to save/restore the current value, +* which is used on the paranoid paths. +* +* Assumes x86_spec_ctrl_{base,current} to have SPEC_CTRL_IBRS set. +*/ +.macro IBRS_ENTER save_reg + ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS + movl $MSR_IA32_SPEC_CTRL, %ecx + +.ifnb \save_reg + rdmsr + shl $32, %rdx + or %rdx, %rax + mov %rax, \save_reg + test $SPEC_CTRL_IBRS, %eax + jz .Ldo_wrmsr_\@ + lfence + jmp .Lend_\@ +.Ldo_wrmsr_\@: +.endif + + movq PER_CPU_VAR(x86_spec_ctrl_current), %rdx + movl %edx, %eax + shr $32, %rdx + wrmsr +.Lend_\@: +.endm + +/* + * Similar to IBRS_ENTER, requires KERNEL GS,CR3 and clobbers (AX, CX, DX) + * regs. Must be called after the last RET. + */ +.macro IBRS_EXIT save_reg + ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS + movl $MSR_IA32_SPEC_CTRL, %ecx + +.ifnb \save_reg + mov \save_reg, %rdx +.else + movq PER_CPU_VAR(x86_spec_ctrl_current), %rdx + andl $(~SPEC_CTRL_IBRS), %edx +.endif + + movl %edx, %eax + shr $32, %rdx + wrmsr +.Lend_\@: +.endm + +/* * Mitigate Spectre v1 for conditional swapgs code paths. * * FENCE_SWAPGS_USER_ENTRY is used in the user entry swapgs code path, to
arch/x86/entry/entry_64.S +39 -5
135 lines not on this page · raw message
arch/x86/entry/entry_64_compat.S +13 -4
@@ -4,7 +4,6 @@ * * Copyright 2000-2002 Andi Kleen, SuSE Labs. */ -#include "calling.h" #include <asm/asm-offsets.h> #include <asm/current.h> #include <asm/errno.h>
@@ -18,6 +17,8 @@ #include <linux/linkage.h> #include <linux/err.h> +#include "calling.h" + .section .entry.text, "ax" /*
@@ -72,7 +73,6 @@ SYM_CODE_START(entry_SYSENTER_compat) pushq $__USER32_CS /* pt_regs->cs */ pushq $0 /* pt_regs->ip = 0 (placeholder) */ SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL) - UNTRAIN_RET /* * User tracing code (ptrace or signal handlers) might assume that
@@ -114,6 +114,9 @@ SYM_INNER_LABEL(entry_SYSENTER_compat_af cld + IBRS_ENTER + UNTRAIN_RET + /* * SYSENTER doesn't filter flags, so we need to clear NT and AC * ourselves. To save a few cycles, we can check whether
@@ -213,7 +216,6 @@ SYM_CODE_START(entry_SYSCALL_compat) movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp SYM_INNER_LABEL(entry_SYSCALL_compat_safe_stack, SYM_L_GLOBAL) - UNTRAIN_RET /* Construct struct pt_regs on stack */ pushq $__USER32_DS /* pt_regs->ss */
@@ -255,6 +257,9 @@ SYM_INNER_LABEL(entry_SYSCALL_compat_aft UNWIND_HINT_REGS + IBRS_ENTER + UNTRAIN_RET + movq %rsp, %rdi call do_fast_syscall_32 /* XEN PV guests always use IRET path */
@@ -269,6 +274,8 @@ sysret32_from_system_call: */ STACKLEAK_ERASE + IBRS_EXIT + movq RBX(%rsp), %rbx /* pt_regs->rbx */ movq RBP(%rsp), %rbp /* pt_regs->rbp */ movq EFLAGS(%rsp), %r11 /* pt_regs->flags (in r11) */
@@ -380,7 +387,6 @@ SYM_CODE_START(entry_INT80_compat) pushq (%rdi) /* pt_regs->di */ .Lint80_keep_stack: - UNTRAIN_RET pushq %rsi /* pt_regs->si */ xorl %esi, %esi /* nospec si */ pushq %rdx /* pt_regs->dx */
@@ -413,6 +419,9 @@ SYM_CODE_START(entry_INT80_compat) cld + IBRS_ENTER + UNTRAIN_RET + movq %rsp, %rdi call do_int80_syscall_32 jmp swapgs_restore_regs_and_return_to_usermode
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -203,7 +203,7 @@#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9)/* AMD ProcFeedbackInterface */ #define X86_FEATURE_SME ( 7*32+10)/* AMD Secure Memory Encryption */ #define X86_FEATURE_PTI ( 7*32+11)/* Kernel Page Table Isolation enabled */ -/* FREE! ( 7*32+12) */ +#define X86_FEATURE_KERNEL_IBRS ( 7*32+12)/* "" Set/clear IBRS on kernel entry/exit */ /* FREE! ( 7*32+13) */ #define X86_FEATURE_INTEL_PPIN ( 7*32+14)/* Intel Processor Inventory Number */ #define X86_FEATURE_CDP_L2 ( 7*32+15)/* Code and Data Prioritization L2 */
Greg Kroah-Hartman
maintainerPATCH 101/130 x86/bugs: Optimize SPEC_CTRL MSR writes
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit c779bc1a9002fa474175b80e72b85c9bf628abb0 upstream.
When changing SPEC_CTRL for user control, the WRMSR can be delayed until return-to-user when KERNEL_IBRS has been enabled.
This avoids an MSR write during context switch.
--- arch/x86/include/asm/nospec-branch.h | 2 +- arch/x86/kernel/cpu/bugs.c | 18 ++++++++++++------ arch/x86/kernel/process.c | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-)
arch/x86/include/asm/nospec-branch.h +1 -1
@@ -254,7 +254,7 @@ static inline void indirect_branch_predi/* The Intel SPEC CTRL MSR base value cache */ extern u64 x86_spec_ctrl_base; -extern void write_spec_ctrl_current (u64 val); +extern void write_spec_ctrl_current (u64 val,bool force);/* * With retpoline, we must use IBRS to restrict branch prediction
arch/x86/kernel/cpu/bugs.c +12 -6
@@ -62,13 +62,19 @@ static DEFINE_MUTEX(spec_ctrl_mutex);* Keep track of the SPEC_CTRL MSR value for the current task, which may differ * from x86_spec_ctrl_base due to STIBP/SSB in __speculation_ctrl_update(). */ -void write_spec_ctrl_current (u64 val) +void write_spec_ctrl_current (u64 val,bool force) {if (this_cpu_read (x86_spec_ctrl_current) == val)return ;this_cpu_write (x86_spec_ctrl_current, val); -wrmsrl (MSR_IA32_SPEC_CTRL , val); + +/* +* When KERNEL_IBRS this MSR is written on return-to-user, unless +* forced the update can be delayed until that time. +*/ +if (force || !cpu_feature_enabled (X86_FEATURE_KERNEL_IBRS )) +wrmsrl (MSR_IA32_SPEC_CTRL , val); }/*
@@ -1253,7 +1259,7 @@ static void __init spectre_v2_select_mitif (spectre_v2_in_eibrs_mode (mode)) {/* Force it so VMEXIT will restore correctly */ x86_spec_ctrl_base |=SPEC_CTRL_IBRS ; -write_spec_ctrl_current (x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base, true); }switch (mode) {
@@ -1308,7 +1314,7 @@ static void __init spectre_v2_select_mitstatic void update_stibp_msr (void * __unused) { -write_spec_ctrl_current (x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base, true); }/* Update x86_spec_ctrl_base in case SMT state changed. */
@@ -1551,7 +1557,7 @@ static enum ssb_mitigation __init __ssb_x86_amd_ssb_disable (); }else { x86_spec_ctrl_base |=SPEC_CTRL_SSBD ; -write_spec_ctrl_current (x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base, true); } }
@@ -1769,7 +1775,7 @@ int arch_prctl_spec_ctrl_get(struct taskvoid x86_spec_ctrl_setup_ap (void ) {if (boot_cpu_has (X86_FEATURE_MSR_SPEC_CTRL )) -write_spec_ctrl_current (x86_spec_ctrl_base); +write_spec_ctrl_current (x86_spec_ctrl_base, true);if (ssb_mode ==SPEC_STORE_BYPASS_DISABLE )x86_amd_ssb_disable ();
arch/x86/kernel/process.c +1 -1
@@ -556,7 +556,7 @@ static __always_inline void __speculatio }if (updmsr) -write_spec_ctrl_current (msr); +write_spec_ctrl_current (msr, false); }static unsigned long speculation_ctrl_update_tif (struct task_struct *tsk)
Greg Kroah-Hartman
maintainerPATCH 102/130 x86/speculation: Add spectre_v2=ibrs option to support Kernel IBRS
In reply to Greg Kroah-HartmanFrom: Pawan Gupta <[email protected]>
commit 7c693f54c873691a4b7da05c7e0f74e67745d144 upstream.
Extend spectre_v2= boot option with Kernel IBRS.
[jpoimboe: no STIBP with IBRS]
--- Documentation/admin-guide/kernel-parameters.txt | 1 arch/x86/include/asm/nospec-branch.h | 1 arch/x86/kernel/cpu/bugs.c | 66 ++++++++++++++++++------ 3 files changed, 54 insertions(+), 14 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -0
@@ -5026,6 +5026,7 @@ eibrs - enhanced IBRS eibrs,retpoline - enhanced IBRS + Retpolines eibrs,lfence - enhanced IBRS + LFENCE + ibrs - use IBRS to protect kernel Not specifying this option is equivalent to spectre_v2=auto.
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -212,6 +212,7 @@ enum spectre_v2_mitigation {SPECTRE_V2_EIBRS ,SPECTRE_V2_EIBRS_RETPOLINE ,SPECTRE_V2_EIBRS_LFENCE , + SPECTRE_V2_IBRS, };/* The indirect branch speculation control variants */
arch/x86/kernel/cpu/bugs.c +52 -14
148 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 103/130 x86/bugs: Split spectre_v2_select_mitigation() and spectre_v2_user_select_mitigation()
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 166115c08a9b0b846b783088808a27d739be6e8d upstream.
retbleed will depend on spectre_v2, while spectre_v2_user depends on retbleed. Break this cycle.
--- arch/x86/kernel/cpu/bugs.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/bugs.c +17 -8
@@ -37,8 +37,9 @@#include "cpu.h" static void __init spectre_v1_select_mitigation (void ); -static void __init retbleed_select_mitigation (void );static void __init spectre_v2_select_mitigation (void ); +static void __init retbleed_select_mitigation (void ); +static void __init spectre_v2_user_select_mitigation (void );static void __init ssb_select_mitigation (void );static void __init l1tf_select_mitigation (void );static void __init mds_select_mitigation (void );
@@ -137,13 +138,19 @@ void __init check_bugs(void)/* Select the proper CPU mitigations before patching alternatives: */ spectre_v1_select_mitigation (); +spectre_v2_select_mitigation (); +/* +* retbleed_select_mitigation() relies on the state set by +* spectre_v2_select_mitigation(); specifically it wants to know about +* spectre_v2=ibrs. +*/ retbleed_select_mitigation ();/* -* spectre_v2_select_mitigation() relies on the state set by +* spectre_v2_user_select_mitigation() relies on the state set by * retbleed_select_mitigation(); specifically the STIBP selection is * forced for UNRET. */ -spectre_v2_select_mitigation (); +spectre_v2_user_select_mitigation ();ssb_select_mitigation ();l1tf_select_mitigation ();md_clear_select_mitigation ();
@@ -969,13 +976,15 @@ static void __init spec_v2_user_print_copr_info ("spectre_v2_user=%s forced on command line.\n" , reason); } +static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd; +static enum spectre_v2_user_cmd __init -spectre_v2_parse_user_cmdline (enum spectre_v2_mitigation_cmd v2_cmd) +spectre_v2_parse_user_cmdline (void ) {char arg[20 ];int ret, i; -switch (v2_cmd) { +switch (spectre_v2_cmd) {case SPECTRE_V2_CMD_NONE :return SPECTRE_V2_USER_CMD_NONE ;case SPECTRE_V2_CMD_FORCE :
@@ -1010,7 +1019,7 @@ static inline bool spectre_v2_in_ibrs_mo }static void __init -spectre_v2_user_select_mitigation (enum spectre_v2_mitigation_cmd v2_cmd) +spectre_v2_user_select_mitigation (void ) {enum spectre_v2_user_mitigation mode =SPECTRE_V2_USER_NONE ;bool smt_possible =IS_ENABLED (CONFIG_SMP );
@@ -1023,7 +1032,7 @@ spectre_v2_user_select_mitigation(enum s cpu_smt_control == CPU_SMT_NOT_SUPPORTED) smt_possible = false; - cmd =spectre_v2_parse_user_cmdline (v2_cmd); + cmd =spectre_v2_parse_user_cmdline ();switch (cmd) {case SPECTRE_V2_USER_CMD_NONE : goto set_mode;
@@ -1347,7 +1356,7 @@ static void __init spectre_v2_select_mit }/* Set up IBPB and STIBP depending on the general spectre V2 command */ -spectre_v2_user_select_mitigation (cmd); + spectre_v2_cmd = cmd; }static void update_stibp_msr (void * __unused)
Greg Kroah-Hartman
maintainerPATCH 104/130 x86/bugs: Report Intel retbleed vulnerability
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 6ad0ad2bf8a67e27d1f9d006a1dabb0e1c360cc3 upstream.
Skylake suffers from RSB underflow speculation issues; report this vulnerability and it's mitigation (spectre_v2=ibrs).
[jpoimboe: cleanups, eibrs]
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/bugs.c | 39 +++++++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/common.c | 24 ++++++++++++------------ 3 files changed, 46 insertions(+), 18 deletions(-)
arch/x86/include/asm/msr-index.h +1 -0
@@ -91,6 +91,7 @@#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a#define ARCH_CAP_RDCL_NO BIT(0)/* Not susceptible to Meltdown */ #define ARCH_CAP_IBRS_ALL BIT(1)/* Enhanced IBRS support */ +#define ARCH_CAP_RSBA BIT(2)/* RET may use alternative branch predictors */ #define ARCH_CAP_SKIP_VMENTRY_L1DFLUSH BIT(3)/* Skip L1D flush on vmentry */ #define ARCH_CAP_SSB_NO BIT(4)/* * Not susceptible to Speculative Store Bypass
arch/x86/kernel/cpu/bugs.c +33 -6
@@ -746,12 +746,17 @@ static int __init nospectre_v1_cmdline(c }early_param ("nospectre_v1" , nospectre_v1_cmdline); +static enum spectre_v2_mitigation spectre_v2_enabled__ro_after_init = +SPECTRE_V2_NONE ; +#undef pr_fmt#define pr_fmt (fmt) "RETBleed: " fmtenum retbleed_mitigation {RETBLEED_MITIGATION_NONE ,RETBLEED_MITIGATION_UNRET , +RETBLEED_MITIGATION_IBRS , +RETBLEED_MITIGATION_EIBRS , };enum retbleed_mitigation_cmd {
@@ -763,6 +768,8 @@ enum retbleed_mitigation_cmd {const char *const retbleed_strings[] = { [RETBLEED_MITIGATION_NONE ] ="Vulnerable" , [RETBLEED_MITIGATION_UNRET ] ="Mitigation: untrained return thunk" , + [RETBLEED_MITIGATION_IBRS ] ="Mitigation: IBRS" , + [RETBLEED_MITIGATION_EIBRS ] ="Mitigation: Enhanced IBRS" , }; static enum retbleed_mitigation retbleed_mitigation __ro_after_init =
@@ -805,6 +812,7 @@ early_param("retbleed", retbleed_parse_c#define RETBLEED_UNTRAIN_MSG "WARNING: BTB untrained return thunk mitigation is only effective on AMD/Hygon!\n"#define RETBLEED_COMPILER_MSG "WARNING: kernel not compiled with RETPOLINE or -mfunction-return capable compiler!\n" +#define RETBLEED_INTEL_MSG "WARNING: Spectre v2 mitigation leaves CPU vulnerable to RETBleed attacks, data leaks possible!\n"static void __init retbleed_select_mitigation (void ) {
@@ -821,12 +829,15 @@ static void __init retbleed_select_mitigcase RETBLEED_CMD_AUTO :default : -if (!boot_cpu_has_bug (X86_BUG_RETBLEED )) -break ; -if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD || boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ) retbleed_mitigation =RETBLEED_MITIGATION_UNRET ; + +/* +* The Intel mitigation (IBRS) was already selected in +* spectre_v2_select_mitigation(). +*/ +break ; }
@@ -856,15 +867,31 @@ static void __init retbleed_select_mitigbreak ; } +/* +* Let IBRS trump all on Intel without affecting the effects of the +* retbleed= cmdline option. +*/ +if (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) { +switch (spectre_v2_enabled) { +case SPECTRE_V2_IBRS : + retbleed_mitigation =RETBLEED_MITIGATION_IBRS ; +break ; +case SPECTRE_V2_EIBRS : +case SPECTRE_V2_EIBRS_RETPOLINE : +case SPECTRE_V2_EIBRS_LFENCE : + retbleed_mitigation =RETBLEED_MITIGATION_EIBRS ; +break ; +default : +pr_err (RETBLEED_INTEL_MSG ); + } + } +pr_info ("%s\n" , retbleed_strings[retbleed_mitigation]); }#undef pr_fmt#define pr_fmt (fmt) "Spectre V2 : " fmt -static enum spectre_v2_mitigation spectre_v2_enabled__ro_after_init = -SPECTRE_V2_NONE ; -static enum spectre_v2_user_mitigation spectre_v2_user_stibp__ro_after_init =SPECTRE_V2_USER_NONE ; static enum spectre_v2_user_mitigation spectre_v2_user_ibpb __ro_after_init =
arch/x86/kernel/cpu/common.c +12 -12
@@ -1124,24 +1124,24 @@ static const struct x86_cpu_id cpu_vuln_VULNBL_INTEL_STEPPINGS (BROADWELL_G ,X86_STEPPING_ANY ,SRBDS ),VULNBL_INTEL_STEPPINGS (BROADWELL_X ,X86_STEPPING_ANY ,MMIO ),VULNBL_INTEL_STEPPINGS (BROADWELL ,X86_STEPPING_ANY ,SRBDS ), -VULNBL_INTEL_STEPPINGS (SKYLAKE_L ,X86_STEPPINGS (0x3 ,0x3 ),SRBDS |MMIO ), +VULNBL_INTEL_STEPPINGS (SKYLAKE_L ,X86_STEPPINGS (0x3 ,0x3 ),SRBDS |MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (SKYLAKE_L ,X86_STEPPING_ANY ,SRBDS ),VULNBL_INTEL_STEPPINGS (SKYLAKE_X ,BIT (3 ) |BIT (4 ) |BIT (6 ) | -BIT (7 ) |BIT (0xB ),MMIO ), -VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPINGS (0x3 ,0x3 ),SRBDS |MMIO ), +BIT (7 ) |BIT (0xB ),MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPINGS (0x3 ,0x3 ),SRBDS |MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPING_ANY ,SRBDS ), -VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPINGS (0x9 ,0xC ),SRBDS |MMIO ), +VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPINGS (0x9 ,0xC ),SRBDS |MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPINGS (0x0 ,0x8 ),SRBDS ), -VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPINGS (0x9 ,0xD ),SRBDS |MMIO ), +VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPINGS (0x9 ,0xD ),SRBDS |MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPINGS (0x0 ,0x8 ),SRBDS ), -VULNBL_INTEL_STEPPINGS (ICELAKE_L ,X86_STEPPINGS (0x5 ,0x5 ),MMIO |MMIO_SBDS ), +VULNBL_INTEL_STEPPINGS (ICELAKE_L ,X86_STEPPINGS (0x5 ,0x5 ),MMIO |MMIO_SBDS |RETBLEED ),VULNBL_INTEL_STEPPINGS (ICELAKE_D ,X86_STEPPINGS (0x1 ,0x1 ),MMIO ),VULNBL_INTEL_STEPPINGS (ICELAKE_X ,X86_STEPPINGS (0x4 ,0x6 ),MMIO ), -VULNBL_INTEL_STEPPINGS (COMETLAKE ,BIT (2 ) |BIT (3 ) |BIT (5 ),MMIO |MMIO_SBDS ), -VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS ), -VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPINGS (0x0 ,0x0 ),MMIO ), -VULNBL_INTEL_STEPPINGS (LAKEFIELD ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS ), -VULNBL_INTEL_STEPPINGS (ROCKETLAKE ,X86_STEPPINGS (0x1 ,0x1 ),MMIO ), +VULNBL_INTEL_STEPPINGS (COMETLAKE ,BIT (2 ) |BIT (3 ) |BIT (5 ),MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPINGS (0x0 ,0x0 ),MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (LAKEFIELD ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (ROCKETLAKE ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (ATOM_TREMONT ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS ),VULNBL_INTEL_STEPPINGS (ATOM_TREMONT_D ,X86_STEPPING_ANY ,MMIO ), VULNBL_INTEL_STEPPINGS(ATOM_TREMONT_L, X86_STEPPINGS(0x0, 0x0), MMIO | MMIO_SBDS),
@@ -1251,7 +1251,7 @@ static void __init cpu_set_bug_bits(stru !arch_cap_mmio_immune(ia32_cap))setup_force_cpu_bug (X86_BUG_MMIO_STALE_DATA ); -if (cpu_matches (cpu_vuln_blacklist,RETBLEED )) +if ((cpu_matches (cpu_vuln_blacklist,RETBLEED ) || (ia32_cap &ARCH_CAP_RSBA )))setup_force_cpu_bug (X86_BUG_RETBLEED );if (cpu_matches (cpu_vuln_whitelist,NO_MELTDOWN ))
Greg Kroah-Hartman
maintainerPATCH 105/130 intel_idle: Disable IBRS during long idle
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit bf5835bcdb9635c97f85120dba9bfa21e111130f upstream.
Having IBRS enabled while the SMT sibling is idle unnecessarily slows down the running sibling. OTOH, disabling IBRS around idle takes two MSR writes, which will increase the idle latency.
Therefore, only disable IBRS around deeper idle states. Shallow idle states are bounded by the tick in duration, since NOHZ is not allowed for them by virtue of their short target residency.
Only do this for mwait-driven idle, since that keeps interrupts disabled across idle, which makes disabling IBRS vs IRQ-entry a non-issue.
Note: C6 is a random threshold, most importantly C1 probably shouldn't disable IBRS, benchmarking needed.
--- arch/x86/include/asm/nospec-branch.h | 1 arch/x86/kernel/cpu/bugs.c | 6 ++++ drivers/idle/intel_idle.c | 43 ++++++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 6 deletions(-)
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -256,6 +256,7 @@ static inline void indirect_branch_predi/* The Intel SPEC CTRL MSR base value cache */ extern u64 x86_spec_ctrl_base;extern void write_spec_ctrl_current (u64 val,bool force); +extern u64 spec_ctrl_current (void );/* * With retpoline, we must use IBRS to restrict branch prediction
arch/x86/kernel/cpu/bugs.c +6 -0
@@ -78,6 +78,12 @@ void write_spec_ctrl_current(u64 val, bowrmsrl (MSR_IA32_SPEC_CTRL , val); } +u64 spec_ctrl_current (void ) +{ +return this_cpu_read (x86_spec_ctrl_current); +} +EXPORT_SYMBOL_GPL (spec_ctrl_current); +/* * The vendor and possibly platform specific bits which can be modified in * x86_spec_ctrl_base.
drivers/idle/intel_idle.c +37 -6
108 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 106/130 objtool: Update Retpoline validation
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 9bb2ec608a209018080ca262f771e6a9ff203b6f upstream.
Update retpoline validation with the new CONFIG_RETPOLINE requirement of not having bare naked RET instructions.
--- arch/x86/include/asm/nospec-branch.h | 6 ++++++ arch/x86/mm/mem_encrypt_boot.S | 2 ++ arch/x86/xen/xen-head.S | 1 + tools/objtool/check.c | 19 +++++++++++++------ 4 files changed, 22 insertions(+), 6 deletions(-)
arch/x86/include/asm/nospec-branch.h +6 -0
@@ -76,6 +76,12 @@ .endm/* +* (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions +* vs RETBleed validation. +*/ +#define ANNOTATE_UNRET_SAFE ANNOTATE_RETPOLINE_SAFE + +/* * JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple * indirect jmp/call which may be susceptible to the Spectre variant 2 * attack.
arch/x86/mm/mem_encrypt_boot.S +2 -0
@@ -66,6 +66,7 @@ SYM_FUNC_START(sme_encrypt_execute) pop %rbp /* Offset to __x86_return_thunk would be wrong here */ + ANNOTATE_UNRET_SAFE ret int3 SYM_FUNC_END(sme_encrypt_execute)
@@ -154,6 +155,7 @@ SYM_FUNC_START(__enc_copy) pop %r15 /* Offset to __x86_return_thunk would be wrong here */ + ANNOTATE_UNRET_SAFE ret int3 .L__enc_copy_end:
arch/x86/xen/xen-head.S +1 -0
@@ -70,6 +70,7 @@ SYM_CODE_START(hypercall_page) .rept (PAGE_SIZE / 32) UNWIND_HINT_FUNC .skip 31, 0x90 + ANNOTATE_UNRET_SAFE RET .endr
tools/objtool/check.c +13 -6
@@ -1799,8 +1799,9 @@ static int read_retpoline_hints(struct o }if (insn->type !=INSN_JUMP_DYNAMIC && - insn->type !=INSN_CALL_DYNAMIC ) { -WARN_FUNC ("retpoline_safe hint not an indirect jump/call" , + insn->type !=INSN_CALL_DYNAMIC && + insn->type !=INSN_RETURN ) { +WARN_FUNC ("retpoline_safe hint not an indirect jump/call/ret" , insn->sec, insn->offset);return -1 ; }
@@ -3051,7 +3052,8 @@ static int validate_retpoline(struct objfor_each_insn (file, insn) {if (insn->type !=INSN_JUMP_DYNAMIC && - insn->type !=INSN_CALL_DYNAMIC ) + insn->type !=INSN_CALL_DYNAMIC && + insn->type !=INSN_RETURN )continue ;if (insn->retpoline_safe)
@@ -3066,9 +3068,14 @@ static int validate_retpoline(struct objif (!strcmp (insn->sec->name,".init.text" ) && !module)continue ; -WARN_FUNC ("indirect %s found in RETPOLINE build" , - insn->sec, insn->offset, - insn->type ==INSN_JUMP_DYNAMIC ?"jump" :"call" ); +if (insn->type ==INSN_RETURN ) { +WARN_FUNC ("'naked' return found in RETPOLINE build" , + insn->sec, insn->offset); + }else { +WARN_FUNC ("indirect %s found in RETPOLINE build" , + insn->sec, insn->offset, + insn->type ==INSN_JUMP_DYNAMIC ?"jump" :"call" ); + } warnings++; }
Greg Kroah-Hartman
maintainerPATCH 107/130 x86/xen: Rename SYS* entry points
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit b75b7f8ef1148be1b9321ffc2f6c19238904b438 upstream.
Native SYS{CALL,ENTER} entry points are called entry_SYS{CALL,ENTER}_{64,compat}, make sure the Xen versions are named consistently.
--- arch/x86/xen/setup.c | 6 +++--- arch/x86/xen/xen-asm.S | 20 ++++++++++---------- arch/x86/xen/xen-ops.h | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-)
arch/x86/xen/setup.c +3 -3
@@ -922,7 +922,7 @@ void xen_enable_sysenter(void)if (!boot_cpu_has (sysenter_feature))return ; - ret =register_callback (CALLBACKTYPE_sysenter, xen_sysenter_target); + ret =register_callback (CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat);if (ret !=0 )setup_clear_cpu_cap (sysenter_feature); }
@@ -931,7 +931,7 @@ void xen_enable_syscall(void) {int ret; - ret =register_callback (CALLBACKTYPE_syscall, xen_syscall_target); + ret =register_callback (CALLBACKTYPE_syscall, xen_entry_SYSCALL_64);if (ret !=0 ) {printk (KERN_ERR "Failed to set syscall callback: %d\n" , ret);/* Pretty fatal; 64-bit userspace has no other
@@ -940,7 +940,7 @@ void xen_enable_syscall(void)if (boot_cpu_has (X86_FEATURE_SYSCALL32 )) { ret =register_callback (CALLBACKTYPE_syscall32, - xen_syscall32_target); + xen_entry_SYSCALL_compat);if (ret !=0 )setup_clear_cpu_cap (X86_FEATURE_SYSCALL32 ); }
arch/x86/xen/xen-asm.S +10 -10
@@ -276,7 +276,7 @@ SYM_CODE_END(xenpv_restore_regs_and_retu */ /* Normal 64-bit system call target */ -SYM_CODE_START(xen_syscall_target) +SYM_CODE_START(xen_entry_SYSCALL_64) UNWIND_HINT_EMPTY popq %rcx popq %r11
@@ -290,12 +290,12 @@ SYM_CODE_START(xen_syscall_target) movq $__USER_CS, 1*8(%rsp) jmp entry_SYSCALL_64_after_hwframe -SYM_CODE_END(xen_syscall_target) +SYM_CODE_END(xen_entry_SYSCALL_64) #ifdef CONFIG_IA32_EMULATION /* 32-bit compat syscall target */ -SYM_CODE_START(xen_syscall32_target) +SYM_CODE_START(xen_entry_SYSCALL_compat) UNWIND_HINT_EMPTY popq %rcx popq %r11
@@ -309,10 +309,10 @@ SYM_CODE_START(xen_syscall32_target) movq $__USER32_CS, 1*8(%rsp) jmp entry_SYSCALL_compat_after_hwframe -SYM_CODE_END(xen_syscall32_target) +SYM_CODE_END(xen_entry_SYSCALL_compat) /* 32-bit compat sysenter target */ -SYM_CODE_START(xen_sysenter_target) +SYM_CODE_START(xen_entry_SYSENTER_compat) UNWIND_HINT_EMPTY /* * NB: Xen is polite and clears TF from EFLAGS for us. This means
@@ -330,18 +330,18 @@ SYM_CODE_START(xen_sysenter_target) movq $__USER32_CS, 1*8(%rsp) jmp entry_SYSENTER_compat_after_hwframe -SYM_CODE_END(xen_sysenter_target) +SYM_CODE_END(xen_entry_SYSENTER_compat) #else /* !CONFIG_IA32_EMULATION */ -SYM_CODE_START(xen_syscall32_target) -SYM_CODE_START(xen_sysenter_target) +SYM_CODE_START(xen_entry_SYSCALL_compat) +SYM_CODE_START(xen_entry_SYSENTER_compat) UNWIND_HINT_EMPTY lea 16(%rsp), %rsp /* strip %rcx, %r11 */ mov $-ENOSYS, %rax pushq $0 jmp hypercall_iret -SYM_CODE_END(xen_sysenter_target) -SYM_CODE_END(xen_syscall32_target) +SYM_CODE_END(xen_entry_SYSENTER_compat) +SYM_CODE_END(xen_entry_SYSCALL_compat) #endif /* CONFIG_IA32_EMULATION */
arch/x86/xen/xen-ops.h +3 -3
@@ -10,10 +10,10 @@/* These are code, but not functions. Defined in entry.S */ extern const char xen_failsafe_callback[]; -void xen_sysenter_target (void ); +void xen_entry_SYSENTER_compat (void );#ifdef CONFIG_X86_64 -void xen_syscall_target (void ); -void xen_syscall32_target (void ); +void xen_entry_SYSCALL_64 (void ); +void xen_entry_SYSCALL_compat (void );#endif extern void *xen_initial_gdt;
Greg Kroah-Hartman
maintainerPATCH 108/130 x86/bugs: Add retbleed=ibpb
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 3ebc170068885b6fc7bedda6c667bb2c4d533159 upstream.
jmp2ret mitigates the easy-to-attack case at relatively low overhead. It mitigates the long speculation windows after a mispredicted RET, but it does not mitigate the short speculation window from arbitrary instruction boundaries.
On Zen2, there is a chicken bit which needs setting, which mitigates "arbitrary instruction boundaries" down to just "basic block boundaries".
But there is no fix for the short speculation window on basic block boundaries, other than to flush the entire BTB to evict all attacker predictions.
On the spectrum of "fast & blurry" -> "safe", there is (on top of STIBP or no-SMT):
1) Nothing System wide open
2) jmp2ret May stop a script kiddy
3) jmp2ret+chickenbit Raises the bar rather further
4) IBPB Only thing which can count as "safe".
Tentative numbers put IBPB-on-entry at a 2.5x hit on Zen2, and a 10x hit on Zen1 according to lmbench.
[ bp: Fixup feature bit comments, document option, 32-bit build fix. ]
--- Documentation/admin-guide/kernel-parameters.txt | 3 + arch/x86/entry/Makefile | 2 - arch/x86/entry/entry.S | 22 ++++++++++++ arch/x86/include/asm/cpufeatures.h | 2 - arch/x86/include/asm/nospec-branch.h | 8 +++- arch/x86/kernel/cpu/bugs.c | 43 ++++++++++++++++++------ 6 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 arch/x86/entry/entry.S
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -4666,6 +4666,9 @@ disabling SMT if necessary for the full mitigation (only on Zen1 and older without STIBP). + ibpb - mitigate short speculation windows on + basic block boundaries too. Safe, highest + perf impact. unret - force enable untrained return thunks, only effective on AMD f15h-f17h based systems.
arch/x86/entry/Makefile +1 -1
@@ -21,7 +21,7 @@ CFLAGS_syscall_64.o += $(call cc-option CFLAGS_syscall_32.o += $(call cc-option,-Wno-override-init,) CFLAGS_syscall_x32.o += $(call cc-option,-Wno-override-init,) -obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o +obj-y := entry.o entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o obj-y += common.o obj-y += vdso/
arch/x86/entry/entry.S new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Common place for both 32- and 64-bit entry routines. + */ + +#include <linux/linkage.h> +#include <asm/export.h> +#include <asm/msr-index.h> + +.pushsection .noinstr.text, "ax" + +SYM_FUNC_START(entry_ibpb) + movl $MSR_IA32_PRED_CMD, %ecx + movl $PRED_CMD_IBPB, %eax + xorl %edx, %edx + wrmsr + RET +SYM_FUNC_END(entry_ibpb) +/* For KVM */ +EXPORT_SYMBOL_GPL(entry_ibpb); + +.popsection
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -292,7 +292,7 @@#define X86_FEATURE_PER_THREAD_MBA (11*32+ 7)/* "" Per-thread Memory Bandwidth Allocation */ /* FREE! (11*32+ 8) */ /* FREE! (11*32+ 9) */ -/* FREE! (11*32+10) */ +#define X86_FEATURE_ENTRY_IBPB (11*32+10)/* "" Issue an IBPB on kernel entry */ /* FREE! (11*32+11) */ #define X86_FEATURE_RETPOLINE (11*32+12)/* "" Generic Retpoline mitigation for Spectre variant 2 */ #define X86_FEATURE_RETPOLINE_LFENCE (11*32+13)/* "" Use LFENCE for Spectre variant 2 */
arch/x86/include/asm/nospec-branch.h +6 -2
@@ -123,14 +123,17 @@* return thunk isn't mapped into the userspace tables (then again, AMD * typically has NO_MELTDOWN). * -* Doesn't clobber any registers but does require a stable stack. +* While zen_untrain_ret() doesn't clobber anything but requires stack, +* entry_ibpb() will clobber AX, CX, DX. * * As such, this must be placed after every *SWITCH_TO_KERNEL_CR3 at a point * where we have a stack but before any RET instruction. */ .macro UNTRAIN_RET#ifdef CONFIG_RETPOLINE -ALTERNATIVE "" ,"call zen_untrain_ret" ,X86_FEATURE_UNRET +ALTERNATIVE_2 "" , \ +"call zen_untrain_ret" ,X86_FEATURE_UNRET , \ +"call entry_ibpb" ,X86_FEATURE_ENTRY_IBPB #endif .endm
@@ -144,6 +147,7 @@extern void __x86_return_thunk (void );extern void zen_untrain_ret (void ); +extern void entry_ibpb (void );#ifdef CONFIG_RETPOLINE
arch/x86/kernel/cpu/bugs.c +34 -9
105 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 109/130 x86/bugs: Do IBPB fallback check only once
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit 0fe4aeea9c01baabecc8c3afc7889c809d939bc2 upstream.
When booting with retbleed=auto, if the kernel wasn't built with CONFIG_CC_HAS_RETURN_THUNK, the mitigation falls back to IBPB. Make sure a warning is printed in that case. The IBPB fallback check is done twice, but it really only needs to be done once.
--- arch/x86/kernel/cpu/bugs.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/bugs.c +5 -10
@@ -847,18 +847,13 @@ static void __init retbleed_select_mitigcase RETBLEED_CMD_AUTO :default :if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD || - boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ) { - -if (IS_ENABLED (CONFIG_RETPOLINE ) && -IS_ENABLED (CONFIG_CC_HAS_RETURN_THUNK )) - retbleed_mitigation =RETBLEED_MITIGATION_UNRET ; -else - retbleed_mitigation =RETBLEED_MITIGATION_IBPB ; - } + boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ) + retbleed_mitigation =RETBLEED_MITIGATION_UNRET ;/* -* The Intel mitigation (IBRS) was already selected in -* spectre_v2_select_mitigation(). +* The Intel mitigation (IBRS or eIBRS) was already selected in +* spectre_v2_select_mitigation(). 'retbleed_mitigation' will +* be set accordingly below. */ break ;
Greg Kroah-Hartman
maintainerPATCH 110/130 objtool: Add entry UNRET validation
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit a09a6e2399ba0595c3042b3164f3ca68a3cff33e upstream.
Since entry asm is tricky, add a validation pass that ensures the retbleed mitigation has been done before the first actual RET instruction.
Entry points are those that either have UNWIND_HINT_ENTRY, which acts as UNWIND_HINT_EMPTY but marks the instruction as an entry point, or those that have UWIND_HINT_IRET_REGS at +0.
This is basically a variant of validate_branch() that is intra-function and it will simply follow all branches from marked entry points and ensures that all paths lead to ANNOTATE_UNRET_END.
If a path hits RET or an indirection the path is a fail and will be reported.
There are 3 ANNOTATE_UNRET_END instances:
- UNTRAIN_RET itself
- exception from-kernel; this path doesn't need UNTRAIN_RET
- all early exceptions; these also don't need UNTRAIN_RET
[bwh: Backported to 5.10:
- In scripts/link-vmlinux.sh, use "test -n" instead of is_enabled
- Adjust context]
--- arch/x86/entry/entry_64.S | 3 arch/x86/entry/entry_64_compat.S | 6 - arch/x86/include/asm/nospec-branch.h | 12 ++ arch/x86/include/asm/unwind_hints.h | 4 arch/x86/kernel/head_64.S | 5 + arch/x86/xen/xen-asm.S | 10 +- include/linux/objtool.h | 3 scripts/link-vmlinux.sh | 3 tools/include/linux/objtool.h | 3 tools/objtool/builtin-check.c | 3 tools/objtool/builtin.h | 2 tools/objtool/check.c | 172 ++++++++++++++++++++++++++++++++++- tools/objtool/check.h | 6 + 13 files changed, 217 insertions(+), 15 deletions(-)
arch/x86/entry/entry_64.S +2 -1
@@ -93,7 +93,7 @@ SYM_CODE_END(native_usergs_sysret64) */ SYM_CODE_START(entry_SYSCALL_64) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY swapgs /* tss.sp2 is scratch space. */
@@ -1094,6 +1094,7 @@ SYM_CODE_START_LOCAL(error_entry) */ .Lerror_entry_done_lfence: FENCE_SWAPGS_KERNEL_ENTRY + ANNOTATE_UNRET_END RET .Lbstep_iret:
arch/x86/entry/entry_64_compat.S +3 -3
@@ -49,7 +49,7 @@ * 0(%ebp) arg6 */ SYM_CODE_START(entry_SYSENTER_compat) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY /* Interrupts are off on entry. */ SWAPGS
@@ -202,7 +202,7 @@ SYM_CODE_END(entry_SYSENTER_compat) * 0(%esp) arg6 */ SYM_CODE_START(entry_SYSCALL_compat) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY /* Interrupts are off on entry. */ swapgs
@@ -349,7 +349,7 @@ SYM_CODE_END(entry_SYSCALL_compat) * ebp arg6 */ SYM_CODE_START(entry_INT80_compat) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY /* * Interrupts are off on entry. */
arch/x86/include/asm/nospec-branch.h +12 -0
@@ -82,6 +82,17 @@#define ANNOTATE_UNRET_SAFE ANNOTATE_RETPOLINE_SAFE/* +* Abuse ANNOTATE_RETPOLINE_SAFE on a NOP to indicate UNRET_END, should +* eventually turn into it's own annotation. +*/ +.macro ANNOTATE_UNRET_END +#ifdef CONFIG_DEBUG_ENTRY +ANNOTATE_RETPOLINE_SAFE + nop +#endif +.endm + +/* * JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple * indirect jmp/call which may be susceptible to the Spectre variant 2 * attack.
@@ -131,6 +142,7 @@*/ .macro UNTRAIN_RET#ifdef CONFIG_RETPOLINE +ANNOTATE_UNRET_END ALTERNATIVE_2 "", \"call zen_untrain_ret" ,X86_FEATURE_UNRET , \"call entry_ibpb" ,X86_FEATURE_ENTRY_IBPB
arch/x86/include/asm/unwind_hints.h +4 -0
@@ -11,6 +11,10 @@ UNWIND_HINT sp_reg=ORC_REG_UNDEFINED type=UNWIND_HINT_TYPE_CALL end=1 .endm +.macro UNWIND_HINT_ENTRY + UNWIND_HINT sp_reg=ORC_REG_UNDEFINED type=UNWIND_HINT_TYPE_ENTRY end=1 +.endm + .macro UNWIND_HINT_REGS base=%rsp offset=0 indirect=0 extra=1 partial=0 .if \base == %rsp .if \indirect
arch/x86/kernel/head_64.S +5 -0
@@ -321,6 +321,8 @@ SYM_CODE_END(start_cpu0) SYM_CODE_START_NOALIGN(vc_boot_ghcb) UNWIND_HINT_IRET_REGS offset=8 + ANNOTATE_UNRET_END + /* Build pt_regs */ PUSH_AND_CLEAR_REGS
@@ -378,6 +380,7 @@ SYM_CODE_START(early_idt_handler_array) SYM_CODE_END(early_idt_handler_array) SYM_CODE_START_LOCAL(early_idt_handler_common) + ANNOTATE_UNRET_END /* * The stack is the hardware frame, an error code or zero, and the * vector number.
@@ -424,6 +427,8 @@ SYM_CODE_END(early_idt_handler_common) SYM_CODE_START_NOALIGN(vc_no_ghcb) UNWIND_HINT_IRET_REGS offset=8 + ANNOTATE_UNRET_END + /* Build pt_regs */ PUSH_AND_CLEAR_REGS
arch/x86/xen/xen-asm.S +5 -5
@@ -148,7 +148,7 @@ SYM_FUNC_END(xen_read_cr2_direct); .macro xen_pv_trap name SYM_CODE_START(xen_\name) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY pop %rcx pop %r11 jmp \name
@@ -277,7 +277,7 @@ SYM_CODE_END(xenpv_restore_regs_and_retu /* Normal 64-bit system call target */ SYM_CODE_START(xen_entry_SYSCALL_64) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY popq %rcx popq %r11
@@ -296,7 +296,7 @@ SYM_CODE_END(xen_entry_SYSCALL_64) /* 32-bit compat syscall target */ SYM_CODE_START(xen_entry_SYSCALL_compat) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY popq %rcx popq %r11
@@ -313,7 +313,7 @@ SYM_CODE_END(xen_entry_SYSCALL_compat) /* 32-bit compat sysenter target */ SYM_CODE_START(xen_entry_SYSENTER_compat) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY /* * NB: Xen is polite and clears TF from EFLAGS for us. This means * that we don't need to guard against single step exceptions here.
@@ -336,7 +336,7 @@ SYM_CODE_END(xen_entry_SYSENTER_compat) SYM_CODE_START(xen_entry_SYSCALL_compat) SYM_CODE_START(xen_entry_SYSENTER_compat) - UNWIND_HINT_EMPTY + UNWIND_HINT_ENTRY lea 16(%rsp), %rsp /* strip %rcx, %r11 */ mov $-ENOSYS, %rax pushq $0
include/linux/objtool.h +3 -0
@@ -32,11 +32,14 @@ struct unwind_hint {* * UNWIND_HINT_FUNC: Generate the unwind metadata of a callable function. * Useful for code which doesn't have an ELF function annotation. +* +* UNWIND_HINT_ENTRY: machine entry without stack, SYSCALL/SYSENTER etc. */ #define UNWIND_HINT_TYPE_CALL 0#define UNWIND_HINT_TYPE_REGS 1#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3 +#define UNWIND_HINT_TYPE_ENTRY 4#ifdef CONFIG_STACK_VALIDATION
scripts/link-vmlinux.sh +3 -0
@@ -65,6 +65,9 @@ objtool_link() if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then objtoolopt="check" + if [ -n "${CONFIG_RETPOLINE}" ]; then + objtoolopt="${objtoolopt} --unret" + fi if [ -z "${CONFIG_FRAME_POINTER}" ]; then objtoolopt="${objtoolopt} --no-fp" fi
tools/include/linux/objtool.h +3 -0
@@ -32,11 +32,14 @@ struct unwind_hint {* * UNWIND_HINT_FUNC: Generate the unwind metadata of a callable function. * Useful for code which doesn't have an ELF function annotation. +* +* UNWIND_HINT_ENTRY: machine entry without stack, SYSCALL/SYSENTER etc. */ #define UNWIND_HINT_TYPE_CALL 0#define UNWIND_HINT_TYPE_REGS 1#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3 +#define UNWIND_HINT_TYPE_ENTRY 4#ifdef CONFIG_STACK_VALIDATION
tools/objtool/builtin-check.c +2 -1
@@ -19,7 +19,7 @@#include "objtool.h" bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - validate_dup, vmlinux, sls; + validate_dup, vmlinux, sls, unret;static const char *const check_usage[] = {"objtool check [<options>] file.o" ,
@@ -30,6 +30,7 @@ const struct option check_options[] = {OPT_BOOLEAN ('f' ,"no-fp" , &no_fp,"Skip frame pointer validation" ),OPT_BOOLEAN ('u' ,"no-unreachable" , &no_unreachable,"Skip 'unreachable instruction' warnings" ),OPT_BOOLEAN ('r' ,"retpoline" , &retpoline,"Validate retpoline assumptions" ), +OPT_BOOLEAN (0 ,"unret" , &unret,"validate entry unret placement" ),OPT_BOOLEAN ('m' ,"module" , &module,"Indicates the object will be part of a kernel module" ),OPT_BOOLEAN ('b' ,"backtrace" , &backtrace,"unwind on error" ), OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"),
tools/objtool/builtin.h +1 -1
@@ -9,7 +9,7 @@extern const struct option check_options[];extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - validate_dup, vmlinux, sls; + validate_dup, vmlinux, sls, unret;extern int cmd_check (int argc,const char **argv);extern int cmd_orc (int argc,const char **argv);
tools/objtool/check.c +168 -4
202 lines not on this page · raw message
tools/objtool/check.h +6 -0
@@ -48,6 +48,7 @@ struct instruction {bool dead_end, ignore, ignore_alts;bool hint;bool retpoline_safe; +bool entry;s8 instr;u8 visited;struct alt_group *alt_group;
@@ -62,6 +63,11 @@ struct instruction {struct cfi_state *cfi; }; +#define VISITED_BRANCH 0x01 +#define VISITED_BRANCH_UACCESS 0x02 +#define VISITED_BRANCH_MASK 0x03 +#define VISITED_ENTRY 0x04 +static inline bool is_static_jump (struct instruction *insn) { return insn->type == INSN_JUMP_CONDITIONAL ||
Greg Kroah-Hartman
maintainerPATCH 111/130 x86/cpu/amd: Add Spectral Chicken
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit d7caac991feeef1b871ee6988fd2c9725df09039 upstream.
Zen2 uarchs have an undocumented, unnamed, MSR that contains a chicken bit for some speculation behaviour. It needs setting.
Note: very belatedly AMD released naming; it's now officially called
MSR_AMD64_DE_CFG2 and MSR_AMD64_DE_CFG2_SUPPRESS_NOBR_PRED_BIT but shall remain the SPECTRAL CHICKEN.
--- arch/x86/include/asm/msr-index.h | 3 +++ arch/x86/kernel/cpu/amd.c | 23 ++++++++++++++++++++++- arch/x86/kernel/cpu/cpu.h | 2 ++ arch/x86/kernel/cpu/hygon.c | 6 ++++++ 4 files changed, 33 insertions(+), 1 deletion(-)
arch/x86/include/asm/msr-index.h +3 -0
@@ -508,6 +508,9 @@/* Fam 17h MSRs */ #define MSR_F17H_IRPERF 0xc00000e9 +#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3 +#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1) +/* Fam 16h MSRs */ #define MSR_F16H_L2I_PERF_CTL 0xc0010230#define MSR_F16H_L2I_PERF_CTR 0xc0010231
arch/x86/kernel/cpu/amd.c +22 -1
@@ -914,6 +914,26 @@ static void init_amd_bd(struct cpuinfo_xclear_rdrand_cpuid_bit (c); } +void init_spectral_chicken (struct cpuinfo_x86 *c) +{ +u64 value; + +/* +* On Zen2 we offer this chicken (bit) on the altar of Speculation. +* +* This suppresses speculation from the middle of a basic block, i.e. it +* suppresses non-branch predictions. +* +* We use STIBP as a heuristic to filter out Zen2 from the rest of F17H +*/ +if (!cpu_has (c,X86_FEATURE_HYPERVISOR ) &&cpu_has (c,X86_FEATURE_AMD_STIBP )) { +if (!rdmsrl_safe (MSR_ZEN2_SPECTRAL_CHICKEN , &value)) { + value |=MSR_ZEN2_SPECTRAL_CHICKEN_BIT ; +wrmsrl_safe (MSR_ZEN2_SPECTRAL_CHICKEN , value); + } + } +} +static void init_amd_zn (struct cpuinfo_x86 *c) {set_cpu_cap (c,X86_FEATURE_ZEN );
@@ -959,7 +979,8 @@ static void init_amd(struct cpuinfo_x86case 0x12 :init_amd_ln (c);break ;case 0x15 :init_amd_bd (c);break ;case 0x16 :init_amd_jg (c);break ; -case 0x17 : fallthrough; +case 0x17 :init_spectral_chicken (c); + fallthrough;case 0x19 :init_amd_zn (c);break ; }
arch/x86/kernel/cpu/cpu.h +2 -0
@@ -60,6 +60,8 @@ extern void tsx_disable(void);static inline void tsx_init (void ) { }#endif /* CONFIG_CPU_SUP_INTEL */ +extern void init_spectral_chicken (struct cpuinfo_x86 *c); +extern void get_cpu_cap (struct cpuinfo_x86 *c);extern void get_cpu_address_sizes (struct cpuinfo_x86 *c);extern void cpu_detect_cache_sizes (struct cpuinfo_x86 *c);
arch/x86/kernel/cpu/hygon.c +6 -0
@@ -318,6 +318,12 @@ static void init_hygon(struct cpuinfo_x8/* get apicid instead of initial apic id from cpuid */ c->apicid =hard_smp_processor_id (); +/* +* XXX someone from Hygon needs to confirm this DTRT +* +init_spectral_chicken(c); +*/ +set_cpu_cap (c,X86_FEATURE_ZEN );set_cpu_cap (c,X86_FEATURE_CPB );
Greg Kroah-Hartman
maintainerPATCH 112/130 x86/speculation: Fix RSB filling with CONFIG_RETPOLINE=n
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit b2620facef4889fefcbf2e87284f34dcd4189bce upstream.
If a kernel is built with CONFIG_RETPOLINE=n, but the user still wants to mitigate Spectre v2 using IBRS or eIBRS, the RSB filling will be silently disabled.
There's nothing retpoline-specific about RSB buffer filling. Remove the CONFIG_RETPOLINE guards around it.
--- arch/x86/entry/entry_32.S | 2 -- arch/x86/entry/entry_64.S | 2 -- arch/x86/include/asm/nospec-branch.h | 2 -- 3 files changed, 6 deletions(-)
arch/x86/entry/entry_32.S +0 -2
@@ -782,7 +782,6 @@ SYM_CODE_START(__switch_to_asm) movl %ebx, PER_CPU_VAR(stack_canary)+stack_canary_offset #endif -#ifdef CONFIG_RETPOLINE /* * When switching from a shallower to a deeper call stack * the RSB may either underflow or use entries populated
@@ -791,7 +790,6 @@ SYM_CODE_START(__switch_to_asm) * speculative execution to prevent attack. */ FILL_RETURN_BUFFER %ebx, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW -#endif /* Restore flags or the incoming task to restore AC state. */ popfl
arch/x86/entry/entry_64.S +0 -2
@@ -249,7 +249,6 @@ SYM_FUNC_START(__switch_to_asm) movq %rbx, PER_CPU_VAR(fixed_percpu_data) + stack_canary_offset #endif -#ifdef CONFIG_RETPOLINE /* * When switching from a shallower to a deeper call stack * the RSB may either underflow or use entries populated
@@ -258,7 +257,6 @@ SYM_FUNC_START(__switch_to_asm) * speculative execution to prevent attack. */ FILL_RETURN_BUFFER %r12, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW -#endif /* restore callee-saved registers */ popq %r15
arch/x86/include/asm/nospec-branch.h +0 -2
@@ -122,11 +122,9 @@* monstrosity above, manually. */ .macro FILL_RETURN_BUFFER reg:req nr:req ftr:req -#ifdef CONFIG_RETPOLINE ALTERNATIVE "jmp .Lskip_rsb_\@", "", \ftr __FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP) .Lskip_rsb_\@: -#endif .endm/*
Greg Kroah-Hartman
maintainerPATCH 113/130 x86/speculation: Fix firmware entry SPEC_CTRL handling
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit e6aa13622ea8283cc699cac5d018cc40a2ba2010 upstream.
The firmware entry code may accidentally clear STIBP or SSBD. Fix that.
--- arch/x86/include/asm/nospec-branch.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
arch/x86/include/asm/nospec-branch.h +4 -6
@@ -286,18 +286,16 @@ extern u64 spec_ctrl_current(void);*/ #define firmware_restrict_branch_speculation_start () \ do { \ - u64 val = x86_spec_ctrl_base | SPEC_CTRL_IBRS; \ - \ preempt_disable(); \ - alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \ + alternative_msr_write(MSR_IA32_SPEC_CTRL, \ + spec_ctrl_current() | SPEC_CTRL_IBRS, \ X86_FEATURE_USE_IBRS_FW); \ } while (0)#define firmware_restrict_branch_speculation_end () \ do { \ - u64 val = x86_spec_ctrl_base; \ - \ - alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \ + alternative_msr_write(MSR_IA32_SPEC_CTRL, \ + spec_ctrl_current(), \ X86_FEATURE_USE_IBRS_FW); \ preempt_enable(); \ } while (0)
Greg Kroah-Hartman
maintainerPATCH 114/130 x86/speculation: Fix SPEC_CTRL write on SMT state change
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit 56aa4d221f1ee2c3a49b45b800778ec6e0ab73c5 upstream.
If the SMT state changes, SSBD might get accidentally disabled. Fix that.
--- arch/x86/kernel/cpu/bugs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +2 -1
@@ -1414,7 +1414,8 @@ static void __init spectre_v2_select_mitstatic void update_stibp_msr (void * __unused) { -write_spec_ctrl_current (x86_spec_ctrl_base, true); +u64 val =spec_ctrl_current () | (x86_spec_ctrl_base &SPEC_CTRL_STIBP ); +write_spec_ctrl_current (val, true); }/* Update x86_spec_ctrl_base in case SMT state changed. */
Greg Kroah-Hartman
maintainerPATCH 115/130 x86/speculation: Use cached host SPEC_CTRL value for guest entry/exit
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit bbb69e8bee1bd882784947095ffb2bfe0f7c9470 upstream.
There's no need to recalculate the host value for every entry/exit. Just use the cached value in spec_ctrl_current().
--- arch/x86/kernel/cpu/bugs.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
arch/x86/kernel/cpu/bugs.c +1 -11
@@ -199,7 +199,7 @@ void __init check_bugs(void)void x86_virt_spec_ctrl (u64 guest_spec_ctrl,u64 guest_virt_spec_ctrl,bool setguest) { -u64 msrval, guestval, hostval = x86_spec_ctrl_base; +u64 msrval, guestval, hostval =spec_ctrl_current ();struct thread_info *ti =current_thread_info ();/* Is MSR_SPEC_CTRL implemented ? */
@@ -212,15 +212,6 @@ x86_virt_spec_ctrl(u64 guest_spec_ctrl, guestval = hostval & ~x86_spec_ctrl_mask; guestval |= guest_spec_ctrl & x86_spec_ctrl_mask; -/* SSBD controlled in MSR_SPEC_CTRL */ -if (static_cpu_has (X86_FEATURE_SPEC_CTRL_SSBD ) || -static_cpu_has (X86_FEATURE_AMD_SSBD )) - hostval |=ssbd_tif_to_spec_ctrl (ti->flags); - -/* Conditional STIBP enabled? */ -if (static_branch_unlikely (&switch_to_cond_stibp)) - hostval |=stibp_tif_to_spec_ctrl (ti->flags); -if (hostval != guestval) { msrval = setguest ? guestval : hostval;wrmsrl (MSR_IA32_SPEC_CTRL , msrval);
@@ -1353,7 +1344,6 @@ static void __init spectre_v2_select_mitpr_err (SPECTRE_V2_EIBRS_EBPF_MSG );if (spectre_v2_in_ibrs_mode (mode)) { -/* Force it so VMEXIT will restore correctly */ x86_spec_ctrl_base |=SPEC_CTRL_IBRS ;write_spec_ctrl_current (x86_spec_ctrl_base, true); }
Greg Kroah-Hartman
maintainerPATCH 116/130 x86/speculation: Remove x86_spec_ctrl_mask
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit acac5e98ef8d638a411cfa2ee676c87e1973f126 upstream.
This mask has been made redundant by kvm_spec_ctrl_test_value(). And it doesn't even work when MSR interception is disabled, as the guest can just write to SPEC_CTRL directly.
--- arch/x86/kernel/cpu/bugs.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-)
arch/x86/kernel/cpu/bugs.c +1 -30
@@ -85,12 +85,6 @@ u64 spec_ctrl_current(void)EXPORT_SYMBOL_GPL (spec_ctrl_current);/* -* The vendor and possibly platform specific bits which can be modified in -* x86_spec_ctrl_base. -*/ -static u64 __ro_after_init x86_spec_ctrl_mask =SPEC_CTRL_IBRS ; - -/* * AMD specific MSR info for Speculative Store Bypass control. * x86_amd_ls_cfg_ssbd_mask is initialized in identify_boot_cpu(). */
@@ -138,10 +132,6 @@ void __init check_bugs(void)if (boot_cpu_has (X86_FEATURE_MSR_SPEC_CTRL ))rdmsrl (MSR_IA32_SPEC_CTRL , x86_spec_ctrl_base); -/* Allow STIBP in MSR_SPEC_CTRL if supported */ -if (boot_cpu_has (X86_FEATURE_STIBP )) - x86_spec_ctrl_mask |=SPEC_CTRL_STIBP ; -/* Select the proper CPU mitigations before patching alternatives: */ spectre_v1_select_mitigation ();spectre_v2_select_mitigation ();
@@ -199,19 +189,10 @@ void __init check_bugs(void)void x86_virt_spec_ctrl (u64 guest_spec_ctrl,u64 guest_virt_spec_ctrl,bool setguest) { -u64 msrval, guestval, hostval =spec_ctrl_current (); +u64 msrval, guestval = guest_spec_ctrl, hostval =spec_ctrl_current ();struct thread_info *ti =current_thread_info (); -/* Is MSR_SPEC_CTRL implemented ? */ if (static_cpu_has (X86_FEATURE_MSR_SPEC_CTRL )) { -/* -* Restrict guest_spec_ctrl to supported values. Clear the -* modifiable bits in the host base value and or the -* modifiable bits from the guest value. -*/ - guestval = hostval & ~x86_spec_ctrl_mask; - guestval |= guest_spec_ctrl & x86_spec_ctrl_mask; -if (hostval != guestval) { msrval = setguest ? guestval : hostval;wrmsrl (MSR_IA32_SPEC_CTRL , msrval);
@@ -1622,16 +1603,6 @@ static enum ssb_mitigation __init __ssb_ }/* -* If SSBD is controlled by the SPEC_CTRL MSR, then set the proper -* bit in the mask to allow guests to use the mitigation even in the -* case where the host does not enable it. -*/ -if (static_cpu_has (X86_FEATURE_SPEC_CTRL_SSBD ) || -static_cpu_has (X86_FEATURE_AMD_SSBD )) { - x86_spec_ctrl_mask |=SPEC_CTRL_SSBD ; - } - -/* * We have three CPU feature flags that are in play here: * - X86_BUG_SPEC_STORE_BYPASS - CPU is susceptible. * - X86_FEATURE_SSBD - CPU is able to turn off speculative store bypass
Greg Kroah-Hartman
maintainerPATCH 117/130 objtool: Re-add UNWIND_HINT_{SAVE_RESTORE}
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit 8faea26e611189e933ea2281975ff4dc7c1106b6 upstream.
Commit
c536ed2fffd5 ("objtool: Remove SAVE/RESTORE hints")
removed the save/restore unwind hints because they were no longer needed. Now they're going to be needed again so re-add them.
--- arch/x86/include/asm/unwind_hints.h | 12 +++++++++- include/linux/objtool.h | 6 +++-- tools/include/linux/objtool.h | 6 +++-- tools/objtool/check.c | 40 ++++++++++++++++++++++++++++++++++++ tools/objtool/check.h | 1 5 files changed, 59 insertions(+), 6 deletions(-)
arch/x86/include/asm/unwind_hints.h +10 -2
@@ -8,11 +8,11 @@#ifdef __ASSEMBLY__ .macro UNWIND_HINT_EMPTY - UNWIND_HINT sp_reg=ORC_REG_UNDEFINED type=UNWIND_HINT_TYPE_CALL end=1 + UNWIND_HINT type=UNWIND_HINT_TYPE_CALL end=1 .endm .macro UNWIND_HINT_ENTRY - UNWIND_HINT sp_reg=ORC_REG_UNDEFINED type=UNWIND_HINT_TYPE_ENTRY end=1 + UNWIND_HINT type=UNWIND_HINT_TYPE_ENTRY end=1 .endm .macro UNWIND_HINT_REGS base=%rsp offset=0 indirect=0 extra=1 partial=0
@@ -56,6 +56,14 @@ UNWIND_HINT sp_reg=ORC_REG_SP sp_offset=8 type=UNWIND_HINT_TYPE_FUNC .endm +.macro UNWIND_HINT_SAVE + UNWIND_HINT type=UNWIND_HINT_TYPE_SAVE +.endm + +.macro UNWIND_HINT_RESTORE + UNWIND_HINT type=UNWIND_HINT_TYPE_RESTORE +.endm +#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_UNWIND_HINTS_H */
include/linux/objtool.h +4 -2
@@ -40,6 +40,8 @@ struct unwind_hint {#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3#define UNWIND_HINT_TYPE_ENTRY 4 +#define UNWIND_HINT_TYPE_SAVE 5 +#define UNWIND_HINT_TYPE_RESTORE 6#ifdef CONFIG_STACK_VALIDATION
@@ -102,7 +104,7 @@ struct unwind_hint {* the debuginfo as necessary. It will also warn if it sees any * inconsistencies. */ -.macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0 +.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 end=0 .Lunwind_hint_ip_\@: .pushsection .discard.unwind_hints/* struct unwind_hint */
@@ -126,7 +128,7 @@ struct unwind_hint {#define STACK_FRAME_NON_STANDARD (func)#else #define ANNOTATE_INTRA_FUNCTION_CALL -.macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0 +.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 end=0 .endm #endif
tools/include/linux/objtool.h +4 -2
@@ -40,6 +40,8 @@ struct unwind_hint {#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3#define UNWIND_HINT_TYPE_ENTRY 4 +#define UNWIND_HINT_TYPE_SAVE 5 +#define UNWIND_HINT_TYPE_RESTORE 6#ifdef CONFIG_STACK_VALIDATION
@@ -102,7 +104,7 @@ struct unwind_hint {* the debuginfo as necessary. It will also warn if it sees any * inconsistencies. */ -.macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0 +.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 end=0 .Lunwind_hint_ip_\@: .pushsection .discard.unwind_hints/* struct unwind_hint */
@@ -126,7 +128,7 @@ struct unwind_hint {#define STACK_FRAME_NON_STANDARD (func)#else #define ANNOTATE_INTRA_FUNCTION_CALL -.macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0 +.macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 end=0 .endm #endif
tools/objtool/check.c +40 -0
@@ -1752,6 +1752,17 @@ static int read_unwind_hints(struct objt insn->hint = true; +if (hint->type ==UNWIND_HINT_TYPE_SAVE ) { + insn->hint = false; + insn->save = true; +continue ; + } + +if (hint->type ==UNWIND_HINT_TYPE_RESTORE ) { + insn->restore = true; +continue ; + } +if (hint->type ==UNWIND_HINT_TYPE_REGS_PARTIAL ) {struct symbol *sym =find_symbol_by_offset (insn->sec, insn->offset);
@@ -2847,6 +2858,35 @@ static int validate_branch(struct objtoo state.instr += insn->instr;if (insn->hint) { +if (insn->restore) { +struct instruction *save_insn, *i; + + i = insn; + save_insn =NULL ; + +sym_for_each_insn_continue_reverse (file, func, i) { +if (i->save) { + save_insn = i; +break ; + } + } + +if (!save_insn) { +WARN_FUNC ("no corresponding CFI save for CFI restore" , + sec, insn->offset); +return 1 ; + } + +if (!save_insn->visited) { +WARN_FUNC ("objtool isn't smart enough to handle this CFI save/restore combo" , + sec, insn->offset); +return 1 ; + } + + insn->cfi = save_insn->cfi; + nr_cfi_reused++; + } + state.cfi = *insn->cfi; }else {/* XXX track if we actually changed state.cfi */
tools/objtool/check.h +1 -0
@@ -47,6 +47,7 @@ struct instruction {unsigned long immediate;bool dead_end, ignore, ignore_alts;bool hint; +bool save, restore;bool retpoline_safe;bool entry;s8 instr;
Greg Kroah-Hartman
maintainerPATCH 118/130 KVM: VMX: Flatten __vmx_vcpu_run()
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit 8bd200d23ec42d66ccd517a72dd0b9cc6132d2fd upstream.
Move the vmx_vm{enter,exit}() functionality into __vmx_vcpu_run(). This will make it easier to do the spec_ctrl handling before the first RET.
--- arch/x86/kvm/vmx/vmenter.S | 118 +++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 73 deletions(-)
arch/x86/kvm/vmx/vmenter.S +45 -73
@@ -31,68 +31,6 @@ .section .noinstr.text, "ax" /** - * vmx_vmenter - VM-Enter the current loaded VMCS - * - * %RFLAGS.ZF: !VMCS.LAUNCHED, i.e. controls VMLAUNCH vs. VMRESUME - * - * Returns: - * %RFLAGS.CF is set on VM-Fail Invalid - * %RFLAGS.ZF is set on VM-Fail Valid - * %RFLAGS.{CF,ZF} are cleared on VM-Success, i.e. VM-Exit - * - * Note that VMRESUME/VMLAUNCH fall-through and return directly if - * they VM-Fail, whereas a successful VM-Enter + VM-Exit will jump - * to vmx_vmexit. - */ -SYM_FUNC_START_LOCAL(vmx_vmenter) - /* EFLAGS.ZF is set if VMCS.LAUNCHED == 0 */ - je 2f - -1: vmresume - RET - -2: vmlaunch - RET - -3: cmpb $0, kvm_rebooting - je 4f - RET -4: ud2 - - _ASM_EXTABLE(1b, 3b) - _ASM_EXTABLE(2b, 3b) - -SYM_FUNC_END(vmx_vmenter) - -/** - * vmx_vmexit - Handle a VMX VM-Exit - * - * Returns: - * %RFLAGS.{CF,ZF} are cleared on VM-Success, i.e. VM-Exit - * - * This is vmx_vmenter's partner in crime. On a VM-Exit, control will jump - * here after hardware loads the host's state, i.e. this is the destination - * referred to by VMCS.HOST_RIP. - */ -SYM_FUNC_START(vmx_vmexit) -#ifdef CONFIG_RETPOLINE - ALTERNATIVE "jmp .Lvmexit_skip_rsb", "", X86_FEATURE_RETPOLINE - /* Preserve guest's RAX, it's used to stuff the RSB. */ - push %_ASM_AX - - /* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */ - FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE - - /* Clear RFLAGS.CF and RFLAGS.ZF to preserve VM-Exit, i.e. !VM-Fail. */ - or $1, %_ASM_AX - - pop %_ASM_AX -.Lvmexit_skip_rsb: -#endif - RET -SYM_FUNC_END(vmx_vmexit) - -/** * __vmx_vcpu_run - Run a vCPU via a transition to VMX guest mode * @vmx: struct vcpu_vmx * (forwarded to vmx_update_host_rsp) * @regs: unsigned long * (to guest registers)
@@ -124,8 +62,7 @@ SYM_FUNC_START(__vmx_vcpu_run) /* Copy @launched to BL, _ASM_ARG3 is volatile. */ mov %_ASM_ARG3B, %bl - /* Adjust RSP to account for the CALL to vmx_vmenter(). */ - lea -WORD_SIZE(%_ASM_SP), %_ASM_ARG2 + lea (%_ASM_SP), %_ASM_ARG2 call vmx_update_host_rsp /* Load @regs to RAX. */
@@ -154,11 +91,36 @@ SYM_FUNC_START(__vmx_vcpu_run) /* Load guest RAX. This kills the @regs pointer! */ mov VCPU_RAX(%_ASM_AX), %_ASM_AX - /* Enter guest mode */ - call vmx_vmenter + /* Check EFLAGS.ZF from 'testb' above */ + je .Lvmlaunch - /* Jump on VM-Fail. */ - jbe 2f + /* + * After a successful VMRESUME/VMLAUNCH, control flow "magically" + * resumes below at 'vmx_vmexit' due to the VMCS HOST_RIP setting. + * So this isn't a typical function and objtool needs to be told to + * save the unwind state here and restore it below. + */ + UNWIND_HINT_SAVE + +/* + * If VMRESUME/VMLAUNCH and corresponding vmexit succeed, execution resumes at + * the 'vmx_vmexit' label below. + */ +.Lvmresume: + vmresume + jmp .Lvmfail + +.Lvmlaunch: + vmlaunch + jmp .Lvmfail + + _ASM_EXTABLE(.Lvmresume, .Lfixup) + _ASM_EXTABLE(.Lvmlaunch, .Lfixup) + +SYM_INNER_LABEL(vmx_vmexit, SYM_L_GLOBAL) + + /* Restore unwind state from before the VMRESUME/VMLAUNCH. */ + UNWIND_HINT_RESTORE /* Temporarily save guest's RAX. */ push %_ASM_AX
@@ -185,9 +147,13 @@ SYM_FUNC_START(__vmx_vcpu_run) mov %r15, VCPU_R15(%_ASM_AX) #endif + /* IMPORTANT: RSB must be stuffed before the first return. */ + FILL_RETURN_BUFFER %_ASM_BX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE + /* Clear RAX to indicate VM-Exit (as opposed to VM-Fail). */ xor %eax, %eax +.Lclear_regs: /* * Clear all general purpose registers except RSP and RAX to prevent * speculative use of the guest's values, even those that are reloaded
@@ -197,7 +163,7 @@ SYM_FUNC_START(__vmx_vcpu_run) * free. RSP and RAX are exempt as RSP is restored by hardware during * VM-Exit and RAX is explicitly loaded with 0 or 1 to return VM-Fail. */ -1: xor %ecx, %ecx + xor %ecx, %ecx xor %edx, %edx xor %ebx, %ebx xor %ebp, %ebp
@@ -216,8 +182,8 @@ SYM_FUNC_START(__vmx_vcpu_run) /* "POP" @regs. */ add $WORD_SIZE, %_ASM_SP - pop %_ASM_BX + pop %_ASM_BX #ifdef CONFIG_X86_64 pop %r12 pop %r13
@@ -230,9 +196,15 @@ SYM_FUNC_START(__vmx_vcpu_run) pop %_ASM_BP RET - /* VM-Fail. Out-of-line to avoid a taken Jcc after VM-Exit. */ -2: mov $1, %eax - jmp 1b +.Lfixup: + cmpb $0, kvm_rebooting + jne .Lvmfail + ud2 +.Lvmfail: + /* VM-Fail: set return value to 1 */ + mov $1, %eax + jmp .Lclear_regs + SYM_FUNC_END(__vmx_vcpu_run)
Greg Kroah-Hartman
maintainerPATCH 119/130 KVM: VMX: Convert launched argument to flags
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit bb06650634d3552c0f8557e9d16aa1a408040e28 upstream.
Convert __vmx_vcpu_run()'s 'launched' argument to 'flags', in preparation for doing SPEC_CTRL handling immediately after vmexit, which will need another flag.
This is much easier than adding a fourth argument, because this code supports both 32-bit and 64-bit, and the fourth argument on 32-bit would have to be pushed on the stack.
Note that __vmx_vcpu_run_flags() is called outside of the noinstr critical section because it will soon start calling potentially traceable functions.
--- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/run_flags.h | 7 +++++++ arch/x86/kvm/vmx/vmenter.S | 9 +++++---- arch/x86/kvm/vmx/vmx.c | 17 ++++++++++++++--- arch/x86/kvm/vmx/vmx.h | 5 ++++- 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 arch/x86/kvm/vmx/run_flags.h
arch/x86/kvm/vmx/nested.c +1 -1
@@ -3077,7 +3077,7 @@ static int nested_vmx_check_vmentry_hw(s } vm_fail =__vmx_vcpu_run (vmx, (unsigned long *)&vcpu->arch.regs, - vmx->loaded_vmcs->launched); +__vmx_vcpu_run_flags (vmx));if (vmx->msr_autoload.host.nr)vmcs_write32 (VM_EXIT_MSR_LOAD_COUNT , vmx->msr_autoload.host.nr);
arch/x86/kvm/vmx/run_flags.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __KVM_X86_VMX_RUN_FLAGS_H +#define __KVM_X86_VMX_RUN_FLAGS_H + +#define VMX_RUN_VMRESUME (1 << 0) + +#endif /* __KVM_X86_VMX_RUN_FLAGS_H */
arch/x86/kvm/vmx/vmenter.S +5 -4
@@ -5,6 +5,7 @@ #include <asm/kvm_vcpu_regs.h> #include <asm/nospec-branch.h> #include <asm/segment.h> +#include "run_flags.h" #define WORD_SIZE (BITS_PER_LONG / 8)
@@ -34,7 +35,7 @@ * __vmx_vcpu_run - Run a vCPU via a transition to VMX guest mode * @vmx: struct vcpu_vmx * (forwarded to vmx_update_host_rsp) * @regs: unsigned long * (to guest registers) - * @launched: %true if the VMCS has been launched + * @flags: VMX_RUN_VMRESUME: use VMRESUME instead of VMLAUNCH * * Returns: * 0 on VM-Exit, 1 on VM-Fail
@@ -59,7 +60,7 @@ SYM_FUNC_START(__vmx_vcpu_run) */ push %_ASM_ARG2 - /* Copy @launched to BL, _ASM_ARG3 is volatile. */ + /* Copy @flags to BL, _ASM_ARG3 is volatile. */ mov %_ASM_ARG3B, %bl lea (%_ASM_SP), %_ASM_ARG2
@@ -69,7 +70,7 @@ SYM_FUNC_START(__vmx_vcpu_run) mov (%_ASM_SP), %_ASM_AX /* Check if vmlaunch or vmresume is needed */ - testb %bl, %bl + testb $VMX_RUN_VMRESUME, %bl /* Load guest registers. Don't clobber flags. */ mov VCPU_RCX(%_ASM_AX), %_ASM_CX
@@ -92,7 +93,7 @@ SYM_FUNC_START(__vmx_vcpu_run) mov VCPU_RAX(%_ASM_AX), %_ASM_AX /* Check EFLAGS.ZF from 'testb' above */ - je .Lvmlaunch + jz .Lvmlaunch /* * After a successful VMRESUME/VMLAUNCH, control flow "magically"
arch/x86/kvm/vmx/vmx.c +14 -3
@@ -936,6 +936,16 @@ static bool msr_write_intercepted(structreturn true; } +unsigned int __vmx_vcpu_run_flags (struct vcpu_vmx *vmx) +{ +unsigned int flags =0 ; + +if (vmx->loaded_vmcs->launched) + flags |=VMX_RUN_VMRESUME ; + +return flags; +} +static void clear_atomic_switch_msr_special (struct vcpu_vmx *vmx,unsigned long entry,unsigned long exit) {
@@ -6688,7 +6698,8 @@ static fastpath_t vmx_exit_handlers_fast } static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, -struct vcpu_vmx *vmx) +struct vcpu_vmx *vmx, +unsigned long flags) {/* * VMENTER enables interrupts (host state), but the kernel state is
@@ -6725,7 +6736,7 @@ static noinstr void vmx_vcpu_enter_exit(native_write_cr2 (vcpu->arch.cr2); vmx->fail =__vmx_vcpu_run (vmx, (unsigned long *)&vcpu->arch.regs, - vmx->loaded_vmcs->launched); + flags); vcpu->arch.cr2 =native_read_cr2 ();
@@ -6824,7 +6835,7 @@ reenter_guest:x86_spec_ctrl_set_guest (vmx->spec_ctrl,0 );/* The actual VMENTER/EXIT is in the .noinstr.text section. */ -vmx_vcpu_enter_exit (vcpu, vmx); +vmx_vcpu_enter_exit (vcpu, vmx,__vmx_vcpu_run_flags (vmx));/* * We do not use IBRS in the kernel. If this vCPU has used the
arch/x86/kvm/vmx/vmx.h +4 -1
@@ -13,6 +13,7 @@#include "vmcs.h" #include "vmx_ops.h" #include "cpuid.h" +#include "run_flags.h" extern const u32 vmx_msr_index[];
@@ -365,7 +366,9 @@ void vmx_set_virtual_apic_mode(struct kvstruct vmx_uret_msr *vmx_find_uret_msr (struct vcpu_vmx *vmx,u32 msr);void pt_update_intercept_for_msr (struct kvm_vcpu *vcpu);void vmx_update_host_rsp (struct vcpu_vmx *vmx,unsigned long host_rsp); -bool __vmx_vcpu_run (struct vcpu_vmx *vmx,unsigned long *regs,bool launched); +unsigned int __vmx_vcpu_run_flags (struct vcpu_vmx *vmx); +bool __vmx_vcpu_run (struct vcpu_vmx *vmx,unsigned long *regs, +unsigned int flags);int vmx_find_loadstore_msr_slot (struct vmx_msrs *m,u32 msr);void vmx_ept_load_pdptrs (struct kvm_vcpu *vcpu);
Greg Kroah-Hartman
maintainerPATCH 120/130 KVM: VMX: Prevent guest RSB poisoning attacks with eIBRS
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit fc02735b14fff8c6678b521d324ade27b1a3d4cf upstream.
On eIBRS systems, the returns in the vmexit return path from __vmx_vcpu_run() to vmx_vcpu_run() are exposed to RSB poisoning attacks.
Fix that by moving the post-vmexit spec_ctrl handling to immediately after the vmexit.
--- arch/x86/include/asm/nospec-branch.h | 1 arch/x86/kernel/cpu/bugs.c | 4 ++ arch/x86/kvm/vmx/run_flags.h | 1 arch/x86/kvm/vmx/vmenter.S | 49 +++++++++++++++++++++++++++-------- arch/x86/kvm/vmx/vmx.c | 48 ++++++++++++++++++++-------------- arch/x86/kvm/vmx/vmx.h | 1 6 files changed, 73 insertions(+), 31 deletions(-)
arch/x86/include/asm/nospec-branch.h +1 -0
@@ -275,6 +275,7 @@ static inline void indirect_branch_predi/* The Intel SPEC CTRL MSR base value cache */ extern u64 x86_spec_ctrl_base; +extern u64 x86_spec_ctrl_current;extern void write_spec_ctrl_current (u64 val,bool force);extern u64 spec_ctrl_current (void );
arch/x86/kernel/cpu/bugs.c +4 -0
@@ -186,6 +186,10 @@ void __init check_bugs(void)#endif } +/* +* NOTE: For VMX, this function is not called in the vmexit path. +* It uses vmx_spec_ctrl_restore_host() instead. +*/ void x86_virt_spec_ctrl (u64 guest_spec_ctrl,u64 guest_virt_spec_ctrl,bool setguest) {
arch/x86/kvm/vmx/run_flags.h +1 -0
@@ -3,5 +3,6 @@#define __KVM_X86_VMX_RUN_FLAGS_H#define VMX_RUN_VMRESUME (1 << 0) +#define VMX_RUN_SAVE_SPEC_CTRL (1 << 1)#endif /* __KVM_X86_VMX_RUN_FLAGS_H */
arch/x86/kvm/vmx/vmenter.S +38 -11
91 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.c +28 -20
66 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.h +1 -0
@@ -366,6 +366,7 @@ void vmx_set_virtual_apic_mode(struct kvstruct vmx_uret_msr *vmx_find_uret_msr (struct vcpu_vmx *vmx,u32 msr);void pt_update_intercept_for_msr (struct kvm_vcpu *vcpu);void vmx_update_host_rsp (struct vcpu_vmx *vmx,unsigned long host_rsp); +void vmx_spec_ctrl_restore_host (struct vcpu_vmx *vmx,unsigned int flags);unsigned int __vmx_vcpu_run_flags (struct vcpu_vmx *vmx);bool __vmx_vcpu_run (struct vcpu_vmx *vmx,unsigned long *regs,unsigned int flags);
Greg Kroah-Hartman
maintainerPATCH 121/130 KVM: VMX: Fix IBRS handling after vmexit
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit bea7e31a5caccb6fe8ed989c065072354f0ecb52 upstream.
For legacy IBRS to work, the IBRS bit needs to be always re-written after vmexit, even if it's already on.
--- arch/x86/kvm/vmx/vmx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +6 -1
@@ -6706,8 +6706,13 @@ void noinstr vmx_spec_ctrl_restore_host(/* * If the guest/host SPEC_CTRL values differ, restore the host value. +* +* For legacy IBRS, the IBRS bit always needs to be written after +* transitioning from a less privileged predictor mode, regardless of +* whether the guest/host values differ. */ -if (vmx->spec_ctrl != hostval) +if (cpu_feature_enabled (X86_FEATURE_KERNEL_IBRS ) || + vmx->spec_ctrl != hostval)native_wrmsrl (MSR_IA32_SPEC_CTRL , hostval);barrier_nospec ();
Greg Kroah-Hartman
maintainerPATCH 122/130 x86/speculation: Fill RSB on vmexit for IBRS
In reply to Greg Kroah-HartmanFrom: Josh Poimboeuf <[email protected]>
commit 9756bba28470722dacb79ffce554336dd1f6a6cd upstream.
Prevent RSB underflow/poisoning attacks with RSB. While at it, add a bunch of comments to attempt to document the current state of tribal knowledge about RSB attacks and what exactly is being mitigated.
--- arch/x86/include/asm/cpufeatures.h | 2 - arch/x86/kernel/cpu/bugs.c | 63 ++++++++++++++++++++++++++++++++++--- arch/x86/kvm/vmx/vmenter.S | 6 +-- 3 files changed, 62 insertions(+), 9 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -204,7 +204,7 @@#define X86_FEATURE_SME ( 7*32+10)/* AMD Secure Memory Encryption */ #define X86_FEATURE_PTI ( 7*32+11)/* Kernel Page Table Isolation enabled */ #define X86_FEATURE_KERNEL_IBRS ( 7*32+12)/* "" Set/clear IBRS on kernel entry/exit */ -/* FREE! ( 7*32+13) */ +#define X86_FEATURE_RSB_VMEXIT ( 7*32+13)/* "" Fill RSB on VM-Exit */ #define X86_FEATURE_INTEL_PPIN ( 7*32+14)/* Intel Processor Inventory Number */ #define X86_FEATURE_CDP_L2 ( 7*32+15)/* Code and Data Prioritization L2 */ #define X86_FEATURE_MSR_SPEC_CTRL ( 7*32+16)/* "" MSR SPEC_CTRL is implemented */
arch/x86/kernel/cpu/bugs.c +58 -5
75 lines not on this page · raw message
arch/x86/kvm/vmx/vmenter.S +3 -3
@@ -193,15 +193,15 @@ SYM_INNER_LABEL(vmx_vmexit, SYM_L_GLOBAL * IMPORTANT: RSB filling and SPEC_CTRL handling must be done before * the first unbalanced RET after vmexit! * - * For retpoline, RSB filling is needed to prevent poisoned RSB entries - * and (in some cases) RSB underflow. + * For retpoline or IBRS, RSB filling is needed to prevent poisoned RSB + * entries and (in some cases) RSB underflow. * * eIBRS has its own protection against poisoned RSB, so it doesn't * need the RSB filling sequence. But it does need to be enabled * before the first unbalanced RET. */ - FILL_RETURN_BUFFER %_ASM_CX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE + FILL_RETURN_BUFFER %_ASM_CX, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT pop %_ASM_ARG2 /* @flags */ pop %_ASM_ARG1 /* @vmx */
Greg Kroah-Hartman
maintainerPATCH 123/130 x86/common: Stamp out the stepping madness
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 7a05bc95ed1c5a59e47aaade9fb4083c27de9e62 upstream.
The whole MMIO/RETBLEED enumeration went overboard on steppings. Get rid of all that and simply use ANY.
If a future stepping of these models would not be affected, it had better set the relevant ARCH_CAP_$FOO_NO bit in IA32_ARCH_CAPABILITIES.
--- arch/x86/kernel/cpu/common.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
arch/x86/kernel/cpu/common.c +16 -21
@@ -1119,32 +1119,27 @@ static const struct x86_cpu_id cpu_vuln_VULNBL_INTEL_STEPPINGS (HASWELL ,X86_STEPPING_ANY ,SRBDS ),VULNBL_INTEL_STEPPINGS (HASWELL_L ,X86_STEPPING_ANY ,SRBDS ),VULNBL_INTEL_STEPPINGS (HASWELL_G ,X86_STEPPING_ANY ,SRBDS ), -VULNBL_INTEL_STEPPINGS (HASWELL_X ,BIT (2 ) |BIT (4 ),MMIO ), -VULNBL_INTEL_STEPPINGS (BROADWELL_D ,X86_STEPPINGS (0x3 ,0x5 ),MMIO ), +VULNBL_INTEL_STEPPINGS (HASWELL_X ,X86_STEPPING_ANY ,MMIO ), +VULNBL_INTEL_STEPPINGS (BROADWELL_D ,X86_STEPPING_ANY ,MMIO ),VULNBL_INTEL_STEPPINGS (BROADWELL_G ,X86_STEPPING_ANY ,SRBDS ),VULNBL_INTEL_STEPPINGS (BROADWELL_X ,X86_STEPPING_ANY ,MMIO ),VULNBL_INTEL_STEPPINGS (BROADWELL ,X86_STEPPING_ANY ,SRBDS ), -VULNBL_INTEL_STEPPINGS (SKYLAKE_L ,X86_STEPPINGS (0x3 ,0x3 ),SRBDS |MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (SKYLAKE_L ,X86_STEPPING_ANY ,SRBDS ), -VULNBL_INTEL_STEPPINGS (SKYLAKE_X ,BIT (3 ) |BIT (4 ) |BIT (6 ) | -BIT (7 ) |BIT (0xB ),MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPINGS (0x3 ,0x3 ),SRBDS |MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPING_ANY ,SRBDS ), -VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPINGS (0x9 ,0xC ),SRBDS |MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPINGS (0x0 ,0x8 ),SRBDS ), -VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPINGS (0x9 ,0xD ),SRBDS |MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPINGS (0x0 ,0x8 ),SRBDS ), -VULNBL_INTEL_STEPPINGS (ICELAKE_L ,X86_STEPPINGS (0x5 ,0x5 ),MMIO |MMIO_SBDS |RETBLEED ), -VULNBL_INTEL_STEPPINGS (ICELAKE_D ,X86_STEPPINGS (0x1 ,0x1 ),MMIO ), -VULNBL_INTEL_STEPPINGS (ICELAKE_X ,X86_STEPPINGS (0x4 ,0x6 ),MMIO ), -VULNBL_INTEL_STEPPINGS (COMETLAKE ,BIT (2 ) |BIT (3 ) |BIT (5 ),MMIO |MMIO_SBDS |RETBLEED ), -VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (SKYLAKE_L ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (SKYLAKE_X ,X86_STEPPING_ANY ,MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (ICELAKE_L ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (ICELAKE_D ,X86_STEPPING_ANY ,MMIO ), +VULNBL_INTEL_STEPPINGS (ICELAKE_X ,X86_STEPPING_ANY ,MMIO ), +VULNBL_INTEL_STEPPINGS (COMETLAKE ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS |RETBLEED ),VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPINGS (0x0 ,0x0 ),MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (LAKEFIELD ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS |RETBLEED ), -VULNBL_INTEL_STEPPINGS (ROCKETLAKE ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |RETBLEED ), -VULNBL_INTEL_STEPPINGS (ATOM_TREMONT ,X86_STEPPINGS (0x1 ,0x1 ),MMIO |MMIO_SBDS ), +VULNBL_INTEL_STEPPINGS (COMETLAKE_L ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (LAKEFIELD ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS |RETBLEED ), +VULNBL_INTEL_STEPPINGS (ROCKETLAKE ,X86_STEPPING_ANY ,MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (ATOM_TREMONT ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS ),VULNBL_INTEL_STEPPINGS (ATOM_TREMONT_D ,X86_STEPPING_ANY ,MMIO ), -VULNBL_INTEL_STEPPINGS (ATOM_TREMONT_L ,X86_STEPPINGS (0x0 ,0x0 ),MMIO |MMIO_SBDS ), +VULNBL_INTEL_STEPPINGS (ATOM_TREMONT_L ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS ),VULNBL_AMD (0x15 ,RETBLEED ), VULNBL_AMD(0x16, RETBLEED),
Greg Kroah-Hartman
maintainerPATCH 124/130 x86/cpu/amd: Enumerate BTC_NO
In reply to Greg Kroah-HartmanFrom: Andrew Cooper <[email protected]>
commit 26aae8ccbc1972233afd08fb3f368947c0314265 upstream.
BTC_NO indicates that hardware is not susceptible to Branch Type Confusion.
Zen3 CPUs don't suffer BTC.
Hypervisors are expected to synthesise BTC_NO when it is appropriate given the migration pool, to prevent kernels using heuristics.
[ bp: Massage. ]
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/amd.c | 21 +++++++++++++++------ arch/x86/kernel/cpu/common.c | 6 ++++-- 3 files changed, 20 insertions(+), 8 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -316,6 +316,7 @@#define X86_FEATURE_AMD_SSBD (13*32+24)/* "" Speculative Store Bypass Disable */ #define X86_FEATURE_VIRT_SSBD (13*32+25)/* Virtualized Speculative Store Bypass Disable */ #define X86_FEATURE_AMD_SSB_NO (13*32+26)/* "" Speculative Store Bypass is fixed in hardware. */ +#define X86_FEATURE_BTC_NO (13*32+29)/* "" Not vulnerable to Branch Type Confusion */ /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ #define X86_FEATURE_DTHERM (14*32+ 0)/* Digital Thermal Sensor */
arch/x86/kernel/cpu/amd.c +15 -6
@@ -942,12 +942,21 @@ static void init_amd_zn(struct cpuinfo_x node_reclaim_distance =32 ;#endif -/* -* Fix erratum 1076: CPB feature bit not being set in CPUID. -* Always set it, except when running under a hypervisor. -*/ -if (!cpu_has (c,X86_FEATURE_HYPERVISOR ) && !cpu_has (c,X86_FEATURE_CPB )) -set_cpu_cap (c,X86_FEATURE_CPB ); +/* Fix up CPUID bits, but only if not virtualised. */ +if (!cpu_has (c,X86_FEATURE_HYPERVISOR )) { + +/* Erratum 1076: CPB feature bit not being set in CPUID. */ +if (!cpu_has (c,X86_FEATURE_CPB )) +set_cpu_cap (c,X86_FEATURE_CPB ); + +/* +* Zen3 (Fam19 model < 0x10) parts are not susceptible to +* Branch Type Confusion, but predate the allocation of the +* BTC_NO bit. +*/ +if (c->x86 ==0x19 && !cpu_has (c,X86_FEATURE_BTC_NO )) +set_cpu_cap (c,X86_FEATURE_BTC_NO ); + } }static void init_amd (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/common.c +4 -2
@@ -1246,8 +1246,10 @@ static void __init cpu_set_bug_bits(stru !arch_cap_mmio_immune(ia32_cap))setup_force_cpu_bug (X86_BUG_MMIO_STALE_DATA ); -if ((cpu_matches (cpu_vuln_blacklist,RETBLEED ) || (ia32_cap &ARCH_CAP_RSBA ))) -setup_force_cpu_bug (X86_BUG_RETBLEED ); +if (!cpu_has (c,X86_FEATURE_BTC_NO )) { +if (cpu_matches (cpu_vuln_blacklist,RETBLEED ) || (ia32_cap &ARCH_CAP_RSBA )) +setup_force_cpu_bug (X86_BUG_RETBLEED ); + }if (cpu_matches (cpu_vuln_whitelist,NO_MELTDOWN ))return ;
Greg Kroah-Hartman
maintainerPATCH 125/130 x86/retbleed: Add fine grained Kconfig knobs
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit f43b9876e857c739d407bc56df288b0ebe1a9164 upstream.
Do fine-grained Kconfig for all the various retbleed parts.
NOTE: if your compiler doesn't support return thunks this will silently 'upgrade' your mitigation to IBPB, you might not like this.
[bwh: Backported to 5.10:
- In scripts/Makefile.build, add the objtool option with an ifdef block, same as for other options
- Adjust filename, context]
--- Makefile | 8 +- arch/x86/Kconfig | 106 +++++++++++++++++++++++-------- arch/x86/entry/calling.h | 4 + arch/x86/include/asm/disabled-features.h | 18 ++++- arch/x86/include/asm/linkage.h | 4 - arch/x86/include/asm/nospec-branch.h | 10 ++ arch/x86/include/asm/static_call.h | 2 arch/x86/kernel/alternative.c | 5 + arch/x86/kernel/cpu/amd.c | 2 arch/x86/kernel/cpu/bugs.c | 42 +++++++----- arch/x86/kernel/static_call.c | 2 arch/x86/kvm/emulate.c | 4 - arch/x86/lib/retpoline.S | 4 + scripts/Makefile.build | 3 scripts/link-vmlinux.sh | 2 security/Kconfig | 11 --- tools/objtool/builtin-check.c | 3 tools/objtool/builtin.h | 2 tools/objtool/check.c | 9 ++ 19 files changed, 172 insertions(+), 69 deletions(-)
Makefile +6 -2
@@ -672,14 +672,18 @@ endif ifdef CONFIG_CC_IS_GCC RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) -RETPOLINE_CFLAGS += $(call cc-option,-mfunction-return=thunk-extern) RETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register) endif ifdef CONFIG_CC_IS_CLANG RETPOLINE_CFLAGS := -mretpoline-external-thunk RETPOLINE_VDSO_CFLAGS := -mretpoline -RETPOLINE_CFLAGS += $(call cc-option,-mfunction-return=thunk-extern) endif + +ifdef CONFIG_RETHUNK +RETHUNK_CFLAGS := -mfunction-return=thunk-extern +RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS) +endif + export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS
arch/x86/Kconfig +82 -24
118 lines not on this page · raw message
arch/x86/entry/calling.h +4 -0
@@ -323,6 +323,7 @@ For 32-bit we have the following convent* Assumes x86_spec_ctrl_{base,current} to have SPEC_CTRL_IBRS set. */ .macro IBRS_ENTER save_reg +#ifdef CONFIG_CPU_IBRS_ENTRY ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS movl $MSR_IA32_SPEC_CTRL, %ecx
@@ -343,6 +344,7 @@ For 32-bit we have the following convent shr $32, %rdx wrmsr .Lend_\@: +#endif .endm/*
@@ -350,6 +352,7 @@ For 32-bit we have the following convent* regs. Must be called after the last RET. */ .macro IBRS_EXIT save_reg +#ifdef CONFIG_CPU_IBRS_ENTRY ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS movl $MSR_IA32_SPEC_CTRL, %ecx
@@ -364,6 +367,7 @@ For 32-bit we have the following convent shr $32, %rdx wrmsr .Lend_\@: +#endif .endm/*
arch/x86/include/asm/disabled-features.h +14 -4
@@ -60,9 +60,19 @@# define DISABLE_RETPOLINE 0#else # define DISABLE_RETPOLINE ((1 << (X86_FEATURE_RETPOLINE & 31)) | \ - (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31)) | \ - (1 << (X86_FEATURE_RETHUNK & 31)) | \ - (1 << (X86_FEATURE_UNRET & 31))) + (1 << (X86_FEATURE_RETPOLINE_LFENCE & 31))) +#endif + +#ifdef CONFIG_RETHUNK +# define DISABLE_RETHUNK 0 +#else +# define DISABLE_RETHUNK (1 << (X86_FEATURE_RETHUNK & 31)) +#endif + +#ifdef CONFIG_CPU_UNRET_ENTRY +# define DISABLE_UNRET 0 +#else +# define DISABLE_UNRET (1 << (X86_FEATURE_UNRET & 31))#endif /* Force disable because it's broken beyond repair */
@@ -82,7 +92,7 @@#define DISABLED_MASK8 0#define DISABLED_MASK9 (DISABLE_SMAP)#define DISABLED_MASK10 0 -#define DISABLED_MASK11 (DISABLE_RETPOLINE) +#define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET)#define DISABLED_MASK12 0#define DISABLED_MASK13 0#define DISABLED_MASK14 0
arch/x86/include/asm/linkage.h +2 -2
@@ -18,7 +18,7 @@#define __ALIGN_STR __stringify(__ALIGN)#endif -#if defined(CONFIG_RETPOLINE ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO ) +#if defined(CONFIG_RETHUNK ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO )#define RET jmp __x86_return_thunk#else /* CONFIG_RETPOLINE */ #ifdef CONFIG_SLS
@@ -30,7 +30,7 @@#else /* __ASSEMBLY__ */ -#if defined(CONFIG_RETPOLINE ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO ) +#if defined(CONFIG_RETHUNK ) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO )#define ASM_RET "jmp __x86_return_thunk\n\t"#else /* CONFIG_RETPOLINE */ #ifdef CONFIG_SLS
arch/x86/include/asm/nospec-branch.h +8 -2
@@ -127,6 +127,12 @@ .Lskip_rsb_\@: .endm +#ifdef CONFIG_CPU_UNRET_ENTRY +#define CALL_ZEN_UNTRAIN_RET "call zen_untrain_ret" +#else +#define CALL_ZEN_UNTRAIN_RET "" +#endif +/* * Mitigate RETBleed for AMD/Hygon Zen uarch. Requires KERNEL CR3 because the * return thunk isn't mapped into the userspace tables (then again, AMD
@@ -139,10 +145,10 @@* where we have a stack but before any RET instruction. */ .macro UNTRAIN_RET -#ifdef CONFIG_RETPOLINE +#if defined(CONFIG_CPU_UNRET_ENTRY ) || defined(CONFIG_CPU_IBPB_ENTRY )ANNOTATE_UNRET_END ALTERNATIVE_2 "", \ -"call zen_untrain_ret" ,X86_FEATURE_UNRET , \ +CALL_ZEN_UNTRAIN_RET ,X86_FEATURE_UNRET , \"call entry_ibpb" ,X86_FEATURE_ENTRY_IBPB #endif .endm
arch/x86/include/asm/static_call.h +1 -1
@@ -44,7 +44,7 @@#define ARCH_DEFINE_STATIC_CALL_TRAMP (name, func) \ __ARCH_DEFINE_STATIC_CALL_TRAMP(name, ".byte 0xe9; .long " #func " - (. + 4)") -#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_RETHUNK #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP (name) \ __ARCH_DEFINE_STATIC_CALL_TRAMP(name, "jmp __x86_return_thunk")#else
arch/x86/kernel/alternative.c +5 -0
@@ -662,6 +662,7 @@ void __init_or_module noinline apply_ret } } +#ifdef CONFIG_RETHUNK /* * Rewrite the compiler generated return thunk tail-calls. *
@@ -723,6 +724,10 @@ void __init_or_module noinline apply_ret } } } +#else +void __init_or_module noinline apply_returns(s32 *start, s32 *end) { } +#endif /* CONFIG_RETHUNK */ +#else /* !RETPOLINES || !CONFIG_STACK_VALIDATION */ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) { }
arch/x86/kernel/cpu/amd.c +2 -0
@@ -916,6 +916,7 @@ static void init_amd_bd(struct cpuinfo_xvoid init_spectral_chicken (struct cpuinfo_x86 *c) { +#ifdef CONFIG_CPU_UNRET_ENTRY u64 value;/*
@@ -932,6 +933,7 @@ void init_spectral_chicken(struct cpuinf wrmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value); } } +#endif }static void init_amd_zn (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/bugs.c +27 -15
86 lines not on this page · raw message
arch/x86/kernel/static_call.c +1 -1
@@ -108,7 +108,7 @@ void arch_static_call_transform(void *si }EXPORT_SYMBOL_GPL (arch_static_call_transform); -#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_RETHUNK /* * This is called by apply_returns() to fix up static call trampolines, * specifically ARCH_DEFINE_STATIC_CALL_NULL_TRAMP which is recorded as
arch/x86/kvm/emulate.c +2 -2
@@ -435,10 +435,10 @@ static int fastop(struct x86_emulate_ctx* Depending on .config the SETcc functions look like: * * SETcc %al [3 bytes] -* RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETPOLINE] +* RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETHUNK] * INT3 [1 byte; CONFIG_SLS] */ -#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETPOLINE)) + \ +#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETHUNK)) + \ IS_ENABLED(CONFIG_SLS))#define SETCC_LENGTH (3 + RET_LENGTH)#define SETCC_ALIGN (4 << ((SETCC_LENGTH > 4) & 1) << ((SETCC_LENGTH > 8) & 1))
arch/x86/lib/retpoline.S +4 -0
@@ -71,6 +71,8 @@ SYM_CODE_END(__x86_indirect_thunk_array) * This function name is magical and is used by -mfunction-return=thunk-extern * for the compiler to generate JMPs to it. */ +#ifdef CONFIG_RETHUNK + .section .text.__x86.return_thunk /*
@@ -135,3 +137,5 @@ SYM_FUNC_END(zen_untrain_ret) __EXPORT_THUNK(zen_untrain_ret) EXPORT_SYMBOL(__x86_return_thunk) + +#endif /* CONFIG_RETHUNK */
scripts/Makefile.build +3 -0
@@ -227,6 +227,9 @@ endif ifdef CONFIG_RETPOLINE objtool_args += --retpoline endif +ifdef CONFIG_RETHUNK + objtool_args += --rethunk +endif ifdef CONFIG_X86_SMAP objtool_args += --uaccess endif
scripts/link-vmlinux.sh +1 -1
@@ -65,7 +65,7 @@ objtool_link() if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then objtoolopt="check" - if [ -n "${CONFIG_RETPOLINE}" ]; then + if [ -n "${CONFIG_CPU_UNRET_ENTRY}" ]; then objtoolopt="${objtoolopt} --unret" fi if [ -z "${CONFIG_FRAME_POINTER}" ]; then
security/Kconfig +0 -11
@@ -54,17 +54,6 @@ config SECURITY_NETWORK implement socket and networking access controls. If you are unsure how to answer this question, answer N. -config PAGE_TABLE_ISOLATION - bool "Remove the kernel mapping in user mode" - default y - depends on (X86_64 || X86_PAE) && !UML - help - This feature reduces the number of hardware side channels by - ensuring that the majority of kernel addresses are not mapped - into userspace. - - See Documentation/x86/pti.rst for more details. - config SECURITY_INFINIBAND bool "Infiniband Security Hooks" depends on SECURITY && INFINIBAND
tools/objtool/builtin-check.c +2 -1
@@ -19,7 +19,7 @@#include "objtool.h" bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - validate_dup, vmlinux, sls, unret; + validate_dup, vmlinux, sls, unret, rethunk;static const char *const check_usage[] = {"objtool check [<options>] file.o" ,
@@ -30,6 +30,7 @@ const struct option check_options[] = {OPT_BOOLEAN ('f' ,"no-fp" , &no_fp,"Skip frame pointer validation" ),OPT_BOOLEAN ('u' ,"no-unreachable" , &no_unreachable,"Skip 'unreachable instruction' warnings" ),OPT_BOOLEAN ('r' ,"retpoline" , &retpoline,"Validate retpoline assumptions" ), +OPT_BOOLEAN (0 ,"rethunk" , &rethunk,"validate and annotate rethunk usage" ),OPT_BOOLEAN (0 ,"unret" , &unret,"validate entry unret placement" ),OPT_BOOLEAN ('m' ,"module" , &module,"Indicates the object will be part of a kernel module" ), OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"),
tools/objtool/builtin.h +1 -1
@@ -9,7 +9,7 @@extern const struct option check_options[];extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - validate_dup, vmlinux, sls, unret; + validate_dup, vmlinux, sls, unret, rethunk;extern int cmd_check (int argc,const char **argv);extern int cmd_orc (int argc,const char **argv);
tools/objtool/check.c +7 -2
@@ -3262,8 +3262,11 @@ static int validate_retpoline(struct objcontinue ;if (insn->type ==INSN_RETURN ) { -WARN_FUNC ("'naked' return found in RETPOLINE build" , - insn->sec, insn->offset); +if (rethunk) { +WARN_FUNC ("'naked' return found in RETHUNK build" , + insn->sec, insn->offset); + }else +continue ; }else { WARN_FUNC("indirect %s found in RETPOLINE build", insn->sec, insn->offset,
@@ -3533,7 +3536,9 @@ int check(struct objtool_file *file)if (ret <0 ) goto out; warnings += ret; + } +if (rethunk) { ret =create_return_sites_sections (file);if (ret <0 ) goto out;
Greg Kroah-Hartman
maintainerPATCH 126/130 x86/bugs: Add Cannon lake to RETBleed affected CPU list
In reply to Greg Kroah-HartmanFrom: Pawan Gupta <[email protected]>
commit f54d45372c6ac9c993451de5e51312485f7d10bc upstream.
Cannon lake is also affected by RETBleed, add it to the list.
--- arch/x86/kernel/cpu/common.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/common.c +1 -0
@@ -1129,6 +1129,7 @@ static const struct x86_cpu_id cpu_vuln_VULNBL_INTEL_STEPPINGS (SKYLAKE ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (KABYLAKE_L ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ),VULNBL_INTEL_STEPPINGS (KABYLAKE ,X86_STEPPING_ANY ,SRBDS |MMIO |RETBLEED ), +VULNBL_INTEL_STEPPINGS (CANNONLAKE_L ,X86_STEPPING_ANY ,RETBLEED ),VULNBL_INTEL_STEPPINGS (ICELAKE_L ,X86_STEPPING_ANY ,MMIO |MMIO_SBDS |RETBLEED ),VULNBL_INTEL_STEPPINGS (ICELAKE_D ,X86_STEPPING_ANY ,MMIO ), VULNBL_INTEL_STEPPINGS(ICELAKE_X, X86_STEPPING_ANY, MMIO),
Greg Kroah-Hartman
maintainerPATCH 127/130 x86/bugs: Do not enable IBPB-on-entry when IBPB is not supported
In reply to Greg Kroah-HartmanFrom: Thadeu Lima de Souza Cascardo <[email protected]>
commit 2259da159fbe5dba8ac00b560cf00b6a6537fa18 upstream.
There are some VM configurations which have Skylake model but do not support IBPB. In those cases, when using retbleed=ibpb, userspace is going to be killed and kernel is going to panic.
If the CPU does not support IBPB, warn and proceed with the auto option. Also, do not fallback to IBPB on AMD/Hygon systems if it is not supported.
--- arch/x86/kernel/cpu/bugs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/bugs.c +5 -2
@@ -821,7 +821,10 @@ static void __init retbleed_select_mitigbreak ;case RETBLEED_CMD_IBPB : -if (IS_ENABLED (CONFIG_CPU_IBPB_ENTRY )) { +if (!boot_cpu_has (X86_FEATURE_IBPB )) { +pr_err ("WARNING: CPU does not support IBPB.\n" ); + goto do_cmd_auto; + }else if (IS_ENABLED (CONFIG_CPU_IBPB_ENTRY )) { retbleed_mitigation =RETBLEED_MITIGATION_IBPB ; }else {pr_err ("WARNING: kernel not compiled with CPU_IBPB_ENTRY.\n" );
@@ -836,7 +839,7 @@ do_cmd_auto: boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {if (IS_ENABLED (CONFIG_CPU_UNRET_ENTRY )) retbleed_mitigation =RETBLEED_MITIGATION_UNRET ; -else if (IS_ENABLED (CONFIG_CPU_IBPB_ENTRY )) +else if (IS_ENABLED (CONFIG_CPU_IBPB_ENTRY ) &&boot_cpu_has (X86_FEATURE_IBPB )) retbleed_mitigation =RETBLEED_MITIGATION_IBPB ; }
Greg Kroah-Hartman
maintainerPATCH 128/130 x86/kexec: Disable RET on kexec
In reply to Greg Kroah-HartmanFrom: Konrad Rzeszutek Wilk <[email protected]>
commit 697977d8415d61f3acbc4ee6d564c9dcf0309507 upstream.
All the invocations unroll to __x86_return_thunk and this file must be PIC independent.
This fixes kexec on 64-bit AMD boxes.
[ bp: Fix 32-bit build. ]
--- arch/x86/kernel/relocate_kernel_32.S | 25 +++++++++++++++++++------ arch/x86/kernel/relocate_kernel_64.S | 23 +++++++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-)
arch/x86/kernel/relocate_kernel_32.S +19 -6
@@ -7,10 +7,12 @@ #include <linux/linkage.h> #include <asm/page_types.h> #include <asm/kexec.h> +#include <asm/nospec-branch.h> #include <asm/processor-flags.h> /* - * Must be relocatable PIC code callable as a C function + * Must be relocatable PIC code callable as a C function, in particular + * there must be a plain RET and not jump to return thunk. */ #define PTR(x) (x << 2)
@@ -91,7 +93,9 @@ SYM_CODE_START_NOALIGN(relocate_kernel) movl %edi, %eax addl $(identity_mapped - relocate_kernel), %eax pushl %eax - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(relocate_kernel) SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
@@ -159,12 +163,15 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_ma xorl %edx, %edx xorl %esi, %esi xorl %ebp, %ebp - RET + ANNOTATE_UNRET_SAFE + ret + int3 1: popl %edx movl CP_PA_SWAP_PAGE(%edi), %esp addl $PAGE_SIZE, %esp 2: + ANNOTATE_RETPOLINE_SAFE call *%edx /* get the re-entry point of the peer system */
@@ -190,7 +197,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_ma movl %edi, %eax addl $(virtual_mapped - relocate_kernel), %eax pushl %eax - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(identity_mapped) SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
@@ -208,7 +217,9 @@ SYM_CODE_START_LOCAL_NOALIGN(virtual_map popl %edi popl %esi popl %ebx - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(virtual_mapped) /* Do the copies */
@@ -271,7 +282,9 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) popl %edi popl %ebx popl %ebp - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(swap_pages) .globl kexec_control_code_size
arch/x86/kernel/relocate_kernel_64.S +17 -6
@@ -13,7 +13,8 @@ #include <asm/unwind_hints.h> /* - * Must be relocatable PIC code callable as a C function + * Must be relocatable PIC code callable as a C function, in particular + * there must be a plain RET and not jump to return thunk. */ #define PTR(x) (x << 3)
@@ -104,7 +105,9 @@ SYM_CODE_START_NOALIGN(relocate_kernel) /* jump to identity mapped page */ addq $(identity_mapped - relocate_kernel), %r8 pushq %r8 - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(relocate_kernel) SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
@@ -191,7 +194,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_ma xorl %r14d, %r14d xorl %r15d, %r15d - RET + ANNOTATE_UNRET_SAFE + ret + int3 1: popq %rdx
@@ -210,7 +215,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_ma call swap_pages movq $virtual_mapped, %rax pushq %rax - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(identity_mapped) SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
@@ -231,7 +238,9 @@ SYM_CODE_START_LOCAL_NOALIGN(virtual_map popq %r12 popq %rbp popq %rbx - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(virtual_mapped) /* Do the copies */
@@ -288,7 +297,9 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) lea PAGE_SIZE(%rax), %rsi jmp 0b 3: - RET + ANNOTATE_UNRET_SAFE + ret + int3 SYM_CODE_END(swap_pages) .globl kexec_control_code_size
Greg Kroah-Hartman
maintainerPATCH 129/130 x86/speculation: Disable RRSBA behavior
In reply to Greg Kroah-HartmanFrom: Pawan Gupta <[email protected]>
commit 4ad3278df6fe2b0852b00d5757fc2ccd8e92c26e upstream.
Some Intel processors may use alternate predictors for RETs on RSB-underflow. This condition may be vulnerable to Branch History Injection (BHI) and intramode-BTI.
Kernel earlier added spectre_v2 mitigation modes (eIBRS+Retpolines, eIBRS+LFENCE, Retpolines) which protect indirect CALLs and JMPs against such attacks. However, on RSB-underflow, RET target prediction may fallback to alternate predictors. As a result, RET's predicted target may get influenced by branch history.
A new MSR_IA32_SPEC_CTRL bit (RRSBA_DIS_S) controls this fallback behavior when in kernel mode. When set, RETs will not take predictions from alternate predictors, hence mitigating RETs as well. Support for this is enumerated by CPUID.7.2.EDX[RRSBA_CTRL] (bit2).
For spectre v2 mitigation, when a user selects a mitigation that protects indirect CALLs and JMPs against BHI and intramode-BTI, set RRSBA_DIS_S also to protect RETs for RSB-underflow case.
--- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/msr-index.h | 9 +++++++++ arch/x86/kernel/cpu/bugs.c | 26 ++++++++++++++++++++++++++ arch/x86/kernel/cpu/scattered.c | 1 + tools/arch/x86/include/asm/msr-index.h | 9 +++++++++ 5 files changed, 46 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -293,7 +293,7 @@/* FREE! (11*32+ 8) */ /* FREE! (11*32+ 9) */ #define X86_FEATURE_ENTRY_IBPB (11*32+10)/* "" Issue an IBPB on kernel entry */ -/* FREE! (11*32+11) */ +#define X86_FEATURE_RRSBA_CTRL (11*32+11)/* "" RET prediction control */ #define X86_FEATURE_RETPOLINE (11*32+12)/* "" Generic Retpoline mitigation for Spectre variant 2 */ #define X86_FEATURE_RETPOLINE_LFENCE (11*32+13)/* "" Use LFENCE for Spectre variant 2 */ #define X86_FEATURE_RETHUNK (11*32+14)/* "" Use REturn THUNK */
arch/x86/include/asm/msr-index.h +9 -0
@@ -51,6 +51,8 @@#define SPEC_CTRL_STIBP BIT(SPEC_CTRL_STIBP_SHIFT)/* STIBP mask */ #define SPEC_CTRL_SSBD_SHIFT 2/* Speculative Store Bypass Disable bit */ #define SPEC_CTRL_SSBD BIT(SPEC_CTRL_SSBD_SHIFT)/* Speculative Store Bypass Disable */ +#define SPEC_CTRL_RRSBA_DIS_S_SHIFT 6/* Disable RRSBA behavior */ +#define SPEC_CTRL_RRSBA_DIS_S BIT(SPEC_CTRL_RRSBA_DIS_S_SHIFT)#define MSR_IA32_PRED_CMD 0x00000049/* Prediction Command */ #define PRED_CMD_IBPB BIT(0)/* Indirect Branch Prediction Barrier */
@@ -139,6 +141,13 @@* bit available to control VERW * behavior. */ +#define ARCH_CAP_RRSBA BIT(19)/* +* Indicates RET may use predictors +* other than the RSB. With eIBRS +* enabled predictions in kernel mode +* are restricted to targets in +* kernel. +*/ #define MSR_IA32_FLUSH_CMD 0x0000010b#define L1D_FLUSH BIT(0)/*
arch/x86/kernel/cpu/bugs.c +26 -0
@@ -1274,6 +1274,22 @@ static enum spectre_v2_mitigation __initreturn SPECTRE_V2_RETPOLINE ; } +/* Disable in-kernel use of non-RSB RET predictors */ +static void __init spec_ctrl_disable_kernel_rrsba (void ) +{ +u64 ia32_cap; + +if (!boot_cpu_has (X86_FEATURE_RRSBA_CTRL )) +return ; + + ia32_cap =x86_read_arch_cap_msr (); + +if (ia32_cap &ARCH_CAP_RRSBA ) { + x86_spec_ctrl_base |=SPEC_CTRL_RRSBA_DIS_S ; +write_spec_ctrl_current (x86_spec_ctrl_base, true); + } +} +static void __init spectre_v2_select_mitigation (void ) {enum spectre_v2_mitigation_cmd cmd =spectre_v2_parse_cmdline ();
@@ -1368,6 +1384,16 @@ static void __init spectre_v2_select_mitbreak ; } +/* +* Disable alternate RSB predictions in kernel when indirect CALLs and +* JMPs gets protection against BHI and Intramode-BTI, but RET +* prediction from a non-RSB predictor is still a risk. +*/ +if (mode ==SPECTRE_V2_EIBRS_LFENCE || + mode ==SPECTRE_V2_EIBRS_RETPOLINE || + mode ==SPECTRE_V2_RETPOLINE ) +spec_ctrl_disable_kernel_rrsba (); + spectre_v2_enabled = mode;pr_info ("%s\n" , spectre_v2_strings[mode]);
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -26,6 +26,7 @@ struct cpuid_bit {static const struct cpuid_bit cpuid_bits[] = { {X86_FEATURE_APERFMPERF ,CPUID_ECX ,0 ,0x00000006 ,0 }, {X86_FEATURE_EPB ,CPUID_ECX ,3 ,0x00000006 ,0 }, + {X86_FEATURE_RRSBA_CTRL ,CPUID_EDX ,2 ,0x00000007 ,2 }, {X86_FEATURE_CQM_LLC ,CPUID_EDX ,1 ,0x0000000f ,0 }, {X86_FEATURE_CQM_OCCUP_LLC ,CPUID_EDX ,0 ,0x0000000f ,1 }, {X86_FEATURE_CQM_MBM_TOTAL ,CPUID_EDX ,1 ,0x0000000f ,1 },
tools/arch/x86/include/asm/msr-index.h +9 -0
@@ -51,6 +51,8 @@#define SPEC_CTRL_STIBP BIT(SPEC_CTRL_STIBP_SHIFT)/* STIBP mask */ #define SPEC_CTRL_SSBD_SHIFT 2/* Speculative Store Bypass Disable bit */ #define SPEC_CTRL_SSBD BIT(SPEC_CTRL_SSBD_SHIFT)/* Speculative Store Bypass Disable */ +#define SPEC_CTRL_RRSBA_DIS_S_SHIFT 6/* Disable RRSBA behavior */ +#define SPEC_CTRL_RRSBA_DIS_S BIT(SPEC_CTRL_RRSBA_DIS_S_SHIFT)#define MSR_IA32_PRED_CMD 0x00000049/* Prediction Command */ #define PRED_CMD_IBPB BIT(0)/* Indirect Branch Prediction Barrier */
@@ -138,6 +140,13 @@* bit available to control VERW * behavior. */ +#define ARCH_CAP_RRSBA BIT(19)/* +* Indicates RET may use predictors +* other than the RSB. With eIBRS +* enabled predictions in kernel mode +* are restricted to targets in +* kernel. +*/ #define MSR_IA32_FLUSH_CMD 0x0000010b#define L1D_FLUSH BIT(0)/*
Greg Kroah-Hartman
maintainerPATCH 130/130 x86/static_call: Serialize __static_call_fixup() properly
In reply to Greg Kroah-HartmanFrom: Thomas Gleixner <[email protected]>
commit c27c753ea6fd1237f4f96abf8b623d7bab505513 upstream.
__static_call_fixup() invokes __static_call_transform() without holding text_mutex, which causes lockdep to complain in text_poke_bp().
Adding the proper locking cures that, but as this is either used during early boot or during module finalizing, it's not required to use text_poke_bp(). Add an argument to __static_call_transform() which tells it to use text_poke_early() for it.
--- arch/x86/kernel/static_call.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
arch/x86/kernel/static_call.c +8 -5
@@ -20,7 +20,8 @@ static const u8 tramp_ud[] = { 0x0f, 0xbstatic const u8 retinsn[] = {RET_INSN_OPCODE ,0xcc ,0xcc ,0xcc ,0xcc }; -static void __ref __static_call_transform (void *insn,enum insn_type type,void *func) +static void __ref __static_call_transform (void *insn,enum insn_type type, +void *func,bool modinit) {int size =CALL_INSN_SIZE ;const void *code;
@@ -49,7 +50,7 @@ static void __ref __static_call_transforif (memcmp (insn, code, size) ==0 )return ; -if (unlikely (system_state ==SYSTEM_BOOTING )) +if (system_state ==SYSTEM_BOOTING || modinit)return text_poke_early (insn, code, size);text_poke_bp (insn, code, size,NULL );
@@ -96,12 +97,12 @@ void arch_static_call_transform(void *siif (tramp) {__static_call_validate (tramp, true); -__static_call_transform (tramp,__sc_insn (!func, true), func); +__static_call_transform (tramp,__sc_insn (!func, true), func, false); }if (IS_ENABLED (CONFIG_HAVE_STATIC_CALL_INLINE ) && site) {__static_call_validate (site, tail); -__static_call_transform (site,__sc_insn (!func, tail), func); +__static_call_transform (site,__sc_insn (!func, tail), func, false); }mutex_unlock (&text_mutex);
@@ -127,8 +128,10 @@ bool __static_call_fixup(void *tramp, u8return false; } +mutex_lock (&text_mutex);if (op ==RET_INSN_OPCODE || dest == &__x86_return_thunk) -__static_call_transform (tramp,RET ,NULL ); +__static_call_transform (tramp,RET ,NULL , true); +mutex_unlock (&text_mutex);return true; }
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.131-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
perf fails to build with:
CC
/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.o In file included from util/intel-pt-decoder/intel-pt-insn-decoder.c:15:util/intel-pt-decoder/../../../arch/x86/lib/insn.c:13:10: fatal error: asm/inat.h: No such file or directory
#include <asm/inat.h> /* __ignore_sync_check__ */
^~~~~~~~~~~~compilation terminated.
make[7]: *** [util/intel-pt-decoder/Build:14: /local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.o] Error 1 make[6]: *** [/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/build/Makefile.build:139: intel-pt-decoder] Error 2
make[5]: *** [/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/build/Makefile.build:139: util] Error 2
make[4]: *** [Makefile.perf:643: /local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/perf/perf-in.o] Error 2
make[3]: *** [Makefile.perf:229: sub-make] Error 2
make[2]: *** [Makefile:70: all] Error 2
make[1]: *** [package/pkg-generic.mk:294: /local/users/fainelli/buildroot/output/arm64/build/linux-tools/.stamp_built] Error 2
make: *** [Makefile:27: _all] Error 2
you will need to pick this patch as well:
With that one applied:
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels:
Signature · 1 line
Florian
Quoted 16 lines · Florian Fainelli
Quoted 14 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.131-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.
Quoted 6 lines
Quoted 3 lines
thanks,
greg k-h
perf fails to build with:
I have also noticed perf build failed.
In file included from util/intel-pt-decoder/intel-pt-insn-decoder.c:15:util/intel-pt-decoder/../../../arch/x86/lib/insn.c:13:10: fatal error:asm/inat.h: No such file or directory
13 | #include <asm/inat.h> /* __ignore_sync_check__ */
| ^~~~~~~~~~~~
compilation terminated.
Build log:
https://builds.tuxbuild.com/2BrKWlDZbrZwQIfxzeMf6fv37sn/
Quoted 31 lines
CC
/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.o In file included fromutil/intel-pt-decoder/intel-pt-insn-decoder.c:15:util/intel-pt-decoder/../../../arch/x86/lib/insn.c:13:10: fatal error:asm/inat.h: No such file or directory#include <asm/inat.h> /* __ignore_sync_check__ */ ^~~~~~~~~~~~compilation terminated.
make[7]: *** [util/intel-pt-decoder/Build:14:
/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.o] Error 1
make[6]: *** [/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/build/Makefile.build:139:
intel-pt-decoder] Error 2
make[5]: *** [/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/build/Makefile.build:139:
util] Error 2
make[4]: *** [Makefile.perf:643:
/local/users/fainelli/buildroot/output/arm64/build/linux-custom/tools/perf/perf-in.o]
Error 2
make[3]: *** [Makefile.perf:229: sub-make] Error 2
make[2]: *** [Makefile:70: all] Error 2
make[1]: *** [package/pkg-generic.mk:294:
/local/users/fainelli/buildroot/output/arm64/build/linux-tools/.stamp_built]
Error 2
make: *** [Makefile:27:_all] Error 2you will need to pick this patch as well:
Quoted 7 lines
With that one applied:
On
ARCH_BRCMSTBusing 32-bit and 64-bit ARM kernels:Tested-by Florian Fainelli <[email protected]>--
Florian
- Naresh
Greg Kroah-Hartman
maintainerQuoted 32 lines · Naresh Kamboju
Quoted 16 lines · Florian Fainelli
Quoted 14 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.131-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.Quoted 6 lines
Quoted 3 lines
thanks,
greg k-h
perf fails to build with:
I have also noticed perf build failed.
In file included from
util/intel-pt-decoder/intel-pt-insn-decoder.c:15:util/intel-pt-decoder/../../../arch/x86/lib/insn.c:13:10: fatal error:asm/inat.h: No such file or directory
13 | #include <asm/inat.h> /*__ignore_sync_check__*/
Quoted 5 lines
| ^~~~~~~~~~~~compilation terminated.
Build log:
https://builds.tuxbuild.com/2BrKWlDZbrZwQIfxzeMf6fv37sn/
Should now be fixed in the tree, I'll push out a -rc2 so that your build tools will pick it up.
thanks,
greg k-h
Quoted 18 lines · Naresh Kamboju
Quoted 16 lines · Florian Fainelli
Quoted 14 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.131-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
thanks,
greg k-h
Results from Linaro’s test farm.
Regressions on x86_64.
Kernel panic noticed on x86 while running kvm-unit-tests. - https://lkft.validation.linaro.org/scheduler/job/5280665#L1696
TESTNAME=emulator TIMEOUT=90s ACCEL= ./x86/run x86/emulator.flat -smp 1
[ 62.210623] APIC base relocation is unsupported by KVM [ 104.645616] kvm: emulating exchange as write [ 104.656718] int3: 0000 [#1] SMP PTI [ 104.656719] CPU: 1 PID: 3785 Comm: qemu-system-x86 Not tainted 5.10.131-rc2 #1 [ 104.656719] Hardware name: Supermicro SYS-5019S-ML/X11SSH-F, BIOS 2.2 05/23/2018 [ 104.656720] RIP: 0010:xaddw_ax_dx+0x9/0x10 [ 104.656720] Code: 00 0f bb d0 c3 cc cc cc cc 48 0f bb d0 c3 cc cc cc cc 0f 1f 80 00 00 00 00 0f c0 d0 c3 cc cc cc cc 66 0f c1 d0 c3 cc cc cc cc <0f> 1f 80 00 00 00 00 0f c1 d0 c3 cc cc cc cc 48 0f c1 d0 c3 cc cc [ 104.656720] RSP: 0018:ffffb823431c7d00 EFLAGS: 00000206 [ 104.656721] RAX: 0000000089abcdef RBX: 0000000000000001 RCX: 0000000000000000 [ 104.656721] RDX: 0000000076543210 RSI: ffffffff91a4d4d0 RDI: 0000000000000204 [ 104.656722] RBP: ffffb823431c7d08 R08: ffff9a578cbaddf0 R09: 0000000000000002 [ 104.656722] R10: ffff9a578cbaddf0 R11: 0000000000000000 R12: ffff9a578cbaddf0 [ 104.656722] R13: ffffffff92e08040 R14: 0000000000000000 R15: 0000000000000000 [ 104.656723] FS: 00007f3f3f53c700(0000) GS:ffff9a58afa80000(0000) knlGS:0000000000000000 [ 104.656723] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 104.656723] CR2: 0000000000000000 CR3: 00000001068b6003 CR4: 00000000003726e0 [ 104.656724] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 104.656724] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 104.656724] Call Trace: [ 104.656724] ? fastop+0x5a/0xa0 [ 104.656725] x86_emulate_insn+0x7c9/0xf20 [ 104.656725] x86_emulate_instruction+0x2ec/0x7b0 [ 104.656725] ? __local_bh_enable_ip+0x48/0x80 [ 104.656725] complete_emulated_mmio+0x238/0x310 [ 104.656726] kvm_arch_vcpu_ioctl_run+0x1799/0x1980 [ 104.656726] ? vfs_writev+0xcb/0x140 [ 104.656726] kvm_vcpu_ioctl+0x243/0x5e0 [ 104.656726] ? selinux_file_ioctl+0xae/0x140 [ 104.656727] ? selinux_file_ioctl+0xae/0x140 [ 104.656727] __x64_sys_ioctl+0x92/0xd0 [ 104.656727] do_syscall_64+0x35/0x50 [ 104.656727] entry_SYSCALL_64_after_hwframe+0x61/0xc6 [ 104.656728] RIP: 0033:0x7f3f40ec68f7 [ 104.656728] Code: b3 66 90 48 8b 05 a1 35 2c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 71 35 2c 00 f7 d8 64 89 01 48 [ 104.656729] RSP: 002b:00007f3f3f53ba28 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [ 104.656729] RAX: ffffffffffffffda RBX: 000000000000ae80 RCX: 00007f3f40ec68f7 [ 104.656729] RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 000000000000000f [ 104.656730] RBP: 00005624bc6bdaa0 R08: 00005624ba47c450 R09: 00000000ffffffff [ 104.656730] R10: 00000000000ff000 R11: 0000000000000246 R12: 0000000000000000 [ 104.656730] R13: 00007f3f431f6000 R14: 0000000000000006 R15: 00005624bc6bdaa0 [ 104.656731] Modules linked in: x86_pkg_temp_thermal [ 104.900206] ---[ end trace 51088e5987576a23 ]--- [ 104.900206] RIP: 0010:xaddw_ax_dx+0x9/0x10 [ 104.900207] Code: 00 0f bb d0 c3 cc cc cc cc 48 0f bb d0 c3 cc cc cc cc 0f 1f 80 00 00 00 00 0f c0 d0 c3 cc cc cc cc 66 0f c1 d0 c3 cc cc cc cc <0f> 1f 80 00 00 00 00 0f c1 d0 c3 cc cc cc cc 48 0f c1 d0 c3 cc cc [ 104.900207] RSP: 0018:ffffb823431c7d00 EFLAGS: 00000206 [ 104.900207] RAX: 0000000089abcdef RBX: 0000000000000001 RCX: 0000000000000000 [ 104.900208] RDX: 0000000076543210 RSI: ffffffff91a4d4d0 RDI: 0000000000000204 [ 104.900208] RBP: ffffb823431c7d08 R08: ffff9a578cbaddf0 R09: 0000000000000002 [ 104.900208] R10: ffff9a578cbaddf0 R11: 0000000000000000 R12: ffff9a578cbaddf0 [ 104.900209] R13: ffffffff92e08040 R14: 0000000000000000 R15: 0000000000000000 [ 104.900209] FS: 00007f3f3f53c700(0000) GS:ffff9a58afa80000(0000) knlGS:0000000000000000 [ 104.900209] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 104.900210] CR2: 0000000000000000 CR3: 00000001068b6003 CR4: 00000000003726e0 [ 104.900210] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 104.900210] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 104.900211] Kernel panic - not syncing: Fatal exception in interrupt [ 104.900250] Kernel Offset: 0x10a00000 from 0xffffffff81000000
(relocation range: 0xffffffff80000000-0xffffffffbfffffff)
--
Linaro LKFT
https://lkft.linaro.org
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.131-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.131-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
All tests passing for Tegra ...
Test results for stable-v5.10:
10 builds: 10 pass, 0 fail
28 boots: 28 pass, 0 fail
75 tests: 75 pass, 0 failLinux version: 5.10.131-rc1-g53b881e19526
Boards tested: tegra124-jetson-tk1, tegra186-p2771-0000,
tegra194-p2972-0000, tegra194-p3509-0000+p3668-0000,
tegra20-ventana, tegra210-p2371-2180,
tegra210-p3450-0000, tegra30-cardhu-a04Jon
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-5.10.y
Best regards,
Pavel
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Hi Greg,
Quoted 7 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.131 release. There are 130 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 14 Jul 2022 18:32:19 +0000. Anything received after that time might be too late.
Build test (gcc version 11.3.1 20220706):
mips: 63 configs -> no failure
arm: 104 configs -> no failure
arm64: 3 configs -> no failurex86_64: 4 configs -> no failure alpha allmodconfig -> no failure powerpc allmodconfig -> no failure riscv allmodconfig -> no failure s390 allmodconfig -> no failure xtensa allmodconfig -> no failure
Boot test:x86_64: Booted on my test laptop. No regression.x86_64: Booted on qemu. No regression. [1]
arm64: Booted on rpi4b (4GB model). No regression. [2]
[1]. https://openqa.qa.codethink.co.uk/tests/1505
[2]. https://openqa.qa.codethink.co.uk/tests/1509
--
Regards
Sudip