Skip to content

Commit cbc0425

Browse files
committed
sefltest/ima: support appended signatures (modsig)
In addition to the PE/COFF and IMA xattr signatures, the kexec kernel image can be signed with an appended signature, using the same scripts/sign-file tool that is used to sign kernel modules. This patch adds support for detecting a kernel image signed with an appended signature and updates the existing test messages appropriately. Reviewed-by: Petr Vorel <[email protected]> Acked-by: Shuah Khan <[email protected]> Reviewed-by: Thiago Jung Bauermann <[email protected]> Reviewed-by: Jordan Hand <[email protected]> (x86_64 QEMU) Tested-by: Jordan Hand <[email protected]> (x86_64 QEMU) Signed-off-by: Mimi Zohar <[email protected]>
1 parent 556d971 commit cbc0425

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

tools/testing/selftests/kexec/test_kexec_file_load.sh

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@ is_ima_sig_required()
3737
# sequentially. As a result, a policy rule may be defined, but
3838
# might not necessarily be used. This test assumes if a policy
3939
# rule is specified, that is the intent.
40+
41+
# First check for appended signature (modsig), then xattr
4042
if [ $ima_read_policy -eq 1 ]; then
4143
check_ima_policy "appraise" "func=KEXEC_KERNEL_CHECK" \
42-
"appraise_type=imasig"
44+
"appraise_type=imasig|modsig"
4345
ret=$?
44-
[ $ret -eq 1 ] && log_info "IMA signature required";
46+
if [ $ret -eq 1 ]; then
47+
log_info "IMA or appended(modsig) signature required"
48+
else
49+
check_ima_policy "appraise" "func=KEXEC_KERNEL_CHECK" \
50+
"appraise_type=imasig"
51+
ret=$?
52+
[ $ret -eq 1 ] && log_info "IMA signature required";
53+
fi
4554
fi
4655
return $ret
4756
}
@@ -84,6 +93,22 @@ check_for_imasig()
8493
return $ret
8594
}
8695

96+
# Return 1 for appended signature (modsig) found and 0 for not found.
97+
check_for_modsig()
98+
{
99+
local module_sig_string="~Module signature appended~"
100+
local sig="$(tail --bytes $((${#module_sig_string} + 1)) $KERNEL_IMAGE)"
101+
local ret=0
102+
103+
if [ "$sig" == "$module_sig_string" ]; then
104+
ret=1
105+
log_info "kexec kernel image modsig signed"
106+
else
107+
log_info "kexec kernel image not modsig signed"
108+
fi
109+
return $ret
110+
}
111+
87112
kexec_file_load_test()
88113
{
89114
local succeed_msg="kexec_file_load succeeded"
@@ -98,7 +123,8 @@ kexec_file_load_test()
98123
# In secureboot mode with an architecture specific
99124
# policy, make sure either an IMA or PE signature exists.
100125
if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ] && \
101-
[ $ima_signed -eq 0 ] && [ $pe_signed -eq 0 ]; then
126+
[ $ima_signed -eq 0 ] && [ $pe_signed -eq 0 ] \
127+
&& [ $ima_modsig -eq 0 ]; then
102128
log_fail "$succeed_msg (missing sig)"
103129
fi
104130

@@ -107,7 +133,8 @@ kexec_file_load_test()
107133
log_fail "$succeed_msg (missing PE sig)"
108134
fi
109135

110-
if [ $ima_sig_required -eq 1 ] && [ $ima_signed -eq 0 ]; then
136+
if [ $ima_sig_required -eq 1 ] && [ $ima_signed -eq 0 ] \
137+
&& [ $ima_modsig -eq 0 ]; then
111138
log_fail "$succeed_msg (missing IMA sig)"
112139
fi
113140

@@ -204,5 +231,8 @@ pe_signed=$?
204231
check_for_imasig
205232
ima_signed=$?
206233

234+
check_for_modsig
235+
ima_modsig=$?
236+
207237
# Test loading the kernel image via kexec_file_load syscall
208238
kexec_file_load_test

0 commit comments

Comments
 (0)