diff options
author | Lans Zhang <jia.zhang@windriver.com> | 2017-08-15 16:15:38 +0800 |
---|---|---|
committer | Lans Zhang <jia.zhang@windriver.com> | 2017-08-15 16:15:38 +0800 |
commit | eb08a619d88b853aed181502dff277de5c4caedf (patch) | |
tree | ca61d455b8c1683f22262cd3be36cbcac94c53d9 | |
parent | 656706373f42dedd9763134d048dd42fc43aa31b (diff) | |
download | meta-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-x | meta-integrity/recipes-core/initrdscripts/files/init.ima | 28 |
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() { | |||
72 | trap "trap_handler $?" SIGINT EXIT | 72 | trap "trap_handler $?" SIGINT EXIT |
73 | 73 | ||
74 | if grep -q "ima_appraise=off" "${ROOT_DIR}/proc/cmdline"; then | 74 | if 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 |
77 | fi | 77 | fi |
78 | 78 | ||
@@ -97,25 +97,33 @@ fi | |||
97 | 97 | ||
98 | keyring_id=0x`grep '\skeyring\s*\.ima: ' "${ROOT_DIR}/proc/keys" | awk '{ print $1 }'` | 98 | keyring_id=0x`grep '\skeyring\s*\.ima: ' "${ROOT_DIR}/proc/keys" | awk '{ print $1 }'` |
99 | 99 | ||
100 | for 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. | ||
103 | for 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 |
108 | done | 111 | done |
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 | ||
118 | echo "${IMA_POLICY}" > "$securityfs_dir/ima/policy" && { | 121 | echo "${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}" |