Skip to contentSkip to conversation

new module - 98evm

PATCH In review Mimi Zohar 2 participants 3 messages May 24, 2011 – May 25, 2011 2 messages not in the archive

lore
Share & tools
lore

Mimi Zohar

author
#0 lore raw

PATCH 1/1 new module - 98evm

EVM verifies file metadata integrity based on a keyed HMAC. The key should be loaded in the initramfs before pivoting root. This patch loads the trusted and encrypted EVM keys onto root's keyring before enabling EVM.

98evm/install new file +4 -0
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+dracut_install keyctl
+inst_hook pre-pivot 60 "$moddir/evm-enable.sh"
98evm/check new file +9 -0
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+[[ $1 = '-h' ]] && {
+    [ -x "/bin/keyctl" ] || exit 1
+    exit 0
+}
+
+exit 0
+
98evm/evm-enable.sh new file +65 -0

65 lines not on this page · raw message

98evm/README new file +47 -0

47 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): 1306243102.3231.14.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

Hi all

i think we should have two separate dracut modules: one for the loading of a trusted or an user key and another for the initialization of EVM, so that other modules which need to load an encrypted key will depend only on the former.

Roberto Sassu

Quoted 149 lines · Mimi Zohar

EVM verifies file metadata integrity based on a keyed HMAC. The key should be loaded in the initramfs before pivoting root. This patch loads the trusted and encrypted EVM keys onto root's keyring before enabling EVM.

98evm/install new file +4 -0
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+dracut_install keyctl
+inst_hook pre-pivot 60 "$moddir/evm-enable.sh"
98evm/check new file +9 -0
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+[[ $1 = '-h' ]] && {
+    [ -x "/bin/keyctl" ] || exit 1
+    exit 0
+}
+
+exit 0
+
98evm/evm-enable.sh new file +65 -0
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+security_evm_exists()
+{
+    RC=0
+
+    if [ ! -d "/security" ]; then
+       mkdir /security
+    fi
+    mount -t securityfs /security /security >/dev/null 2>&1
+    if [ ! -e "/security/evm" ]; then
+       RC=1
+    fi
+    umount /security
+    return $RC
+}
+
+enable_evm()
+{
+    if [ ! -d "/security" ]; then
+       mkdir /security
+    fi
+    mount -t securityfs /security /security >/dev/null 2>&1
+    if [ -e "/security/evm" ]; then
+       echo 1 > /security/evm
+    fi
+    umount /security
+}
+
+load_keys()
+{
+    RC=0
+
+    MASTERKEY=$(getarg masterkey=)
+    if [ $? -ne 0 ]; then
+        MASTERKEY='kmk-trusted.blob'
+    fi
+
+    EVMKEY=$(getarg evmkey=)
+    if [ $? -ne 0 ]; then
+        EVMKEY='evm-trusted.blob'
+    fi
+
+    if [ ! -f "$NEWROOT/etc/keys/$MASTERKEY" ]; then
+	info "EVM: missing master key"
+        RC=1
+    elif [ ! -f "$NEWROOT/etc/keys/$EVMKEY" ]; then
+	info "EVM: missing EVM key"
+        RC=1
+    else
+        keyctl add trusted kmk-trusted "load `cat $NEWROOT/etc/keys/$MASTERKEY`" @u
+        keyctl add encrypted evm-key "load `cat $NEWROOT/etc/keys/$EVMKEY`" @u
+    fi
+    return $RC
+}
+
+security_evm_exists
+RC=$?
+if [ $RC -eq 0 ]; then
+   load_keys
+   RC=$?
+fi
+if [ $RC -eq 0 ]; then
+   enable_evm
+fi
98evm/README new file +47 -1
@@ -0,0 +1,47 @@
+# Directions for creating an EVM key, encrypted/decrypted using a trusted key.
+
+# Create the kernel master key (trusted key type) for encrypting/decrypting
+# other keys, including the EVM key.
+ 
+# A trusted key is a TPM random number, which is only ever exposed to
+# userspace as an encrypted datablob. A trusted key can be sealed to a 
+# set of PCR values. For more details on trusted keys, refer to the 
+# kernel keys-trusted-encrypted.txt documentation.
+$ keyctl add trusted kmk-trusted "new 32" @u
+801713097
+
+# Save the kernel master key
+$ su -c 'keyctl pipe 801713097 > /etc/keys/kmk-trusted.blob'
+
+# Create the EVM key (encrypted key type)
+#
+# The encrypted key is a random number encrypted/decrypted using the
+# kernel master key.  The encrypted key is only exposed to userspace
+# as an encrypted datablob.
+$ keyctl add encrypted evm-key "new trusted:kmk-trusted 32" @u
+782117972
+
+# Save the encrypted key
+$ su -c 'keyctl pipe 782117972 > /etc/keys/evm-trusted.blob'
+
+------------------------------------------------------------------
+# Directions for creating an EVM key, encrypted/decrypted using a user key.
+# (Dracut support for encrypting/decrypting the EVM key using a user key is
+# not provided.)
+
+# For those systems which don't have a TPM, create a user key of 32 
+# random bytes. Unlike trusted/encrypted keys, user type key data is
+# visible to userspace.
+$ keyctl add user kmk-user "`dd if=/dev/urandom bs=1 count=32 2>/dev/null`" @u
+144468621
+
+# Save the user key
+$ su -c 'keyctl pipe 144468621 > /etc/keys/kmk-user.blob'
+
+# Create the EVM key (encrypted key type), using the user key to
+# encrypt/decrypt it.
+$ keyctl add encrypted evm-key "new user:kmk-user 32" @u
+432095285
+
+# Save the encrypted key
+$ su -c 'keyctl pipe 432095285 > /etc/keys/evm-user.blob'
 
 
--

To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 201105251755.09520.roberto.sassu-8RLafaVCWuNeoWH0uzbU5w@public.gmane.org

author
#4 lore raw
Quoted 8 lines · Roberto Sassu

Hi all

i think we should have two separate dracut modules: one for the loading of a trusted or an user key and another for the initialization of EVM, so that other modules which need to load an encrypted key will depend only on the former.

Roberto Sassu

Thanks, Roberto, for pointing this out. There should also be another module for removing the trusted key from the keyring, before pivoting root.

thanks,

Mimi