|
18 | 18 | #include <keys/system_keyring.h>
|
19 | 19 | #include <crypto/pkcs7.h>
|
20 | 20 |
|
21 |
| -static struct key *system_trusted_keyring; |
| 21 | +static struct key *builtin_trusted_keys; |
| 22 | +#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
| 23 | +static struct key *secondary_trusted_keys; |
| 24 | +#endif |
22 | 25 |
|
23 | 26 | extern __initconst const u8 system_certificate_list[];
|
24 | 27 | extern __initconst const unsigned long system_certificate_list_size;
|
25 | 28 |
|
26 | 29 | /**
|
27 |
| - * restrict_link_by_builtin_trusted - Restrict keyring addition by system CA |
| 30 | + * restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA |
28 | 31 | *
|
29 | 32 | * Restrict the addition of keys into a keyring based on the key-to-be-added
|
30 |
| - * being vouched for by a key in the system keyring. |
| 33 | + * being vouched for by a key in the built in system keyring. |
31 | 34 | */
|
32 | 35 | int restrict_link_by_builtin_trusted(struct key *keyring,
|
33 | 36 | const struct key_type *type,
|
34 | 37 | const union key_payload *payload)
|
35 | 38 | {
|
36 |
| - return restrict_link_by_signature(system_trusted_keyring, |
37 |
| - type, payload); |
| 39 | + return restrict_link_by_signature(builtin_trusted_keys, type, payload); |
38 | 40 | }
|
39 | 41 |
|
| 42 | +#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
| 43 | +/** |
| 44 | + * restrict_link_by_builtin_and_secondary_trusted - Restrict keyring |
| 45 | + * addition by both builtin and secondary keyrings |
| 46 | + * |
| 47 | + * Restrict the addition of keys into a keyring based on the key-to-be-added |
| 48 | + * being vouched for by a key in either the built-in or the secondary system |
| 49 | + * keyrings. |
| 50 | + */ |
| 51 | +int restrict_link_by_builtin_and_secondary_trusted( |
| 52 | + struct key *keyring, |
| 53 | + const struct key_type *type, |
| 54 | + const union key_payload *payload) |
| 55 | +{ |
| 56 | + /* If we have a secondary trusted keyring, then that contains a link |
| 57 | + * through to the builtin keyring and the search will follow that link. |
| 58 | + */ |
| 59 | + if (type == &key_type_keyring && |
| 60 | + keyring == secondary_trusted_keys && |
| 61 | + payload == &builtin_trusted_keys->payload) |
| 62 | + /* Allow the builtin keyring to be added to the secondary */ |
| 63 | + return 0; |
| 64 | + |
| 65 | + return restrict_link_by_signature(secondary_trusted_keys, type, payload); |
| 66 | +} |
| 67 | +#endif |
| 68 | + |
40 | 69 | /*
|
41 |
| - * Load the compiled-in keys |
| 70 | + * Create the trusted keyrings |
42 | 71 | */
|
43 | 72 | static __init int system_trusted_keyring_init(void)
|
44 | 73 | {
|
45 |
| - pr_notice("Initialise system trusted keyring\n"); |
| 74 | + pr_notice("Initialise system trusted keyrings\n"); |
46 | 75 |
|
47 |
| - system_trusted_keyring = |
48 |
| - keyring_alloc(".system_keyring", |
| 76 | + builtin_trusted_keys = |
| 77 | + keyring_alloc(".builtin_trusted_keys", |
49 | 78 | KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
|
50 | 79 | ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
|
51 | 80 | KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH),
|
52 | 81 | KEY_ALLOC_NOT_IN_QUOTA,
|
53 |
| - restrict_link_by_builtin_trusted, NULL); |
54 |
| - if (IS_ERR(system_trusted_keyring)) |
55 |
| - panic("Can't allocate system trusted keyring\n"); |
| 82 | + NULL, NULL); |
| 83 | + if (IS_ERR(builtin_trusted_keys)) |
| 84 | + panic("Can't allocate builtin trusted keyring\n"); |
| 85 | + |
| 86 | +#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
| 87 | + secondary_trusted_keys = |
| 88 | + keyring_alloc(".secondary_trusted_keys", |
| 89 | + KUIDT_INIT(0), KGIDT_INIT(0), current_cred(), |
| 90 | + ((KEY_POS_ALL & ~KEY_POS_SETATTR) | |
| 91 | + KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH | |
| 92 | + KEY_USR_WRITE), |
| 93 | + KEY_ALLOC_NOT_IN_QUOTA, |
| 94 | + restrict_link_by_builtin_and_secondary_trusted, |
| 95 | + NULL); |
| 96 | + if (IS_ERR(secondary_trusted_keys)) |
| 97 | + panic("Can't allocate secondary trusted keyring\n"); |
| 98 | + |
| 99 | + if (key_link(secondary_trusted_keys, builtin_trusted_keys) < 0) |
| 100 | + panic("Can't link trusted keyrings\n"); |
| 101 | +#endif |
| 102 | + |
56 | 103 | return 0;
|
57 | 104 | }
|
58 | 105 |
|
@@ -88,7 +135,7 @@ static __init int load_system_certificate_list(void)
|
88 | 135 | if (plen > end - p)
|
89 | 136 | goto dodgy_cert;
|
90 | 137 |
|
91 |
| - key = key_create_or_update(make_key_ref(system_trusted_keyring, 1), |
| 138 | + key = key_create_or_update(make_key_ref(builtin_trusted_keys, 1), |
92 | 139 | "asymmetric",
|
93 | 140 | NULL,
|
94 | 141 | p,
|
@@ -125,7 +172,8 @@ late_initcall(load_system_certificate_list);
|
125 | 172 | * @len: Size of @data.
|
126 | 173 | * @raw_pkcs7: The PKCS#7 message that is the signature.
|
127 | 174 | * @pkcs7_len: The size of @raw_pkcs7.
|
128 |
| - * @trusted_keys: Trusted keys to use (NULL for system_trusted_keyring). |
| 175 | + * @trusted_keys: Trusted keys to use (NULL for builtin trusted keys only, |
| 176 | + * (void *)1UL for all trusted keys). |
129 | 177 | * @usage: The use to which the key is being put.
|
130 | 178 | * @view_content: Callback to gain access to content.
|
131 | 179 | * @ctx: Context for callback.
|
@@ -157,8 +205,15 @@ int verify_pkcs7_signature(const void *data, size_t len,
|
157 | 205 | if (ret < 0)
|
158 | 206 | goto error;
|
159 | 207 |
|
160 |
| - if (!trusted_keys) |
161 |
| - trusted_keys = system_trusted_keyring; |
| 208 | + if (!trusted_keys) { |
| 209 | + trusted_keys = builtin_trusted_keys; |
| 210 | + } else if (trusted_keys == (void *)1UL) { |
| 211 | +#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING |
| 212 | + trusted_keys = secondary_trusted_keys; |
| 213 | +#else |
| 214 | + trusted_keys = builtin_trusted_keys; |
| 215 | +#endif |
| 216 | + } |
162 | 217 | ret = pkcs7_validate_trust(pkcs7, trusted_keys);
|
163 | 218 | if (ret < 0) {
|
164 | 219 | if (ret == -ENOKEY)
|
|
0 commit comments