ea38f2f
From 2a54526850121cd0d7cf649a321488b4dab5731d Mon Sep 17 00:00:00 2001
6a91557
From: Josh Boyer <jwboyer@fedoraproject.org>
6a91557
Date: Fri, 26 Oct 2012 12:36:24 -0400
ea38f2f
Subject: [PATCH 17/20] KEYS: Add a system blacklist keyring
6a91557
6a91557
This adds an additional keyring that is used to store certificates that
6a91557
are blacklisted.  This keyring is searched first when loading signed modules
6a91557
and if the module's certificate is found, it will refuse to load.  This is
6a91557
useful in cases where third party certificates are used for module signing.
6a91557
6a91557
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
6a91557
---
42d2805
 certs/system_keyring.c        | 22 ++++++++++++++++++++++
6a91557
 include/keys/system_keyring.h |  4 ++++
6a91557
 init/Kconfig                  |  9 +++++++++
42d2805
 3 files changed, 35 insertions(+)
6a91557
18c8249
diff --git a/certs/system_keyring.c b/certs/system_keyring.c
42d2805
index 50979d6dcecd..787eeead2f57 100644
18c8249
--- a/certs/system_keyring.c
18c8249
+++ b/certs/system_keyring.c
42d2805
@@ -22,6 +22,9 @@ static struct key *builtin_trusted_keys;
42d2805
 #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
42d2805
 static struct key *secondary_trusted_keys;
42d2805
 #endif
6a91557
+#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
6a91557
+struct key *system_blacklist_keyring;
6a91557
+#endif
6a91557
 
6a91557
 extern __initconst const u8 system_certificate_list[];
6a91557
 extern __initconst const unsigned long system_certificate_list_size;
42d2805
@@ -99,6 +102,16 @@ static __init int system_trusted_keyring_init(void)
42d2805
 	if (key_link(secondary_trusted_keys, builtin_trusted_keys) < 0)
42d2805
 		panic("Can't link trusted keyrings\n");
42d2805
 #endif
42d2805
+#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
6a91557
+	system_blacklist_keyring = keyring_alloc(".system_blacklist_keyring",
42d2805
+			KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
42d2805
+			((KEY_POS_ALL & ~KEY_POS_SETATTR) |
42d2805
+			 KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH),
42d2805
+			KEY_ALLOC_NOT_IN_QUOTA,
42d2805
+			NULL, NULL);
6a91557
+	if (IS_ERR(system_blacklist_keyring))
6a91557
+		panic("Can't allocate system blacklist keyring\n");
6a91557
+#endif
42d2805
 
6a91557
 	return 0;
6a91557
 }
42d2805
@@ -214,6 +227,15 @@ int verify_pkcs7_signature(const void *data, size_t len,
42d2805
 		trusted_keys = builtin_trusted_keys;
42d2805
 #endif
42d2805
 	}
18c8249
+#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
42d2805
+	ret = pkcs7_validate_trust(pkcs7, system_blacklist_keyring);
18c8249
+	if (!ret) {
18c8249
+		/* module is signed with a cert in the blacklist.  reject */
18c8249
+		pr_err("Module key is in the blacklist\n");
18c8249
+		ret = -EKEYREJECTED;
18c8249
+		goto error;
18c8249
+	}
18c8249
+#endif
42d2805
 	ret = pkcs7_validate_trust(pkcs7, trusted_keys);
42d2805
 	if (ret < 0) {
42d2805
 		if (ret == -ENOKEY)
18c8249
diff --git a/include/keys/system_keyring.h b/include/keys/system_keyring.h
42d2805
index fbd4647767e9..5bc291a3d261 100644
18c8249
--- a/include/keys/system_keyring.h
18c8249
+++ b/include/keys/system_keyring.h
42d2805
@@ -33,6 +33,10 @@ extern int restrict_link_by_builtin_and_secondary_trusted(
42d2805
 #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
18c8249
 #endif
18c8249
 
18c8249
+#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
18c8249
+extern struct key *system_blacklist_keyring;
18c8249
+#endif
18c8249
+
42d2805
 #ifdef CONFIG_IMA_BLACKLIST_KEYRING
42aa432
 extern struct key *ima_blacklist_keyring;
42d2805
 
18c8249
diff --git a/init/Kconfig b/init/Kconfig
ea38f2f
index 34407f15e6d3..461ad575a608 100644
18c8249
--- a/init/Kconfig
18c8249
+++ b/init/Kconfig
ea38f2f
@@ -1859,6 +1859,15 @@ config SYSTEM_DATA_VERIFICATION
18c8249
 	  module verification, kexec image verification and firmware blob
18c8249
 	  verification.
18c8249
 
18c8249
+config SYSTEM_BLACKLIST_KEYRING
18c8249
+	bool "Provide system-wide ring of blacklisted keys"
18c8249
+	depends on KEYS
18c8249
+	help
18c8249
+	  Provide a system keyring to which blacklisted keys can be added.
18c8249
+	  Keys in the keyring are considered entirely untrusted.  Keys in this
18c8249
+	  keyring are used by the module signature checking to reject loading
18c8249
+	  of modules signed with a blacklisted key.
18c8249
+
18c8249
 config PROFILING
18c8249
 	bool "Profiling support"
18c8249
 	help
18c8249
-- 
ea38f2f
2.9.3
18c8249