lockdown fixups
cover lockdown fixups
Fixups for the lockdown patchset. Potentially makes more sense to merge these into the relevant original patches rather than keeping them separate, but sending them for review.
PATCH 1/6 tracefs: Fix potential null dereference in default_file_open()
From: Ben Hutchings <[email protected]>
The "open" operation in struct file_operations is optional, and ftrace_event_id_fops does not set it. In default_file_open(), after all other checks have passed, return 0 if the underlying struct file_operations does not implement open.
References: https://bugs.debian.org/934304
--- fs/tracefs/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/tracefs/inode.c +2 -0
@@ -42,6 +42,8 @@ static int default_open_file(struct inode *inode, struct file *filp)return ret; real_fops = dentry->d_fsdata; +if (!real_fops->open) +return 0 ;return real_fops->open (inode, filp); }
Signature · 1 line
2.23.0.rc1.153.gdeed80330f-goog
PATCH 2/6 early_security_init() needs a stub got !CONFIG_SECURITY
In reply to Matthew GarrettFrom: Stephen Rothwell <[email protected]>
An arm multi_v7_defconfig fails like this:
init/main.c: In function 'start_kernel':init/main.c:596:2: error: implicit declaration of function 'early_security_init'; did you mean 'security_init'? [-Werror=implicit-function-declaration]
early_security_init();
^~~~~~~~~~~~~~~~~~~
security_init
--- include/linux/security.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/security.h +5 -0
@@ -473,6 +473,11 @@ static inline int security_init(void)return 0 ; } +static inline int early_security_init (void ) +{ +return 0 ; +} +static inline int security_binder_set_context_mgr (struct task_struct *mgr) {return 0 ;
Signature · 1 line
2.23.0.rc1.153.gdeed80330f-goog
PATCH 3/6 Avoid build warning when !CONFIG_KEXEC_SIG
In reply to Matthew GarrettRefactor the signature validation and lockdown integration a little in order to avoid an unused variable.
--- kernel/kexec_file.c | 72 ++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 27 deletions(-)
kernel/kexec_file.c +45 -27
@@ -177,36 +177,13 @@ void kimage_file_post_load_cleanup(struct kimage *image) image->image_loader_data =NULL ; } -/* -* In file mode list of segments is prepared by kernel. Copy relevant -* data from user space, do error checking, prepare segment list -*/ +#ifdef CONFIG_KEXEC_SIG static int -kimage_file_prepare_segments (struct kimage *image,int kernel_fd,int initrd_fd, -const char __user *cmdline_ptr, -unsigned long cmdline_len,unsigned flags) +kimage_validate_signature (struct kimage *image) {const char *reason;int ret; -void *ldata; -loff_t size; - - ret =kernel_read_file_from_fd (kernel_fd, &image->kernel_buf, - &size,INT_MAX ,READING_KEXEC_IMAGE ); -if (ret) -return ret; - image->kernel_buf_len = size; - -/* IMA needs to pass the measurement list to the next kernel. */ -ima_add_kexec_buffer (image); -/* Call arch image probe handlers */ - ret =arch_kexec_kernel_image_probe (image, image->kernel_buf, - image->kernel_buf_len); -if (ret) - goto out; - -#ifdef CONFIG_KEXEC_SIG ret =arch_kexec_kernel_verify_sig (image, image->kernel_buf, image->kernel_buf_len);switch (ret) {
@@ -228,7 +205,7 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, decide:if (IS_ENABLED (CONFIG_KEXEC_SIG_FORCE )) {pr_notice ("%s rejected\n" , reason); - goto out; +break ; } ret =0 ;
@@ -251,9 +228,44 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,*/ default :pr_notice ("kernel signature verification failed (%d).\n" , ret); - goto out; + break; } + +return ret; +} +#endif + +/* +* In file mode list of segments is prepared by kernel. Copy relevant +* data from user space, do error checking, prepare segment list +*/ +static int +kimage_file_prepare_segments (struct kimage *image,int kernel_fd,int initrd_fd, +const char __user *cmdline_ptr, +unsigned long cmdline_len,unsigned flags) +{ +int ret; +void *ldata; +loff_t size; + + ret =kernel_read_file_from_fd (kernel_fd, &image->kernel_buf, + &size,INT_MAX ,READING_KEXEC_IMAGE ); +if (ret) +return ret; + image->kernel_buf_len = size; + +/* Call arch image probe handlers */ + ret =arch_kexec_kernel_image_probe (image, image->kernel_buf, + image->kernel_buf_len); +if (ret) + goto out; + +#ifdef CONFIG_KEXEC_SIG + ret =kimage_validate_signature (image); +if (ret) + goto out;#endif +/* It is possible that there no initramfs is being loaded */ if (!(flags &KEXEC_FILE_NO_INITRAMFS )) { ret = kernel_read_file_from_fd(initrd_fd, &image->initrd_buf,
@@ -279,8 +291,14 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, ret = -EINVAL ; goto out; } + +ima_kexec_cmdline (image->cmdline_buf, + image->cmdline_buf_len -1 ); } +/* IMA needs to pass the measurement list to the next kernel. */ +ima_add_kexec_buffer (image); +/* Call arch image load handlers */ ldata =arch_kexec_kernel_image_load (image);
Signature · 1 line
2.23.0.rc1.153.gdeed80330f-goog
PATCH 4/6 security: fix ptr_ret.cocci warnings
In reply to Matthew GarrettFrom: kbuild test robot <[email protected]>
security/lockdown/lockdown.c:157:1-3: WARNING: PTR_ERR_OR_ZERO can be used
Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
Generated by: scripts/coccinelle/api/ptr_ret.cocci
--- security/lockdown/lockdown.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
security/lockdown/lockdown.c +1 -4
@@ -176,10 +176,7 @@ static int __init lockdown_secfs_init(void) dentry =securityfs_create_file ("lockdown" ,0600 ,NULL ,NULL , &lockdown_ops); -if (IS_ERR (dentry)) -return PTR_ERR (dentry); - -return 0 ; +return PTR_ERR_OR_ZERO (dentry); }core_initcall (lockdown_secfs_init);
Signature · 1 line
2.23.0.rc1.153.gdeed80330f-goog
PATCH 5/6 kexec: s/KEXEC_VERIFY_SIG/KEXEC_SIG/ for consistency
In reply to Matthew Garrett47b88836 ("kexec_file: split KEXEC_VERIFY_SIG into KEXEC_SIG and KEXEC_SIG_FORCE") removed CONFIG_KEXEC_VERIFY_SIG, but it's still present in other architectures and we end up with build breakage as a result. Make this consistent across architectures.
--- arch/arm64/Kconfig | 6 +++--- arch/s390/Kconfig | 2 +- arch/s390/configs/debug_defconfig | 2 +- arch/s390/configs/defconfig | 2 +- arch/s390/configs/performance_defconfig | 2 +- arch/s390/kernel/kexec_elf.c | 4 ++-- arch/s390/kernel/kexec_image.c | 4 ++-- arch/s390/kernel/machine_kexec_file.c | 4 ++-- arch/x86/kernel/ima_arch.c | 4 ++-- security/integrity/ima/Kconfig | 2 +- security/integrity/ima/ima_main.c | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-)
arch/arm64/Kconfig +3 -3
@@ -961,7 +961,7 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. -config KEXEC_VERIFY_SIG +config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE help
@@ -976,13 +976,13 @@ config KEXEC_VERIFY_SIG config KEXEC_IMAGE_VERIFY_SIG bool "Enable Image signature verification support" default y - depends on KEXEC_VERIFY_SIG + depends on KEXEC_SIG depends on EFI && SIGNED_PE_FILE_VERIFICATION help Enable Image signature verification support. comment "Support for PE file signature verification disabled" - depends on KEXEC_VERIFY_SIG + depends on KEXEC_SIG depends on !EFI || !SIGNED_PE_FILE_VERIFICATION config CRASH_DUMP
arch/s390/Kconfig +1 -1
@@ -555,7 +555,7 @@ config ARCH_HAS_KEXEC_PURGATORY def_bool y depends on KEXEC_FILE -config KEXEC_VERIFY_SIG +config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE && SYSTEM_DATA_VERIFICATION help
arch/s390/configs/debug_defconfig +1 -1
@@ -64,7 +64,7 @@ CONFIG_NUMA=y CONFIG_PREEMPT=y CONFIG_HZ_100=y CONFIG_KEXEC_FILE=y -CONFIG_KEXEC_VERIFY_SIG=y +CONFIG_KEXEC_SIG=y CONFIG_EXPOLINE=y CONFIG_EXPOLINE_AUTO=y CONFIG_MEMORY_HOTPLUG=y
arch/s390/configs/defconfig +1 -1
@@ -39,7 +39,7 @@ CONFIG_NR_CPUS=256 CONFIG_NUMA=y CONFIG_HZ_100=y CONFIG_KEXEC_FILE=y -CONFIG_KEXEC_VERIFY_SIG=y +CONFIG_KEXEC_SIG=y CONFIG_CRASH_DUMP=y CONFIG_HIBERNATION=y CONFIG_PM_DEBUG=y
arch/s390/configs/performance_defconfig +1 -1
@@ -65,7 +65,7 @@ CONFIG_NR_CPUS=512 CONFIG_NUMA=y CONFIG_HZ_100=y CONFIG_KEXEC_FILE=y -CONFIG_KEXEC_VERIFY_SIG=y +CONFIG_KEXEC_SIG=y CONFIG_EXPOLINE=y CONFIG_EXPOLINE_AUTO=y CONFIG_MEMORY_HOTPLUG=y
arch/s390/kernel/kexec_elf.c +2 -2
@@ -130,7 +130,7 @@ static int s390_elf_probe(const char *buf, unsigned long len)const struct kexec_file_ops s390_kexec_elf_ops = { .probe = s390_elf_probe, .load = s390_elf_load, -#ifdef CONFIG_KEXEC_VERIFY_SIG +#ifdef CONFIG_KEXEC__SIG .verify_sig = s390_verify_sig, -#endif /* CONFIG_KEXEC_VERIFY_SIG */ +#endif /* CONFIG_KEXEC_SIG */ };
arch/s390/kernel/kexec_image.c +2 -2
@@ -59,7 +59,7 @@ static int s390_image_probe(const char *buf, unsigned long len)const struct kexec_file_ops s390_kexec_image_ops = { .probe = s390_image_probe, .load = s390_image_load, -#ifdef CONFIG_KEXEC_VERIFY_SIG +#ifdef CONFIG_KEXEC_SIG .verify_sig = s390_verify_sig, -#endif /* CONFIG_KEXEC_VERIFY_SIG */ +#endif /* CONFIG_KEXEC_SIG */ };
arch/s390/kernel/machine_kexec_file.c +2 -2
@@ -22,7 +22,7 @@ const struct kexec_file_ops * const kexec_file_loaders[] = { NULL, }; -#ifdef CONFIG_KEXEC_VERIFY_SIG +#ifdef CONFIG_KEXEC_SIG /* * Module signature information block. *
@@ -90,7 +90,7 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len)VERIFYING_MODULE_SIGNATURE , NULL, NULL); } -#endif /* CONFIG_KEXEC_VERIFY_SIG */ +#endif /* CONFIG_KEXEC_SIG */ static int kexec_file_update_purgatory (struct kimage *image,struct s390_load_data *data)
arch/x86/kernel/ima_arch.c +2 -2
@@ -66,9 +66,9 @@ bool arch_ima_get_secureboot(void)/* secureboot arch rules */ static const char *const sb_arch_rules[] = { -#if !IS_ENABLED(CONFIG_KEXEC_VERIFY_SIG) +#if !IS_ENABLED(CONFIG_KEXEC_SIG)"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig" , -#endif /* CONFIG_KEXEC_VERIFY_SIG */ +#endif /* CONFIG_KEXEC_SIG */"measure func=KEXEC_KERNEL_CHECK" , #if !IS_ENABLED(CONFIG_MODULE_SIG) "appraise func=MODULE_CHECK appraise_type=imasig",
security/integrity/ima/Kconfig +1 -1
@@ -160,7 +160,7 @@ config IMA_APPRAISE config IMA_ARCH_POLICY bool "Enable loading an IMA architecture specific policy" - depends on KEXEC_VERIFY_SIG || IMA_APPRAISE && INTEGRITY_ASYMMETRIC_KEYS + depends on KEXEC_SIG || IMA_APPRAISE && INTEGRITY_ASYMMETRIC_KEYS default n help This option enables loading an IMA architecture specific policy
security/integrity/ima/ima_main.c +1 -1
@@ -541,7 +541,7 @@ int ima_load_data(enum kernel_load_data_id id)switch (id) {case LOADING_KEXEC_IMAGE : -if (IS_ENABLED (CONFIG_KEXEC_VERIFY_SIG ) +if (IS_ENABLED (CONFIG_KEXEC_SIG ) &&arch_ima_get_secureboot ()) {pr_err ("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n" );return -EACCES ;
Signature · 1 line
2.23.0.rc1.153.gdeed80330f-goog
PATCH 6/6 Document locked_down LSM hook
In reply to Matthew GarrettThe kbuild test robot pointed out that this wasn't documented.
--- include/linux/lsm_hooks.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/lsm_hooks.h +5 -0
@@ -1446,6 +1446,11 @@* @bpf_prog_free_security: * Clean up the security information stored inside bpf prog. * +* @locked_down +* Determine whether a kernel feature that potentially enables arbitrary +* code execution in kernel space should be permitted. +* +* @what: kernel feature being accessed */ union security_list_options {int (*binder_set_context_mgr)(struct task_struct *mgr);
Signature · 1 line
2.23.0.rc1.153.gdeed80330f-goog
James Morris
maintainerQuoted 3 lines · Matthew Garrett
Fixups for the lockdown patchset. Potentially makes more sense to merge these into the relevant original patches rather than keeping them separate, but sending them for review.
Yep, it's difficult to guess which Linus would prefer, as this is also public development history now.
Signature · 2 lines
James Morris <[email protected]>
James Morris
maintainerQuoted 3 lines · Matthew Garrett
Fixups for the lockdown patchset. Potentially makes more sense to merge these into the relevant original patches rather than keeping them separate, but sending them for review.
Which kernel version are these against?
kernel/kexec_file.c: In function ‘kimage_validate_signature’:kernel/kexec_file.c:220:4: error: label ‘out’ used but not defined
220 | goto out;
| ^~~~
kernel/kexec_file.c: In function ‘kimage_file_prepare_segments’:
kernel/kexec_file.c:295:3: error: implicit declaration of function
‘ima_kexec_cmdline’ [-Werror=implicit-function-declaration]
295 | ima_kexec_cmdline(image->cmdline_buf,
| ^~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
My next-lockdown branch is based on v5.2.
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH 3/6] Avoid build warning when !CONFIG_KEXEC_SIG
In reply to Matthew GarrettQuoted 114 lines · Matthew Garrett
Refactor the signature validation and lockdown integration a little in order to avoid an unused variable.
Signed-off-by Matthew Garrett <[email protected]>Cc Jiri Bohac <[email protected]>Cc Dave Young <[email protected]>--- kernel/kexec_file.c | 72 ++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 27 deletions(-)kernel/kexec_file.c +40
-27@@ -177,36 +177,13 @@ void kimage_file_post_load_cleanup(struct kimage *image) image->image_loader_data =NULL ; } -/* -* In file mode list of segments is prepared by kernel. Copy relevant -* data from user space, do error checking, prepare segment list -*/ +#ifdef CONFIG_KEXEC_SIG static int -kimage_file_prepare_segments (struct kimage *image,int kernel_fd,int initrd_fd, -const char __user *cmdline_ptr, -unsigned long cmdline_len,unsigned flags) +kimage_validate_signature (struct kimage *image) {const char *reason;int ret; -void *ldata; -loff_t size; - - ret =kernel_read_file_from_fd (kernel_fd, &image->kernel_buf, - &size,INT_MAX ,READING_KEXEC_IMAGE ); -if (ret) -return ret; - image->kernel_buf_len = size; - -/* IMA needs to pass the measurement list to the next kernel. */ -ima_add_kexec_buffer (image); -/* Call arch image probe handlers */ - ret =arch_kexec_kernel_image_probe (image, image->kernel_buf, - image->kernel_buf_len); -if (ret) - goto out; - -#ifdef CONFIG_KEXEC_SIG ret =arch_kexec_kernel_verify_sig (image, image->kernel_buf, image->kernel_buf_len);switch (ret) {@@ -228,7 +205,7 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, decide:if (IS_ENABLED (CONFIG_KEXEC_SIG_FORCE )) {pr_notice ("%s rejected\n" , reason); - goto out; +break ; } ret =0 ;@@ -251,9 +228,44 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,*/ default :pr_notice ("kernel signature verification failed (%d).\n" , ret); - goto out; + break; } + +return ret; +} +#endif + +/* +* In file mode list of segments is prepared by kernel. Copy relevant +* data from user space, do error checking, prepare segment list +*/ +static int +kimage_file_prepare_segments (struct kimage *image,int kernel_fd,int initrd_fd, +const char __user *cmdline_ptr, +unsigned long cmdline_len,unsigned flags) +{ +int ret; +void *ldata; +loff_t size; + + ret =kernel_read_file_from_fd (kernel_fd, &image->kernel_buf, + &size,INT_MAX ,READING_KEXEC_IMAGE ); +if (ret) +return ret; + image->kernel_buf_len = size; + +/* Call arch image probe handlers */ + ret =arch_kexec_kernel_image_probe (image, image->kernel_buf, + image->kernel_buf_len); +if (ret) + goto out; + +#ifdef CONFIG_KEXEC_SIG + ret =kimage_validate_signature (image); +if (ret) + goto out;#endif +/* It is possible that there no initramfs is being loaded */ if (!(flags &KEXEC_FILE_NO_INITRAMFS )) { ret = kernel_read_file_from_fd(initrd_fd, &image->initrd_buf,@@ -279,8 +291,14 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, ret = -EINVAL ; goto out; } +
kernel/kexec_file.c kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, · line 304
Quoted 10 lines
kernel/kexec_file.c +5
-0+ima_kexec_cmdline (image->cmdline_buf, + image->cmdline_buf_len -1 ); } +/* IMA needs to pass the measurement list to the next kernel. */ +ima_add_kexec_buffer (image); +/* Call arch image load handlers */ ldata =arch_kexec_kernel_image_load (image);
I can not get the whole thread, also not sure which tree it should apply.
I assume it is based on your series for lockdown. But it is really hard to review because of no context in this patch.
Also I think it should be good to split the preparation piece of kexec and send them separately. Since it is improve the signature verification logic, they do not necessarily depend on the lockdown series.
Thanks
Dave
Re: [PATCH 3/6] Avoid build warning when !CONFIG_KEXEC_SIG
Quoted 2 lines · Dave Young
I can not get the whole thread, also not sure which tree it should apply.
This should be against -next.
Quoted 4 lines
Also I think it should be good to split the preparation piece of kexec and send them separately. Since it is improve the signature verification logic, they do not necessarily depend on the lockdown series.
Sorry, which preparation piece? There shouldn't be any logic change in this patch.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 1 line · James Morris
Which kernel version are these against?
Crap. Sorry, these ended up derived from HEAD. Let me fix that up and resend. Sorry about that!
James Morris
maintainerQuoted 5 lines · Matthew Garrett
Quoted 1 line · James Morris
Which kernel version are these against?
Crap. Sorry, these ended up derived from HEAD. Let me fix that up and resend. Sorry about that!
Do you have an upstream dependency on Mimi's code in -rc?
If so, just tell me which commit it is and I'll find the next good merge point.
Signature · 2 lines
James Morris <[email protected]>
Quoted 10 lines · James Morris
Quoted 5 lines · Matthew Garrett
Quoted 1 line · James Morris
Which kernel version are these against?
Crap. Sorry, these ended up derived from HEAD. Let me fix that up and resend. Sorry about that!
Do you have an upstream dependency on Mimi's code in -rc?
No, there's no dependency, I just ended up with an additional hunk when rebasing.