diff options
author | Mimi Zohar <zohar@linux.ibm.com> | 2019-08-25 09:58:16 -0400 |
---|---|---|
committer | Mimi Zohar <zohar@linux.ibm.com> | 2019-08-29 12:45:30 -0400 |
commit | cbc0425d3dd370a6f0bf23589dc7b6955a53a9ce (patch) | |
tree | 0d3fe5ed0859d442d225a26f6b25550f86f2c686 /tools/testing/selftests | |
parent | 556d971bdae643de4cd7e2976e14f70ca2a3061d (diff) |
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 <pvorel@suse.cz>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Reviewed-by: Jordan Hand <jorhand@linux.microsoft.com> (x86_64 QEMU)
Tested-by: Jordan Hand <jorhand@linux.microsoft.com> (x86_64 QEMU)
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Diffstat (limited to 'tools/testing/selftests')
-rwxr-xr-x | tools/testing/selftests/kexec/test_kexec_file_load.sh | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tools/testing/selftests/kexec/test_kexec_file_load.sh b/tools/testing/selftests/kexec/test_kexec_file_load.sh index fa7c24e8eefb..2ff600388c30 100755 --- a/tools/testing/selftests/kexec/test_kexec_file_load.sh +++ b/tools/testing/selftests/kexec/test_kexec_file_load.sh | |||
@@ -37,11 +37,20 @@ is_ima_sig_required() | |||
37 | # sequentially. As a result, a policy rule may be defined, but | 37 | # sequentially. As a result, a policy rule may be defined, but |
38 | # might not necessarily be used. This test assumes if a policy | 38 | # might not necessarily be used. This test assumes if a policy |
39 | # rule is specified, that is the intent. | 39 | # rule is specified, that is the intent. |
40 | |||
41 | # First check for appended signature (modsig), then xattr | ||
40 | if [ $ima_read_policy -eq 1 ]; then | 42 | if [ $ima_read_policy -eq 1 ]; then |
41 | check_ima_policy "appraise" "func=KEXEC_KERNEL_CHECK" \ | 43 | check_ima_policy "appraise" "func=KEXEC_KERNEL_CHECK" \ |
42 | "appraise_type=imasig" | 44 | "appraise_type=imasig|modsig" |
43 | ret=$? | 45 | 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 | ||
45 | fi | 54 | fi |
46 | return $ret | 55 | return $ret |
47 | } | 56 | } |
@@ -84,6 +93,22 @@ check_for_imasig() | |||
84 | return $ret | 93 | return $ret |
85 | } | 94 | } |
86 | 95 | ||
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 | |||
87 | kexec_file_load_test() | 112 | kexec_file_load_test() |
88 | { | 113 | { |
89 | local succeed_msg="kexec_file_load succeeded" | 114 | local succeed_msg="kexec_file_load succeeded" |
@@ -98,7 +123,8 @@ kexec_file_load_test() | |||
98 | # In secureboot mode with an architecture specific | 123 | # In secureboot mode with an architecture specific |
99 | # policy, make sure either an IMA or PE signature exists. | 124 | # policy, make sure either an IMA or PE signature exists. |
100 | if [ $secureboot -eq 1 ] && [ $arch_policy -eq 1 ] && \ | 125 | 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 | ||
102 | log_fail "$succeed_msg (missing sig)" | 128 | log_fail "$succeed_msg (missing sig)" |
103 | fi | 129 | fi |
104 | 130 | ||
@@ -107,7 +133,8 @@ kexec_file_load_test() | |||
107 | log_fail "$succeed_msg (missing PE sig)" | 133 | log_fail "$succeed_msg (missing PE sig)" |
108 | fi | 134 | fi |
109 | 135 | ||
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 | ||
111 | log_fail "$succeed_msg (missing IMA sig)" | 138 | log_fail "$succeed_msg (missing IMA sig)" |
112 | fi | 139 | fi |
113 | 140 | ||
@@ -204,5 +231,8 @@ pe_signed=$? | |||
204 | check_for_imasig | 231 | check_for_imasig |
205 | ima_signed=$? | 232 | ima_signed=$? |
206 | 233 | ||
234 | check_for_modsig | ||
235 | ima_modsig=$? | ||
236 | |||
207 | # Test loading the kernel image via kexec_file_load syscall | 237 | # Test loading the kernel image via kexec_file_load syscall |
208 | kexec_file_load_test | 238 | kexec_file_load_test |