1#!/bin/sh
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.
6
7TEST="$0"
8. ./kexec_common_lib.sh
9
10# kexec requires root privileges
11require_root_privileges
12
13# get the kernel config
14get_kconfig
15
16kconfig_enabled "CONFIG_KEXEC=y" "kexec_load is enabled"
17if [ $? -eq 0 ]; then
18	log_skip "kexec_load is not enabled"
19fi
20
21get_secureboot_mode
22secureboot=$?
23
24# kexec_load should fail in secure boot mode
25kexec --load $KERNEL_IMAGE > /dev/null 2>&1
26if [ $? -eq 0 ]; then
27	kexec --unload
28	if [ $secureboot -eq 1 ]; then
29		log_fail "kexec_load succeeded"
30	else
31		log_pass "kexec_load succeeded"
32	fi
33else
34	if [ $secureboot -eq 1 ]; then
35		log_pass "kexec_load failed"
36	else
37		log_fail "kexec_load failed"
38	fi
39fi
40