Skip to content

Commit 05017fe

Browse files
committed
Merge tag 'x86_urgent_for_v5.19_rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Borislav Petkov: "A couple more retbleed fallout fixes. It looks like their urgency is decreasing so it seems like we've managed to catch whatever snafus the limited -rc testing has exposed. Maybe we're getting ready... :) - Make retbleed mitigations 64-bit only (32-bit will need a bit more work if even needed, at all). - Prevent return thunks patching of the LKDTM modules as it is not needed there - Avoid writing the SPEC_CTRL MSR on every kernel entry on eIBRS parts - Enhance error output of apply_returns() when it fails to patch a return thunk - A sparse fix to the sev-guest module - Protect EFI fw calls by issuing an IBPB on AMD" * tag 'x86_urgent_for_v5.19_rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/speculation: Make all RETbleed mitigations 64-bit only lkdtm: Disable return thunks in rodata.c x86/bugs: Warn when "ibrs" mitigation is selected on Enhanced IBRS parts x86/alternative: Report missing return thunk details virt: sev-guest: Pass the appropriate argument type to iounmap() x86/amd: Use IBPB for firmware calls
2 parents 714b82c + b648ab4 commit 05017fe

File tree

8 files changed

+36
-12
lines changed

8 files changed

+36
-12
lines changed

arch/x86/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ config RETHUNK
24742474
bool "Enable return-thunks"
24752475
depends on RETPOLINE && CC_HAS_RETURN_THUNK
24762476
select OBJTOOL if HAVE_OBJTOOL
2477-
default y
2477+
default y if X86_64
24782478
help
24792479
Compile the kernel with the return-thunks compiler option to guard
24802480
against kernel-to-user data leaks by avoiding return speculation.
@@ -2483,21 +2483,21 @@ config RETHUNK
24832483

24842484
config CPU_UNRET_ENTRY
24852485
bool "Enable UNRET on kernel entry"
2486-
depends on CPU_SUP_AMD && RETHUNK
2486+
depends on CPU_SUP_AMD && RETHUNK && X86_64
24872487
default y
24882488
help
24892489
Compile the kernel with support for the retbleed=unret mitigation.
24902490

24912491
config CPU_IBPB_ENTRY
24922492
bool "Enable IBPB on kernel entry"
2493-
depends on CPU_SUP_AMD
2493+
depends on CPU_SUP_AMD && X86_64
24942494
default y
24952495
help
24962496
Compile the kernel with support for the retbleed=ibpb mitigation.
24972497

24982498
config CPU_IBRS_ENTRY
24992499
bool "Enable IBRS on kernel entry"
2500-
depends on CPU_SUP_INTEL
2500+
depends on CPU_SUP_INTEL && X86_64
25012501
default y
25022502
help
25032503
Compile the kernel with support for the spectre_v2=ibrs mitigation.

arch/x86/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RETHUNK_CFLAGS := -mfunction-return=thunk-extern
2727
RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS)
2828
endif
2929

30+
export RETHUNK_CFLAGS
3031
export RETPOLINE_CFLAGS
3132
export RETPOLINE_VDSO_CFLAGS
3233

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
#define X86_FEATURE_RETPOLINE_LFENCE (11*32+13) /* "" Use LFENCE for Spectre variant 2 */
303303
#define X86_FEATURE_RETHUNK (11*32+14) /* "" Use REturn THUNK */
304304
#define X86_FEATURE_UNRET (11*32+15) /* "" AMD BTB untrain return */
305+
#define X86_FEATURE_USE_IBPB_FW (11*32+16) /* "" Use IBPB during runtime firmware calls */
305306

306307
/* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
307308
#define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */

arch/x86/include/asm/nospec-branch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ do { \
297297
alternative_msr_write(MSR_IA32_SPEC_CTRL, \
298298
spec_ctrl_current() | SPEC_CTRL_IBRS, \
299299
X86_FEATURE_USE_IBRS_FW); \
300+
alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB, \
301+
X86_FEATURE_USE_IBPB_FW); \
300302
} while (0)
301303

302304
#define firmware_restrict_branch_speculation_end() \

arch/x86/kernel/alternative.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ void __init_or_module noinline apply_returns(s32 *start, s32 *end)
555555
dest = addr + insn.length + insn.immediate.value;
556556

557557
if (__static_call_fixup(addr, op, dest) ||
558-
WARN_ON_ONCE(dest != &__x86_return_thunk))
558+
WARN_ONCE(dest != &__x86_return_thunk,
559+
"missing return thunk: %pS-%pS: %*ph",
560+
addr, dest, 5, addr))
559561
continue;
560562

