diff options
| -rw-r--r-- | include/keys/system_keyring.h | 13 | ||||
| -rw-r--r-- | security/integrity/digsig.c | 30 | ||||
| -rw-r--r-- | security/integrity/ima/Kconfig | 36 | ||||
| -rw-r--r-- | security/integrity/ima/Makefile | 2 | ||||
| -rw-r--r-- | security/integrity/ima/ima_mok.c | 17 |
5 files changed, 34 insertions, 64 deletions
diff --git a/include/keys/system_keyring.h b/include/keys/system_keyring.h index 614424029de7..fbd4647767e9 100644 --- a/include/keys/system_keyring.h +++ b/include/keys/system_keyring.h | |||
| @@ -33,28 +33,19 @@ extern int restrict_link_by_builtin_and_secondary_trusted( | |||
| 33 | #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted | 33 | #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted |
| 34 | #endif | 34 | #endif |
| 35 | 35 | ||
| 36 | #ifdef CONFIG_IMA_MOK_KEYRING | 36 | #ifdef CONFIG_IMA_BLACKLIST_KEYRING |
| 37 | extern struct key *ima_mok_keyring; | ||
| 38 | extern struct key *ima_blacklist_keyring; | 37 | extern struct key *ima_blacklist_keyring; |
| 39 | 38 | ||
| 40 | static inline struct key *get_ima_mok_keyring(void) | ||
| 41 | { | ||
| 42 | return ima_mok_keyring; | ||
| 43 | } | ||
| 44 | static inline struct key *get_ima_blacklist_keyring(void) | 39 | static inline struct key *get_ima_blacklist_keyring(void) |
| 45 | { | 40 | { |
| 46 | return ima_blacklist_keyring; | 41 | return ima_blacklist_keyring; |
| 47 | } | 42 | } |
| 48 | #else | 43 | #else |
| 49 | static inline struct key *get_ima_mok_keyring(void) | ||
| 50 | { | ||
| 51 | return NULL; | ||
| 52 | } | ||
| 53 | static inline struct key *get_ima_blacklist_keyring(void) | 44 | static inline struct key *get_ima_blacklist_keyring(void) |
| 54 | { | 45 | { |
| 55 | return NULL; | 46 | return NULL; |
| 56 | } | 47 | } |
| 57 | #endif /* CONFIG_IMA_MOK_KEYRING */ | 48 | #endif /* CONFIG_IMA_BLACKLIST_KEYRING */ |
| 58 | 49 | ||
| 59 | 50 | ||
| 60 | #endif /* _KEYS_SYSTEM_KEYRING_H */ | 51 | #endif /* _KEYS_SYSTEM_KEYRING_H */ |
diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c index 98ee4c752cf5..4304372b323f 100644 --- a/security/integrity/digsig.c +++ b/security/integrity/digsig.c | |||
| @@ -42,32 +42,10 @@ static bool init_keyring __initdata = true; | |||
| 42 | static bool init_keyring __initdata; | 42 | static bool init_keyring __initdata; |
| 43 | #endif | 43 | #endif |
| 44 | 44 | ||
| 45 | #ifdef CONFIG_SYSTEM_TRUSTED_KEYRING | 45 | #ifdef CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY |
| 46 | /* | 46 | #define restrict_link_to_ima restrict_link_by_builtin_and_secondary_trusted |
| 47 | * Restrict the addition of keys into the IMA keyring. | ||
| 48 | * | ||
| 49 | * Any key that needs to go in .ima keyring must be signed by CA in | ||
| 50 | * either .system or .ima_mok keyrings. | ||
| 51 | */ | ||
| 52 | static int restrict_link_by_ima_mok(struct key *keyring, | ||
| 53 | const struct key_type *type, | ||
| 54 | const union key_payload *payload) | ||
| 55 | { | ||
| 56 | int ret; | ||
| 57 | |||
| 58 | ret = restrict_link_by_builtin_trusted(keyring, type, payload); | ||
| 59 | if (ret != -ENOKEY) | ||
| 60 | return ret; | ||
| 61 | |||
| 62 | return restrict_link_by_signature(get_ima_mok_keyring(), | ||
| 63 | type, payload); | ||
| 64 | } | ||
| 65 | #else | 47 | #else |
| 66 | /* | 48 | #define restrict_link_to_ima restrict_link_by_builtin_trusted |
| 67 | * If there's no system trusted keyring, then keys cannot be loaded into | ||
| 68 | * .ima_mok and added keys cannot be marked trusted. | ||
| 69 | */ | ||
| 70 | #define restrict_link_by_ima_mok restrict_link_reject | ||
| 71 | #endif | 49 | #endif |
| 72 | 50 | ||
| 73 | int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, | 51 | int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, |
| @@ -114,7 +92,7 @@ int __init integrity_init_keyring(const unsigned int id) | |||
| 114 | KEY_USR_VIEW | KEY_USR_READ | | 92 | KEY_USR_VIEW | KEY_USR_READ | |
| 115 | KEY_USR_WRITE | KEY_USR_SEARCH), | 93 | KEY_USR_WRITE | KEY_USR_SEARCH), |
| 116 | KEY_ALLOC_NOT_IN_QUOTA, | 94 | KEY_ALLOC_NOT_IN_QUOTA, |
| 117 | restrict_link_by_ima_mok, NULL); | 95 | restrict_link_to_ima, NULL); |
| 118 | if (IS_ERR(keyring[id])) { | 96 | if (IS_ERR(keyring[id])) { |
| 119 | err = PTR_ERR(keyring[id]); | 97 | err = PTR_ERR(keyring[id]); |
| 120 | pr_info("Can't allocate %s keyring (%d)\n", | 98 | pr_info("Can't allocate %s keyring (%d)\n", |
diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig index e54a8a8dae94..5487827fa86c 100644 --- a/security/integrity/ima/Kconfig +++ b/security/integrity/ima/Kconfig | |||
| @@ -155,23 +155,33 @@ config IMA_TRUSTED_KEYRING | |||
| 155 | 155 | ||
| 156 | This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING | 156 | This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING |
| 157 | 157 | ||
| 158 | config IMA_MOK_KEYRING | 158 | config IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY |
| 159 | bool "Create IMA machine owner keys (MOK) and blacklist keyrings" | 159 | bool "Permit keys validly signed by a built-in or secondary CA cert (EXPERIMENTAL)" |
| 160 | depends on SYSTEM_TRUSTED_KEYRING | ||
| 161 | depends on SECONDARY_TRUSTED_KEYRING | ||
| 162 | depends on INTEGRITY_ASYMMETRIC_KEYS | ||
| 163 | select INTEGRITY_TRUSTED_KEYRING | ||
| 164 | default n | ||
| 165 | help | ||
| 166 | Keys may be added to the IMA or IMA blacklist keyrings, if the | ||
| 167 | key is validly signed by a CA cert in the system built-in or | ||
| 168 | secondary trusted keyrings. | ||
| 169 | |||
| 170 | Intermediate keys between those the kernel has compiled in and the | ||
| 171 | IMA keys to be added may be added to the system secondary keyring, | ||
| 172 | provided they are validly signed by a key already resident in the | ||
| 173 | built-in or secondary trusted keyrings. | ||
| 174 | |||
| 175 | config IMA_BLACKLIST_KEYRING | ||
| 176 | bool "Create IMA machine owner blacklist keyrings (EXPERIMENTAL)" | ||
| 160 | depends on SYSTEM_TRUSTED_KEYRING | 177 | depends on SYSTEM_TRUSTED_KEYRING |
| 161 | depends on IMA_TRUSTED_KEYRING | 178 | depends on IMA_TRUSTED_KEYRING |
| 162 | default n | 179 | default n |
| 163 | help | 180 | help |
| 164 | This option creates IMA MOK and blacklist keyrings. IMA MOK is an | 181 | This option creates an IMA blacklist keyring, which contains all |
| 165 | intermediate keyring that sits between .system and .ima keyrings, | 182 | revoked IMA keys. It is consulted before any other keyring. If |
| 166 | effectively forming a simple CA hierarchy. To successfully import a | 183 | the search is successful the requested operation is rejected and |
| 167 | key into .ima_mok it must be signed by a key which CA is in .system | 184 | an error is returned to the caller. |
| 168 | keyring. On turn any key that needs to go in .ima keyring must be | ||
| 169 | signed by CA in either .system or .ima_mok keyrings. IMA MOK is empty | ||
| 170 | at kernel boot. | ||
| 171 | |||
| 172 | IMA blacklist keyring contains all revoked IMA keys. It is consulted | ||
| 173 | before any other keyring. If the search is successful the requested | ||
| 174 | operation is rejected and error is returned to the caller. | ||
| 175 | 185 | ||
| 176 | config IMA_LOAD_X509 | 186 | config IMA_LOAD_X509 |
| 177 | bool "Load X509 certificate onto the '.ima' trusted keyring" | 187 | bool "Load X509 certificate onto the '.ima' trusted keyring" |
diff --git a/security/integrity/ima/Makefile b/security/integrity/ima/Makefile index a8539f9e060f..9aeaedad1e2b 100644 --- a/security/integrity/ima/Makefile +++ b/security/integrity/ima/Makefile | |||
| @@ -8,4 +8,4 @@ obj-$(CONFIG_IMA) += ima.o | |||
| 8 | ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ | 8 | ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ |
| 9 | ima_policy.o ima_template.o ima_template_lib.o | 9 | ima_policy.o ima_template.o ima_template_lib.o |
| 10 | ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o | 10 | ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o |
| 11 | obj-$(CONFIG_IMA_MOK_KEYRING) += ima_mok.o | 11 | obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o |
diff --git a/security/integrity/ima/ima_mok.c b/security/integrity/ima/ima_mok.c index 2988726d30d6..74a279957464 100644 --- a/security/integrity/ima/ima_mok.c +++ b/security/integrity/ima/ima_mok.c | |||
| @@ -20,23 +20,14 @@ | |||
| 20 | #include <keys/system_keyring.h> | 20 | #include <keys/system_keyring.h> |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | struct key *ima_mok_keyring; | ||
| 24 | struct key *ima_blacklist_keyring; | 23 | struct key *ima_blacklist_keyring; |
| 25 | 24 | ||
| 26 | /* | 25 | /* |
| 27 | * Allocate the IMA MOK and blacklist keyrings | 26 | * Allocate the IMA blacklist keyring |
| 28 | */ | 27 | */ |
| 29 | __init int ima_mok_init(void) | 28 | __init int ima_mok_init(void) |
| 30 | { | 29 | { |
| 31 | pr_notice("Allocating IMA MOK and blacklist keyrings.\n"); | 30 | pr_notice("Allocating IMA blacklist keyring.\n"); |
| 32 | |||
| 33 | ima_mok_keyring = keyring_alloc(".ima_mok", | ||
| 34 | KUIDT_INIT(0), KGIDT_INIT(0), current_cred(), | ||
| 35 | (KEY_POS_ALL & ~KEY_POS_SETATTR) | | ||
| 36 | KEY_USR_VIEW | KEY_USR_READ | | ||
| 37 | KEY_USR_WRITE | KEY_USR_SEARCH, | ||
| 38 | KEY_ALLOC_NOT_IN_QUOTA, | ||
| 39 | restrict_link_by_builtin_trusted, NULL); | ||
| 40 | 31 | ||
| 41 | ima_blacklist_keyring = keyring_alloc(".ima_blacklist", | 32 | ima_blacklist_keyring = keyring_alloc(".ima_blacklist", |
| 42 | KUIDT_INIT(0), KGIDT_INIT(0), current_cred(), | 33 | KUIDT_INIT(0), KGIDT_INIT(0), current_cred(), |
| @@ -46,8 +37,8 @@ __init int ima_mok_init(void) | |||
| 46 | KEY_ALLOC_NOT_IN_QUOTA, | 37 | KEY_ALLOC_NOT_IN_QUOTA, |
| 47 | restrict_link_by_builtin_trusted, NULL); | 38 | restrict_link_by_builtin_trusted, NULL); |
| 48 | 39 | ||
| 49 | if (IS_ERR(ima_mok_keyring) || IS_ERR(ima_blacklist_keyring)) | 40 | if (IS_ERR(ima_blacklist_keyring)) |
| 50 | panic("Can't allocate IMA MOK or blacklist keyrings."); | 41 | panic("Can't allocate IMA blacklist keyring."); |
| 51 | 42 | ||
| 52 | set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags); | 43 | set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags); |
| 53 | return 0; | 44 | return 0; |
