@@ -645,6 +645,12 @@
cio_ignore= [S390]
See Documentation/arch/s390/common_io.rst for details.
+ clavis= [SECURITY,EARLY]
+ Identifies a specific key contained in one of the system
+ keyrings (builtin, secondary, or platform) to be used as
+ the Clavis root of trust.
+ Format: { <keyid> }
+
clearcpuid=X[,X...] [X86]
Disable CPUID feature X for the kernel. See
arch/x86/include/asm/cpufeatures.h for the valid bit
@@ -23,6 +23,14 @@ enum integrity_status {
#ifdef CONFIG_INTEGRITY
extern void __init integrity_load_keys(void);
+#ifdef CONFIG_SECURITY_CLAVIS
+void __init late_init_clavis_setup(void);
+#else
+static inline void late_init_clavis_setup(void)
+{
+}
+#endif
+
#else
static inline void integrity_load_keys(void)
{
@@ -225,6 +225,7 @@ source "security/safesetid/Kconfig"
source "security/lockdown/Kconfig"
source "security/landlock/Kconfig"
source "security/ipe/Kconfig"
+source "security/clavis/Kconfig"
source "security/integrity/Kconfig"
@@ -26,6 +26,7 @@ obj-$(CONFIG_CGROUPS) += device_cgroup.o
obj-$(CONFIG_BPF_LSM) += bpf/
obj-$(CONFIG_SECURITY_LANDLOCK) += landlock/
obj-$(CONFIG_SECURITY_IPE) += ipe/
+obj-$(CONFIG_SECURITY_CLAVIS) += clavis/
# Object integrity file lists
obj-$(CONFIG_INTEGRITY) += integrity/
new file mode 100644
@@ -0,0 +1,11 @@
+config SECURITY_CLAVIS
+ bool "Clavis keyring"
+ depends on SECURITY
+ select SYSTEM_DATA_VERIFICATION
+ select CRYPTO_SHA256
+ help
+ Enable the clavis keyring. This keyring shall contain a single asymmetric key.
+ This key shall be linked to a key already contained in one of the system
+ keyrings (builtin, secondary, or platform). One way to add this key
+ is during boot by passing in the asymmetric key id within the "clavis=" boot
+ param. This keyring is required by the Clavis LSM.
new file mode 100644
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_SECURITY_CLAVIS) += clavis_keyring.o
new file mode 100644
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SECURITY_CLAVIS_H_
+#define _SECURITY_CLAVIS_H_
+#include <keys/asymmetric-type.h>
+
+/* Max length for the asymmetric key id contained on the boot param */
+#define CLAVIS_BIN_KID_MAX 32
+
+struct asymmetric_setup_kid {
+ struct asymmetric_key_id id;
+ unsigned char data[CLAVIS_BIN_KID_MAX];
+};
+#endif /* _SECURITY_CLAVIS_H_ */
new file mode 100644
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/security.h>
+#include <linux/integrity.h>
+#include <keys/asymmetric-type.h>
+#include <keys/system_keyring.h>
+#include "clavis.h"
+
+static struct key *clavis_keyring;
+static struct asymmetric_key_id *clavis_boot_akid;
+static struct asymmetric_setup_kid clavis_setup_akid;
+static bool clavis_enforced;
+
+static bool clavis_acl_enforced(void)
+{
+ return clavis_enforced;
+}
+static int restrict_link_for_clavis(struct key *dest_keyring, const struct key_type *type,
+ const union key_payload *payload, struct key *restrict_key)
+{
+ /*
+ * Allow a single asymmetric key into this keyring. This key is used as the
+ * root of trust for anything added afterwards.
+ */
+ if (type == &key_type_asymmetric && dest_keyring == clavis_keyring &&
+ !clavis_acl_enforced()) {
+ clavis_enforced = true;
+ return 0;
+ }
+
+ return -EOPNOTSUPP;
+}
+
+static struct asymmetric_key_id *clavis_parse_boot_param(char *kid, struct asymmetric_key_id *akid,
+ int akid_max_len)
+{
+ int error, hex_len;
+
+ if (!kid)
+ return 0;
+
+ hex_len = strlen(kid) / 2;
+
+ if (hex_len > akid_max_len)
+ return 0;
+
+ akid->len = hex_len;
+ error = hex2bin(akid->data, kid, akid->len);
+
+ if (error < 0) {
+ pr_err("Unparsable clavis key id\n");
+ return 0;
+ }
+
+ return akid;
+}
+
+static int __init clavis_param(char *kid)
+{
+ clavis_boot_akid = clavis_parse_boot_param(kid, &clavis_setup_akid.id,
+ ARRAY_SIZE(clavis_setup_akid.data));
+
+ return 1;
+}
+
+__setup("clavis=", clavis_param);
+
+static struct key *clavis_keyring_alloc(const char *desc, struct key_restriction *restriction)
+{
+ struct key *keyring;
+
+ keyring = keyring_alloc(desc, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
+ KEY_POS_VIEW | KEY_POS_READ | KEY_POS_SEARCH | KEY_POS_WRITE |
+ KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH | KEY_USR_WRITE,
+ KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP,
+ restriction, NULL);
+ return keyring;
+}
+
+static struct key_restriction *clavis_restriction_alloc(key_restrict_link_func_t check_func)
+{
+ struct key_restriction *restriction;
+
+ restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
+
+ if (restriction)
+ restriction->check = check_func;
+
+ return restriction;
+}
+
+static int __init clavis_keyring_init(void)
+{
+ struct key_restriction *restriction;
+
+ restriction = clavis_restriction_alloc(restrict_link_for_clavis);
+ if (!restriction)
+ panic("Can't allocate clavis keyring restriction\n");
+
+ clavis_keyring = clavis_keyring_alloc(".clavis", restriction);
+ if (IS_ERR(clavis_keyring))
+ panic("Can't allocate clavis keyring\n");
+
+ return 0;
+}
+
+void __init late_init_clavis_setup(void)
+{
+ clavis_keyring_init();
+
+ if (!clavis_boot_akid)
+ return;
+
+ system_key_link(clavis_keyring, clavis_boot_akid);
+}
@@ -36,6 +36,8 @@ int integrity_kernel_read(struct file *file, loff_t offset,
*/
void __init integrity_load_keys(void)
{
+ late_init_clavis_setup();
+
ima_load_x509();
if (!IS_ENABLED(CONFIG_IMA_LOAD_X509))
Introduce a new system keyring called clavis. This keyring shall contain a single asymmetric key. This key may be a linked to a key already contained in one of the system keyrings (builtin, secondary, or platform). One way to add this key into this keyring is during boot by passing in the asymmetric key id within the new "clavis=" boot param. If a matching key is found in one of the system keyrings, a link shall be created. This keyring will be used in the future by the new Clavis LSM. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com> --- .../admin-guide/kernel-parameters.txt | 6 + include/linux/integrity.h | 8 ++ security/Kconfig | 1 + security/Makefile | 1 + security/clavis/Kconfig | 11 ++ security/clavis/Makefile | 3 + security/clavis/clavis.h | 13 ++ security/clavis/clavis_keyring.c | 115 ++++++++++++++++++ security/integrity/iint.c | 2 + 9 files changed, 160 insertions(+) create mode 100644 security/clavis/Kconfig create mode 100644 security/clavis/Makefile create mode 100644 security/clavis/clavis.h create mode 100644 security/clavis/clavis_keyring.c