Skip to contentSkip to conversation

Verify measurement of certificate imported into a keyring

PATCH New Lachlan Sneff 1 participant 4 messages Aug 3, 2020 Keys-trusted

lore
Share & tools
lore
#0 lore raw

cover Verify measurement of certificate imported into a keyring

The IMA subsystem supports measuring certificates that have been loaded into user-defined keyrings and system built-in keyrings. A test to verify that those measurements are correct is required.

The first two patches in this patchset fix up left-over documentation and move some datafiles around to prepare for more datafiles in the 3rd patch.

The third patch adds a new test to the ima_keys.sh file, which imports a certificate into a user-defined keyring, and then verifies that the certificate has been measured correctly by the IMA subsystem.

Lachlan Sneff (3):
IMA: Update key test documentation
IMA: Refactor datafiles directory
IMA: Add a test to verify measurement of certificate imported into a
keyring

 .../kernel/security/integrity/ima/README.md   |  32 +++++++------
 .../security/integrity/ima/datafiles/Makefile |   6 +--
 .../integrity/ima/datafiles/keys/Makefile     |  15 ++++++
 .../integrity/ima/datafiles/keys/x509_ima.der | Bin 0 -> 650 bytes
 .../integrity/ima/datafiles/policy/Makefile   |  15 ++++++
 .../ima/datafiles/{ => policy}/kexec.policy   |   0
 .../datafiles/{ => policy}/keycheck.policy    |   0
 .../ima/datafiles/{ => policy}/measure.policy |   0
 .../{ => policy}/measure.policy-invalid       |   0
 .../security/integrity/ima/tests/ima_keys.sh  |  44 +++++++++++++++++-
 10 files changed, 91 insertions(+), 21 deletions(-)
 create mode 100644 testcases/kernel/security/integrity/ima/datafiles/keys/Makefile
 create mode 100644 testcases/kernel/security/integrity/ima/datafiles/keys/x509_ima.der
 create mode 100644 testcases/kernel/security/integrity/ima/datafiles/policy/Makefile
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/kexec.policy (100%)
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/keycheck.policy (100%)
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/measure.policy (100%)
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/measure.policy-invalid (100%)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 IMA: Update key test documentation

The current documentation for the existing IMA key test was left in by accident by a previous merge. It does not apply to the test that is currently included in the LTP.

Update the documentation for the IMA key test.

---
 .../kernel/security/integrity/ima/README.md   | 22 +++++--------------
 1 file changed, 5 insertions(+), 17 deletions(-)
testcases/kernel/security/integrity/ima/README.md +5 -17
index d4644ba39..2956ac7fd 100644
@@ -15,27 +15,15 @@ Although a custom policy, loaded via dracut, systemd or manually from user
 space, may contain equivalent measurement tcb rules, detecting them would
 require `IMA_READ_POLICY=y` therefore ignore this option.
 
-### IMA key import test
-`ima_keys.sh` requires a x509 public key, by default in `/etc/keys/x509_ima.der`
-(defined in `CONFIG_IMA_X509_PATH` kernel config option).
-The key must be signed by the private key you generate. Follow these instructions:
-https://manpages.ubuntu.com/manpages/disco/man1/evmctl.1.html#generate%20trusted%20keys
-
-The test cannot be set-up automatically because the x509 public key must be
-built into the kernel and loaded onto a trusted keyring
-(e.g. `.builtin_trusted_keys`, `.secondary_trusted_keyring`).
-
-As well as what's required for the IMA tests, the following are also required
-in the kernel configuration:
+### IMA key test
+`ima_keys.sh` requires a readable IMA policy, as well as a loaded policy
+with `func=KEY_CHECK keyrings=...`, see example in `keycheck.policy`.
+
+Mandatory kernel configuration for IMA:
 ```
 CONFIG_IMA_READ_POLICY=y
-CONFIG_IMA_X509_PATH="/etc/keys/x509_ima.der"
-CONFIG_SYSTEM_TRUSTED_KEYRING=y
-CONFIG_SYSTEM_TRUSTED_KEYS="/etc/keys/ima-local-ca.pem"
 ```
 
-Test also requires loaded policy with `func=KEY_CHECK`, see example in `keycheck.policy`.
-
 ### IMA kexec test
 
 `ima_kexec.sh` requires loaded policy which contains `measure func=KEXEC_CMDLINE`,
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/3 IMA: Refactor datafiles directory

In reply to Lachlan Sneff

The IMA datafiles directory is structured so that it cannot be directly expanded to include datafiles for tests other than ima_policy.sh.

Move the contents of the IMA datafiles directory into an IMA datafiles/policy directory.

---
 .../security/integrity/ima/datafiles/Makefile     |  6 ++----
 .../integrity/ima/datafiles/policy/Makefile       | 15 +++++++++++++++
 .../ima/datafiles/{ => policy}/kexec.policy       |  0
 .../ima/datafiles/{ => policy}/keycheck.policy    |  0
 .../ima/datafiles/{ => policy}/measure.policy     |  0
 .../datafiles/{ => policy}/measure.policy-invalid |  0
 6 files changed, 17 insertions(+), 4 deletions(-)
 create mode 100644 testcases/kernel/security/integrity/ima/datafiles/policy/Makefile
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/kexec.policy (100%)
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/keycheck.policy (100%)
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/measure.policy (100%)
 rename testcases/kernel/security/integrity/ima/datafiles/{ => policy}/measure.policy-invalid (100%)
