summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-15 13:25:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-15 13:25:26 -0400
commit92d4a03674b8c399c2f547580fa509db78226170 (patch)
treee5492e0214e31a10a79dbad6135a047f37721fc9 /security
parent1eb46908b35dfbac0ec1848d4b1e39667e0187e9 (diff)
parent87ea58433208d17295e200d56be5e2a4fe4ce7d6 (diff)
Merge branch 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security subsystem updates from James Morris: - kstrdup() return value fix from Eric Biggers - Add new security_load_data hook to differentiate security checking of kernel-loaded binaries in the case of there being no associated file descriptor, from Mimi Zohar. - Add ability to IMA to specify a policy at build-time, rather than just via command line params or by loading a custom policy, from Mimi. - Allow IMA and LSMs to prevent sysfs firmware load fallback (e.g. if using signed firmware), from Mimi. - Allow IMA to deny loading of kexec kernel images, as they cannot be measured by IMA, from Mimi. * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: security: check for kstrdup() failure in lsm_append() security: export security_kernel_load_data function ima: based on policy warn about loading firmware (pre-allocated buffer) module: replace the existing LSM hook in init_module ima: add build time policy ima: based on policy require signed firmware (sysfs fallback) firmware: add call to LSM hook before firmware sysfs fallback ima: based on policy require signed kexec kernel images kexec: add call to LSM hook in original kexec_load syscall security: define new LSM hook named security_kernel_load_data MAINTAINERS: remove the outdated "LINUX SECURITY MODULE (LSM) FRAMEWORK" entry
Diffstat (limited to 'security')
-rw-r--r--security/integrity/ima/Kconfig58
-rw-r--r--security/integrity/ima/ima.h1
-rw-r--r--security/integrity/ima/ima_main.c68
-rw-r--r--security/integrity/ima/ima_policy.c48
-rw-r--r--security/loadpin/loadpin.c6
-rw-r--r--security/security.c13
-rw-r--r--security/selinux/hooks.c15
7 files changed, 192 insertions, 17 deletions
diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig
index 6a8f67714c83..004919d9bf09 100644
--- a/security/integrity/ima/Kconfig
+++ b/security/integrity/ima/Kconfig
@@ -156,6 +156,64 @@ config IMA_APPRAISE
156 <http://linux-ima.sourceforge.net> 156 <http://linux-ima.sourceforge.net>
157 If unsure, say N. 157 If unsure, say N.
158 158
159config IMA_APPRAISE_BUILD_POLICY
160 bool "IMA build time configured policy rules"
161 depends on IMA_APPRAISE && INTEGRITY_ASYMMETRIC_KEYS
162 default n
163 help
164 This option defines an IMA appraisal policy at build time, which
165 is enforced at run time without having to specify a builtin
166 policy name on the boot command line. The build time appraisal
167 policy rules persist after loading a custom policy.
168
169 Depending on the rules configured, this policy may require kernel
170 modules, firmware, the kexec kernel image, and/or the IMA policy
171 to be signed. Unsigned files might prevent the system from
172 booting or applications from working properly.
173
174config IMA_APPRAISE_REQUIRE_FIRMWARE_SIGS
175 bool "Appraise firmware signatures"
176 depends on IMA_APPRAISE_BUILD_POLICY
177 default n
178 help
179 This option defines a policy requiring all firmware to be signed,
180 including the regulatory.db. If both this option and
181 CFG80211_REQUIRE_SIGNED_REGDB are enabled, then both signature
182 verification methods are necessary.
183
184config IMA_APPRAISE_REQUIRE_KEXEC_SIGS
185 bool "Appraise kexec kernel image signatures"
186 depends on IMA_APPRAISE_BUILD_POLICY
187 default n
188 help
189 Enabling this rule will require all kexec'ed kernel images to
190 be signed and verified by a public key on the trusted IMA
191 keyring.
192
193 Kernel image signatures can not be verified by the original
194 kexec_load syscall. Enabling this rule will prevent its
195 usage.
196
197config IMA_APPRAISE_REQUIRE_MODULE_SIGS
198 bool "Appraise kernel modules signatures"
199 depends on IMA_APPRAISE_BUILD_POLICY
200 default n
201 help
202 Enabling this rule will require all kernel modules to be signed
203 and verified by a public key on the trusted IMA keyring.
204
205 Kernel module signatures can only be verified by IMA-appraisal,
206 via the finit_module syscall. Enabling this rule will prevent
207 the usage of the init_module syscall.
208
209config IMA_APPRAISE_REQUIRE_POLICY_SIGS
210 bool "Appraise IMA policy signature"
211 depends on IMA_APPRAISE_BUILD_POLICY
212 default n
213 help
214 Enabling this rule will require the IMA policy to be signed and
215 and verified by a key on the trusted IMA keyring.
216
159config IMA_APPRAISE_BOOTPARAM 217config IMA_APPRAISE_BOOTPARAM
160 bool "ima_appraise boot parameter" 218 bool "ima_appraise boot parameter"
161 depends on IMA_APPRAISE 219 depends on IMA_APPRAISE
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
index e4c1a236976c..a597b2795d2d 100644
--- a/security/integrity/ima/ima.h
+++ b/security/integrity/ima/ima.h
@@ -232,6 +232,7 @@ int ima_policy_show(struct seq_file *m, void *v);
232#define IMA_APPRAISE_MODULES 0x08 232#define IMA_APPRAISE_MODULES 0x08
233#define IMA_APPRAISE_FIRMWARE 0x10 233#define IMA_APPRAISE_FIRMWARE 0x10
234#define IMA_APPRAISE_POLICY 0x20 234#define IMA_APPRAISE_POLICY 0x20
235#define IMA_APPRAISE_KEXEC 0x40
235 236
236#ifdef CONFIG_IMA_APPRAISE 237#ifdef CONFIG_IMA_APPRAISE
237int ima_appraise_measurement(enum ima_hooks func, 238int ima_appraise_measurement(enum ima_hooks func,
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index b286f37712d5..2d31921fbda4 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -429,16 +429,14 @@ void ima_post_path_mknod(struct dentry *dentry)
429 */ 429 */
430int ima_read_file(struct file *file, enum kernel_read_file_id read_id) 430int ima_read_file(struct file *file, enum kernel_read_file_id read_id)
431{ 431{
432 bool sig_enforce = is_module_sig_enforced(); 432 /*
433 433 * READING_FIRMWARE_PREALLOC_BUFFER
434 if (!file && read_id == READING_MODULE) { 434 *
435 if (!sig_enforce && (ima_appraise & IMA_APPRAISE_MODULES) && 435 * Do devices using pre-allocated memory run the risk of the
436 (ima_appraise & IMA_APPRAISE_ENFORCE)) { 436 * firmware being accessible to the device prior to the completion
437 pr_err("impossible to appraise a module without a file descriptor. sig_enforce kernel parameter might help\n"); 437 * of IMA's signature verification any more than when using two
438 return -EACCES; /* INTEGRITY_UNKNOWN */ 438 * buffers?
439 } 439 */
440 return 0; /* We rely on module signature checking */
441 }
442 return 0; 440 return 0;
443} 441}
444 442
@@ -472,14 +470,13 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size,
472 470
473 if (!file && read_id == READING_FIRMWARE) { 471 if (!file && read_id == READING_FIRMWARE) {
474 if ((ima_appraise & IMA_APPRAISE_FIRMWARE) && 472 if ((ima_appraise & IMA_APPRAISE_FIRMWARE) &&
475 (ima_appraise & IMA_APPRAISE_ENFORCE)) 473 (ima_appraise & IMA_APPRAISE_ENFORCE)) {
474 pr_err("Prevent firmware loading_store.\n");
476 return -EACCES; /* INTEGRITY_UNKNOWN */ 475 return -EACCES; /* INTEGRITY_UNKNOWN */
476 }
477 return 0; 477 return 0;
478 } 478 }
479 479
480 if (!file && read_id == READING_MODULE) /* MODULE_SIG_FORCE enabled */
481 return 0;
482
483 /* permit signed certs */ 480 /* permit signed certs */
484 if (!file && read_id == READING_X509_CERTIFICATE) 481 if (!file && read_id == READING_X509_CERTIFICATE)
485 return 0; 482 return 0;
@@ -496,6 +493,49 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size,
496 MAY_READ, func); 493 MAY_READ, func);
497} 494}
498 495
496/**
497 * ima_load_data - appraise decision based on policy
498 * @id: kernel load data caller identifier
499 *
500 * Callers of this LSM hook can not measure, appraise, or audit the
501 * data provided by userspace. Enforce policy rules requring a file
502 * signature (eg. kexec'ed kernel image).
503 *
504 * For permission return 0, otherwise return -EACCES.
505 */
506int ima_load_data(enum kernel_load_data_id id)
507{
508 bool sig_enforce;
509
510 if ((ima_appraise & IMA_APPRAISE_ENFORCE) != IMA_APPRAISE_ENFORCE)
511 return 0;
512
513 switch (id) {
514 case LOADING_KEXEC_IMAGE:
515 if (ima_appraise & IMA_APPRAISE_KEXEC) {
516 pr_err("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n");
517 return -EACCES; /* INTEGRITY_UNKNOWN */
518 }
519 break;
520 case LOADING_FIRMWARE:
521 if (ima_appraise & IMA_APPRAISE_FIRMWARE) {
522 pr_err("Prevent firmware sysfs fallback loading.\n");
523 return -EACCES; /* INTEGRITY_UNKNOWN */
524 }
525 break;
526 case LOADING_MODULE:
527 sig_enforce = is_module_sig_enforced();
528
529 if (!sig_enforce && (ima_appraise & IMA_APPRAISE_MODULES)) {
530 pr_err("impossible to appraise a module without a file descriptor. sig_enforce kernel parameter might help\n");
531 return -EACCES; /* INTEGRITY_UNKNOWN */
532 }
533 default:
534 break;
535 }
536 return 0;
537}
538
499static int __init init_ima(void) 539static int __init init_ima(void)
500{ 540{
501 int error; 541 int error;
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index cdcc9a7b4e24..1659abb344f9 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -49,6 +49,7 @@
49 49
50int ima_policy_flag; 50int ima_policy_flag;
51static int temp_ima_appraise; 51static int temp_ima_appraise;
52static int build_ima_appraise __ro_after_init;
52 53
53#define MAX_LSM_RULES 6 54#define MAX_LSM_RULES 6
54enum lsm_rule_types { LSM_OBJ_USER, LSM_OBJ_ROLE, LSM_OBJ_TYPE, 55enum lsm_rule_types { LSM_OBJ_USER, LSM_OBJ_ROLE, LSM_OBJ_TYPE,
@@ -162,6 +163,25 @@ static struct ima_rule_entry default_appraise_rules[] __ro_after_init = {
162#endif 163#endif
163}; 164};
164 165
166static struct ima_rule_entry build_appraise_rules[] __ro_after_init = {
167#ifdef CONFIG_IMA_APPRAISE_REQUIRE_MODULE_SIGS
168 {.action = APPRAISE, .func = MODULE_CHECK,
169 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
170#endif
171#ifdef CONFIG_IMA_APPRAISE_REQUIRE_FIRMWARE_SIGS
172 {.action = APPRAISE, .func = FIRMWARE_CHECK,
173 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
174#endif
175#ifdef CONFIG_IMA_APPRAISE_REQUIRE_KEXEC_SIGS
176 {.action = APPRAISE, .func = KEXEC_KERNEL_CHECK,
177 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
178#endif
179#ifdef CONFIG_IMA_APPRAISE_REQUIRE_POLICY_SIGS
180 {.action = APPRAISE, .func = POLICY_CHECK,
181 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
182#endif
183};
184
165static struct ima_rule_entry secure_boot_rules[] __ro_after_init = { 185static struct ima_rule_entry secure_boot_rules[] __ro_after_init = {
166 {.action = APPRAISE, .func = MODULE_CHECK, 186 {.action = APPRAISE, .func = MODULE_CHECK,
167 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED}, 187 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
@@ -435,7 +455,7 @@ void ima_update_policy_flag(void)
435 ima_policy_flag |= entry->action; 455 ima_policy_flag |= entry->action;
436 } 456 }
437 457
438 ima_appraise |= temp_ima_appraise; 458 ima_appraise |= (build_ima_appraise | temp_ima_appraise);
439 if (!ima_appraise) 459 if (!ima_appraise)
440 ima_policy_flag &= ~IMA_APPRAISE; 460 ima_policy_flag &= ~IMA_APPRAISE;
441} 461}
@@ -448,6 +468,8 @@ static int ima_appraise_flag(enum ima_hooks func)
448 return IMA_APPRAISE_FIRMWARE; 468 return IMA_APPRAISE_FIRMWARE;
449 else if (func == POLICY_CHECK) 469 else if (func == POLICY_CHECK)
450 return IMA_APPRAISE_POLICY; 470 return IMA_APPRAISE_POLICY;
471 else if (func == KEXEC_KERNEL_CHECK)
472 return IMA_APPRAISE_KEXEC;
451 return 0; 473 return 0;
452} 474}
453 475
@@ -486,8 +508,8 @@ void __init ima_init_policy(void)
486 } 508 }
487 509
488 /* 510 /*
489 * Insert the appraise rules requiring file signatures, prior to 511 * Insert the builtin "secure_boot" policy rules requiring file
490 * any other appraise rules. 512 * signatures, prior to any other appraise rules.
491 */ 513 */
492 for (i = 0; i < secure_boot_entries; i++) { 514 for (i = 0; i < secure_boot_entries; i++) {
493 list_add_tail(&secure_boot_rules[i].list, &ima_default_rules); 515 list_add_tail(&secure_boot_rules[i].list, &ima_default_rules);
@@ -495,6 +517,26 @@ void __init ima_init_policy(void)
495 ima_appraise_flag(secure_boot_rules[i].func); 517 ima_appraise_flag(secure_boot_rules[i].func);
496 } 518 }
497 519
520 /*
521 * Insert the build time appraise rules requiring file signatures
522 * for both the initial and custom policies, prior to other appraise
523 * rules.
524 */
525 for (i = 0; i < ARRAY_SIZE(build_appraise_rules); i++) {
526 struct ima_rule_entry *entry;
527
528 if (!secure_boot_entries)
529 list_add_tail(&build_appraise_rules[i].list,
530 &ima_default_rules);
531
532 entry = kmemdup(&build_appraise_rules[i], sizeof(*entry),
533 GFP_KERNEL);
534 if (entry)
535 list_add_tail(&entry->list, &ima_policy_rules);
536 build_ima_appraise |=
537 ima_appraise_flag(build_appraise_rules[i].func);
538 }
539
498 for (i = 0; i < appraise_entries; i++) { 540 for (i = 0; i < appraise_entries; i++) {
499 list_add_tail(&default_appraise_rules[i].list, 541 list_add_tail(&default_appraise_rules[i].list,
500 &ima_default_rules); 542 &ima_default_rules);
diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
index 5fa191252c8f..0716af28808a 100644
--- a/security/loadpin/loadpin.c
+++ b/security/loadpin/loadpin.c
@@ -173,9 +173,15 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id)
173 return 0; 173 return 0;
174} 174}
175 175
176static int loadpin_load_data(enum kernel_load_data_id id)
177{
178 return loadpin_read_file(NULL, (enum kernel_read_file_id) id);
179}
180
176static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = { 181static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {
177 LSM_HOOK_INIT(sb_free_security, loadpin_sb_free_security), 182 LSM_HOOK_INIT(sb_free_security, loadpin_sb_free_security),
178 LSM_HOOK_INIT(kernel_read_file, loadpin_read_file), 183 LSM_HOOK_INIT(kernel_read_file, loadpin_read_file),
184 LSM_HOOK_INIT(kernel_load_data, loadpin_load_data),
179}; 185};
180 186
181void __init loadpin_add_hooks(void) 187void __init loadpin_add_hooks(void)
diff --git a/security/security.c b/security/security.c
index 5dce67070cdf..ab4f96347ebb 100644
--- a/security/security.c
+++ b/security/security.c
@@ -118,6 +118,8 @@ static int lsm_append(char *new, char **result)
118 118
119 if (*result == NULL) { 119 if (*result == NULL) {
120 *result = kstrdup(new, GFP_KERNEL); 120 *result = kstrdup(new, GFP_KERNEL);
121 if (*result == NULL)
122 return -ENOMEM;
121 } else { 123 } else {
122 /* Check if it is the last registered name */ 124 /* Check if it is the last registered name */
123 if (match_last_lsm(*result, new)) 125 if (match_last_lsm(*result, new))
@@ -1056,6 +1058,17 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
1056} 1058}
1057EXPORT_SYMBOL_GPL(security_kernel_post_read_file); 1059EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
1058 1060
1061int security_kernel_load_data(enum kernel_load_data_id id)
1062{
1063 int ret;
1064
1065 ret = call_int_hook(kernel_load_data, 0, id);
1066 if (ret)
1067 return ret;
1068 return ima_load_data(id);
1069}
1070EXPORT_SYMBOL_GPL(security_kernel_load_data);
1071
1059int security_task_fix_setuid(struct cred *new, const struct cred *old, 1072int security_task_fix_setuid(struct cred *new, const struct cred *old,
1060 int flags) 1073 int flags)
1061{ 1074{
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 18006be15713..589c6b4023ce 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -4073,6 +4073,20 @@ static int selinux_kernel_read_file(struct file *file,
4073 return rc; 4073 return rc;
4074} 4074}
4075 4075
4076static int selinux_kernel_load_data(enum kernel_load_data_id id)
4077{
4078 int rc = 0;
4079
4080 switch (id) {
4081 case LOADING_MODULE:
4082 rc = selinux_kernel_module_from_file(NULL);
4083 default:
4084 break;
4085 }
4086
4087 return rc;
4088}
4089
4076static int selinux_task_setpgid(struct task_struct *p, pid_t pgid) 4090static int selinux_task_setpgid(struct task_struct *p, pid_t pgid)
4077{ 4091{
4078 return avc_has_perm(&selinux_state, 4092 return avc_has_perm(&selinux_state,
@@ -6972,6 +6986,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
6972 LSM_HOOK_INIT(kernel_act_as, selinux_kernel_act_as), 6986 LSM_HOOK_INIT(kernel_act_as, selinux_kernel_act_as),
6973 LSM_HOOK_INIT(kernel_create_files_as, selinux_kernel_create_files_as), 6987 LSM_HOOK_INIT(kernel_create_files_as, selinux_kernel_create_files_as),
6974 LSM_HOOK_INIT(kernel_module_request, selinux_kernel_module_request), 6988 LSM_HOOK_INIT(kernel_module_request, selinux_kernel_module_request),
6989 LSM_HOOK_INIT(kernel_load_data, selinux_kernel_load_data),
6975 LSM_HOOK_INIT(kernel_read_file, selinux_kernel_read_file), 6990 LSM_HOOK_INIT(kernel_read_file, selinux_kernel_read_file),
6976 LSM_HOOK_INIT(task_setpgid, selinux_task_setpgid), 6991 LSM_HOOK_INIT(task_setpgid, selinux_task_setpgid),
6977 LSM_HOOK_INIT(task_getpgid, selinux_task_getpgid), 6992 LSM_HOOK_INIT(task_getpgid, selinux_task_getpgid),