Add lockdown mode
cover Add lockdown mode
Add lockdown mode
The intention of lockdown mode is to prevent attacks from a rogue dom0 userspace from compromising the system. Lockdown mode can be controlled by a Kconfig option and a command-line parameter. It is also enabled automatically when Secure Boot is enabled and it cannot be disabled in that case.
Ross Lagerwall (3):
lib: Add strcspn function
efi: Add a function to check if Secure Boot mode is enabled Add lockdown mode
Kevin Lampis (1):
Disallow most command-line options when lockdown mode is enabled
xen/arch/arm/domain_build.c | 4 +-- xen/arch/x86/acpi/cpu_idle.c | 2 +- xen/arch/x86/cpu/amd.c | 2 +- xen/arch/x86/cpu/mcheck/mce.c | 2 +- xen/arch/x86/cpu/microcode/core.c | 2 +- xen/arch/x86/dom0_build.c | 4 +-- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/irq.c | 2 +- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/setup.c | 3 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/mmconfig-shared.c | 2 +- xen/common/Kconfig | 8 +++++ xen/common/Makefile | 1 + xen/common/domain.c | 2 +- xen/common/efi/boot.c | 23 ++++++++++++ xen/common/efi/runtime.c | 3 ++ xen/common/kernel.c | 13 ++++++- xen/common/kexec.c | 2 +- xen/common/lockdown.c | 52 +++++++++++++++++++++++++++ xen/common/numa.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/drivers/char/ns16550.c | 4 +-- xen/drivers/video/vga.c | 2 +- xen/include/xen/efi.h | 6 ++++ xen/include/xen/lockdown.h | 9 +++++ xen/include/xen/param.h | 49 +++++++++++++++++++------ xen/include/xen/string.h | 1 + xen/lib/Makefile | 1 + xen/lib/strcspn.c | 22 ++++++++++++ 32 files changed, 200 insertions(+), 35 deletions(-) create mode 100644 xen/common/lockdown.c create mode 100644 xen/include/xen/lockdown.h create mode 100644 xen/lib/strcspn.c
Signature · 1 line
2.42.0
Hello Kevin,
Quoted 2 lines
The intention of lockdown mode is to prevent attacks from a rogue dom0 userspace from compromising the system.
Do we consider Dom0 kernel-space as well (thus Dom0 as a whole), or only userland, what about privcmd device (which can issue hypercalls) ?
Teddy
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 4/4 Disallow most command-line options when lockdown mode is enabled
In reply to Kevin LampisA subset of command-line parameters that are specifically safe to use when lockdown mode is enabled are annotated as such.
--- xen/arch/arm/domain_build.c | 4 +-- xen/arch/x86/acpi/cpu_idle.c | 2 +- xen/arch/x86/cpu/amd.c | 2 +- xen/arch/x86/cpu/mcheck/mce.c | 2 +- xen/arch/x86/cpu/microcode/core.c | 2 +- xen/arch/x86/dom0_build.c | 4 +-- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/irq.c | 2 +- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/setup.c | 2 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/mmconfig-shared.c | 2 +- xen/common/domain.c | 2 +- xen/common/kernel.c | 10 +++++- xen/common/kexec.c | 2 +- xen/common/numa.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/drivers/char/ns16550.c | 4 +-- xen/drivers/video/vga.c | 2 +- xen/include/xen/param.h | 49 +++++++++++++++++++++------ 22 files changed, 70 insertions(+), 35 deletions(-)
xen/arch/arm/domain_build.c +2 -2
@@ -41,7 +41,7 @@#include <xen/serial.h> static unsigned int __initdata opt_dom0_max_vcpus; -integer_param ("dom0_max_vcpus" , opt_dom0_max_vcpus); +integer_secure_param ("dom0_max_vcpus" , opt_dom0_max_vcpus);/* * If true, the extended regions support is enabled for dom0 and
@@ -61,7 +61,7 @@ static int __init parse_dom0_mem(const char *s)return *s ? -EINVAL :0 ; } -custom_param ("dom0_mem" , parse_dom0_mem); +custom_secure_param ("dom0_mem" , parse_dom0_mem);int __init parse_arch_dom0_param (const char *s,const char *e) {
xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -113,7 +113,7 @@ static int __init cf_check parse_cstate(const char *s) max_csubstate =simple_strtoul (s +1 ,NULL ,0 );return 0 ; } -custom_param ("max_cstate" , parse_cstate); +custom_secure_param ("max_cstate" , parse_cstate);static bool __read_mostly local_apic_timer_c2_ok;boolean_param ("lapic_timer_c2_ok" , local_apic_timer_c2_ok);
xen/arch/x86/cpu/amd.c +1 -1
@@ -47,7 +47,7 @@ integer_param("cpuid_mask_thermal_ecx", opt_cpuid_mask_thermal_ecx);/* 1 = allow, 0 = don't allow guest creation, -1 = don't allow boot */ int8_t __read_mostly opt_allow_unsafe; -boolean_param ("allow_unsafe" , opt_allow_unsafe); +boolean_secure_param ("allow_unsafe" , opt_allow_unsafe);/* Signal whether the ACPI C1E quirk is required. */ bool __read_mostly amd_acpi_c1e_quirk;
xen/arch/x86/cpu/mcheck/mce.c +1 -1
@@ -31,7 +31,7 @@#include "vmce.h" bool __read_mostly opt_mce = true; -boolean_param ("mce" , opt_mce); +boolean_secure_param ("mce" , opt_mce);bool __read_mostly mce_broadcast;bool is_mc_panic; DEFINE_PER_CPU_READ_MOSTLY(unsigned int, nr_mce_banks);
xen/arch/x86/cpu/microcode/core.c +1 -1
@@ -160,7 +160,7 @@ static int __init cf_check parse_ucode(const char *s)return rc; } -custom_param ("ucode" , parse_ucode); +custom_secure_param ("ucode" , parse_ucode);static struct microcode_ops __ro_after_init ucode_ops;
xen/arch/x86/dom0_build.c +2 -2
@@ -142,7 +142,7 @@ static int __init cf_check parse_dom0_mem(const char *s)return s[-1 ] ? -EINVAL : ret; } -custom_param ("dom0_mem" , parse_dom0_mem); +custom_secure_param ("dom0_mem" , parse_dom0_mem);static unsigned int __initdata opt_dom0_max_vcpus_min =1 ;static unsigned int __initdata opt_dom0_max_vcpus_max =UINT_MAX ;
@@ -164,7 +164,7 @@ static int __init cf_check parse_dom0_max_vcpus(const char *s)return *s ? -EINVAL :0 ; } -custom_param ("dom0_max_vcpus" , parse_dom0_max_vcpus); +custom_secure_param ("dom0_max_vcpus" , parse_dom0_max_vcpus);static __initdata unsigned int dom0_nr_pxms; static __initdata unsigned int dom0_pxms[MAX_NUMNODES] =
xen/arch/x86/hvm/hvm.c +1 -1
@@ -87,7 +87,7 @@ unsigned long __section(".bss.page_aligned") __aligned(PAGE_SIZE)/* Xen command-line option to enable HAP */ static bool __initdata opt_hap_enabled = true; -boolean_param ("hap" , opt_hap_enabled); +boolean_secure_param ("hap" , opt_hap_enabled);#ifndef opt_hvm_fep/* Permit use of the Forced Emulation Prefix in HVM guests */
xen/arch/x86/irq.c +1 -1
@@ -34,7 +34,7 @@/* opt_noirqbalance: If true, software IRQ balancing/affinity is disabled. */ bool __read_mostly opt_noirqbalance; -boolean_param ("noirqbalance" , opt_noirqbalance); +boolean_secure_param ("noirqbalance" , opt_noirqbalance);unsigned int __read_mostly nr_irqs_gsi =NR_ISA_IRQS ;unsigned int __read_mostly nr_irqs;
xen/arch/x86/nmi.c +1 -1
@@ -73,7 +73,7 @@ static int __init cf_check parse_watchdog(const char *s)return 0 ; } -custom_param ("watchdog" , parse_watchdog); +custom_secure_param ("watchdog" , parse_watchdog);/* opt_watchdog_timeout: Number of seconds to wait before panic. */ static unsigned int opt_watchdog_timeout =5 ;
xen/arch/x86/setup.c +1 -1
@@ -70,7 +70,7 @@/* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp; -boolean_param ("nosmp" , opt_nosmp); +boolean_secure_param ("nosmp" , opt_nosmp);/* maxcpus: maximum number of CPUs to activate. */ static unsigned int __initdata max_cpus;
xen/arch/x86/traps.c +1 -1
@@ -86,7 +86,7 @@ static char __read_mostly opt_nmi[10] = "dom0";#else static char __read_mostly opt_nmi[10 ] ="fatal" ;#endif -string_param ("nmi" , opt_nmi); +string_secure_param ("nmi" , opt_nmi);DEFINE_PER_CPU (uint64_t, efer); static DEFINE_PER_CPU(unsigned long, last_extable_addr);
xen/arch/x86/x86_64/mmconfig-shared.c +1 -1
@@ -60,7 +60,7 @@ static int __init cf_check parse_mmcfg(const char *s)return rc; } -custom_param ("mmcfg" , parse_mmcfg); +custom_secure_param ("mmcfg" , parse_mmcfg); static const char *__init cf_check pci_mmcfg_e7520(void) {
xen/common/domain.c +1 -1
@@ -55,7 +55,7 @@ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX;/* opt_dom0_vcpus_pin: If true, dom0 VCPUs are pinned. */ bool opt_dom0_vcpus_pin; -boolean_param ("dom0_vcpus_pin" , opt_dom0_vcpus_pin); +boolean_secure_param ("dom0_vcpus_pin" , opt_dom0_vcpus_pin);/* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK (domlist_update_lock);
xen/common/kernel.c +9 -1
@@ -14,6 +14,8 @@#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/hypfs.h> +#include <xen/efi.h> +#include <xen/lockdown.h> #include <xsm/xsm.h> #include <asm/current.h> #include <public/version.h>
@@ -135,9 +137,15 @@ static int parse_params(const char *cmdline, const struct kernel_param *start, }continue ; } + found = true; + +if ( !param->is_lockdown_safe &&is_locked_down () ) + { +printk ("Ignoring unsafe cmdline option %s in lockdown mode\n" , param->name); +break ; + } rctmp =0 ; - found = true;switch ( param->type ) {case OPT_STR :
xen/common/kexec.c +1 -1
@@ -189,7 +189,7 @@ static int __init cf_check parse_crashkernel(const char *str)return rc; } -custom_param ("crashkernel" , parse_crashkernel); +custom_secure_param ("crashkernel" , parse_crashkernel);/* Parse command lines in the format: *
xen/common/numa.c +1 -1
@@ -687,7 +687,7 @@ static int __init cf_check numa_setup(const char *opt)return 0 ; } -custom_param ("numa" , numa_setup); +custom_secure_param ("numa" , numa_setup); static void cf_check dump_numa(unsigned char key) {
xen/common/page_alloc.c +1 -1
@@ -235,7 +235,7 @@ static int __init cf_check parse_bootscrub_param(const char *s)return 0 ; } -custom_param ("bootscrub" , parse_bootscrub_param); +custom_secure_param ("bootscrub" , parse_bootscrub_param);/* * bootscrub_chunk -> Amount of bytes to scrub lockstep on non-SMT CPUs
xen/common/shutdown.c +1 -1
@@ -13,7 +13,7 @@/* opt_noreboot: If true, machine will need manual reset on error. */ bool __ro_after_init opt_noreboot; -boolean_param ("noreboot" , opt_noreboot); +boolean_secure_param ("noreboot" , opt_noreboot);static void noreturnreboot_or_halt (void ) {
xen/drivers/char/console.c +1 -1
@@ -43,7 +43,7 @@/* console: comma-separated list of console outputs. */ static char __initdata opt_console[30 ] =OPT_CONSOLE_STR ; -string_param ("console" , opt_console); +string_secure_param ("console" , opt_console);/* conswitch: a character pair controlling console switching. */ /* Char 1: CTRL+<char1> is used to switch console input between Xen and DOM0 */
xen/drivers/char/ns16550.c +2 -2
@@ -1390,8 +1390,8 @@ static void enable_exar_enhanced_bits(const struct ns16550 *uart)*/ static char __initdata opt_com1[128 ] ="" ;static char __initdata opt_com2[128 ] ="" ; -string_param ("com1" , opt_com1); -string_param ("com2" , opt_com2); +string_secure_param ("com1" , opt_com1); +string_secure_param ("com2" , opt_com2);enum serial_param_type { baud_rate,
xen/drivers/video/vga.c +1 -1
@@ -48,7 +48,7 @@ void (*video_puts)(const char *s, size_t nr) = vga_noop_puts;* control of the console to domain 0. */ static char __initdata opt_vga[30 ] ="" ; -string_param ("vga" , opt_vga); +string_secure_param ("vga" , opt_vga);/* VGA text-mode definitions. */ static unsigned int columns, lines;
xen/include/xen/param.h +38 -11
90 lines not on this page · raw message
Signature · 1 line
2.42.0
Re: [PATCH 4/4] Disallow most command-line options when lockdown mode is enabled
Quoted 2 lines · Kevin Lampis
A subset of command-line parameters that are specifically safe to use when lockdown mode is enabled are annotated as such.
You want to go into more detail here, specifically to describe the criteria of "specifically safe". The command line doc may also want updating.
Jan
Re: [PATCH 4/4] Disallow most command-line options when lockdown mode is enabled
In reply to Kevin LampisHello,
Le 12/05/2025 à 11:04, Kevin Lampis a écrit :
Quoted 56 lines
A subset of command-line parameters that are specifically safe to use when lockdown mode is enabled are annotated as such.
Signed-off-by Kevin Lampis <[email protected]>--- xen/arch/arm/domain_build.c | 4 +-- xen/arch/x86/acpi/cpu_idle.c | 2 +- xen/arch/x86/cpu/amd.c | 2 +- xen/arch/x86/cpu/mcheck/mce.c | 2 +- xen/arch/x86/cpu/microcode/core.c | 2 +- xen/arch/x86/dom0_build.c | 4 +-- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/irq.c | 2 +- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/setup.c | 2 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/mmconfig-shared.c | 2 +- xen/common/domain.c | 2 +- xen/common/kernel.c | 10 +++++- xen/common/kexec.c | 2 +- xen/common/numa.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/drivers/char/ns16550.c | 4 +-- xen/drivers/video/vga.c | 2 +- xen/include/xen/param.h | 49 +++++++++++++++++++++------ 22 files changed, 70 insertions(+), 35 deletions(-)xen/arch/arm/domain_build.c +2
-2@@ -41,7 +41,7 @@#include <xen/serial.h> static unsigned int __initdata opt_dom0_max_vcpus; -integer_param ("dom0_max_vcpus" , opt_dom0_max_vcpus); +integer_secure_param ("dom0_max_vcpus" , opt_dom0_max_vcpus);/* * If true, the extended regions support is enabled for dom0 and @@ -61,7 +61,7 @@ static int __init parse_dom0_mem(const char *s)return *s ? -EINVAL :0 ; } -custom_param ("dom0_mem" , parse_dom0_mem); +custom_secure_param ("dom0_mem" , parse_dom0_mem);int __init parse_arch_dom0_param (const char *s,const char *e) {xen/arch/x86/acpi/cpu_idle.c +0
-0
xen/arch/x86/acpi/cpu_idle.c static int __init cf_check parse_cstate(const char *s) · line 115
Quoted 3 lines
xen/arch/x86/acpi/cpu_idle.c +0
-0@@ -113,7 +113,7 @@ static int __init cf_check parse_cstate(const char *s) max_csubstate =simple_strtoul (s +1 ,NULL ,0 );return 0 ; }
What makes ...
xen/arch/x86/acpi/cpu_idle.c static int __init cf_check parse_cstate(const char *s) · line 116
Quoted 2 lines
xen/arch/x86/acpi/cpu_idle.c +1
-1-custom_param ("max_cstate" , parse_cstate); +custom_secure_param ("max_cstate" , parse_cstate);
... specifically unsafe ?
Quoted 56 lines
xen/arch/x86/acpi/cpu_idle.c +0
-0static bool __read_mostly local_apic_timer_c2_ok;boolean_param ("lapic_timer_c2_ok" , local_apic_timer_c2_ok);xen/arch/x86/cpu/amd.c +1
-1@@ -47,7 +47,7 @@ integer_param("cpuid_mask_thermal_ecx", opt_cpuid_mask_thermal_ecx);/* 1 = allow, 0 = don't allow guest creation, -1 = don't allow boot */ int8_t __read_mostly opt_allow_unsafe; -boolean_param ("allow_unsafe" , opt_allow_unsafe); +boolean_secure_param ("allow_unsafe" , opt_allow_unsafe);/* Signal whether the ACPI C1E quirk is required. */ bool __read_mostly amd_acpi_c1e_quirk;xen/arch/x86/cpu/mcheck/mce.c +1
-1@@ -31,7 +31,7 @@#include "vmce.h" bool __read_mostly opt_mce = true; -boolean_param ("mce" , opt_mce); +boolean_secure_param ("mce" , opt_mce);bool __read_mostly mce_broadcast;bool is_mc_panic; DEFINE_PER_CPU_READ_MOSTLY(unsigned int, nr_mce_banks);xen/arch/x86/cpu/microcode/core.c +1
-1@@ -160,7 +160,7 @@ static int __init cf_check parse_ucode(const char *s)return rc; } -custom_param ("ucode" , parse_ucode); +custom_secure_param ("ucode" , parse_ucode);static struct microcode_ops __ro_after_init ucode_ops;xen/arch/x86/dom0_build.c +1
-1@@ -142,7 +142,7 @@ static int __init cf_check parse_dom0_mem(const char *s)return s[-1 ] ? -EINVAL : ret; } -custom_param ("dom0_mem" , parse_dom0_mem); +custom_secure_param ("dom0_mem" , parse_dom0_mem);static unsigned int __initdata opt_dom0_max_vcpus_min =1 ;static unsigned int __initdata opt_dom0_max_vcpus_max =UINT_MAX ;
xen/arch/x86/dom0_build.c static int __init cf_check parse_dom0_max_vcpus(const char *s) · line 168
Quoted 6 lines
xen/arch/x86/dom0_build.c +1
-1@@ -164,7 +164,7 @@ static int __init cf_check parse_dom0_max_vcpus(const char *s)return *s ? -EINVAL :0 ; } -custom_param ("dom0_max_vcpus" , parse_dom0_max_vcpus); +custom_secure_param ("dom0_max_vcpus" , parse_dom0_max_vcpus);
I think it is acceptable for being able to configure dom0-max-vcpus and dom0-mem. It's very likely that the toolstack/user wants to configure that.
xen/arch/x86/hvm/hvm.c unsigned long __section(".bss.page_aligned") __aligned(PAGE_SIZE) · line 90
Quoted 12 lines
xen/arch/x86/dom0_build.c +0
-0static __initdata unsigned int dom0_nr_pxms; static __initdata unsigned int dom0_pxms[MAX_NUMNODES] =xen/arch/x86/hvm/hvm.c +1
-1@@ -87,7 +87,7 @@ unsigned long __section(".bss.page_aligned") __aligned(PAGE_SIZE)/* Xen command-line option to enable HAP */ static bool __initdata opt_hap_enabled = true; -boolean_param ("hap" , opt_hap_enabled); +boolean_secure_param ("hap" , opt_hap_enabled);
---
I think there are several lockdown missing parameters, for instance (dom0-)iommu related parameters should be definetely supposed unsafe.
(dom0-)iommu parameter can be used to disable PCI Passthrough related security features (quarantine thus disabling fix for some XSA variants) or using invalid IOMMU configurations (e.g dom0-iommu=none).
In the same idea, PCI Passthrough to PV guests without a IOMMU should be made impossible in this mode, as it actually allows the guest to perform a privilege escalation using (actually unrestricted) DMA.
Teddy
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 4/4] Disallow most command-line options when lockdown mode is enabled
Quoted 2 lines · Teddy Astie
What makes
max_cstate/ dom0-max-vcpus / dom0-mem specifically unsafe ?
These arguments are all allowed. The *_secure_param macros mean the argument is safe for lockdown mode.
Making PCI passthrough safe for secure boot will be handled in a different patch.
Quoted 7 lines · Kevin Lampis
Add lockdown mode
The intention of lockdown mode is to prevent attacks from a rogue dom0 userspace from compromising the system. Lockdown mode can be controlled by a
Kconfigoption and a command-line parameter. It is also enabled automatically when Secure Boot is enabled and it cannot be disabled in that case.
Quoted 7 lines
Ross Lagerwall (3):
lib: Add strcspn function
efi: Add a function to check if Secure Boot mode is enabled Add lockdown modeKevin Lampis (1):
Disallow most command-line options when lockdown mode is enabled
Returning from vacation, this series is a mess in my inbox (and also on
https://lists.xen.org/archives/html/xen-devel/2025-05/threads.html): Only patch 4 is properly threaded. Please can you see about adjusting your mail configuration?
Jan
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Kevin Lampis
Add lockdown mode
The intention of lockdown mode is to prevent attacks from a rogue dom0 userspace from compromising the system. Lockdown mode can be controlled by a
Kconfigoption and a command-line parameter. It is also enabled automatically when Secure Boot is enabled and it cannot be disabled in that case.Ross Lagerwall (3):
lib: Add strcspn function
efi: Add a function to check if Secure Boot mode is enabled Add lockdown mode
Quoted 6 lines
Quoted 2 lines
Kevin Lampis (1):
Disallow most command-line options when lockdown mode is enabledReturning from vacation, this series is a mess in my inbox (and also on
https://lists.xen.org/archives/html/xen-devel/2025-05/threads.html): Only patch 4 is properly threaded. Please can you see about adjusting your mail configuration?
We had corporate mail problems last week, which was interfering with posting patches. It's hopefully been resolved now.
Kevin: It will be best to resend the series in full.
~Andrew
Quoted 2 lines · Andrew Cooper
Kevin: It will be best to resend the series in full.
Ok.