lkundrak / rpms / kernel

Forked from rpms/kernel 4 years ago
Clone
c6ca7ce
From fb2ac204a70da565de9ef9a9d6d69a40c2d59727 Mon Sep 17 00:00:00 2001
c6ca7ce
From: David Howells <dhowells@redhat.com>
c6ca7ce
Date: Fri, 5 May 2017 08:21:56 +0100
c6ca7ce
Subject: [PATCH] KEYS: Allow unrestricted boot-time addition of keys to
c6ca7ce
 secondary keyring
c6ca7ce
c6ca7ce
Allow keys to be added to the system secondary certificates keyring during
c6ca7ce
kernel initialisation in an unrestricted fashion.  Such keys are implicitly
c6ca7ce
trusted and don't have their trust chains checked on link.
c6ca7ce
c6ca7ce
This allows keys in the UEFI database to be added in secure boot mode for
c6ca7ce
the purposes of module signing.
c6ca7ce
c6ca7ce
Signed-off-by: David Howells <dhowells@redhat.com>
c6ca7ce
---
c6ca7ce
 certs/internal.h       | 18 ++++++++++++++++++
c6ca7ce
 certs/system_keyring.c | 33 +++++++++++++++++++++++++++++++++
c6ca7ce
 2 files changed, 51 insertions(+)
c6ca7ce
 create mode 100644 certs/internal.h
c6ca7ce
c6ca7ce
diff --git a/certs/internal.h b/certs/internal.h
c6ca7ce
new file mode 100644
c6ca7ce
index 0000000..5dcbefb
c6ca7ce
--- /dev/null
c6ca7ce
+++ b/certs/internal.h
c6ca7ce
@@ -0,0 +1,18 @@
c6ca7ce
+/* Internal definitions
c6ca7ce
+ *
c6ca7ce
+ * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
c6ca7ce
+ * Written by David Howells (dhowells@redhat.com)
c6ca7ce
+ *
c6ca7ce
+ * This program is free software; you can redistribute it and/or
c6ca7ce
+ * modify it under the terms of the GNU General Public Licence
c6ca7ce
+ * as published by the Free Software Foundation; either version
c6ca7ce
+ * 2 of the Licence, or (at your option) any later version.
c6ca7ce
+ */
c6ca7ce
+
c6ca7ce
+/*
c6ca7ce
+ * system_keyring.c
c6ca7ce
+ */
c6ca7ce
+#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
c6ca7ce
+extern void __init add_trusted_secondary_key(const char *source,
c6ca7ce
+					     const void *data, size_t len);
c6ca7ce
+#endif
c6ca7ce
diff --git a/certs/system_keyring.c b/certs/system_keyring.c
c6ca7ce
index 6251d1b..5ac8ba6 100644
c6ca7ce
--- a/certs/system_keyring.c
c6ca7ce
+++ b/certs/system_keyring.c
c6ca7ce
@@ -18,6 +18,7 @@
c6ca7ce
 #include <keys/asymmetric-type.h>
c6ca7ce
 #include <keys/system_keyring.h>
c6ca7ce
 #include <crypto/pkcs7.h>
c6ca7ce
+#include "internal.h"
c6ca7ce
c6ca7ce
 static struct key *builtin_trusted_keys;
c6ca7ce
 #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
c6ca7ce
@@ -265,3 +266,35 @@ int verify_pkcs7_signature(const void *data, size_t len,
c6ca7ce
 EXPORT_SYMBOL_GPL(verify_pkcs7_signature);
c6ca7ce
c6ca7ce
 #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
c6ca7ce
+
c6ca7ce
+#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
c6ca7ce
+/**
c6ca7ce
+ * add_trusted_secondary_key - Add to secondary keyring with no validation
c6ca7ce
+ * @source: Source of key
c6ca7ce
+ * @data: The blob holding the key
c6ca7ce
+ * @len: The length of the data blob
c6ca7ce
+ *
c6ca7ce
+ * Add a key to the secondary keyring without checking its trust chain.  This
c6ca7ce
+ * is available only during kernel initialisation.
c6ca7ce
+ */
c6ca7ce
+void __init add_trusted_secondary_key(const char *source,
c6ca7ce
+				      const void *data, size_t len)
c6ca7ce
+{
c6ca7ce
+	key_ref_t key;
c6ca7ce
+
c6ca7ce
+	key = key_create_or_update(make_key_ref(secondary_trusted_keys, 1),
c6ca7ce
+				   "asymmetric",
c6ca7ce
+				   NULL, data, len,
c6ca7ce
+				   (KEY_POS_ALL & ~KEY_POS_SETATTR) |
c6ca7ce
+				   KEY_USR_VIEW,
c6ca7ce
+				   KEY_ALLOC_NOT_IN_QUOTA |
c6ca7ce
+				   KEY_ALLOC_BYPASS_RESTRICTION);
c6ca7ce
+
c6ca7ce
+	if (IS_ERR(key))
c6ca7ce
+		pr_err("Problem loading %s X.509 certificate (%ld)\n",
c6ca7ce
+		       source, PTR_ERR(key));
c6ca7ce
+	else
c6ca7ce
+		pr_notice("Loaded %s cert '%s' linked to secondary sys keyring\n",
c6ca7ce
+			  source, key_ref_to_ptr(key)->description);
c6ca7ce
+}
c6ca7ce
+#endif /* CONFIG_SECONDARY_TRUSTED_KEYRING */
c6ca7ce
-- 
c6ca7ce
2.9.3
c6ca7ce