mirror of
https://git.yoctoproject.org/meta-security
synced 2026-01-11 15:00:34 +00:00
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>
This commit is contained in:
committed by
Armin Kuster
parent
292b49342c
commit
76f1f539a6
@@ -62,17 +62,32 @@ ima_evm_sign_rootfs () {
|
||||
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
|
||||
fi
|
||||
|
||||
# Sign file with private IMA key. EVM not supported at the moment.
|
||||
bbnote "IMA/EVM: signing files 'find ${IMA_EVM_ROOTFS_SIGNED}' with private key '${IMA_EVM_PRIVKEY}'"
|
||||
find ${IMA_EVM_ROOTFS_SIGNED} | xargs -d "\n" --no-run-if-empty --verbose evmctl ima_sign --key ${IMA_EVM_PRIVKEY}
|
||||
bbnote "IMA/EVM: hashing files 'find ${IMA_EVM_ROOTFS_HASHED}'"
|
||||
find ${IMA_EVM_ROOTFS_HASHED} | xargs -d "\n" --no-run-if-empty --verbose evmctl ima_hash
|
||||
# Detect 32bit target to pass --m32 to evmctl by looking at libc
|
||||
tmp="$(file "${IMAGE_ROOTFS}/lib/libc.so.6" | grep -o 'ELF .*-bit')"
|
||||
if [ "${tmp}" = "ELF 32-bit" ]; then
|
||||
evmctl_param="--m32"
|
||||
elif [ "${tmp}" = "ELF 64-bit" ]; then
|
||||
evmctl_param=""
|
||||
else
|
||||
bberror "Unknown target architecture bitness: '${tmp}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bbnote "IMA/EVM: Signing root filesystem at ${IMAGE_ROOTFS} with key ${IMA_EVM_PRIVKEY}"
|
||||
evmctl sign --imasig ${evmctl_param} --portable -a sha256 --key ${IMA_EVM_PRIVKEY} -r "${IMAGE_ROOTFS}"
|
||||
|
||||
# check signing key and signature verification key
|
||||
evmctl ima_verify ${evmctl_param} --key "${IMA_EVM_X509}" "${IMAGE_ROOTFS}/lib/libc.so.6" || exit 1
|
||||
evmctl verify ${evmctl_param} --key "${IMA_EVM_X509}" "${IMAGE_ROOTFS}/lib/libc.so.6" || exit 1
|
||||
|
||||
# Optionally install custom policy for loading by systemd.
|
||||
if [ "${IMA_EVM_POLICY}" ]; then
|
||||
install -d ./${sysconfdir}/ima
|
||||
rm -f ./${sysconfdir}/ima/ima-policy
|
||||
install "${IMA_EVM_POLICY}" ./${sysconfdir}/ima/ima-policy
|
||||
|
||||
bbnote "IMA/EVM: Signing IMA policy with key ${IMA_EVM_PRIVKEY}"
|
||||
evmctl sign --imasig ${evmctl_param} --portable -a sha256 --key "${IMA_EVM_PRIVKEY}" "${IMAGE_ROOTFS}/etc/ima/ima-policy"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user