All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Aloni <dan@kernelim.com>
To: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com
Cc: Dan Aloni <dan@kernelim.com>
Subject: [kernel-hardening] [PATCH 2/5] certs: allow in-kernel access of trusted keys
Date: Sat, 30 Dec 2017 19:58:01 +0200	[thread overview]
Message-ID: <20171230175804.7354-3-alonid@gmail.com> (raw)
In-Reply-To: <20171230175804.7354-1-alonid@gmail.com>

From: Dan Aloni <dan@kernelim.com>

Signed-off-by: Dan Aloni <dan@kernelim.com>
---
 certs/system_keyring.c        | 56 ++++++++++++++++++++++++++++++++++++++++++-
 include/keys/system_keyring.h |  3 +++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/certs/system_keyring.c b/certs/system_keyring.c
index 6251d1b27f0c..ff7c18d8e67c 100644
--- a/certs/system_keyring.c
+++ b/certs/system_keyring.c
@@ -131,6 +131,8 @@ static __init int system_trusted_keyring_init(void)
  */
 device_initcall(system_trusted_keyring_init);
 
+static char *first_asymmetric_key_description;
+
 /*
  * Load the compiled-in list of X.509 certificates.
  */
@@ -172,8 +174,11 @@ static __init int load_system_certificate_list(void)
 			pr_err("Problem loading in-kernel X.509 certificate (%ld)\n",
 			       PTR_ERR(key));
 		} else {
+			first_asymmetric_key_description =
+				kstrdup(key_ref_to_ptr(key)->description,
+					GFP_KERNEL);
 			pr_notice("Loaded X.509 cert '%s'\n",
-				  key_ref_to_ptr(key)->description);
+				  first_asymmetric_key_description);
 			key_ref_put(key);
 		}
 		p += plen;
@@ -265,3 +270,52 @@ int verify_pkcs7_signature(const void *data, size_t len,
 EXPORT_SYMBOL_GPL(verify_pkcs7_signature);
 
 #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
+
+/**
+ * get_first_asymmetric_key - Find a key by ID.
+ * @keyring: The keys to search.
+ *
+ * Return the first assymmetric key in a keyring.
+ */
+static struct key *get_first_asymmetric_key(struct key *keyring)
+{
+	key_ref_t ref;
+
+	ref = keyring_search(make_key_ref(keyring, 1),
+	          &key_type_asymmetric,
+		  first_asymmetric_key_description);
+	if (IS_ERR(ref)) {
+		switch (PTR_ERR(ref)) {
+		case -EACCES:
+		case -ENOTDIR:
+		case -EAGAIN:
+			return ERR_PTR(-ENOKEY);
+		default:
+			return ERR_CAST(ref);
+		}
+	}
+
+	return key_ref_to_ptr(ref);
+}
+
+/**
+ * find_asymmetric_key - Find a key by ID in the builtin trusted keys
+ * keyring, or return the first key in that keyring.
+ *
+ * @id_0: The first ID to look for or NULL.
+ * @id_1: The second ID to look for or NULL.
+ *
+ * The preferred identifier is the id_0 and the fallback identifier is
+ * the id_1. If both are given, the lookup is by the former, but the
+ * latter must also match. If none are given, the first key is returned.
+ */
+struct key *find_trusted_asymmetric_key(const struct asymmetric_key_id *id_0,
+					const struct asymmetric_key_id *id_1)
+{
+	struct key *keyring = builtin_trusted_keys;
+	if (!id_0 && !id_1) {
+		return get_first_asymmetric_key(keyring);
+	}
+
+	return find_asymmetric_key(keyring, id_0, id_1, false);
+}
diff --git a/include/keys/system_keyring.h b/include/keys/system_keyring.h
index 359c2f936004..0bef29eb8297 100644
--- a/include/keys/system_keyring.h
+++ b/include/keys/system_keyring.h
@@ -13,6 +13,7 @@
 #define _KEYS_SYSTEM_KEYRING_H
 
 #include <linux/key.h>
+#include <keys/asymmetric-type.h>
 
 #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
 
@@ -61,5 +62,7 @@ static inline struct key *get_ima_blacklist_keyring(void)
 }
 #endif /* CONFIG_IMA_BLACKLIST_KEYRING */
 
+struct key *find_trusted_asymmetric_key(const struct asymmetric_key_id *id_0,
+					const struct asymmetric_key_id *id_1);
 
 #endif /* _KEYS_SYSTEM_KEYRING_H */
-- 
2.13.6

WARNING: multiple messages have this Message-ID (diff)
From: Dan Aloni <dan@kernelim.com>
To: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com
Cc: Dan Aloni <dan@kernelim.com>
Subject: [PATCH 2/5] certs: allow in-kernel access of trusted keys
Date: Sat, 30 Dec 2017 19:58:01 +0200	[thread overview]
Message-ID: <20171230175804.7354-3-alonid@gmail.com> (raw)
In-Reply-To: <20171230175804.7354-1-alonid@gmail.com>

From: Dan Aloni <dan@kernelim.com>

Signed-off-by: Dan Aloni <dan@kernelim.com>
---
 certs/system_keyring.c        | 56 ++++++++++++++++++++++++++++++++++++++++++-
 include/keys/system_keyring.h |  3 +++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/certs/system_keyring.c b/certs/system_keyring.c
index 6251d1b27f0c..ff7c18d8e67c 100644
--- a/certs/system_keyring.c
+++ b/certs/system_keyring.c
@@ -131,6 +131,8 @@ static __init int system_trusted_keyring_init(void)
  */
 device_initcall(system_trusted_keyring_init);
 
+static char *first_asymmetric_key_description;
+
 /*
  * Load the compiled-in list of X.509 certificates.
  */
