aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2019-01-18 05:15:59 -0500
committerJames Morris <james.morris@microsoft.com>2019-01-18 14:44:02 -0500
commit1cfb2a512e74e577bb0ed7c8d76df90a41a83f6a (patch)
treef628dd07b171deba0cdc1ff48621f6c07aa0de2a
parentc1a85a00ea66cb6f0bd0f14e47c28c2b0999799f (diff)
LSM: Make lsm_early_cred() and lsm_early_task() local functions.
Since current->cred == current->real_cred when ordered_lsm_init() is called, and lsm_early_cred()/lsm_early_task() need to be called between the amount of required bytes is determined and module specific initialization function is called, we can move these calls from individual modules to ordered_lsm_init(). Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Acked-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: James Morris <james.morris@microsoft.com>
-rw-r--r--include/linux/lsm_hooks.h5
-rw-r--r--security/apparmor/lsm.c2
-rw-r--r--security/security.c27
-rw-r--r--security/selinux/hooks.c1
-rw-r--r--security/smack/smack_lsm.c2
-rw-r--r--security/tomoyo/tomoyo.c1
6 files changed, 11 insertions, 27 deletions
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 195707210975..22fc786d723a 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -2112,9 +2112,4 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
2112 2112
2113extern int lsm_inode_alloc(struct inode *inode); 2113extern int lsm_inode_alloc(struct inode *inode);
2114 2114
2115#ifdef CONFIG_SECURITY
2116void __init lsm_early_cred(struct cred *cred);
2117void __init lsm_early_task(struct task_struct *task);
2118#endif
2119
2120#endif /* ! __LINUX_LSM_HOOKS_H */ 2115#endif /* ! __LINUX_LSM_HOOKS_H */
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index b6c395e2acd0..bb5a02d2439f 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -1484,8 +1484,6 @@ static int __init set_init_ctx(void)
1484{ 1484{
1485 struct cred *cred = (struct cred *)current->real_cred; 1485 struct cred *cred = (struct cred *)current->real_cred;
1486 1486
1487 lsm_early_cred(cred);
1488 lsm_early_task(current);
1489 set_cred_label(cred, aa_get_label(ns_unconfined(root_ns))); 1487 set_cred_label(cred, aa_get_label(ns_unconfined(root_ns)));
1490 1488
1491 return 0; 1489 return 0;
diff --git a/security/security.c b/security/security.c
index a618e22df5c6..992b612c819a 100644
--- a/security/security.c
+++ b/security/security.c
@@ -278,6 +278,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
278 kfree(sep); 278 kfree(sep);
279} 279}
280 280
281static void __init lsm_early_cred(struct cred *cred);
282static void __init lsm_early_task(struct task_struct *task);
283
281static void __init ordered_lsm_init(void) 284static void __init ordered_lsm_init(void)
282{ 285{
283 struct lsm_info **lsm; 286 struct lsm_info **lsm;
@@ -312,6 +315,8 @@ static void __init ordered_lsm_init(void)
312 blob_sizes.lbs_inode, 0, 315 blob_sizes.lbs_inode, 0,
313 SLAB_PANIC, NULL); 316 SLAB_PANIC, NULL);
314 317
318 lsm_early_cred((struct cred *) current->cred);
319 lsm_early_task(current);
315 for (lsm = ordered_lsms; *lsm; lsm++) 320 for (lsm = ordered_lsms; *lsm; lsm++)
316 initialize_lsm(*lsm); 321 initialize_lsm(*lsm);
317 322
@@ -465,17 +470,12 @@ static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
465 * lsm_early_cred - during initialization allocate a composite cred blob 470 * lsm_early_cred - during initialization allocate a composite cred blob
466 * @cred: the cred that needs a blob 471 * @cred: the cred that needs a blob
467 * 472 *
468 * Allocate the cred blob for all the modules if it's not already there 473 * Allocate the cred blob for all the modules
469 */ 474 */
470void __init lsm_early_cred(struct cred *cred) 475static void __init lsm_early_cred(struct cred *cred)
471{ 476{
472 int rc; 477 int rc = lsm_cred_alloc(cred, GFP_KERNEL);
473 478
474 if (cred == NULL)
475 panic("%s: NULL cred.\n", __func__);
476 if (cred->security != NULL)
477 return;
478 rc = lsm_cred_alloc(cred, GFP_KERNEL);
479 if (rc) 479 if (rc)
480 panic("%s: Early cred alloc failed.\n", __func__); 480 panic("%s: Early cred alloc failed.\n", __func__);
481} 481}
@@ -589,17 +589,12 @@ int lsm_msg_msg_alloc(struct msg_msg *mp)
589 * lsm_early_task - during initialization allocate a composite task blob 589 * lsm_early_task - during initialization allocate a composite task blob
590 * @task: the task that needs a blob 590 * @task: the task that needs a blob
591 * 591 *
592 * Allocate the task blob for all the modules if it's not already there 592 * Allocate the task blob for all the modules
593 */ 593 */
594void __init lsm_early_task(struct task_struct *task) 594static void __init lsm_early_task(struct task_struct *task)
595{ 595{
596 int rc; 596 int rc = lsm_task_alloc(task);
597 597
598 if (task == NULL)
599 panic("%s: task cred.\n", __func__);
600 if (task->security != NULL)
601 return;
602 rc = lsm_task_alloc(task);
603 if (rc) 598 if (rc)
604 panic("%s: Early task alloc failed.\n", __func__); 599 panic("%s: Early task alloc failed.\n", __func__);
605} 600}
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index b2ee49f938f1..5d92167dbe05 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -207,7 +207,6 @@ static void cred_init_security(void)
207 struct cred *cred = (struct cred *) current->real_cred; 207 struct cred *cred = (struct cred *) current->real_cred;
208 struct task_security_struct *tsec; 208 struct task_security_struct *tsec;
209 209
210 lsm_early_cred(cred);
211 tsec = selinux_cred(cred); 210 tsec = selinux_cred(cred);
212 tsec->osid = tsec->sid = SECINITSID_KERNEL; 211 tsec->osid = tsec->sid = SECINITSID_KERNEL;
213} 212}
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 0b848b1f6366..79d6d2a6a0bc 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4671,8 +4671,6 @@ static __init int smack_init(void)
4671 if (!smack_inode_cache) 4671 if (!smack_inode_cache)
4672 return -ENOMEM; 4672 return -ENOMEM;
4673 4673
4674 lsm_early_cred(cred);
4675
4676 /* 4674 /*
4677 * Set the security state for the initial task. 4675 * Set the security state for the initial task.
4678 */ 4676 */
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
index 066c0daf0efc..2b3eee06004b 100644
--- a/security/tomoyo/tomoyo.c
+++ b/security/tomoyo/tomoyo.c
@@ -566,7 +566,6 @@ static int __init tomoyo_init(void)
566 /* register ourselves with the security framework */ 566 /* register ourselves with the security framework */
567 security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo"); 567 security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo");
568 printk(KERN_INFO "TOMOYO Linux initialized\n"); 568 printk(KERN_INFO "TOMOYO Linux initialized\n");
569 lsm_early_cred(cred);
570 blob = tomoyo_cred(cred); 569 blob = tomoyo_cred(cred);
571 *blob = &tomoyo_kernel_domain; 570 *blob = &tomoyo_kernel_domain;
572 tomoyo_mm_init(); 571 tomoyo_mm_init();