x86/kexec: Check for a good per-cpu area before accessing IDTs
PATCH 1/1 x86/kexec: Check for a good per-cpu area before accessing IDTs
Prior to commit 9c20d3c5915d ("x86/IDT: Make idt_tables[] be per_cpu(idt)"), the global idt_tables[] was always safe to use for CPUs in any state.
However, not-yet-onlined CPUs (e.g. MADT with more entries than exist in practice) or offlined CPUs (e.g. xen-hptool) have their per-cpu pointer poisoned to detect incorrect uses. machine_kexec() trips over the posion when clobbering #MC entry paths.
This fixes a fatal #GP (non-canonical memory reference) when trying to enter the crash kernel.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Lin Liu <[email protected]>
The fix here is a bit ugly. nmi_shootdown_cpus() uses the cpu_online_map but this is wrong too; it misses parked CPUs, which do want to be captured.
For 4.22. This is the minimal fix to stop systems crashing, but more work is needed to make this path fully robust.
--- xen/arch/x86/machine_kexec.c | 8 +++++++- xen/common/percpu.c | 1 - xen/include/xen/percpu.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/machine_kexec.c +7 -1
@@ -18,6 +18,7 @@#include <xen/domain_page.h> #include <xen/elfstructs.h> #include <xen/kexec.h> +#include <xen/percpu.h> #include <xen/types.h> #include <asm/fixmap.h>
@@ -171,7 +172,12 @@ void machine_kexec(struct kexec_image *image)*/ for ( i =0 ; i < nr_cpu_ids; i++ ) { -idt_entry_t *idt =per_cpu (idt, i); +idt_entry_t *idt; + +if ( __per_cpu_offset[i] ==INVALID_PERCPU_AREA ) +continue ; + + idt =per_cpu (idt, i);if ( !idt )continue ;
xen/common/percpu.c +0 -1
@@ -13,7 +13,6 @@#define PERCPU_ORDER get_order_from_bytes(__per_cpu_data_end - __per_cpu_start) -extern char __per_cpu_start[];extern const char __per_cpu_data_end[];unsigned long __read_mostly __per_cpu_offset[NR_CPUS ];
xen/include/xen/percpu.h +1 -0
@@ -43,6 +43,7 @@#endif extern unsigned long __per_cpu_offset[]; +extern char __per_cpu_start[];#define per_cpu (var, cpu) \ (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]))
base-commit: 6a21252a742ec021a814e124b88d273da37065db
Signature · 1 line
2.39.5
Quoted 8 lines · Andrew Cooper
Prior to commit
9c20d3c5915d("x86/IDT: Make idt_tables[] beper_cpu(idt)"), the global idt_tables[] was always safe to use for CPUs in any state.However, not-yet-onlined CPUs (e.g. MADT with more entries than exist in practice) or offlined CPUs (e.g. xen-hptool) have their per-cpu pointer poisoned to detect incorrect uses.
machine_kexec()trips over the posion when clobbering #MC entry paths.
Quoted 6 lines
This fixes a fatal #GP (non-canonical memory reference) when trying to enter the crash kernel.
Fixes 9c20d3c5915d ("x86/IDT: Make idt_tables[] be per_cpu(idt)")Reported-by Lin Liu <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
albeit preferably, because of ...
Quoted 2 lines
The fix here is a bit ugly.
nmi_shootdown_cpus()uses thecpu_online_mapbut this is wrong too; it misses parked CPUs, which do want to be captured.
... this, ...
Quoted 4 lines
xen/arch/x86/machine_kexec.c +0
-0@@ -171,7 +172,12 @@ void machine_kexec(struct kexec_image *image)*/ for ( i =0 ; i < nr_cpu_ids; i++ ) {
xen/arch/x86/machine_kexec.c void machine_kexec(struct kexec_image *image) · line 183
Quoted 10 lines
xen/arch/x86/machine_kexec.c +6
-1-idt_entry_t *idt =per_cpu (idt, i); +idt_entry_t *idt; + +if ( __per_cpu_offset[i] ==INVALID_PERCPU_AREA ) +continue ; + + idt =per_cpu (idt, i);if ( !idt )continue ;
... with the comment ahead of the for() also adjusted to at least briefly mention why cpu_online() cannot be used, and why hence this (seemingly) awkward check is needed instead.
Jan
Quoted 21 lines · Andrew Cooper
Prior to commit
9c20d3c5915d("x86/IDT: Make idt_tables[] beper_cpu(idt)"), the global idt_tables[] was always safe to use for CPUs in any state.However, not-yet-onlined CPUs (e.g. MADT with more entries than exist in practice) or offlined CPUs (e.g. xen-hptool) have their per-cpu pointer poisoned to detect incorrect uses.
machine_kexec()trips over the posion when clobbering #MC entry paths.This fixes a fatal #GP (non-canonical memory reference) when trying to enter the crash kernel.
Fixes 9c20d3c5915d ("x86/IDT: Make idt_tables[] be per_cpu(idt)")Reported-by Lin Liu <[email protected]>Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Lin Liu <[email protected]>
Quoted 6 lines
The fix here is a bit ugly.
nmi_shootdown_cpus()uses thecpu_online_mapbut this is wrong too; it misses parked CPUs, which do want to be captured.For 4.22. This is the minimal fix to stop systems crashing, but more work is needed to make this path fully robust.
---
Thanks.
~ Oleksii