18c8249
From f630ce576114bfede02d8a0bafa97e4d6f978a74 Mon Sep 17 00:00:00 2001
6a91557
From: Josh Boyer <jwboyer@fedoraproject.org>
6a91557
Date: Fri, 26 Oct 2012 12:36:24 -0400
18c8249
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
---
18c8249
 certs/system_keyring.c        | 27 +++++++++++++++++++++++++++
6a91557
 include/keys/system_keyring.h |  4 ++++
6a91557
 init/Kconfig                  |  9 +++++++++
18c8249
 3 files changed, 40 insertions(+)
6a91557
18c8249
diff --git a/certs/system_keyring.c b/certs/system_keyring.c
18c8249
index 2570598b784d..53733822993f 100644
18c8249
--- a/certs/system_keyring.c
18c8249
+++ b/certs/system_keyring.c
6a91557
@@ -20,6 +20,9 @@
6a91557
 
6a91557
 struct key *system_trusted_keyring;
6a91557
 EXPORT_SYMBOL_GPL(system_trusted_keyring);
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;
6a91557
@@ -41,6 +44,20 @@ static __init int system_trusted_keyring_init(void)
6a91557
 		panic("Can't allocate system trusted keyring\n");
6a91557
 
6a91557
 	set_bit(KEY_FLAG_TRUSTED_ONLY, &system_trusted_keyring->flags);
6a91557
+
18c8249
+	#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
6a91557
+	system_blacklist_keyring = keyring_alloc(".system_blacklist_keyring",
6a91557
+				    KUIDT_INIT(0), KGIDT_INIT(0),
6a91557
+				    current_cred(),
6a91557
+				    (KEY_POS_ALL & ~KEY_POS_SETATTR) |
6a91557
+				    KEY_USR_VIEW | KEY_USR_READ,
6a91557
+				    KEY_ALLOC_NOT_IN_QUOTA, NULL);
6a91557
+	if (IS_ERR(system_blacklist_keyring))
6a91557
+		panic("Can't allocate system blacklist keyring\n");
6a91557
+
6a91557
+	set_bit(KEY_FLAG_TRUSTED_ONLY, &system_blacklist_keyring->flags);
6a91557
+#endif
6a91557
+
6a91557
 	return 0;
6a91557
 }
6a91557
 
18c8249
@@ -138,6 +155,16 @@ int system_verify_data(const void *data, unsigned long len,
18c8249
 	if (ret < 0)
18c8249
 		goto error;
18c8249
 
18c8249
+#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
18c8249
+	ret = pkcs7_validate_trust(pkcs7, system_blacklist_keyring, &trusted);
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
18c8249
+
18c8249
 	ret = pkcs7_validate_trust(pkcs7, system_trusted_keyring, &trusted);
18c8249
 	if (ret < 0)
18c8249
 		goto error;
18c8249
diff --git a/include/keys/system_keyring.h b/include/keys/system_keyring.h
18c8249
index b20cd885c1fd..51d8ddc60e0f 100644
18c8249
--- a/include/keys/system_keyring.h
18c8249
+++ b/include/keys/system_keyring.h
42aa432
@@ -35,6 +35,10 @@ extern int system_verify_data(const void *data, unsigned long len,
18c8249
 			      enum key_being_used_for usage);
18c8249
 #endif
18c8249
 
18c8249
+#ifdef CONFIG_SYSTEM_BLACKLIST_KEYRING
18c8249
+extern struct key *system_blacklist_keyring;
18c8249
+#endif
18c8249
+
42aa432
 #ifdef CONFIG_IMA_MOK_KEYRING
42aa432
 extern struct key *ima_mok_keyring;
42aa432
 extern struct key *ima_blacklist_keyring;
18c8249
diff --git a/init/Kconfig b/init/Kconfig
18c8249
index 02da9f1fd9df..782d26f02885 100644
18c8249
--- a/init/Kconfig
18c8249
+++ b/init/Kconfig
18c8249
@@ -1783,6 +1783,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
-- 
18c8249
2.4.3
18c8249