@@ -172,8 +174,11 @@ static __init int load_system_certificate_list(void)
 			pr_err("Problem loading in-kernel X.509 certificate (%ld)\n",
 			       PTR_ERR(key));
 		} else {
+			first_asymmetric_key_description =
+				kstrdup(key_ref_to_ptr(key)->description,
+					GFP_KERNEL);
 			pr_notice("Loaded X.509 cert '%s'\n",
-				  key_ref_to_ptr(key)->description);
+				  first_asymmetric_key_description);
 			key_ref_put(key);
 		}
 		p += plen;
@@ -265,3 +270,52 @@ int verify_pkcs7_signature(const void *data, size_t len,
 EXPORT_SYMBOL_GPL(verify_pkcs7_signature);
 
 #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */
+
+/**
+ * get_first_asymmetric_key - Find a key by ID.
+ * @keyring: The keys to search.
+ *
+ * Return the first assymmetric key in a keyring.
+ */
+static struct key *get_first_asymmetric_key(struct key *keyring)
+{
+	key_ref_t ref;
+
+	ref = keyring_search(make_key_ref(keyring, 1),
+	          &key_type_asymmetric,
+		  first_asymmetric_key_description);
+	if (IS_ERR(ref)) {
+		switch (PTR_ERR(ref)) {
+		case -EACCES:
+		case -ENOTDIR:
+		case -EAGAIN:
+			return ERR_PTR(-ENOKEY);
+		default:
+			return ERR_CAST(ref);
+		}
+	}
+
+	return key_ref_to_ptr(ref);
+}
+
+/**
+ * find_asymmetric_key - Find a key by ID in the builtin trusted keys
+ * keyring, or return the first key in that keyring.
+ *
+ * @id_0: The first ID to look for or NULL.
+ * @id_1: The second ID to look for or NULL.
+ *
+ * The preferred identifier is the id_0 and the fallback identifier is
+ * the id_1. If both are given, the lookup is by the former, but the
+ * latter must also match. If none are given, the first key is returned.
+ */
+struct key *find_trusted_asymmetric_key(const struct asymmetric_key_id *id_0,
+					const struct asymmetric_key_id *id_1)
+{
+	struct key *keyring = builtin_trusted_keys;
+	if (!id_0 && !id_1) {
+		return get_first_asymmetric_key(keyring);
+	}
+
+	return find_asymmetric_key(keyring, id_0, id_1, false);
+}
diff --git a/include/keys/system_keyring.h b/include/keys/system_keyring.h
index 359c2f936004..0bef29eb8297 100644
--- a/include/keys/system_keyring.h
+++ b/include/keys/system_keyring.h
@@ -13,6 +13,7 @@
 #define _KEYS_SYSTEM_KEYRING_H
 
 #include <linux/key.h>
+#include <keys/asymmetric-type.h>
 
 #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
 
@@ -61,5 +62,7 @@ static inline struct key *get_ima_blacklist_keyring(void)
 }
 #endif /* CONFIG_IMA_BLACKLIST_KEYRING */
 
+struct key *find_trusted_asymmetric_key(const struct asymmetric_key_id *id_0,
+					const struct asymmetric_key_id *id_1);
 
 #endif /* _KEYS_SYSTEM_KEYRING_H */
-- 
2.13.6

  parent reply	other threads:[~2017-12-30 17:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-30 17:57 [kernel-hardening] [PATCH 0/5] RFC: Public key encryption of dmesg by the kernel Dan Aloni
2017-12-30 17:57 ` Dan Aloni
2017-12-30 17:58 ` [kernel-hardening] [PATCH 1/5] crypto: fix memory leak in rsa-kcs1pad encryption Dan Aloni
2017-12-30 17:58   ` Dan Aloni
2017-12-30 17:58 ` Dan Aloni [this message]
2017-12-30 17:58   ` [PATCH 2/5] certs: allow in-kernel access of trusted keys Dan Aloni
2017-12-30 18:52   ` [kernel-hardening] " Randy Dunlap
2017-12-30 18:52     ` Randy Dunlap
2017-12-30 17:58 ` [kernel-hardening] [PATCH 3/5] kernel/printk: allow kmsg to be encrypted using public key encryption Dan Aloni
2017-12-30 17:58   ` Dan Aloni
2017-12-30 20:39   ` [kernel-hardening] " Randy Dunlap
2017-12-30 20:39     ` Randy Dunlap
2017-12-30 17:58 ` [kernel-hardening] [PATCH 4/5] tools: add dmesg decryption program Dan Aloni
2017-12-30 17:58   ` Dan Aloni
2017-12-30 20:20   ` [kernel-hardening] " Randy Dunlap
2017-12-30 20:20     ` Randy Dunlap
2017-12-30 17:58 ` [kernel-hardening] [PATCH 5/5] docs: add dmesg encryption doc Dan Aloni
2017-12-30 17:58   ` Dan Aloni
2017-12-30 19:14   ` [kernel-hardening] " Boris Lukashev
2017-12-30 19:40   ` [kernel-hardening] " Randy Dunlap
2017-12-30 19:40     ` Randy Dunlap
2018-01-03 20:21     ` [kernel-hardening] " Dan Aloni
2018-01-03 20:21       ` Dan Aloni
2018-01-03 20:45       ` [kernel-hardening] " Randy Dunlap
2018-01-03 20:45         ` Randy Dunlap
2017-12-30 21:42 ` [kernel-hardening] [PATCH 0/5] RFC: Public key encryption of dmesg by the kernel Jann Horn
2018-01-03 20:41   ` Dan Aloni
2018-01-18 21:57 ` [kernel-hardening] " Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171230175804.7354-3-alonid@gmail.com \
    --to=dan@kernelim.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.