Skip to content

Commit 4bdd7eb

Browse files
stefanbergerjohannbg
authored andcommitted
fix(integrity): properly set up EVM when using an x509 cert
The current EVM script does not handle the EVM setup properly when X509 certificates are involved. In this patch we extend the setup and add the necessary flags for support of EVM activation that include x509 certificates, possibly in conjunction with an HMAC key. We also first try activating EVM for x509 certificates using EVM_ALLOW_METADATA_WRITES for newer kernels, then without it for older ones that did not support this flag. We add support for additional EVM activation bits to be set, such as EVM_SETUP_COMPLETE (0x80000000) via the config file and EVM_ACTIVATION_BITS variable. To avoid error messages related to unloading the HMAC key if none is used, only attempt to unload the HMAC key if one was actually set. We add documentation about the variables that can be set in the EVM config file. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Cc: Roberto Sassu <roberto.sassu@huawei.com>
1 parent 8f99fad commit 4bdd7eb

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

modules.d/98integrity/evm-enable.sh

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ EVMCONFIG="${NEWROOT}/etc/sysconfig/evm"
1111
EVMKEYDESC="evm-key"
1212
EVMKEYTYPE="encrypted"
1313
EVMKEYID=""
14+
EVM_ACTIVATION_BITS=0
15+
16+
# The following variables can be set in /etc/sysconfig/evm:
17+
# EVMKEY: path to the symmetric key; defaults to /etc/keys/evm-trusted.blob
18+
# EVMKEYDESC: Description of the symmetric key; default is 'evm-key'
19+
# EVMKEYTYPE: Type of the symmetric key; default is 'encrypted'
20+
# EMX509: path to x509 cert; default is /etc/keys/x509_evm.der
21+
# EVM_ACTIVATION_BITS: additional EVM activation bits, such as
22+
# EVM_SETUP_COMPLETE; default is 0
1423

1524
load_evm_key() {
1625
# read the configuration from the config file
@@ -121,25 +130,35 @@ enable_evm() {
121130
return 0
122131
fi
123132

124-
local evm_configured
133+
local evm_configured=0
134+
local EVM_INIT_HMAC=1 EVM_INIT_X509=2 EVM_ALLOW_METADATA_WRITES=4
125135

126136
# try to load the EVM encrypted key
127-
load_evm_key && evm_configured=1
137+
load_evm_key && evm_configured=${EVM_INIT_HMAC}
128138

129139
# try to load the EVM public key
130-
load_evm_x509 && evm_configured=1
140+
load_evm_x509 && evm_configured=$((evm_configured | EVM_INIT_X509))
131141

132142
# only enable EVM if a key or x509 certificate could be loaded
133-
if [ -z "$evm_configured" ]; then
143+
if [ $evm_configured -eq 0 ]; then
134144
return 1
135145
fi
136146

137147
# initialize EVM
138148
info "Enabling EVM"
139-
echo 1 > "${EVMSECFILE}"
149+
if [ "$((evm_configured & EVM_INIT_X509))" -ne 0 ]; then
150+
# Older kernels did not support EVM_ALLOW_METADATA_WRITES, try for
151+
# newer ones first that need it when an x509 is used
152+
echo $((evm_configured | EVM_ALLOW_METADATA_WRITES | EVM_ACTIVATION_BITS)) > "${EVMSECFILE}" ||
153+
echo $((evm_configured | EVM_ACTIVATION_BITS)) > "${EVMSECFILE}"
154+
else
155+
echo $((evm_configured | EVM_ACTIVATION_BITS)) > "${EVMSECFILE}"
156+
fi
140157

141-
# unload the EVM encrypted key
142-
unload_evm_key || return 1
158+
if [ "$((evm_configured & EVM_INIT_HMAC))" -ne 0 ]; then
159+
# unload the EVM encrypted key
160+
unload_evm_key || return 1
161+
fi
143162

144163
return 0
145164
}

0 commit comments

Comments
 (0)