561563
DPRINTK("return thunk at: %pS (%px) len: %d to: %pS",

arch/x86/kernel/cpu/bugs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ static inline const char *spectre_v2_module_string(void) { return ""; }
975975
#define SPECTRE_V2_LFENCE_MSG "WARNING: LFENCE mitigation is not recommended for this CPU, data leaks possible!\n"
976976
#define SPECTRE_V2_EIBRS_EBPF_MSG "WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!\n"
977977
#define SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG "WARNING: Unprivileged eBPF is enabled with eIBRS+LFENCE mitigation and SMT, data leaks possible via Spectre v2 BHB attacks!\n"
978+
#define SPECTRE_V2_IBRS_PERF_MSG "WARNING: IBRS mitigation selected on Enhanced IBRS CPU, this may cause unnecessary performance loss\n"
978979

979980
#ifdef CONFIG_BPF_SYSCALL
980981
void unpriv_ebpf_notify(int new_state)
@@ -1415,6 +1416,8 @@ static void __init spectre_v2_select_mitigation(void)
14151416

14161417
case SPECTRE_V2_IBRS:
14171418
setup_force_cpu_cap(X86_FEATURE_KERNEL_IBRS);
1419+
if (boot_cpu_has(X86_FEATURE_IBRS_ENHANCED))
1420+
pr_warn(SPECTRE_V2_IBRS_PERF_MSG);
14181421
break;
14191422

14201423
case SPECTRE_V2_LFENCE:
@@ -1516,7 +1519,16 @@ static void __init spectre_v2_select_mitigation(void)
15161519
* the CPU supports Enhanced IBRS, kernel might un-intentionally not
15171520
* enable IBRS around firmware calls.
15181521
*/
1519-
if (boot_cpu_has(X86_FEATURE_IBRS) && !spectre_v2_in_ibrs_mode(mode)) {
1522+
if (boot_cpu_has_bug(X86_BUG_RETBLEED) &&
1523+
(boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
1524+
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)) {
1525+
1526+
if (retbleed_cmd != RETBLEED_CMD_IBPB) {
1527+
setup_force_cpu_cap(X86_FEATURE_USE_IBPB_FW);
1528+
pr_info("Enabling Speculation Barrier for firmware calls\n");
1529+
}
1530+
1531+
} else if (boot_cpu_has(X86_FEATURE_IBRS) && !spectre_v2_in_ibrs_mode(mode)) {
15201532
setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW);
15211533
pr_info("Enabling Restricted Speculation for firmware calls\n");
15221534
}

drivers/misc/lkdtm/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ lkdtm-$(CONFIG_LKDTM) += cfi.o
1313
lkdtm-$(CONFIG_LKDTM) += fortify.o
1414
lkdtm-$(CONFIG_PPC_64S_HASH_MMU) += powerpc.o
1515

16-
KASAN_SANITIZE_rodata.o := n
1716
KASAN_SANITIZE_stackleak.o := n
18-
KCOV_INSTRUMENT_rodata.o := n
19-
CFLAGS_REMOVE_rodata.o += $(CC_FLAGS_LTO)
17+
18+
KASAN_SANITIZE_rodata.o := n
19+
KCSAN_SANITIZE_rodata.o := n
20+
KCOV_INSTRUMENT_rodata.o := n
21+
OBJECT_FILES_NON_STANDARD_rodata.o := y
22+
CFLAGS_REMOVE_rodata.o += $(CC_FLAGS_LTO) $(RETHUNK_CFLAGS)
2023

2124
OBJCOPYFLAGS :=
2225
OBJCOPYFLAGS_rodata_objcopy.o := \

drivers/virt/coco/sev-guest/sev-guest.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,16 +632,19 @@ static int __init sev_guest_probe(struct platform_device *pdev)
632632
struct device *dev = &pdev->dev;
633633
struct snp_guest_dev *snp_dev;
634634
struct miscdevice *misc;
635+
void __iomem *mapping;
635636
int ret;
636637

637638
if (!dev->platform_data)
638639
return -ENODEV;
639640

640641
data = (struct sev_guest_platform_data *)dev->platform_data;
641-
layout = (__force void *)ioremap_encrypted(data->secrets_gpa, PAGE_SIZE);
642-
if (!layout)
642+
mapping = ioremap_encrypted(data->secrets_gpa, PAGE_SIZE);
643+
if (!mapping)
643644
return -ENODEV;
644645

646+
layout = (__force void *)mapping;
647+
645648
ret = -ENOMEM;
646649
snp_dev = devm_kzalloc(&pdev->dev, sizeof(struct snp_guest_dev), GFP_KERNEL);
647650
if (!snp_dev)
@@ -706,7 +709,7 @@ static int __init sev_guest_probe(struct platform_device *pdev)
706709
e_free_request:
707710
free_shared_pages(snp_dev->request, sizeof(struct snp_guest_msg));
708711
e_unmap:
709-
iounmap(layout);
712+
iounmap(mapping);
710713
return ret;
711714
}
712715

0 commit comments

Comments
 (0)