Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
[platform/kernel/linux-rpi.git] / certs / system_keyring.c
index b348e08..9de610b 100644 (file)
@@ -152,6 +152,36 @@ static __init struct key_restriction *get_builtin_and_secondary_restriction(void
 
        return restriction;
 }
+
+/**
+ * add_to_secondary_keyring - Add to secondary keyring.
+ * @source: Source of key
+ * @data: The blob holding the key
+ * @len: The length of the data blob
+ *
+ * Add a key to the secondary keyring. The key must be vouched for by a key in the builtin,
+ * machine or secondary keyring itself.
+ */
+void __init add_to_secondary_keyring(const char *source, const void *data, size_t len)
+{
+       key_ref_t key;
+       key_perm_t perm;
+
+       perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW;
+
+       key = key_create_or_update(make_key_ref(secondary_trusted_keys, 1),
+                                  "asymmetric",
+                                  NULL, data, len, perm,
+                                  KEY_ALLOC_NOT_IN_QUOTA);
+       if (IS_ERR(key)) {
+               pr_err("Problem loading X.509 certificate from %s to secondary keyring %ld\n",
+                      source, PTR_ERR(key));
+               return;
+       }
+
+       pr_notice("Loaded X.509 cert '%s'\n", key_ref_to_ptr(key)->description);
+       key_ref_put(key);
+}
 #endif
 #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
 void __init set_machine_trusted_keys(struct key *keyring)
@@ -300,6 +330,12 @@ int verify_pkcs7_message_sig(const void *data, size_t len,
        if (ret < 0)
                goto error;
 
+       ret = is_key_on_revocation_list(pkcs7);
+       if (ret != -ENOKEY) {
+               pr_devel("PKCS#7 key is on revocation list\n");
+               goto error;
+       }
+
        if (!trusted_keys) {
                trusted_keys = builtin_trusted_keys;
        } else if (trusted_keys == VERIFY_USE_SECONDARY_KEYRING) {
@@ -319,12 +355,6 @@ int verify_pkcs7_message_sig(const void *data, size_t len,
                        pr_devel("PKCS#7 platform keyring is not available\n");
                        goto error;
                }
-
-               ret = is_key_on_revocation_list(pkcs7);
-               if (ret != -ENOKEY) {
-                       pr_devel("PKCS#7 platform key is on revocation list\n");
-                       goto error;
-               }
        }
        ret = pkcs7_validate_trust(pkcs7, trusted_keys);
        if (ret < 0) {