2018-11-14 12:30:19 -05:00
#!/bin/sh
2019-01-24 08:27:25 -05:00
# SPDX-License-Identifier: GPL-2.0
2019-03-25 14:13:27 -04:00
#
# Prevent loading a kernel image via the kexec_load syscall when
# signatures are required. (Dependent on CONFIG_IMA_ARCH_POLICY.)
2018-11-14 12:30:19 -05:00
TEST = " $0 "
2019-01-24 08:57:20 -05:00
. ./kexec_common_lib.sh
2018-11-14 12:30:19 -05:00
# kexec requires root privileges
2019-03-06 11:19:45 -05:00
require_root_privileges
2018-11-14 12:30:19 -05:00
2019-03-12 14:53:54 -04:00
# 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
2019-03-25 14:13:27 -04:00
kconfig_enabled "CONFIG_IMA_APPRAISE=y" "IMA enabled"
ima_appraise = $?
kconfig_enabled "CONFIG_IMA_ARCH_POLICY=y" \
"IMA architecture specific policy enabled"
arch_policy = $?
2019-01-24 08:57:20 -05:00
get_secureboot_mode
secureboot = $?
2018-11-14 12:30:19 -05:00
2019-03-25 14:13:27 -04:00
# kexec_load should fail in secure boot mode and CONFIG_IMA_ARCH_POLICY enabled
2019-01-24 08:27:25 -05:00
kexec --load $KERNEL_IMAGE > /dev/null 2>& 1
if [ $? -eq 0 ] ; then
kexec --unload
2019-03-25 14:13:27 -04:00
if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ] ; then
2019-02-13 11:46:55 -05:00
log_fail "kexec_load succeeded"
2019-03-25 14:13:27 -04:00
elif [ $ima_appraise -eq 0 -o $arch_policy -eq 0 ] ; then
log_info "Either IMA or the IMA arch policy is not enabled"
2018-11-14 12:30:19 -05:00
fi
2019-03-25 14:13:27 -04:00
log_pass "kexec_load succeeded"
2018-11-14 12:30:19 -05:00
else
2019-03-25 14:13:27 -04:00
if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ] ; then
2019-02-13 11:46:55 -05:00
log_pass "kexec_load failed"
2018-11-14 12:30:19 -05:00
else
2019-02-13 11:46:55 -05:00
log_fail "kexec_load failed"
2018-11-14 12:30:19 -05:00
fi
fi