testcases/kernel/security/integrity/ima/datafiles/Makefile +2 -4
index 369407112..3772e9a03 100644
@@ -24,8 +24,6 @@ top_srcdir		?= ../../../../../..
 
 include	$(top_srcdir)/include/mk/env_pre.mk
 
-INSTALL_DIR		:= testcases/data/ima_policy
+SUBDIRS			:= policy
 
-INSTALL_TARGETS		:= measure.policy-invalid *.policy
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
+include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/security/integrity/ima/datafiles/policy/Makefile new file +15 -0
new file mode 100644
index 000000000..84d1424c6
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Microsoft Corporation
+# Author: Lachlan Sneff <[email protected]>
+#
+# IMA datafiles/policy Makefile
+
+top_srcdir		?= ../../../../../../..
+
+include	$(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_DIR		:= testcases/data/ima_policy
+
+INSTALL_TARGETS		:= measure.policy-invalid *.policy
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
\ No newline at end of file
testcases/kernel/security/integrity/ima/datafiles/policy/kexec.policy renamed from testcases/kernel/security/integrity/ima/datafiles/kexec.policy +0 -0
similarity index 100%
rename from testcases/kernel/security/integrity/ima/datafiles/kexec.policy
rename to testcases/kernel/security/integrity/ima/datafiles/policy/kexec.policy
testcases/kernel/security/integrity/ima/datafiles/policy/keycheck.policy renamed from testcases/kernel/security/integrity/ima/datafiles/keycheck.policy +0 -0
similarity index 100%
rename from testcases/kernel/security/integrity/ima/datafiles/keycheck.policy
rename to testcases/kernel/security/integrity/ima/datafiles/policy/keycheck.policy
testcases/kernel/security/integrity/ima/datafiles/policy/measure.policy renamed from testcases/kernel/security/integrity/ima/datafiles/measure.policy +0 -0
similarity index 100%
rename from testcases/kernel/security/integrity/ima/datafiles/measure.policy
rename to testcases/kernel/security/integrity/ima/datafiles/policy/measure.policy
testcases/kernel/security/integrity/ima/datafiles/policy/measure.policy-invalid renamed from testcases/kernel/security/integrity/ima/datafiles/measure.policy-invalid +0 -0
similarity index 100%
rename from testcases/kernel/security/integrity/ima/datafiles/measure.policy-invalid
rename to testcases/kernel/security/integrity/ima/datafiles/policy/measure.policy-invalid
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/3 IMA: Add a test to verify measurement of certificate imported into a keyring

In reply to Lachlan Sneff

The IMA subsystem supports measuring certificates that have been imported into either system built-in or user-defined keyrings. A test to verify measurement of a certificate imported into a keyring is required.

Add an IMA measurement test that verifies that an x509 certificate can be imported into a newly-created, user-defined keyring and measured correctly by the IMA subsystem.

A certificate used by the test is included in the datafiles/keys directory.

There can be restrictions on importing a certificate into a builtin trusted keyring. For example, the .ima keyring requires that imported certs be signed by a kernel private key in certain kernel configurations. For this reason, this test defines a user-defined keyring and imports a certificate into that.

---
 .../kernel/security/integrity/ima/README.md   |  14 ++++++
 .../security/integrity/ima/datafiles/Makefile |   2 +-
 .../integrity/ima/datafiles/keys/Makefile     |  15 ++++++
 .../integrity/ima/datafiles/keys/x509_ima.der | Bin 0 -> 650 bytes
 .../security/integrity/ima/tests/ima_keys.sh  |  44 +++++++++++++++++-
 5 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/security/integrity/ima/datafiles/keys/Makefile
 create mode 100644 testcases/kernel/security/integrity/ima/datafiles/keys/x509_ima.der
testcases/kernel/security/integrity/ima/README.md +14 -0
index 2956ac7fd..bfa015191 100644
@@ -23,6 +23,20 @@ Mandatory kernel configuration for IMA:
 ```
 CONFIG_IMA_READ_POLICY=y
 ```
+The certificate import test in `ima_keys.sh` also requires that
+the `key_import_test` keyring is specified in the IMA policy.
+
+One way to do this is to modify an existing KEY_CHECK entry
+in the IMA policy by adding `key_import_test` for keyrings:
+```
+measure func=KEY_CHECK keyrings=.ima|.evm|key_import_test template=ima-buf
+```
+
+If KEY_CHECK entry does not exist in the IMA policy then by adding
+the following line:
+```
+measure func=KEY_CHECK keyrings=key_import_test template=ima-buf
+```
 
 ### IMA kexec test
 
testcases/kernel/security/integrity/ima/datafiles/Makefile +1 -1
index 3772e9a03..4b4c46b82 100644
@@ -24,6 +24,6 @@ top_srcdir		?= ../../../../../..
 
 include	$(top_srcdir)/include/mk/env_pre.mk
 
-SUBDIRS			:= policy
+SUBDIRS			:= policy keys
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/security/integrity/ima/datafiles/keys/Makefile new file +15 -0
new file mode 100644
index 000000000..a8ab7a1b5
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Microsoft Corporation
+# Author: Lachlan Sneff <[email protected]>
+#
+# IMA datafiles/keys Makefile
+
+top_srcdir		?= ../../../../../../..
+
+include	$(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_DIR		:= testcases/data/ima_keys
+
+INSTALL_TARGETS		:= x509_ima.der
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/security/integrity/ima/datafiles/keys/x509_ima.der new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..92be058da22adffa9d6b6e51efa0c737ebbbbdcd
GIT binary patch
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +42 -2

55 lines not on this page · raw message

Signature · 1 line
2.25.1