Secure Boot lock down
Subsystems (3)
cover Secure Boot lock down
All major distros have had carried a version of this patch-set out of tree for sometime now, but with a bunch of magic (typically sprinkled in setup_arch()). Though we can avoid those architecture specific quirks if we call efi_get_secureboot_mode() from efisubsys_init() and that allows us to have a generic solution.
Hamza Mahfooz (2):
security: introduce security_lock_kernel_down()
efi: introduce EFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOT
drivers/firmware/efi/Kconfig | 10 ++++++++++ drivers/firmware/efi/efi.c | 9 +++++++++ include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 8 ++++++++ security/lockdown/lockdown.c | 1 + security/security.c | 15 +++++++++++++++ 6 files changed, 44 insertions(+)
Signature · 1 line
2.49.0
PATCH 1/2 security: introduce security_lock_kernel_down()
Define and export security_lock_kernel_down(), so that we can lock down the kernel from other parts of the kernel.
--- include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 8 ++++++++ security/lockdown/lockdown.c | 1 + security/security.c | 15 +++++++++++++++ 4 files changed, 25 insertions(+)
include/linux/lsm_hook_defs.h +1 -0
@@ -442,6 +442,7 @@ LSM_HOOK(int, 0, bpf_token_cmd, const struct bpf_token *token, enum bpf_cmd cmd) LSM_HOOK(int, 0, bpf_token_capable, const struct bpf_token *token, int cap)#endif /* CONFIG_BPF_SYSCALL */ +LSM_HOOK(int, 0, lock_down, const char *where, enum lockdown_reason level) LSM_HOOK(int, 0, locked_down, enum lockdown_reason what)#ifdef CONFIG_PERF_EVENTS
include/linux/security.h +8 -0
@@ -573,6 +573,7 @@ void security_inode_invalidate_secctx(struct inode *inode);int security_inode_notifysecctx (struct inode *inode,void *ctx,u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen);int security_inode_getsecctx (struct inode *inode,struct lsm_context *cp); +int security_lock_kernel_down (const char *where,enum lockdown_reason level);int security_locked_down (enum lockdown_reason what);int lsm_fill_user_ctx (struct lsm_ctx __user *uctx,u32 *uctx_len,void *val,size_t val_len,u64 id,u64 flags);
@@ -1576,6 +1577,13 @@ static inline int security_inode_getsecctx(struct inode *inode, {return -EOPNOTSUPP ; } + +static inline int security_lock_kernel_down (const char *where, +enum lockdown_reason level) +{ +return -EOPNOTSUPP ; +} +static inline int security_locked_down (enum lockdown_reason what) {return 0 ;
security/lockdown/lockdown.c +1 -0
@@ -73,6 +73,7 @@ static int lockdown_is_locked_down(enum lockdown_reason what) }static struct security_hook_list lockdown_hooks[]__ro_after_init = { +LSM_HOOK_INIT (lock_down, lock_kernel_down),LSM_HOOK_INIT (locked_down, lockdown_is_locked_down), };
security/security.c +15 -0
@@ -5789,6 +5789,21 @@ void security_bpf_token_free(struct bpf_token *token) }#endif /* CONFIG_BPF_SYSCALL */ +/** +* security_lock_kernel_down() - Lock down the kernel +* @where: the location from where the lock down is being initiated +* @level: requested lock down level +* +* Attempt to lock down the kernel at the requested level. +* +* Return: Returns 0 on success, error on failure. +*/ +int security_lock_kernel_down (const char *where,enum lockdown_reason level) +{ +return call_int_hook (lock_down, where, level); +} +EXPORT_SYMBOL (security_lock_kernel_down); +/** * security_locked_down() - Check if a kernel feature is allowed * @what: requested kernel feature
Signature · 1 line
2.49.0
PATCH 2/2 efi: introduce EFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOT
In reply to Hamza MahfoozAdd a kernel configuration option to lock down the kernel, to restrict userspace's ability to modify the running kernel when Secure Boot is enabled.
--- drivers/firmware/efi/Kconfig | 10 ++++++++++ drivers/firmware/efi/efi.c | 9 +++++++++ 2 files changed, 19 insertions(+)
drivers/firmware/efi/Kconfig +10 -0
@@ -248,6 +248,16 @@ config EFI_DISABLE_RUNTIME This default can be overridden by using the efi=runtime option. +config EFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOT + bool "Lock down the kernel in EFI Secure Boot mode" + default n + depends on EFI + depends on SECURITY_LOCKDOWN_LSM + select SECURITY_LOCKDOWN_LSM_EARLY + help + Enabling this option results in kernel lockdown being + set in integrity mode if EFI Secure Boot is enabled. + config EFI_COCO_SECRET bool "EFI Confidential Computing Secret Area Support" help
drivers/firmware/efi/efi.c +9 -0
@@ -427,6 +427,15 @@ static int __init efisubsys_init(void) } } +#ifdef CONFIG_EFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOT +if (efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { +if (efi_get_secureboot_mode (efi.get_variable) == + efi_secureboot_mode_enabled) +security_lock_kernel_down ("EFI Secure Boot" , +LOCKDOWN_INTEGRITY_MAX ); + } +#endif +if (efi_rt_services_supported (EFI_RT_SUPPORTED_TIME_SERVICES ))platform_device_register_simple ("rtc-efi" ,0 ,NULL ,0 );
Signature · 1 line
2.49.0
Ping?
Quoted 20 lines · Hamza Mahfooz
All major distros have had carried a version of this patch-set out of tree for sometime now, but with a bunch of magic (typically sprinkled in
setup_arch()). Though we can avoid those architecture specific quirks if we callefi_get_secureboot_mode()fromefisubsys_init()and that allows us to have a generic solution.Hamza Mahfooz (2):
security: introducesecurity_lock_kernel_down()
efi: introduceEFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOTdrivers/firmware/efi/Kconfig | 10 ++++++++++ drivers/firmware/efi/efi.c | 9 +++++++++ include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 8 ++++++++ security/lockdown/lockdown.c | 1 + security/security.c | 15 +++++++++++++++ 6 files changed, 44 insertions(+)Signature · 1 line
2.49.0
Paul Moore
maintainerQuoted 2 lines · Hamza Mahfooz
Ping?
Adding the new Lockdown maintainers to the To/CC line for review in case they missed it earlier. For reference, the patchset can be found at the lore link below:
Quoted 18 lines · Hamza Mahfooz
Quoted 17 lines
All major distros have had carried a version of this patch-set out of tree for sometime now, but with a bunch of magic (typically sprinkled in
setup_arch()). Though we can avoid those architecture specific quirks if we callefi_get_secureboot_mode()fromefisubsys_init()and that allows us to have a generic solution.Hamza Mahfooz (2):
security: introducesecurity_lock_kernel_down()
efi: introduceEFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOTdrivers/firmware/efi/Kconfig | 10 ++++++++++ drivers/firmware/efi/efi.c | 9 +++++++++ include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 8 ++++++++ security/lockdown/lockdown.c | 1 + security/security.c | 15 +++++++++++++++ 6 files changed, 44 insertions(+)
Signature · 1 line
paul-moore.com
Nicolas Bouchinet
maintainerHi Hamza, thanks for your patch.
Thanks, Paul, for the forward.
Sorry for the delay, we took a bit of time to do some lore archaeology and discuss it with Xiu.
As you might know, this has already been through debates in 2017 [1]. At that time, the decision was not to merge this behavior.
Distros have indeed carried downstream patches reflecting this behavior for a long time and have been affected by vulnerabilities like CVE-2025-1272 [2], which is caused by the magic sprinkled in setup_arch().
While your implementation looks cleaner to me. One of the points in previous debates was to have a Lockdown side Kconfig knob to enable or not this behavior. It would gate the registration of the Lockdown LSM to the security_lock_kernel_down() hook.
However, what bothers me is that with this patch, if UEFI Secure Boot is activated and a user wants to disable Lockdown, they need to go through disabling Secure Boot. I'm really not fond of that. A user shouldn't have to be forced to disable security firmware settings because of a kernel feature.
We thus might want to add a way to disable Lockdown through kernel cmdline. However, letting a user disable Lockdown through kernel cmdline would allow easy Lockdown bypasses, especially since the kernel cmdline as well as the initramfs are not integrity protected on most distros. A root user would be able to tamper with kernel cmdline and change its behavior across reboot.
IMHO, if someone wants to enable Lockdown, the easy and correct way is to set the kernel cmdline and integrity protect it using an UKI for example. If the chain of trust is respected, no Lockdown bypasses should be possible.
I'm still open to hearing new arguments about this patch.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://access.redhat.com/security/cve/cve-2025-1272
Best regards,
Nicolas
---
Quoted 32 lines · Paul Moore
Quoted 2 lines · Hamza Mahfooz
Ping?
Adding the new Lockdown maintainers to the To/CC line for review in case they missed it earlier. For reference, the patchset can be found at the lore link below:
Quoted 18 lines · Hamza Mahfooz
Quoted 17 lines
All major distros have had carried a version of this patch-set out of tree for sometime now, but with a bunch of magic (typically sprinkled in
setup_arch()). Though we can avoid those architecture specific quirks if we callefi_get_secureboot_mode()fromefisubsys_init()and that allows us to have a generic solution.Hamza Mahfooz (2):
security: introducesecurity_lock_kernel_down()
efi: introduceEFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOTdrivers/firmware/efi/Kconfig | 10 ++++++++++ drivers/firmware/efi/efi.c | 9 +++++++++ include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 8 ++++++++ security/lockdown/lockdown.c | 1 + security/security.c | 15 +++++++++++++++ 6 files changed, 44 insertions(+)Signature · 1 line
paul-moore.com
Quoted 15 lines · Nicolas Bouchinet
Hi Hamza, thanks for your patch.
Thanks, Paul, for the forward.
Sorry for the delay, we took a bit of time to do some lore archaeology and discuss it with Xiu.
As you might know, this has already been through debates in 2017 [1]. At that time, the decision was not to merge this behavior.
Distros have indeed carried downstream patches reflecting this behavior for a long time and have been affected by vulnerabilities like CVE-2025-1272 [2], which is caused by the magic sprinkled in
setup_arch().
Quoted 4 lines
While your implementation looks cleaner to me. One of the points in previous debates was to have a Lockdown side
Kconfigknob to enable or not this behavior. It would gate the registration of the Lockdown LSM to thesecurity_lock_kernel_down()hook.
Well, but there is a default-n kconfig. What do you mean by "Lockdown side Kconfig knob"? I'm sure I'm missing something, but not sure what...
thanks,
-serge
Nicolas Bouchinet
maintainerQuoted 16 lines · On Thu, Jul 24, 2025 at 02:13:41PM +0000, [email protected] wrote:
Quoted 15 lines · Nicolas Bouchinet
Hi Hamza, thanks for your patch.
Thanks, Paul, for the forward.
Sorry for the delay, we took a bit of time to do some lore archaeology and discuss it with Xiu.
As you might know, this has already been through debates in 2017 [1]. At that time, the decision was not to merge this behavior.
Distros have indeed carried downstream patches reflecting this behavior for a long time and have been affected by vulnerabilities like CVE-2025-1272 [2], which is caused by the magic sprinkled in
setup_arch().
Quoted 9 lines
Quoted 4 lines
While your implementation looks cleaner to me. One of the points in previous debates was to have a Lockdown side
Kconfigknob to enable or not this behavior. It would gate the registration of the Lockdown LSM to thesecurity_lock_kernel_down()hook.Well, but there is a default-n kconfig. What do you mean by "Lockdown side
Kconfigknob"? I'm sure I'm missing something, but not sure what...
Sorry, if I have been unclear, I talk about something like a "LOCK_DOWN_IF_SECURE_BOOT" config in security/lockdown/Kconfig. In addition to the "EFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOT" in drivers/firmware/efi/Kconfig.
- "EFI_KERNEL_LOCK_DOWN_IN_SECURE_BOOT" would gate the call to the security_lock_kernel_down hook and thus to any LSM registered to it.
- "LOCK_DOWN_IF_SECURE_BOOT" would gate the Lockdown LSM registration to the security_lock_kernel_down hook.
Thanks,
Nicolas
Paul Moore
maintainerQuoted 21 lines · Nicolas Bouchinet
Hi Hamza, thanks for your patch.
Thanks, Paul, for the forward.
Sorry for the delay, we took a bit of time to do some lore archaeology and discuss it with Xiu.
As you might know, this has already been through debates in 2017 [1]. At that time, the decision was not to merge this behavior.
Distros have indeed carried downstream patches reflecting this behavior for a long time and have been affected by vulnerabilities like CVE-2025-1272 [2], which is caused by the magic sprinkled in
setup_arch().While your implementation looks cleaner to me. One of the points in previous debates was to have a Lockdown side
Kconfigknob to enable or not this behavior. It would gate the registration of the Lockdown LSM to thesecurity_lock_kernel_down()hook.
Quoted 8 lines
However, what bothers me is that with this patch, if UEFI Secure Boot is activated and a user wants to disable Lockdown, they need to go through disabling Secure Boot. I'm really not fond of that. A user shouldn't have to be forced to disable security firmware settings because of a kernel feature.
We thus might want to add a way to disable Lockdown through kernel cmdline.
One can enable/disable "normal" LSMs via the "lsm=" kernel command line option, however, as Lockdown is an "early" LSM, it is enabled prior to the command line option parsing in the kernel so that isn't really an option unless we add some mechanism to later disable Lockdown during the "normal" LSM initialization phase when the command line options are available. This would result in a window of time during very early boot where Lockdown would be enabled, before being disabled, but I have no idea how problematic that might be for users.
Signature · 1 line
paul-moore.com