summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-09-27 22:37:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-09-27 22:37:27 -0400
commitf1f2f614d535564992f32e720739cb53cf03489f (patch)
tree7c363b95df8d63954e822c98462fd3a9a98794ae /tools/testing/selftests
parent298fb76a5583900a155d387efaf37a8b39e5dea2 (diff)
parent2a7f0e53daf29ca6dc9fbe2a27158f13474ec1b5 (diff)
Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull integrity updates from Mimi Zohar: "The major feature in this time is IMA support for measuring and appraising appended file signatures. In addition are a couple of bug fixes and code cleanup to use struct_size(). In addition to the PE/COFF and IMA xattr signatures, the kexec kernel image may be signed with an appended signature, using the same scripts/sign-file tool that is used to sign kernel modules. Similarly, the initramfs may contain an appended signature. This contained a lot of refactoring of the existing appended signature verification code, so that IMA could retain the existing framework of calculating the file hash once, storing it in the IMA measurement list and extending the TPM, verifying the file's integrity based on a file hash or signature (eg. xattrs), and adding an audit record containing the file hash, all based on policy. (The IMA support for appended signatures patch set was posted and reviewed 11 times.) The support for appended signature paves the way for adding other signature verification methods, such as fs-verity, based on a single system-wide policy. The file hash used for verifying the signature and the signature, itself, can be included in the IMA measurement list" * 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: ima: ima_api: Use struct_size() in kzalloc() ima: use struct_size() in kzalloc() sefltest/ima: support appended signatures (modsig) ima: Fix use after free in ima_read_modsig() MODSIGN: make new include file self contained ima: fix freeing ongoing ahash_request ima: always return negative code for error ima: Store the measurement again when appraising a modsig ima: Define ima-modsig template ima: Collect modsig ima: Implement support for module-style appended signatures ima: Factor xattr_verify() out of ima_appraise_measurement() ima: Add modsig appraise_type option for module-style appended signatures integrity: Select CONFIG_KEYS instead of depending on it PKCS#7: Introduce pkcs7_get_digest() PKCS#7: Refactor verify_pkcs7_signature() MODSIGN: Export module signature definitions ima: initialize the "template" field with the default template
Diffstat (limited to 'tools/testing/selftests')
-rwxr-xr-xtools/testing/selftests/kexec/test_kexec_file_load.sh38
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.
97check_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
87kexec_file_load_test() 112kexec_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=$?
204check_for_imasig 231check_for_imasig
205ima_signed=$? 232ima_signed=$?
206 233
234check_for_modsig
235ima_modsig=$?
236
207# Test loading the kernel image via kexec_file_load syscall 237# Test loading the kernel image via kexec_file_load syscall
208kexec_file_load_test 238kexec_file_load_test