2018-11-15 01:30:19 +08:00
|
|
|
#!/bin/sh
|
2019-01-24 21:27:25 +08:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2019-03-26 02:13:27 +08:00
|
|
|
#
|
|
|
|
# Prevent loading a kernel image via the kexec_load syscall when
|
|
|
|
# signatures are required. (Dependent on CONFIG_IMA_ARCH_POLICY.)
|
2018-11-15 01:30:19 +08:00
|
|
|
|
|
|
|
TEST="$0"
|
2019-01-24 21:57:20 +08:00
|
|
|
. ./kexec_common_lib.sh
|
2018-11-15 01:30:19 +08:00
|
|
|
|
|
|
|
# kexec requires root privileges
|
2019-03-07 00:19:45 +08:00
|
|
|
require_root_privileges
|
2018-11-15 01:30:19 +08:00
|
|
|
|
2019-03-13 02:53:54 +08: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-26 02:13:27 +08: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 21:57:20 +08:00
|
|
|
get_secureboot_mode
|
|
|
|
secureboot=$?
|
2018-11-15 01:30:19 +08:00
|
|
|
|
2019-03-26 02:13:27 +08:00
|
|
|
# kexec_load should fail in secure boot mode and CONFIG_IMA_ARCH_POLICY enabled
|
2019-01-24 21:27:25 +08:00
|
|
|
kexec --load $KERNEL_IMAGE > /dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
kexec --unload
|
2019-03-26 02:13:27 +08:00
|
|
|
if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ]; then
|
2019-02-14 00:46:55 +08:00
|
|
|
log_fail "kexec_load succeeded"
|
2019-03-26 02:13:27 +08: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-15 01:30:19 +08:00
|
|
|
fi
|
2019-03-26 02:13:27 +08:00
|
|
|
log_pass "kexec_load succeeded"
|
2018-11-15 01:30:19 +08:00
|
|
|
else
|
2019-03-26 02:13:27 +08:00
|
|
|
if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ] ; then
|
2019-02-14 00:46:55 +08:00
|
|
|
log_pass "kexec_load failed"
|
2018-11-15 01:30:19 +08:00
|
|
|
else
|
2019-02-14 00:46:55 +08:00
|
|
|
log_fail "kexec_load failed"
|
2018-11-15 01:30:19 +08:00
|
|
|
fi
|
|
|
|
fi
|