Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/kexec: make kexec_load test independent of IMA being enabled

Verify IMA is enabled before failing tests or emitting irrelevant
messages.

Suggested-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Dave Young <dyoung@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Mimi Zohar and committed by
Shuah Khan
726ff75f 7cea0b92

+16 -8
+16 -8
tools/testing/selftests/kexec/test_kexec_load.sh
··· 1 1 #!/bin/sh 2 2 # SPDX-License-Identifier: GPL-2.0 3 - # Loading a kernel image via the kexec_load syscall should fail 4 - # when the kernel is CONFIG_KEXEC_VERIFY_SIG enabled and the system 5 - # is booted in secureboot mode. 3 + # 4 + # Prevent loading a kernel image via the kexec_load syscall when 5 + # signatures are required. (Dependent on CONFIG_IMA_ARCH_POLICY.) 6 6 7 7 TEST="$0" 8 8 . ./kexec_common_lib.sh ··· 18 18 log_skip "kexec_load is not enabled" 19 19 fi 20 20 21 + kconfig_enabled "CONFIG_IMA_APPRAISE=y" "IMA enabled" 22 + ima_appraise=$? 23 + 24 + kconfig_enabled "CONFIG_IMA_ARCH_POLICY=y" \ 25 + "IMA architecture specific policy enabled" 26 + arch_policy=$? 27 + 21 28 get_secureboot_mode 22 29 secureboot=$? 23 30 24 - # kexec_load should fail in secure boot mode 31 + # kexec_load should fail in secure boot mode and CONFIG_IMA_ARCH_POLICY enabled 25 32 kexec --load $KERNEL_IMAGE > /dev/null 2>&1 26 33 if [ $? -eq 0 ]; then 27 34 kexec --unload 28 - if [ $secureboot -eq 1 ]; then 35 + if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ]; then 29 36 log_fail "kexec_load succeeded" 30 - else 31 - log_pass "kexec_load succeeded" 37 + elif [ $ima_appraise -eq 0 -o $arch_policy -eq 0 ]; then 38 + log_info "Either IMA or the IMA arch policy is not enabled" 32 39 fi 40 + log_pass "kexec_load succeeded" 33 41 else 34 - if [ $secureboot -eq 1 ]; then 42 + if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ] ; then 35 43 log_pass "kexec_load failed" 36 44 else 37 45 log_fail "kexec_load failed"