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

selftests/ima: kexec_load syscall test

The kernel CONFIG_KEXEC_VERIFY_SIG option is limited to verifying a
kernel image's signature, when loaded via the kexec_file_load syscall.
There is no method for verifying a kernel image's signature loaded
via the kexec_load syscall.

This test verifies loading the kernel image via the kexec_load syscall
fails when the kernel CONFIG_KEXEC_VERIFY_SIG option is enabled on
systems with secureboot enabled[1].

[1] Detecting secureboot enabled is architecture specific.

Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>

+70
+1
tools/testing/selftests/Makefile
··· 13 13 TARGETS += ftrace 14 14 TARGETS += futex 15 15 TARGETS += gpio 16 + TARGETS += ima 16 17 TARGETS += intel_pstate 17 18 TARGETS += ipc 18 19 TARGETS += kcmp
+11
tools/testing/selftests/ima/Makefile
··· 1 + # Makefile for kexec_load 2 + 3 + uname_M := $(shell uname -m 2>/dev/null || echo not) 4 + ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) 5 + 6 + ifeq ($(ARCH),x86) 7 + TEST_PROGS := test_kexec_load.sh 8 + 9 + include ../lib.mk 10 + 11 + endif
+4
tools/testing/selftests/ima/config
··· 1 + CONFIG_IMA_APPRAISE 2 + CONFIG_IMA_ARCH_POLICY 3 + CONFIG_SECURITYFS 4 + CONFIG_KEXEC_VERIFY_SIG
+54
tools/testing/selftests/ima/test_kexec_load.sh
··· 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 kerne is CONFIG_KEXEC_VERIFY_SIG enabled and the system 5 + # is booted in secureboot mode. 6 + 7 + TEST="$0" 8 + EFIVARFS="/sys/firmware/efi/efivars" 9 + rc=0 10 + 11 + # Kselftest framework requirement - SKIP code is 4. 12 + ksft_skip=4 13 + 14 + # kexec requires root privileges 15 + if [ $UID != 0 ]; then 16 + echo "$TEST: must be run as root" >&2 17 + exit $ksft_skip 18 + fi 19 + 20 + # Make sure that efivars is mounted in the normal location 21 + if ! grep -q "^\S\+ $EFIVARFS efivarfs" /proc/mounts; then 22 + echo "$TEST: efivars is not mounted on $EFIVARFS" >&2 23 + exit $ksft_skip 24 + fi 25 + 26 + # Get secureboot mode 27 + file="$EFIVARFS/SecureBoot-*" 28 + if [ ! -e $file ]; then 29 + echo "$TEST: unknown secureboot mode" >&2 30 + exit $ksft_skip 31 + fi 32 + secureboot=`hexdump $file | awk '{print substr($4,length($4),1)}'` 33 + 34 + # kexec_load should fail in secure boot mode 35 + KERNEL_IMAGE="/boot/vmlinuz-`uname -r`" 36 + kexec -l $KERNEL_IMAGE &>> /dev/null 37 + if [ $? == 0 ]; then 38 + kexec -u 39 + if [ "$secureboot" == "1" ]; then 40 + echo "$TEST: kexec_load succeeded [FAIL]" 41 + rc=1 42 + else 43 + echo "$TEST: kexec_load succeeded [PASS]" 44 + fi 45 + else 46 + if [ "$secureboot" == "1" ]; then 47 + echo "$TEST: kexec_load failed [PASS]" 48 + else 49 + echo "$TEST: kexec_load failed [FAIL]" 50 + rc=1 51 + fi 52 + fi 53 + 54 + exit $rc