summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLans Zhang <jia.zhang@windriver.com>2017-08-15 16:15:38 +0800
committerLans Zhang <jia.zhang@windriver.com>2017-08-15 16:15:38 +0800
commiteb08a619d88b853aed181502dff277de5c4caedf (patch)
treeca61d455b8c1683f22262cd3be36cbcac94c53d9
parent656706373f42dedd9763134d048dd42fc43aa31b (diff)
downloadmeta-secure-core-eb08a619d88b853aed181502dff277de5c4caedf.tar.gz
init.ima: clean up and allow to load extra IMA policies from the real rootfs
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
-rwxr-xr-xmeta-integrity/recipes-core/initrdscripts/files/init.ima28
1 files changed, 18 insertions, 10 deletions
diff --git a/meta-integrity/recipes-core/initrdscripts/files/init.ima b/meta-integrity/recipes-core/initrdscripts/files/init.ima
index 65d4a37..5d12945 100755
--- a/meta-integrity/recipes-core/initrdscripts/files/init.ima
+++ b/meta-integrity/recipes-core/initrdscripts/files/init.ima
@@ -3,7 +3,7 @@
3# Initramfs script for IMA initialzation 3# Initramfs script for IMA initialzation
4# 4#
5# This script is a halper used to load the external 5# This script is a halper used to load the external
6# IMA policy and public keys used to verify the IMA 6# IMA policy and certificate used to verify the IMA
7# signature. 7# signature.
8# 8#
9# Copyright (c) 2017, Jia Zhang <lans.zhang2008@gmail.com> 9# Copyright (c) 2017, Jia Zhang <lans.zhang2008@gmail.com>
@@ -15,7 +15,7 @@
15# 0 - IMA initialiazation complete 15# 0 - IMA initialiazation complete
16# 1 - Kernel doesn't support securityfs 16# 1 - Kernel doesn't support securityfs
17# 2 - Kernel doesn't support IMA 17# 2 - Kernel doesn't support IMA
18# 3 - There is no public key to load 18# 3 - There is no IMA certificate to load
19# 4 - There is no IMA policy file defined 19# 4 - There is no IMA policy file defined
20# 5 - Unable to load IMA policy file 20# 5 - Unable to load IMA policy file
21 21
@@ -72,7 +72,7 @@ trap_handler() {
72trap "trap_handler $?" SIGINT EXIT 72trap "trap_handler $?" SIGINT EXIT
73 73
74if grep -q "ima_appraise=off" "${ROOT_DIR}/proc/cmdline"; then 74if grep -q "ima_appraise=off" "${ROOT_DIR}/proc/cmdline"; then
75 print_info "Skip to load the public key and IMA policy" 75 print_info "Skip to load the IMA certificate and policy"
76 exit 0 76 exit 0
77fi 77fi
78 78
@@ -97,25 +97,33 @@ fi
97 97
98keyring_id=0x`grep '\skeyring\s*\.ima: ' "${ROOT_DIR}/proc/keys" | awk '{ print $1 }'` 98keyring_id=0x`grep '\skeyring\s*\.ima: ' "${ROOT_DIR}/proc/keys" | awk '{ print $1 }'`
99 99
100for key in ${ROOT_DIR}/etc/keys/x509_evm*.crt; do 100# The trusted IMA certificate /etc/keys/x509_evm.der in initramfs was
101 [ ! -s "$key" ] && continue 101# automatically loaded by kernel already. Here is the opportunity to load
102# a custom IMA certificate from the real rootfs.
103for cert in ${ROOT_DIR}/etc/keys/x509_evm*.crt; do
104 [ ! -s "$cert" ] && continue
102 105
103 if ! evmctl import "$key" "$keyring_id" >"${ROOT_DIR}/dev/null"; then 106 if ! evmctl import "$cert" "$keyring_id" >"${ROOT_DIR}/dev/null"; then
104 print_critical "Unable to load the public key $key for IMA appraisal" 107 print_critical "Unable to load the custom IMA certificate $cert for IMA appraisal"
105 else 108 else
106 print_verbose "The external public key $key loaded for IMA appraisal" 109 print_verbose "The custom IMA certificate $cert loaded for IMA appraisal"
107 fi 110 fi
108done 111done
109 112
110# Attempt to load the default policy. 113# Attempt to load the default policy.
111[ ! -f "${IMA_POLICY}" ] && IMA_POLICY="${IMA_POLICY}.default" 114[ ! -s "${IMA_POLICY}" ] && IMA_POLICY="${IMA_POLICY}.default"
112 115
113[ ! -f "${IMA_POLICY}" ] && { 116[ ! -s "${IMA_POLICY}" ] && {
114 print_warning "No IMA policy file defined" 117 print_warning "No IMA policy file defined"
115 exit 4 118 exit 4
116} 119}
117 120
118echo "${IMA_POLICY}" > "$securityfs_dir/ima/policy" && { 121echo "${IMA_POLICY}" > "$securityfs_dir/ima/policy" && {
122 # Attempt to load IMA policies from the real rootfs.
123 for policy in ${ROOT_DIR}/etc/ima/ima_policy*; do
124 echo "$policy" > "$securityfs_dir/ima/policy"
125 done
126
119 exit 0 127 exit 0
120} || { 128} || {
121 print_critical "Unable to load the IMA policy ${IMA_POLICY}" 129 print_critical "Unable to load the IMA policy ${IMA_POLICY}"