selftests/kexec: add kexec tests
Subsystems (4)
Mimi Zohar
maintainerv4 cover selftests/kexec: add kexec tests
The kernel may be configured or an IMA policy specified on the boot command line requiring the kexec kernel image signature to be verified. At runtime a custom IMA policy may be loaded, replacing the policy specified on the boot command line. In addition, the arch specific policy rules are dynamically defined based on the secure boot mode that may require the kernel image signature to be verified.
The kernel image may have a PE signature, an IMA signature, or both. In addition, there are two kexec syscalls - kexec_load and kexec_file_load
- but only the kexec_file_load syscall can verify signatures.
These kexec selftests verify that only properly signed kernel images are loaded as required, based on the kernel config, the secure boot mode, and the IMA runtime policy.
Loading a kernel image or kernel module requires root privileges. To run just the KEXEC selftests: sudo make TARGETS=kexec kselftest
Changelog v4:
- Moved the kexec tests to selftests/kexec, as requested by Dave Young.
- Removed the kernel module selftest from this patch set.
- Rewritten cover letter, removing reference to kernel modules.
Changelog v3:
- Updated tests based on Petr's review, including the defining a common test to check for root privileges.
- Modified config, removing the CONFIG_KEXEC_VERIFY_SIG requirement.
- Updated the SPDX license to GPL-2.0 based on Shuah's review.
- Updated the secureboot mode test to check the SetupMode as well, based on David Young's review.
Mimi Zohar (7):
selftests/kexec: move the IMA kexec_load selftest to selftests/kexec selftests/kexec: cleanup the kexec selftest selftests/kexec: define a set of common functions selftests/kexec: define common logging functions kselftest/kexec: define "require_root_privileges" selftests/kexec: kexec_file_load syscall test selftests/kexec: check kexec_load and kexec_file_load are enabled
Petr Vorel (1):
selftests/kexec: Add missing '=y' to config options
tools/testing/selftests/Makefile | 2 +- tools/testing/selftests/ima/Makefile | 11 -- tools/testing/selftests/ima/config | 4 - tools/testing/selftests/ima/test_kexec_load.sh | 54 ------ tools/testing/selftests/kexec/Makefile | 12 ++ tools/testing/selftests/kexec/config | 3 + tools/testing/selftests/kexec/kexec_common_lib.sh | 175 ++++++++++++++++++ .../selftests/kexec/test_kexec_file_load.sh | 195 +++++++++++++++++++++ tools/testing/selftests/kexec/test_kexec_load.sh | 39 +++++ 9 files changed, 425 insertions(+), 70 deletions(-) delete mode 100644 tools/testing/selftests/ima/Makefile delete mode 100644 tools/testing/selftests/ima/config delete mode 100755 tools/testing/selftests/ima/test_kexec_load.sh create mode 100644 tools/testing/selftests/kexec/Makefile create mode 100644 tools/testing/selftests/kexec/config create mode 100755 tools/testing/selftests/kexec/kexec_common_lib.sh create mode 100755 tools/testing/selftests/kexec/test_kexec_file_load.sh create mode 100755 tools/testing/selftests/kexec/test_kexec_load.sh
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 1/8 selftests/kexec: move the IMA kexec_load selftest to selftests/kexec
As requested move the existing kexec_load selftest and subsequent kexec tests to the selftests/kexec directory.
--- tools/testing/selftests/Makefile | 2 +- tools/testing/selftests/ima/Makefile | 11 ----- tools/testing/selftests/ima/config | 4 -- tools/testing/selftests/ima/test_kexec_load.sh | 54 ------------------------ tools/testing/selftests/kexec/Makefile | 11 +++++ tools/testing/selftests/kexec/config | 4 ++ tools/testing/selftests/kexec/test_kexec_load.sh | 54 ++++++++++++++++++++++++ 7 files changed, 70 insertions(+), 70 deletions(-) delete mode 100644 tools/testing/selftests/ima/Makefile delete mode 100644 tools/testing/selftests/ima/config delete mode 100755 tools/testing/selftests/ima/test_kexec_load.sh create mode 100644 tools/testing/selftests/kexec/Makefile create mode 100644 tools/testing/selftests/kexec/config create mode 100755 tools/testing/selftests/kexec/test_kexec_load.sh
tools/testing/selftests/Makefile +1 -1
@@ -14,11 +14,11 @@ TARGETS += firmware TARGETS += ftrace TARGETS += futex TARGETS += gpio -TARGETS += ima TARGETS += intel_pstate TARGETS += ipc TARGETS += ir TARGETS += kcmp +TARGETS += kexec TARGETS += kvm TARGETS += lib TARGETS += membarrier
tools/testing/selftests/ima/Makefile deleted +0 -11
@@ -1,11 +0,0 @@ -# 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 deleted +0 -4
@@ -1,4 +0,0 @@ -CONFIG_IMA_APPRAISE -CONFIG_IMA_ARCH_POLICY -CONFIG_SECURITYFS -CONFIG_KEXEC_VERIFY_SIG
tools/testing/selftests/ima/test_kexec_load.sh deleted +0 -54
54 lines not on this page · raw message
tools/testing/selftests/kexec/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/kexec/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/kexec/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 v4 2/8 selftests/kexec: cleanup the kexec selftest
In reply to Mimi ZoharRemove the few bashisms and use the complete option name for clarity.
--- tools/testing/selftests/kexec/test_kexec_load.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
tools/testing/selftests/kexec/test_kexec_load.sh +9 -9
@@ -1,7 +1,7 @@ #!/bin/sh -# SPDX-License-Identifier: GPL-2.0+ +# SPDX-License-Identifier: GPL-2.0 # Loading a kernel image via the kexec_load syscall should fail -# when the kerne is CONFIG_KEXEC_VERIFY_SIG enabled and the system +# when the kernel is CONFIG_KEXEC_VERIFY_SIG enabled and the system # is booted in secureboot mode. TEST="$0"
@@ -12,8 +12,8 @@ rc=0 ksft_skip=4 # kexec requires root privileges -if [ $UID != 0 ]; then - echo "$TEST: must be run as root" >&2 +if [ $(id -ru) -ne 0 ]; then + echo "$TEST: requires root privileges" >&2 exit $ksft_skip fi
@@ -33,17 +33,17 @@ secureboot=`hexdump $file | awk '{print substr($4,length($4),1)}'` # kexec_load should fail in secure boot mode KERNEL_IMAGE="/boot/vmlinuz-`uname -r`" -kexec -l $KERNEL_IMAGE &>> /dev/null -if [ $? == 0 ]; then - kexec -u - if [ "$secureboot" == "1" ]; then +kexec --load $KERNEL_IMAGE > /dev/null 2>&1 +if [ $? -eq 0 ]; then + kexec --unload + if [ $secureboot -eq 1 ]; then echo "$TEST: kexec_load succeeded [FAIL]" rc=1 else echo "$TEST: kexec_load succeeded [PASS]" fi else - if [ "$secureboot" == "1" ]; then + if [ $secureboot -eq 1 ]; then echo "$TEST: kexec_load failed [PASS]" else echo "$TEST: kexec_load failed [FAIL]"
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 3/8 selftests/kexec: define a set of common functions
In reply to Mimi ZoharDefine, update and move get_secureboot_mode() to a common file for use by other tests.
Updated to check both the efivar SecureBoot-$(UUID) and SetupMode-$(UUID), based on Dave Young's review.
--- tools/testing/selftests/kexec/Makefile | 1 + tools/testing/selftests/kexec/kexec_common_lib.sh | 38 +++++++++++++++++++++++ tools/testing/selftests/kexec/test_kexec_load.sh | 17 ++-------- 3 files changed, 42 insertions(+), 14 deletions(-) create mode 100755 tools/testing/selftests/kexec/kexec_common_lib.sh
tools/testing/selftests/kexec/Makefile +1 -0
@@ -5,6 +5,7 @@ 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 +TEST_FILES := kexec_common_lib.sh include ../lib.mk
tools/testing/selftests/kexec/kexec_common_lib.sh new file +38 -0
@@ -0,0 +1,38 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +# Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID). +# The secure boot mode can be accessed either as the last integer +# of "od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-*" or from +# "od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data". The efi +# SetupMode can be similarly accessed. +# Return 1 for SecureBoot mode enabled and SetupMode mode disabled. +get_secureboot_mode() +{ + local efivarfs="/sys/firmware/efi/efivars" + local secure_boot_file="$efivarfs/../vars/SecureBoot-*/data" + local setup_mode_file="$efivarfs/../vars/SetupMode-*/data" + local secureboot_mode=0 + local setup_mode=0 + + # Make sure that efivars is mounted in the normal location + if ! grep -q "^\S\+ $efivarfs efivarfs" /proc/mounts; then + log_skip "efivars is not mounted on $efivarfs" + fi + + # Due to globbing, quoting "secure_boot_file" and "setup_mode_file" + # is not possible. (Todo: initialize variables using find or ls.) + if [ ! -e $secure_boot_file ] || [ ! -e $setup_mode_file ]; then + log_skip "unknown secureboot/setup mode" + fi + + secureboot_mode=`od -An -t u1 $secure_boot_file` + setup_mode=`od -An -t u1 $setup_mode_file` + + if [ $secureboot_mode -eq 1 ] && [ $setup_mode -eq 0 ]; then + log_info "secure boot mode enabled" + return 1; + fi + log_info "secure boot mode not enabled" + return 0; +}
tools/testing/selftests/kexec/test_kexec_load.sh +3 -14
@@ -5,7 +5,7 @@ # is booted in secureboot mode. TEST="$0" -EFIVARFS="/sys/firmware/efi/efivars" +. ./kexec_common_lib.sh rc=0 # Kselftest framework requirement - SKIP code is 4.
@@ -17,19 +17,8 @@ if [ $(id -ru) -ne 0 ]; then exit $ksft_skip fi -# Make sure that efivars is mounted in the normal location -if ! grep -q "^\S\+ $EFIVARFS efivarfs" /proc/mounts; then - echo "$TEST: efivars is not mounted on $EFIVARFS" >&2 - exit $ksft_skip -fi - -# Get secureboot mode -file="$EFIVARFS/SecureBoot-*" -if [ ! -e $file ]; then - echo "$TEST: unknown secureboot mode" >&2 - exit $ksft_skip -fi -secureboot=`hexdump $file | awk '{print substr($4,length($4),1)}'` +get_secureboot_mode +secureboot=$? # kexec_load should fail in secure boot mode KERNEL_IMAGE="/boot/vmlinuz-`uname -r`"
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 4/8 selftests/kexec: define common logging functions
In reply to Mimi ZoharDefine log_info, log_pass, log_fail, and log_skip functions.
--- tools/testing/selftests/kexec/kexec_common_lib.sh | 31 +++++++++++++++++++++++ tools/testing/selftests/kexec/test_kexec_load.sh | 19 ++++---------- 2 files changed, 36 insertions(+), 14 deletions(-)
tools/testing/selftests/kexec/kexec_common_lib.sh +31 -0
@@ -1,5 +1,36 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 +# +# Kselftest framework defines: ksft_pass=0, ksft_fail=1, ksft_skip=4 + +VERBOSE="${VERBOSE:-1}" + +log_info() +{ + [ $VERBOSE -ne 0 ] && echo "[INFO] $1" +} + +# The ksefltest framework requirement returns 0 for PASS. +log_pass() +{ + + [ $VERBOSE -ne 0 ] && echo "$1 [PASS]" + exit 0 +} + +# The ksefltest framework requirement returns 1 for FAIL. +log_fail() +{ + [ $VERBOSE -ne 0 ] && echo "$1 [FAIL]" + exit 1 +} + +# The ksefltest framework requirement returns 4 for SKIP. +log_skip() +{ + [ $VERBOSE -ne 0 ] && echo "$1" + exit 4 +} # Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID). # The secure boot mode can be accessed either as the last integer
tools/testing/selftests/kexec/test_kexec_load.sh +5 -14
@@ -6,15 +6,10 @@ TEST="$0" . ./kexec_common_lib.sh -rc=0 - -# Kselftest framework requirement - SKIP code is 4. -ksft_skip=4 # kexec requires root privileges if [ $(id -ru) -ne 0 ]; then - echo "$TEST: requires root privileges" >&2 - exit $ksft_skip + log_skip "requires root privileges" fi get_secureboot_mode
@@ -26,18 +21,14 @@ kexec --load $KERNEL_IMAGE > /dev/null 2>&1 if [ $? -eq 0 ]; then kexec --unload if [ $secureboot -eq 1 ]; then - echo "$TEST: kexec_load succeeded [FAIL]" - rc=1 + log_fail "kexec_load succeeded" else - echo "$TEST: kexec_load succeeded [PASS]" + log_pass "kexec_load succeeded" fi else if [ $secureboot -eq 1 ]; then - echo "$TEST: kexec_load failed [PASS]" + log_pass "kexec_load failed" else - echo "$TEST: kexec_load failed [FAIL]" - rc=1 + log_fail "kexec_load failed" fi fi - -exit $rc
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 5/8 kselftest/kexec: define "require_root_privileges"
In reply to Mimi ZoharMany tests require root privileges. Define a common function.
--- tools/testing/selftests/kexec/kexec_common_lib.sh | 7 +++++++ tools/testing/selftests/kexec/test_kexec_load.sh | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-)
tools/testing/selftests/kexec/kexec_common_lib.sh +7 -0
@@ -67,3 +67,10 @@ get_secureboot_mode() log_info "secure boot mode not enabled" return 0; } + +require_root_privileges() +{ + if [ $(id -ru) -ne 0 ]; then + log_skip "requires root privileges" + fi +}
tools/testing/selftests/kexec/test_kexec_load.sh +1 -3
@@ -8,9 +8,7 @@ TEST="$0" . ./kexec_common_lib.sh # kexec requires root privileges -if [ $(id -ru) -ne 0 ]; then - log_skip "requires root privileges" -fi +require_root_privileges get_secureboot_mode secureboot=$?
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 6/8 selftests/kexec: kexec_file_load syscall test
In reply to Mimi ZoharThe kernel can be configured to verify PE signed kernel images, IMA kernel image signatures, both types of signatures, or none. This test verifies only properly signed kernel images are loaded into memory, based on the kernel configuration and runtime policies.
--- tools/testing/selftests/kexec/Makefile | 4 +- tools/testing/selftests/kexec/kexec_common_lib.sh | 99 +++++++++++ .../selftests/kexec/test_kexec_file_load.sh | 190 +++++++++++++++++++++ tools/testing/selftests/kexec/test_kexec_load.sh | 1 - 4 files changed, 291 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/kexec/test_kexec_file_load.sh
tools/testing/selftests/kexec/Makefile +2 -2
@@ -1,10 +1,10 @@ -# Makefile for kexec_load +# Makefile for kexec tests 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 +TEST_PROGS := test_kexec_load.sh test_kexec_file_load.sh TEST_FILES := kexec_common_lib.sh include ../lib.mk
tools/testing/selftests/kexec/kexec_common_lib.sh +99 -0
108 lines not on this page · raw message
tools/testing/selftests/kexec/test_kexec_file_load.sh new file +190 -0
190 lines not on this page · raw message
tools/testing/selftests/kexec/test_kexec_load.sh +0 -1
@@ -14,7 +14,6 @@ get_secureboot_mode secureboot=$? # kexec_load should fail in secure boot mode -KERNEL_IMAGE="/boot/vmlinuz-`uname -r`" kexec --load $KERNEL_IMAGE > /dev/null 2>&1 if [ $? -eq 0 ]; then kexec --unload
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 7/8 selftests/kexec: Add missing '=y' to config options
In reply to Mimi ZoharFrom: Petr Vorel <pvorel at suse.cz>
so the file can be used as kernel config snippet.
--- tools/testing/selftests/kexec/config | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/testing/selftests/kexec/config +3 -4
@@ -1,4 +1,3 @@ -CONFIG_IMA_APPRAISE -CONFIG_IMA_ARCH_POLICY -CONFIG_SECURITYFS -CONFIG_KEXEC_VERIFY_SIG +CONFIG_IMA_APPRAISE=y +CONFIG_IMA_ARCH_POLICY=y +CONFIG_SECURITYFS=y
Signature · 1 line
2.7.5
Mimi Zohar
maintainerPATCH v4 8/8 selftests/kexec: check kexec_load and kexec_file_load are enabled
In reply to Mimi ZoharSkip the kexec_load and kexec_file_load tests, if they aren't configured in the kernel. This change adds a new requirement that ikconfig is configured in the kexec_load test.
--- tools/testing/selftests/kexec/test_kexec_file_load.sh | 5 +++++ tools/testing/selftests/kexec/test_kexec_load.sh | 8 ++++++++ 2 files changed, 13 insertions(+)
tools/testing/selftests/kexec/test_kexec_file_load.sh +5 -0
@@ -151,6 +151,11 @@ require_root_privileges # get the kernel config get_kconfig +kconfig_enabled "CONFIG_KEXEC_FILE=y" "kexec_file_load is enabled" +if [ $? -eq 0 ]; then + log_skip "kexec_file_load is not enabled" +fi + # Determine which kernel config options are enabled kconfig_enabled "CONFIG_IMA_ARCH_POLICY=y" \ "architecture specific policy enabled"
tools/testing/selftests/kexec/test_kexec_load.sh +8 -0
@@ -10,6 +10,14 @@ TEST="$0" # kexec requires root privileges require_root_privileges +# get the kernel config +get_kconfig + +kconfig_enabled "CONFIG_KEXEC=y" "kexec_load is enabled" +if [ $? -eq 0 ]; then + log_skip "kexec_load is not enabled" +fi + get_secureboot_mode secureboot=$?
Signature · 1 line
2.7.5
Hi Mimi,
...
Quoted 4 lines
Changelog v4:
- Moved the kexec tests to selftests/kexec, as requested by Dave Young.
- Removed the kernel module selftest from this patch set.
- Rewritten cover letter, removing reference to kernel modules.
LGTM, to whole patch-set:
Reviewed-by: Petr Vorel <pvorel at suse.cz>
Kind regards,
Petr
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Mimi,
Thank you for help about the pointer about IMA testing. Probably I should cc list as well since we are talking about the patch itself. For the ima test itself I could still ask for help in a private email thread.
Quoted 112 lines · Mimi Zohar
Quoted 35 lines · Dave Young
Hi Mimi,
Quoted 23 lines · Mimi Zohar
The kernel may be configured or an IMA policy specified on the boot command line requiring the kexec kernel image signature to be verified. At runtime a custom IMA policy may be loaded, replacing the policy specified on the boot command line. In addition, the arch specific policy rules are dynamically defined based on the secure boot mode that may require the kernel image signature to be verified.
The kernel image may have a PE signature, an IMA signature, or both. In addition, there are two kexec syscalls -
kexec_loadandkexec_file_load
- but only thekexec_file_loadsyscall can verify signatures.These kexec selftests verify that only properly signed kernel images are loaded as required, based on the kernel config, the secure boot mode, and the IMA runtime policy.
Loading a kernel image or kernel module requires root privileges. To run just the KEXEC selftests: sudo make TARGETS=kexec kselftest
Changelog v4:
- Moved the kexec tests to selftests/kexec, as requested by Dave Young.
- Removed the kernel module selftest from this patch set.
- Rewritten cover letter, removing reference to kernel modules.Quoted 9 lines
Changelog v3:
- Updated tests based on Petr's review, including the defining a common test to check for root privileges.
- Modified config, removing theCONFIG_KEXEC_VERIFY_SIGrequirement.
- Updated the SPDX license to GPL-2.0 based on Shuah's review.
- Updated the secureboot mode test to check the SetupMode as well, based on David Young's review.Quoted 5 lines
I was trying to review the patches although I'm slow due to something else.
But I still did not setup a IMA testable system, need check your old email about how to setup it.
(The ima-evm-utils package contains a README with directions.)
Quoted 7 lines
A quick testing gives me below results
/* test #1, my default kconfig
# NOCONFIG_INTEGRITYcompiled in
*/Quoted 9 lines
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' make[1]: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' TAP version 13
selftests: kexec:test_kexec_load.sh
========================================
selftests: kexec:test_kexec_load.sh: Warning: filetest_kexec_load.shis not executable, correct this.
not ok 1..1 selftests: kexec:test_kexec_load.sh[FAIL]That's really weird. Both before and after applying these patches
test_kexec_load.shis executable (stable linux-5.0.y). Could something else be preventing it from executing?Quoted 10 lines
selftests: kexec:
test_kexec_file_load.sh
========================================
[INFO]kexec_file_loadis enabled
[INFO] secure boot mode not enabled
[INFO] kexec kernel image PE signed
[INFO] kexec kernel image not IMA signedkexec_file_loadsucceeded (possibly missing IMA sig) [FAIL]
not ok 1..2 selftests: kexec:test_kexec_file_load.sh[FAIL]
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec'
make: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests'This message is because neither
CONFIG_KEXEC_BZIMAGE_VERIFY_SIGor an IMA signature is required. It couldn't read the IMA runtime policy rules to determine if an IMA signature is required. So, it's trying to provide a hint as to what happened.I'll update the test to see if
CONFIG_IMA_APPRAISEis enabled, before emitting this message.Quoted 19 lines
/* test #2, enabled IMA kconfigs, simply test without other ima setup eg. use a policy etc. need to follow up some guide to test the ima functionality (TODO..)
*/[root at dhcp-128-65 linux-x86]# make -C
tools/testing/selftestsTARGETS=kexecrun_tests
make: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests' make[1]: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' make[1]: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' TAP version 13
selftests: kexec:test_kexec_load.sh
========================================
selftests: kexec:test_kexec_load.sh: Warning: filetest_kexec_load.shis not executable, correct this. not ok 1..1 selftests: kexec:test_kexec_load.sh[FAIL]
selftests: kexec:test_kexec_file_load.shQuoted 8 lines
========================================
[INFO]kexec_file_loadis enabled
[INFO] reading IMA policy permitted
[INFO] secure boot mode not enabled
No signature verification required
not ok 1..2 selftests: kexec:test_kexec_file_load.sh[SKIP]
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec'
make: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests'
Quoted 6 lines
The purpose of these tests was to coordinate kernel image signature verification.
If you require a PE signature, load an IMA policy requiring an IMA signature, or even enable
CONFIG_IMA_ARCH_POLICY, the test would require some form of signature verification.
Did a test with a embedded ima key in kernel, with secure boot disabled, but with Secure Boot enabled, but failed to sign the kernel with both pesign and evmctl, will continue to see how to work on it and ask in private email if needed :)
About the patch itself, as we talked in another email, I would expect it can work with other test cases eg. without IMA/secure boot. But if that is not easy, maybe you can change the test script filename to something
like: test_kexec_load_sigcheck.sh and test_kexec_file_load_sigcheck.sh then we can add other non-sigcheck related cases to other test scripts later. But ideally if we can handle them in current files it would be better.
Another issue I noticed is even if boot with ima_appraise=off, kexec load still checking the conditions. Will see if I'm having something wrong in test steps.
Thanks
Dave
Mimi Zohar
maintainerQuoted 6 lines · Dave Young
Hi Mimi,
Thank you for help about the pointer about IMA testing. Probably I should cc list as well since we are talking about the patch itself. For the ima test itself I could still ask for help in a private email thread.
Thank you for bringing the discussion back online!
Quoted 38 lines · Mimi Zohar
Quoted 36 lines · Dave Young
Quoted 35 lines
Hi Mimi,
Quoted 32 lines · Mimi Zohar
The kernel may be configured or an IMA policy specified on the boot command line requiring the kexec kernel image signature to be verified. At runtime a custom IMA policy may be loaded, replacing the policy specified on the boot command line. In addition, the arch specific policy rules are dynamically defined based on the secure boot mode that may require the kernel image signature to be verified.
The kernel image may have a PE signature, an IMA signature, or both. In addition, there are two kexec syscalls -
kexec_loadandkexec_file_load
- but only thekexec_file_loadsyscall can verify signatures.These kexec selftests verify that only properly signed kernel images are loaded as required, based on the kernel config, the secure boot mode, and the IMA runtime policy.
Loading a kernel image or kernel module requires root privileges. To run just the KEXEC selftests: sudo make TARGETS=kexec kselftest
Changelog v4:
- Moved the kexec tests to selftests/kexec, as requested by Dave Young.
- Removed the kernel module selftest from this patch set.
- Rewritten cover letter, removing reference to kernel modules.Changelog v3:
- Updated tests based on Petr's review, including the defining a common test to check for root privileges.
- Modified config, removing theCONFIG_KEXEC_VERIFY_SIGrequirement.
- Updated the SPDX license to GPL-2.0 based on Shuah's review.
- Updated the secureboot mode test to check the SetupMode as well, based on David Young's review.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I was trying to review the patches although I'm slow due to something else.
But I still did not setup a IMA testable system, need check your old email about how to setup it.
(The ima-evm-utils package contains a README with directions.)
Suggesting using the EVM README might not have been the best idea, as we're only interested, at the moment, in enabling IMA-appraisal for now.
You need to create 2 public keys - a local CA and an IMA key. The local CA public key needs to be loaded onto the builtin trusted keys keyring. There are a number of different methods of doing this. The simplest method, for those building their own kernel, is to add the local CA public key to the certs signing_key.x509 (PEM) or to the x509_certificate_list (DER).
Create the IMA key and then sign the IMA certificate with the local CA key. After rebooting the kernel with the local CA key loaded onto the builtin trusted keyring, you'll be able to import the IMA key onto the IMA trusted keyring.
To manually load the IMA key, without relying on dracut/systemd:
# id=sudo keyctl describe %keyring:.ima | awk -F ':' '{print $1}';
# evmctl import examples/x509_ima.der $id
(The evm utils package contains two sample scripts in the examples directory to create the local CA and the IMA key.)
Quoted 72 lines
Quoted 72 lines
Quoted 8 lines
A quick testing gives me below results
/* test #1, my default kconfig
# NOCONFIG_INTEGRITYcompiled in
*/Quoted 9 lines
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' make[1]: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' TAP version 13
selftests: kexec:test_kexec_load.sh
========================================
selftests: kexec:test_kexec_load.sh: Warning: filetest_kexec_load.shis not executable, correct this.
not ok 1..1 selftests: kexec:test_kexec_load.sh[FAIL]That's really weird. Both before and after applying these patches
test_kexec_load.shis executable (stable linux-5.0.y). Could something else be preventing it from executing?Quoted 10 lines
selftests: kexec:
test_kexec_file_load.sh
========================================
[INFO]kexec_file_loadis enabled
[INFO] secure boot mode not enabled
[INFO] kexec kernel image PE signed
[INFO] kexec kernel image not IMA signedkexec_file_loadsucceeded (possibly missing IMA sig) [FAIL]
not ok 1..2 selftests: kexec:test_kexec_file_load.sh[FAIL]
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec'
make: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests'This message is because neither
CONFIG_KEXEC_BZIMAGE_VERIFY_SIGor an IMA signature is required. It couldn't read the IMA runtime policy rules to determine if an IMA signature is required. So, it's trying to provide a hint as to what happened.I'll update the test to see if
CONFIG_IMA_APPRAISEis enabled, before emitting this message.Quoted 19 lines
/* test #2, enabled IMA kconfigs, simply test without other ima setup eg. use a policy etc. need to follow up some guide to test the ima functionality (TODO..)
*/[root at dhcp-128-65 linux-x86]# make -C
tools/testing/selftestsTARGETS=kexecrun_tests
make: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests' make[1]: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' make[1]: Entering directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec' TAP version 13
selftests: kexec:test_kexec_load.sh
========================================
selftests: kexec:test_kexec_load.sh: Warning: filetest_kexec_load.shis not executable, correct this. not ok 1..1 selftests: kexec:test_kexec_load.sh[FAIL]
selftests: kexec:test_kexec_file_load.shQuoted 8 lines
========================================
[INFO]kexec_file_loadis enabled
[INFO] reading IMA policy permitted
[INFO] secure boot mode not enabled
No signature verification required
not ok 1..2 selftests: kexec:test_kexec_file_load.sh[SKIP]
make[1]: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests/kexec'
make: Leaving directory '/home/dyoung/git/github/linux/tools/testing/selftests'The purpose of these tests was to coordinate kernel image signature verification.
Quoted 8 lines
Quoted 3 lines
If you require a PE signature, load an IMA policy requiring an IMA signature, or even enable
CONFIG_IMA_ARCH_POLICY, the test would require some form of signature verification.Did a test with a embedded ima key in kernel, with secure boot disabled, but with Secure Boot enabled, but failed to sign the kernel with both pesign and evmctl, will continue to see how to work on it and ask in private email if needed :)
"with secure boot disabled, but with Secure Boot enabled" - I'm missing the nuance between upper and lower case "secure boot".
Quoted 8 lines
About the patch itself, as we talked in another email, I would expect it can work with other test cases eg. without IMA/secure boot. But if that is not easy, maybe you can change the test script filename to something
like:test_kexec_load_sigcheck.shandtest_kexec_file_load_sigcheck.shthen we can add other non-sigcheck related cases to other test scripts later. But ideally if we can handle them in current files it would be better.
Ok
Quoted 3 lines
Another issue I noticed is even if boot with ima_appraise=off, kexec load still checking the conditions. Will see if I'm having something wrong in test steps.
Enabling the arch policy disables the "ima_appraise=" boot command line option. You're right, if the arch policy isn't enabled, this test needs to detect the "ima_appraise" mode.
Mimi