diff options
author | Thiago Jung Bauermann <bauerman@linux.ibm.com> | 2019-06-27 22:19:28 -0400 |
---|---|---|
committer | Mimi Zohar <zohar@linux.ibm.com> | 2019-08-05 18:40:21 -0400 |
commit | 9044d627fd18f9fca49b62d4619ee14914b91464 (patch) | |
tree | db035dc7773f8b8509f87115f510ed340aef7b52 | |
parent | cf38fed1e183dd2410f62d49ae635fe593082f0c (diff) |
ima: Add modsig appraise_type option for module-style appended signatures
Introduce the modsig keyword to the IMA policy syntax to specify that
a given hook should expect the file to have the IMA signature appended
to it. Here is how it can be used in a rule:
appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig
With this rule, IMA will accept either a signature stored in the extended
attribute or an appended signature.
For now, the rule above will behave exactly the same as if
appraise_type=imasig was specified. The actual modsig implementation
will be introduced separately.
Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
-rw-r--r-- | Documentation/ABI/testing/ima_policy | 6 | ||||
-rw-r--r-- | security/integrity/ima/Kconfig | 10 | ||||
-rw-r--r-- | security/integrity/ima/Makefile | 1 | ||||
-rw-r--r-- | security/integrity/ima/ima.h | 9 | ||||
-rw-r--r-- | security/integrity/ima/ima_modsig.c | 31 | ||||
-rw-r--r-- | security/integrity/ima/ima_policy.c | 12 | ||||
-rw-r--r-- | security/integrity/integrity.h | 1 |
7 files changed, 67 insertions, 3 deletions
diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index fc376a323908..29ebe9afdac4 100644 --- a/Documentation/ABI/testing/ima_policy +++ b/Documentation/ABI/testing/ima_policy | |||
@@ -37,7 +37,7 @@ Description: | |||
37 | euid:= decimal value | 37 | euid:= decimal value |
38 | fowner:= decimal value | 38 | fowner:= decimal value |
39 | lsm: are LSM specific | 39 | lsm: are LSM specific |
40 | option: appraise_type:= [imasig] | 40 | option: appraise_type:= [imasig] [imasig|modsig] |
41 | template:= name of a defined IMA template type | 41 | template:= name of a defined IMA template type |
42 | (eg, ima-ng). Only valid when action is "measure". | 42 | (eg, ima-ng). Only valid when action is "measure". |
43 | pcr:= decimal value | 43 | pcr:= decimal value |
@@ -105,3 +105,7 @@ Description: | |||
105 | 105 | ||
106 | measure func=KEXEC_KERNEL_CHECK pcr=4 | 106 | measure func=KEXEC_KERNEL_CHECK pcr=4 |
107 | measure func=KEXEC_INITRAMFS_CHECK pcr=5 | 107 | measure func=KEXEC_INITRAMFS_CHECK pcr=5 |
108 | |||
109 | Example of appraise rule allowing modsig appended signatures: | ||
110 | |||
111 | appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig | ||
diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig index 2ced99dde694..8bf46646b185 100644 --- a/security/integrity/ima/Kconfig +++ b/security/integrity/ima/Kconfig | |||
@@ -233,6 +233,16 @@ config IMA_APPRAISE_BOOTPARAM | |||
233 | This option enables the different "ima_appraise=" modes | 233 | This option enables the different "ima_appraise=" modes |
234 | (eg. fix, log) from the boot command line. | 234 | (eg. fix, log) from the boot command line. |
235 | 235 | ||
236 | config IMA_APPRAISE_MODSIG | ||
237 | bool "Support module-style signatures for appraisal" | ||
238 | depends on IMA_APPRAISE | ||
239 | default n | ||
240 | help | ||
241 | Adds support for signatures appended to files. The format of the | ||
242 | appended signature is the same used for signed kernel modules. | ||
243 | The modsig keyword can be used in the IMA policy to allow a hook | ||
244 | to accept such signatures. | ||
245 | |||
236 | config IMA_TRUSTED_KEYRING | 246 | config IMA_TRUSTED_KEYRING |
237 | bool "Require all keys on the .ima keyring be signed (deprecated)" | 247 | bool "Require all keys on the .ima keyring be signed (deprecated)" |
238 | depends on IMA_APPRAISE && SYSTEM_TRUSTED_KEYRING | 248 | depends on IMA_APPRAISE && SYSTEM_TRUSTED_KEYRING |
diff --git a/security/integrity/ima/Makefile b/security/integrity/ima/Makefile index d921dc4f9eb0..31d57cdf2421 100644 --- a/security/integrity/ima/Makefile +++ b/security/integrity/ima/Makefile | |||
@@ -9,5 +9,6 @@ obj-$(CONFIG_IMA) += ima.o | |||
9 | ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ | 9 | ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ |
10 | ima_policy.o ima_template.o ima_template_lib.o | 10 | ima_policy.o ima_template.o ima_template_lib.o |
11 | ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o | 11 | ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o |
12 | ima-$(CONFIG_IMA_APPRAISE_MODSIG) += ima_modsig.o | ||
12 | ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o | 13 | ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o |
13 | obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o | 14 | obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o |
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 011b91c79351..e21b06942858 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h | |||
@@ -302,6 +302,15 @@ static inline int ima_read_xattr(struct dentry *dentry, | |||
302 | 302 | ||
303 | #endif /* CONFIG_IMA_APPRAISE */ | 303 | #endif /* CONFIG_IMA_APPRAISE */ |
304 | 304 | ||
305 | #ifdef CONFIG_IMA_APPRAISE_MODSIG | ||
306 | bool ima_hook_supports_modsig(enum ima_hooks func); | ||
307 | #else | ||
308 | static inline bool ima_hook_supports_modsig(enum ima_hooks func) | ||
309 | { | ||
310 | return false; | ||
311 | } | ||
312 | #endif /* CONFIG_IMA_APPRAISE_MODSIG */ | ||
313 | |||
305 | /* LSM based policy rules require audit */ | 314 | /* LSM based policy rules require audit */ |
306 | #ifdef CONFIG_IMA_LSM_RULES | 315 | #ifdef CONFIG_IMA_LSM_RULES |
307 | 316 | ||
diff --git a/security/integrity/ima/ima_modsig.c b/security/integrity/ima/ima_modsig.c new file mode 100644 index 000000000000..87503bfe8c8b --- /dev/null +++ b/security/integrity/ima/ima_modsig.c | |||
@@ -0,0 +1,31 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0+ | ||
2 | /* | ||
3 | * IMA support for appraising module-style appended signatures. | ||
4 | * | ||
5 | * Copyright (C) 2019 IBM Corporation | ||
6 | * | ||
7 | * Author: | ||
8 | * Thiago Jung Bauermann <bauerman@linux.ibm.com> | ||
9 | */ | ||
10 | |||
11 | #include "ima.h" | ||
12 | |||
13 | /** | ||
14 | * ima_hook_supports_modsig - can the policy allow modsig for this hook? | ||
15 | * | ||
16 | * modsig is only supported by hooks using ima_post_read_file(), because only | ||
17 | * they preload the contents of the file in a buffer. FILE_CHECK does that in | ||
18 | * some cases, but not when reached from vfs_open(). POLICY_CHECK can support | ||
19 | * it, but it's not useful in practice because it's a text file so deny. | ||
20 | */ | ||
21 | bool ima_hook_supports_modsig(enum ima_hooks func) | ||
22 | { | ||
23 | switch (func) { | ||
24 | case KEXEC_KERNEL_CHECK: | ||
25 | case KEXEC_INITRAMFS_CHECK: | ||
26 | case MODULE_CHECK: | ||
27 | return true; | ||
28 | default: | ||
29 | return false; | ||
30 | } | ||
31 | } | ||
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 36a0727f1d7a..5b6061d6bce0 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c | |||
@@ -1130,6 +1130,10 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) | |||
1130 | ima_log_string(ab, "appraise_type", args[0].from); | 1130 | ima_log_string(ab, "appraise_type", args[0].from); |
1131 | if ((strcmp(args[0].from, "imasig")) == 0) | 1131 | if ((strcmp(args[0].from, "imasig")) == 0) |
1132 | entry->flags |= IMA_DIGSIG_REQUIRED; | 1132 | entry->flags |= IMA_DIGSIG_REQUIRED; |
1133 | else if (ima_hook_supports_modsig(entry->func) && | ||
1134 | strcmp(args[0].from, "imasig|modsig") == 0) | ||
1135 | entry->flags |= IMA_DIGSIG_REQUIRED | | ||
1136 | IMA_MODSIG_ALLOWED; | ||
1133 | else | 1137 | else |
1134 | result = -EINVAL; | 1138 | result = -EINVAL; |
1135 | break; | 1139 | break; |
@@ -1449,8 +1453,12 @@ int ima_policy_show(struct seq_file *m, void *v) | |||
1449 | } | 1453 | } |
1450 | if (entry->template) | 1454 | if (entry->template) |
1451 | seq_printf(m, "template=%s ", entry->template->name); | 1455 | seq_printf(m, "template=%s ", entry->template->name); |
1452 | if (entry->flags & IMA_DIGSIG_REQUIRED) | 1456 | if (entry->flags & IMA_DIGSIG_REQUIRED) { |
1453 | seq_puts(m, "appraise_type=imasig "); | 1457 | if (entry->flags & IMA_MODSIG_ALLOWED) |
1458 | seq_puts(m, "appraise_type=imasig|modsig "); | ||
1459 | else | ||
1460 | seq_puts(m, "appraise_type=imasig "); | ||
1461 | } | ||
1454 | if (entry->flags & IMA_PERMIT_DIRECTIO) | 1462 | if (entry->flags & IMA_PERMIT_DIRECTIO) |
1455 | seq_puts(m, "permit_directio "); | 1463 | seq_puts(m, "permit_directio "); |
1456 | rcu_read_unlock(); | 1464 | rcu_read_unlock(); |
diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index ed12d8e13d04..8c5736b68156 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h | |||
@@ -31,6 +31,7 @@ | |||
31 | #define IMA_NEW_FILE 0x04000000 | 31 | #define IMA_NEW_FILE 0x04000000 |
32 | #define EVM_IMMUTABLE_DIGSIG 0x08000000 | 32 | #define EVM_IMMUTABLE_DIGSIG 0x08000000 |
33 | #define IMA_FAIL_UNVERIFIABLE_SIGS 0x10000000 | 33 | #define IMA_FAIL_UNVERIFIABLE_SIGS 0x10000000 |
34 | #define IMA_MODSIG_ALLOWED 0x20000000 | ||
34 | 35 | ||
35 | #define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ | 36 | #define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ |
36 | IMA_HASH | IMA_APPRAISE_SUBMASK) | 37 | IMA_HASH | IMA_APPRAISE_SUBMASK) |