selftest/ima: fail kexec_load syscall
Subsystems (9)
Mimi Zohar
maintainercover selftest/ima: fail kexec_load syscall
The "ima: add support for arch specific policies" patch set introduced architecture specific policies, including an x86 policy which prevents loading a kernel image via the kexec_load syscall.
This patch set preq's that patch set, adding a missing kexec_load syscall failure message, extending the existing support for detecting secureboot mode, and defining a kexec_load syscall selftest to simplify testing.
To run the kexec_load test requires root privileges. Execute:
"sudo make TARGETS=ima kselftest".
With secure boot enabled, the kexec_load fails, but the test succeeds.
selftests: ima: test_kexec_load.sh
========================================
./test_kexec_load.sh: kexec_load failed [PASS]
ok 1..1 selftests: ima: test_kexec_load.sh [PASS]
Mimi
Mimi Zohar (3):
ima: add error mesage to kexec_load
selftests/ima: kexec_load syscall test
x86/ima: retry detecting secure boot mode
arch/x86/kernel/Makefile | 2 + arch/x86/kernel/ima_arch.c | 46 +++++++++++++++++++++- include/linux/ima.h | 2 +- security/integrity/ima/ima_main.c | 4 +- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/ima/Makefile | 11 ++++++ tools/testing/selftests/ima/config | 4 ++ tools/testing/selftests/ima/test_kexec_load.sh | 54 ++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 tools/testing/selftests/ima/Makefile create mode 100644 tools/testing/selftests/ima/config create mode 100755 tools/testing/selftests/ima/test_kexec_load.sh
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH 1/3 ima: add error mesage to kexec_load
Reject the kexec_load syscall with some indication of the problem.
--- security/integrity/ima/ima_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
security/integrity/ima/ima_main.c +3 -1
@@ -513,8 +513,10 @@ int ima_load_data(enum kernel_load_data_id id)switch (id) {case LOADING_KEXEC_IMAGE :if (IS_ENABLED (CONFIG_KEXEC_VERIFY_SIG ) - &&arch_ima_get_secureboot ()) + &&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 ; + }if (ima_enforce && (ima_appraise &IMA_APPRAISE_KEXEC )) {pr_err ("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n" );
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH 2/3 selftests/ima: kexec_load syscall test
In reply to Mimi ZoharThe kernel CONFIG_KEXEC_VERIFY_SIG option is limited to verifying a kernel image's signature, when loaded via the kexec_file_load syscall. There is no method for verifying a kernel image's signature loaded via the kexec_load syscall.
This test verifies loading the kernel image via the kexec_load syscall fails when the kernel CONFIG_KEXEC_VERIFY_SIG option is enabled on systems with secureboot enabled[1].
[1] Detecting secureboot enabled is architecture specific.
--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/ima/Makefile | 11 ++++++ tools/testing/selftests/ima/config | 4 ++ tools/testing/selftests/ima/test_kexec_load.sh | 54 ++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 tools/testing/selftests/ima/Makefile create mode 100644 tools/testing/selftests/ima/config create mode 100755 tools/testing/selftests/ima/test_kexec_load.sh
tools/testing/selftests/Makefile +1 -0
@@ -13,6 +13,7 @@ TARGETS += firmware TARGETS += ftrace TARGETS += futex TARGETS += gpio +TARGETS += ima TARGETS += intel_pstate TARGETS += ipc TARGETS += kcmp
tools/testing/selftests/ima/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# Makefile for kexec_load + +uname_M := $(shell uname -m 2>/dev/null || echo not) +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) + +ifeq ($(ARCH),x86) +TEST_PROGS := test_kexec_load.sh + +include ../lib.mk + +endif
tools/testing/selftests/ima/config new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_IMA_APPRAISE +CONFIG_IMA_ARCH_POLICY +CONFIG_SECURITYFS +CONFIG_KEXEC_VERIFY_SIG
tools/testing/selftests/ima/test_kexec_load.sh new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH 3/3 x86/ima: retry detecting secure boot mode
In reply to Mimi ZoharThe secure boot mode may not be detected on boot for some reason (eg. buggy firmware). This patch attempts one more time to detect the secure boot mode.
--- arch/x86/kernel/Makefile | 2 ++ arch/x86/kernel/ima_arch.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- include/linux/ima.h | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-)
arch/x86/kernel/Makefile +2 -0
@@ -151,4 +151,6 @@ ifeq ($(CONFIG_X86_64),y) obj-y += vsmp_64.o endif +ifdef CONFIG_EFI obj-$(CONFIG_IMA) += ima_arch.o +endif
arch/x86/kernel/ima_arch.c +44 -2
54 lines not on this page · raw message
include/linux/ima.h +1 -1
@@ -30,7 +30,7 @@ extern void ima_post_path_mknod(struct dentry *dentry);extern void ima_add_kexec_buffer (struct kimage *image);#endif -#ifdef CONFIG_X86 +#if defined(CONFIG_X86 ) && defined(CONFIG_EFI )extern bool arch_ima_get_secureboot (void );extern const char *const *arch_get_ima_policy (void );#else
Signature · 1 line
2.7.5
Re: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 4 lines · Mimi Zohar
The secure boot mode may not be detected on boot for some reason (eg. buggy firmware). This patch attempts one more time to detect the secure boot mode.
Do we have cases where this has actually been seen? I'm not sure what the circumstances are that would result in this behaviour.
A message that is not in the archive (sent off-list or not yet received): CAFbkSA39RwB+E4SaG_ueu-_B=y7JytEYKw1+eXNQ_eCuMfnv=g@mail.gmail.com
Re: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 8 lines · Justin Forbes
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Mimi Zohar
The secure boot mode may not be detected on boot for some reason (eg. buggy firmware). This patch attempts one more time to detect the secure boot mode.
Quoted 5 lines
Quoted 2 lines
Do we have cases where this has actually been seen? I'm not sure what the circumstances are that would result in this behaviour.
We have never seen it in practice, though we only ever do anything with it with x86, so it is possible that some other platforms maybe?
I'm not sure that it buys us anything to check this in both the boot stub and the running kernel. If a platform *is* giving us different results, anything else relying on the information from the boot stub is also going to be broken, so we should do this centrally rather than in the IMA code.
Mimi Zohar
maintainerRe: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 13 lines · Matthew Garrett
Quoted 12 lines · Justin Forbes
Quoted 9 lines · Matthew Garrett
Quoted 4 lines · Mimi Zohar
The secure boot mode may not be detected on boot for some reason (eg. buggy firmware). This patch attempts one more time to detect the secure boot mode.
Do we have cases where this has actually been seen? I'm not sure what the circumstances are that would result in this behaviour.
Quoted 7 lines
Quoted 1 line
We have never seen it in practice, though we only ever do anything with it with x86, so it is possible that some other platforms maybe?
I'm not sure that it buys us anything to check this in both the boot stub and the running kernel. If a platform *is* giving us different results, anything else relying on the information from the boot stub is also going to be broken, so we should do this centrally rather than in the IMA code.
I added this last attempt because I'm seeing this on my laptop, with some older, buggy firmware.
Mimi
Re: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 2 lines · Mimi Zohar
I added this last attempt because I'm seeing this on my laptop, with some older, buggy firmware.
Is the issue that it gives incorrect results on the first read, or is the issue that it gives incorrect results before ExitBootServices() is called? If the former then we should read twice in the boot stub, if the latter then we should figure out a way to do this immediately after ExitBootServices() instead.
Mimi Zohar
maintainerRe: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · Mimi Zohar
I added this last attempt because I'm seeing this on my laptop, with some older, buggy firmware.
Is the issue that it gives incorrect results on the first read, or is the issue that it gives incorrect results before
ExitBootServices()is called? If the former then we should read twice in the boot stub, if the latter then we should figure out a way to do this immediately afterExitBootServices()instead.
Detecting the secure boot mode isn't the problem. On boot, I am seeing "EFI stub: UEFI Secure Boot is enabled", but setup_arch() emits "Secure boot could not be determined".
In efi_main() the secure_boot mode is initially unset, so efi_get_secureboot() is called. efi_get_secureboot() returns the secure_boot mode correctly as enabled. The problem seems to be in saving the secure_boot mode for later use.
Mimi
Re: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 8 lines · Mimi Zohar
Quoted 5 lines · Matthew Garrett
Is the issue that it gives incorrect results on the first read, or is the issue that it gives incorrect results before
ExitBootServices()is called? If the former then we should read twice in the boot stub, if the latter then we should figure out a way to do this immediately afterExitBootServices()instead.
Quoted 8 lines
Detecting the secure boot mode isn't the problem. On boot, I am seeing "EFI stub: UEFI Secure Boot is enabled", but
setup_arch()emits "Secure boot could not be determined".In
efi_main()thesecure_bootmode is initially unset, soefi_get_secureboot()is called.efi_get_secureboot()returns thesecure_bootmode correctly as enabled. The problem seems to be in saving thesecure_bootmode for later use.
Hm. And this only happens on certain firmware versions? If something's stepping on boot_params then we have bigger problems.
Mimi Zohar
maintainerRe: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 13 lines · Matthew Garrett
Quoted 12 lines · Mimi Zohar
Quoted 5 lines · Matthew Garrett
Is the issue that it gives incorrect results on the first read, or is the issue that it gives incorrect results before
ExitBootServices()is called? If the former then we should read twice in the boot stub, if the latter then we should figure out a way to do this immediately afterExitBootServices()instead.Detecting the secure boot mode isn't the problem. On boot, I am seeing "EFI stub: UEFI Secure Boot is enabled", but
setup_arch()emits "Secure boot could not be determined".
Quoted 7 lines
Quoted 4 lines
In
efi_main()thesecure_bootmode is initially unset, soefi_get_secureboot()is called.efi_get_secureboot()returns thesecure_bootmode correctly as enabled. The problem seems to be in saving thesecure_bootmode for later use.Hm. And this only happens on certain firmware versions? If something's stepping on
boot_paramsthen we have bigger problems.
FYI, efi_printk() works before exit_boot(), but not afterwards. The system hangs.
Mimi
Re: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 2 lines · Mimi Zohar
FYI,
efi_printk()works beforeexit_boot(), but not afterwards. The system hangs.
efi_printk() uses boot services to print, so that's not unexpected :) It would probably be sensible to return an error rather than crash, though…
Mimi Zohar
maintainerRe: [PATCH 3/3] x86/ima: retry detecting secure boot mode
In reply to Matthew GarrettQuoted 13 lines · Matthew Garrett
Quoted 12 lines · Mimi Zohar
Quoted 5 lines · Matthew Garrett
Is the issue that it gives incorrect results on the first read, or is the issue that it gives incorrect results before
ExitBootServices()is called? If the former then we should read twice in the boot stub, if the latter then we should figure out a way to do this immediately afterExitBootServices()instead.Detecting the secure boot mode isn't the problem. On boot, I am seeing "EFI stub: UEFI Secure Boot is enabled", but
setup_arch()emits "Secure boot could not be determined".
Quoted 7 lines
Quoted 4 lines
In
efi_main()thesecure_bootmode is initially unset, soefi_get_secureboot()is called.efi_get_secureboot()returns thesecure_bootmode correctly as enabled. The problem seems to be in saving thesecure_bootmode for later use.Hm. And this only happens on certain firmware versions? If something's stepping on
boot_paramsthen we have bigger problems.
I was seeing this problem before and after updating the system firmware on my laptop last summer. If updating the firmware had resolved the problem, I wouldn't have included this patch.
Mimi
Re: [PATCH 3/3] x86/ima: retry detecting secure boot mode
Quoted 8 lines · Mimi Zohar
Quoted 2 lines · Matthew Garrett
Hm. And this only happens on certain firmware versions? If something's stepping on
boot_paramsthen we have bigger problems.I was seeing this problem before and after updating the system firmware on my laptop last summer. If updating the firmware had resolved the problem, I wouldn't have included this patch.
Ah, sorry, when you said that you saw this with older firmware I thought that meant that newer firmware fixed it. What machine are you testing on?