summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.ibm.com>2023-04-28 08:23:13 -0400
committerArmin Kuster <akuster808@gmail.com>2023-05-06 07:54:09 -0400
commit76f1f539a678725211283294c8b6735186055694 (patch)
tree12a876c50195bc9f66bca64ef821444af6903aea
parent292b49342cb47da59525a44227598cf136311e1b (diff)
downloadmeta-security-76f1f539a678725211283294c8b6735186055694.tar.gz
ima: Sign all executables and the ima-policy in the root filesystem
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rw-r--r--meta-integrity/classes/ima-evm-rootfs.bbclass25
1 files changed, 20 insertions, 5 deletions
diff --git a/meta-integrity/classes/ima-evm-rootfs.bbclass b/meta-integrity/classes/ima-evm-rootfs.bbclass
index 6902d69..98c4bc1 100644
--- a/meta-integrity/classes/ima-evm-rootfs.bbclass
+++ b/meta-integrity/classes/ima-evm-rootfs.bbclass
@@ -62,17 +62,32 @@ ima_evm_sign_rootfs () {
62 perl -pi -e 's;(\S+)(\s+)(${@"|".join((d.getVar("IMA_EVM_ROOTFS_IVERSION", True) or "no-such-mount-point").split())})(\s+)(\S+)(\s+)(\S+);\1\2\3\4\5\6\7,iversion;; s/(,iversion)+/,iversion/;' etc/fstab 62 perl -pi -e 's;(\S+)(\s+)(${@"|".join((d.getVar("IMA_EVM_ROOTFS_IVERSION", True) or "no-such-mount-point").split())})(\s+)(\S+)(\s+)(\S+);\1\2\3\4\5\6\7,iversion;; s/(,iversion)+/,iversion/;' etc/fstab
63 fi 63 fi
64 64
65 # Sign file with private IMA key. EVM not supported at the moment. 65 # Detect 32bit target to pass --m32 to evmctl by looking at libc
66 bbnote "IMA/EVM: signing files 'find ${IMA_EVM_ROOTFS_SIGNED}' with private key '${IMA_EVM_PRIVKEY}'" 66 tmp="$(file "${IMAGE_ROOTFS}/lib/libc.so.6" | grep -o 'ELF .*-bit')"
67 find ${IMA_EVM_ROOTFS_SIGNED} | xargs -d "\n" --no-run-if-empty --verbose evmctl ima_sign --key ${IMA_EVM_PRIVKEY} 67 if [ "${tmp}" = "ELF 32-bit" ]; then
68 bbnote "IMA/EVM: hashing files 'find ${IMA_EVM_ROOTFS_HASHED}'" 68 evmctl_param="--m32"
69 find ${IMA_EVM_ROOTFS_HASHED} | xargs -d "\n" --no-run-if-empty --verbose evmctl ima_hash 69 elif [ "${tmp}" = "ELF 64-bit" ]; then
70 evmctl_param=""
71 else
72 bberror "Unknown target architecture bitness: '${tmp}'" >&2
73 exit 1
74 fi
75
76 bbnote "IMA/EVM: Signing root filesystem at ${IMAGE_ROOTFS} with key ${IMA_EVM_PRIVKEY}"
77 evmctl sign --imasig ${evmctl_param} --portable -a sha256 --key ${IMA_EVM_PRIVKEY} -r "${IMAGE_ROOTFS}"
78
79 # check signing key and signature verification key
80 evmctl ima_verify ${evmctl_param} --key "${IMA_EVM_X509}" "${IMAGE_ROOTFS}/lib/libc.so.6" || exit 1
81 evmctl verify ${evmctl_param} --key "${IMA_EVM_X509}" "${IMAGE_ROOTFS}/lib/libc.so.6" || exit 1
70 82
71 # Optionally install custom policy for loading by systemd. 83 # Optionally install custom policy for loading by systemd.
72 if [ "${IMA_EVM_POLICY}" ]; then 84 if [ "${IMA_EVM_POLICY}" ]; then
73 install -d ./${sysconfdir}/ima 85 install -d ./${sysconfdir}/ima
74 rm -f ./${sysconfdir}/ima/ima-policy 86 rm -f ./${sysconfdir}/ima/ima-policy
75 install "${IMA_EVM_POLICY}" ./${sysconfdir}/ima/ima-policy 87 install "${IMA_EVM_POLICY}" ./${sysconfdir}/ima/ima-policy
88
89 bbnote "IMA/EVM: Signing IMA policy with key ${IMA_EVM_PRIVKEY}"
90 evmctl sign --imasig ${evmctl_param} --portable -a sha256 --key "${IMA_EVM_PRIVKEY}" "${IMAGE_ROOTFS}/etc/ima/ima-policy"
76 fi 91 fi
77} 92}
78 93