I am trying to create an init script in Debian Buster kernel v5.7.13 that loads some keys for Linux's IMA subsystem. Following the instructions on this man page for evmctl
, I wrote/copied a script at /etc/initramfs-tools/scripts/local-top/ima.sh
that looks like the following:
#!/bin/sh
# mount securityfs if not mounted
SECFS=/sys/kernel/security
grep -q $SECFS /proc/mounts || mount -n -t securityfs securityfs $SECFS
# search for IMA trusted keyring, then for untrusted
ima_id="`awk '/\.ima/ { printf "%d", "0x"$1; }' /proc/keys`"
if [ -z "$ima_id" ]; then
ima_id=`/bin/keyctl search @u keyring _ima 2>/dev/null`
if [ -z "$ima_id" ]; then
ima_id=`keyctl newring _ima @u`
fi
fi
# import IMA X509 certificate
# evmctl import /etc/keys/x509_ima.der $ima_id
evmctl import /etc/keys/x509_evm.der $ima_id
# search for EVM keyring
evm_id=`keyctl search @u keyring _evm 2>/dev/null`
if [ -z "$evm_id" ]; then
evm_id=`keyctl newring _evm @u`
fi
# import EVM X509 certificate
evmctl import /etc/keys/x509_evm.der $evm_id
# a) import EVM encrypted key
cat /etc/keys/kmk | keyctl padd user kmk @u
keyctl add encrypted evm-key "load `cat /etc/keys/evm-key`" @u
# enable EVM
echo "1" > /sys/kernel/security/evm
After that, I updated my initramfs image by running update-initramfs -u
which ran to completion without error. However, when I try to boot the machine, I get the following errors (screenshotted from my VM).
Am I missing a step here? How do I make certain files available to my initramfs script? I am able to execute the script fine when the system is fully booted.
Thank you for your help.