hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/certs/blacklist.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* System hash blacklist.
23 *
34 * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
45 * Written by David Howells (dhowells@redhat.com)
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public Licence
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the Licence, or (at your option) any later version.
106 */
117
128 #define pr_fmt(fmt) "blacklist: "fmt
....@@ -20,8 +16,14 @@
2016 #include <linux/seq_file.h>
2117 #include <keys/system_keyring.h>
2218 #include "blacklist.h"
19
+#include "common.h"
2320
2421 static struct key *blacklist_keyring;
22
+
23
+#ifdef CONFIG_SYSTEM_REVOCATION_LIST
24
+extern __initconst const u8 revocation_certificate_list[];
25
+extern __initconst const unsigned long revocation_certificate_list_size;
26
+#endif
2527
2628 /*
2729 * The description must be a type prefix, a colon and then an even number of
....@@ -128,7 +130,7 @@
128130 *p = 0;
129131
130132 kref = keyring_search(make_key_ref(blacklist_keyring, true),
131
- &key_type_blacklist, buffer);
133
+ &key_type_blacklist, buffer, false);
132134 if (!IS_ERR(kref)) {
133135 key_ref_put(kref);
134136 ret = -EKEYREJECTED;
....@@ -138,6 +140,58 @@
138140 return ret;
139141 }
140142 EXPORT_SYMBOL_GPL(is_hash_blacklisted);
143
+
144
+int is_binary_blacklisted(const u8 *hash, size_t hash_len)
145
+{
146
+ if (is_hash_blacklisted(hash, hash_len, "bin") == -EKEYREJECTED)
147
+ return -EPERM;
148
+
149
+ return 0;
150
+}
151
+EXPORT_SYMBOL_GPL(is_binary_blacklisted);
152
+
153
+#ifdef CONFIG_SYSTEM_REVOCATION_LIST
154
+/**
155
+ * add_key_to_revocation_list - Add a revocation certificate to the blacklist
156
+ * @data: The data blob containing the certificate
157
+ * @size: The size of data blob
158
+ */
159
+int add_key_to_revocation_list(const char *data, size_t size)
160
+{
161
+ key_ref_t key;
162
+
163
+ key = key_create_or_update(make_key_ref(blacklist_keyring, true),
164
+ "asymmetric",
165
+ NULL,
166
+ data,
167
+ size,
168
+ ((KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW),
169
+ KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_BUILT_IN);
170
+
171
+ if (IS_ERR(key)) {
172
+ pr_err("Problem with revocation key (%ld)\n", PTR_ERR(key));
173
+ return PTR_ERR(key);
174
+ }
175
+
176
+ return 0;
177
+}
178
+
179
+/**
180
+ * is_key_on_revocation_list - Determine if the key for a PKCS#7 message is revoked
181
+ * @pkcs7: The PKCS#7 message to check
182
+ */
183
+int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
184
+{
185
+ int ret;
186
+
187
+ ret = pkcs7_validate_trust(pkcs7, blacklist_keyring);
188
+
189
+ if (ret == 0)
190
+ return -EKEYREJECTED;
191
+
192
+ return -ENOKEY;
193
+}
194
+#endif
141195
142196 /*
143197 * Initialise the blacklist
....@@ -172,3 +226,18 @@
172226 * Must be initialised before we try and load the keys into the keyring.
173227 */
174228 device_initcall(blacklist_init);
229
+
230
+#ifdef CONFIG_SYSTEM_REVOCATION_LIST
231
+/*
232
+ * Load the compiled-in list of revocation X.509 certificates.
233
+ */
234
+static __init int load_revocation_certificate_list(void)
235
+{
236
+ if (revocation_certificate_list_size)
237
+ pr_notice("Loading compiled-in revocation X.509 certificates\n");
238
+
239
+ return load_certificate_list(revocation_certificate_list, revocation_certificate_list_size,
240
+ blacklist_keyring);
241
+}
242
+late_initcall(load_revocation_certificate_list);
243
+#endif