certs: Add wrapper function to check blacklisted binary hash
authorNayna Jain <nayna@linux.ibm.com>
Thu, 31 Oct 2019 03:31:31 +0000 (23:31 -0400)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 12 Nov 2019 01:25:50 +0000 (12:25 +1100)
The -EKEYREJECTED error returned by existing is_hash_blacklisted() is
misleading when called for checking against blacklisted hash of a
binary.

This patch adds a wrapper function is_binary_blacklisted() to return
-EPERM error if binary is blacklisted.

Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1572492694-6520-7-git-send-email-zohar@linux.ibm.com
certs/blacklist.c
include/keys/system_keyring.h

index ec00bf337eb673b28bced4f1521d9d0a007a0c2e..6514f9ebc943f4e7e8cd2f3ceba36da0762c269a 100644 (file)
@@ -135,6 +135,15 @@ int is_hash_blacklisted(const u8 *hash, size_t hash_len, const char *type)
 }
 EXPORT_SYMBOL_GPL(is_hash_blacklisted);
 
+int is_binary_blacklisted(const u8 *hash, size_t hash_len)
+{
+       if (is_hash_blacklisted(hash, hash_len, "bin") == -EKEYREJECTED)
+               return -EPERM;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(is_binary_blacklisted);
+
 /*
  * Initialise the blacklist
  */
index c1a96fdf598bc26346e5581769736cdfbf574b12..fb8b07daa9d15519370e1731b8cf4c726bf83a17 100644 (file)
@@ -35,12 +35,18 @@ extern int restrict_link_by_builtin_and_secondary_trusted(
 extern int mark_hash_blacklisted(const char *hash);
 extern int is_hash_blacklisted(const u8 *hash, size_t hash_len,
                               const char *type);
+extern int is_binary_blacklisted(const u8 *hash, size_t hash_len);
 #else
 static inline int is_hash_blacklisted(const u8 *hash, size_t hash_len,
                                      const char *type)
 {
        return 0;
 }
+
+static inline int is_binary_blacklisted(const u8 *hash, size_t hash_len)
+{
+       return 0;
+}
 #endif
 
 #ifdef CONFIG_IMA_BLACKLIST_KEYRING