linux-stable/arch/x86/kernel
Thomas Gleixner 6778977590 x86/alternatives: Disable interrupts and sync when optimizing NOPs in place
commit 2dc4196138 upstream.

apply_alternatives() treats alternatives with the ALT_FLAG_NOT flag set
special as it optimizes the existing NOPs in place.

Unfortunately, this happens with interrupts enabled and does not provide any
form of core synchronization.

So an interrupt hitting in the middle of the update and using the affected code
path will observe a half updated NOP and crash and burn. The following
3 NOP sequence was observed to expose this crash halfway reliably under QEMU
  32bit:

   0x90 0x90 0x90

which is replaced by the optimized 3 byte NOP:

   0x8d 0x76 0x00

So an interrupt can observe:

   1) 0x90 0x90 0x90		nop nop nop
   2) 0x8d 0x90 0x90		undefined
   3) 0x8d 0x76 0x90		lea    -0x70(%esi),%esi
   4) 0x8d 0x76 0x00		lea     0x0(%esi),%esi

Where only #1 and #4 are true NOPs. The same problem exists for 64bit obviously.

Disable interrupts around this NOP optimization and invoke sync_core()
before re-enabling them.

Fixes: 270a69c448 ("x86/alternative: Support relocations in alternatives")
Reported-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/ZT6narvE%2BLxX%2B7Be@windriver.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-01 12:42:47 +00:00
..
acpi x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility 2023-10-27 20:36:49 +02:00
apic x86/apic/msi: Fix misconfigured non-maskable MSI quirk 2023-11-28 17:19:56 +00:00
cpu x86/CPU/AMD: Check vendor in the AMD microcode callback 2023-12-13 18:45:33 +01:00
fpu KVM: x86: Constrain guest-supported xfeatures only at KVM_GET_XSAVE{2} 2023-10-12 11:08:58 -04:00
kprobes X86 core updates: 2023-08-30 10:10:31 -07:00
.gitignore
alternative.c x86/alternatives: Disable interrupts and sync when optimizing NOPs in place 2024-01-01 12:42:47 +00:00
amd_gart_64.c
amd_nb.c x86/amd_nb: Use Family 19h Models 60h-7Fh Function 4 IDs 2023-11-20 11:59:38 +01:00
aperture_64.c
apm_32.c x86/APM: drop the duplicate APM_MINOR_DEV macro 2023-07-30 14:00:32 +02:00
asm-offsets.c x86/smpboot: Remove initial_stack on 64-bit 2023-03-21 13:35:53 +01:00
asm-offsets_32.c
asm-offsets_64.c
audit_64.c x86/audit: Fix -Wmissing-variable-declarations warning for ia32_xyz_class 2023-08-30 10:11:16 +02:00
bootflag.c
callthunks.c x86,static_call: Fix static-call vs return-thunk 2023-09-22 18:58:24 +02:00
cet.c x86/ibt: Convert IBT selftest to asm 2023-08-17 17:07:09 +02:00
cfi.c
check.c
cpuid.c x86/cpuid: make cpuid_class a static const structure 2023-08-05 08:31:41 +02:00
crash.c ARM: 2023-09-07 13:52:20 -07:00
crash_core_32.c
crash_core_64.c
crash_dump_32.c
crash_dump_64.c
devicetree.c x86/apic: Make some APIC init functions bool 2023-08-09 11:58:20 -07:00
doublefault_32.c x86: Avoid missing-prototype warnings for doublefault code 2023-05-18 11:56:18 -07:00
dumpstack.c x86/show_trace_log_lvl: Ensure stack pointer is aligned, again 2023-05-16 06:31:04 -07:00
dumpstack_32.c
dumpstack_64.c
e820.c
early-quirks.c
early_printk.c
ebda.c
eisa.c
espfix_64.c
ftrace.c x86/ftrace: Remove unsued extern declaration ftrace_regs_caller_ret() 2023-07-10 21:38:13 -04:00
ftrace_32.S x86/ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL 2023-06-20 18:38:38 -04:00
ftrace_64.S x86/ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL 2023-06-20 18:38:38 -04:00
head32.c x86: Add dummy prototype for mk_early_pgtbl_32() 2023-05-18 11:56:16 -07:00
head64.c x86/boot: Fix incorrect startup_gdt_descr.size 2023-11-20 11:58:53 +01:00
head_32.S x86/smpboot: Restrict soft_restart_cpu() to SEV 2023-05-15 13:44:50 +02:00
head_64.S x86/head_64: Store boot_params pointer in callee save register 2023-08-07 19:20:32 +02:00
hpet.c x86/hpet: Refactor code using deprecated strncpy() interface to use strscpy() 2023-08-24 21:22:40 +02:00
hw_breakpoint.c x86/amd: Cache debug register values in percpu variables 2023-01-31 20:09:26 +01:00
i8237.c
i8253.c
i8259.c x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility 2023-10-27 20:36:49 +02:00
ibt_selftest.S x86/ibt: Convert IBT selftest to asm 2023-08-17 17:07:09 +02:00
idt.c x86/entry: Convert INT 0x80 emulation to IDTENTRY 2023-12-13 18:45:02 +01:00
io_delay.c
ioport.c
irq.c x86/apic: Nuke ack_APIC_irq() 2023-08-09 11:58:34 -07:00
irq_32.c
irq_64.c
irq_work.c x86/apic: Wrap IPI calls into helper functions 2023-08-09 12:00:55 -07:00
irqflags.S
irqinit.c
itmt.c x86/sched/itmt: Give all SMT siblings of a core the same priority 2023-05-08 10:58:38 +02:00
jailhouse.c x86/apic: Remove the pointless APIC version check 2023-08-09 11:58:19 -07:00
jump_label.c
kdebugfs.c
kexec-bzimage64.c docs: move x86 documentation into Documentation/arch/ 2023-03-30 12:58:51 -06:00
kgdb.c x86/kgdb: Fix a kerneldoc warning when build with W=1 2023-09-24 11:00:13 +02:00
ksysfs.c
kvm.c * Rework apic callbacks, getting rid of unnecessary ones and 2023-08-30 10:44:46 -07:00
kvmclock.c x86/tsc: Provide sched_clock_noinstr() 2023-06-05 21:11:08 +02:00
ldt.c x86: allow get_locked_pte() to fail 2023-06-19 16:19:10 -07:00
machine_kexec_32.c
machine_kexec_64.c x86/kexec: remove unnecessary arch_kexec_kernel_image_load() 2023-04-08 13:45:38 -07:00
Makefile Add x86 shadow stack support 2023-08-31 12:20:12 -07:00
mmconf-fam10h_64.c
module.c x86/alternative: Rename apply_ibt_endbr() 2023-07-10 09:52:23 +02:00
mpparse.c x86/apic: Sanitize APIC address setup 2023-08-09 11:58:20 -07:00
msr.c x86/MSR: make msr_class a static const structure 2023-08-05 08:31:42 +02:00
nmi.c x86/nmi: Fix out-of-order NMI nesting checks & false positive warning 2023-11-20 11:58:53 +01:00
nmi_selftest.c x86/apic: Wrap IPI calls into helper functions 2023-08-09 12:00:55 -07:00
paravirt-spinlocks.c
paravirt.c x86/xen: move paravirt lazy code 2023-09-19 07:04:49 +02:00
pci-dma.c x86: always initialize xen-swiotlb when xen-pcifront is enabling 2023-07-31 17:54:27 +02:00
pcspeaker.c
perf_regs.c
platform-quirks.c x86/quirks: Include linux/pnp.h for arch_pnpbios_disabled() 2023-05-18 11:56:18 -07:00
pmem.c
probe_roms.c
process.c x86/shstk: Remove useless clone error handling 2023-09-19 09:18:34 -07:00
process.h
process_32.c x86/resctl: fix scheduler confusion with 'current' 2023-03-08 11:48:11 -08:00
process_64.c x86/shstk: Add ARCH_SHSTK_STATUS 2023-08-02 15:01:51 -07:00
ptrace.c x86: Add PTRACE interface for shadow stack 2023-08-02 15:01:51 -07:00
pvclock.c locking/atomic: treewide: use raw_atomic*_<op>() 2023-06-05 09:57:20 +02:00
quirks.c
reboot.c x86/reboot: Expose VMCS crash hooks if and only if KVM_{INTEL,AMD} is enabled 2023-08-03 15:37:14 -07:00
reboot_fixups_32.c
relocate_kernel_32.S
relocate_kernel_64.S x86,objtool: Split UNWIND_HINT_EMPTY in two 2023-03-23 23:18:58 +01:00
resource.c
rethook.c
rtc.c
setup.c x86/mm, kexec, ima: Use memblock_free_late() from ima_free_kexec_buffer() 2023-09-18 09:24:15 +02:00
setup_percpu.c x86/apic/32: Remove x86_cpu_to_logical_apicid 2023-08-09 11:58:23 -07:00
sev-shared.c Take care of a race between when the #VC exception is raised and when 2023-10-19 18:12:08 -07:00
sev.c x86/sev: Fix kernel crash due to late update to read-only ghcb_version 2023-12-13 18:45:30 +01:00
sev_verify_cbit.S
shstk.c x86/shstk: Add warning for shadow stack double unmap 2023-09-19 09:18:34 -07:00
signal.c x86/shstk: Handle signals for shadow stack 2023-08-02 15:01:50 -07:00
signal_32.c x86/shstk: Add user control-protection fault handler 2023-08-02 15:01:50 -07:00
signal_64.c x86/shstk: Delay signal entry SSP write until after user accesses 2023-11-28 17:19:55 +00:00
smp.c Revert "x86/smp: Put CPUs into INIT on shutdown if possible" 2023-10-15 12:02:02 -07:00
smpboot.c Revert "x86/smp: Put CPUs into INIT on shutdown if possible" 2023-10-15 12:02:02 -07:00
stacktrace.c
static_call.c x86/static_call: Fix __static_call_fixup() 2023-08-17 13:24:09 +02:00
step.c
sys_ia32.c
sys_x86_64.c x86/mm: Introduce MAP_ABOVE4G 2023-07-11 14:12:19 -07:00
tboot.c
time.c
tls.c
tls.h
topology.c cpu-hotplug: Provide prototypes for arch CPU registration 2023-10-11 14:27:37 +02:00
trace.c
trace_clock.c
tracepoint.c
traps.c Add x86 shadow stack support 2023-08-31 12:20:12 -07:00
tsc.c x86/tsc: Extend watchdog check exemption to 4-Sockets platform 2023-07-14 15:17:09 -07:00
tsc_msr.c
tsc_sync.c x86/tsc: Defer marking TSC unstable to a worker 2023-10-27 20:36:57 +02:00
umip.c
unwind_frame.c
unwind_guess.c
unwind_orc.c objtool changes for v6.5: 2023-06-27 15:05:41 -07:00
uprobes.c
verify_cpu.S
vm86_32.c
vmlinux.lds.S x86/build: Fix linker fill bytes quirk/incompatibility for ld.lld 2023-09-06 23:49:12 +02:00
vsmp_64.c x86/apic: Get rid of hard_smp_processor_id() 2023-08-09 11:58:17 -07:00
x86_init.c - Fix a race window where load_unaligned_zeropad() could cause 2023-06-26 16:32:47 -07:00