Skip to content

Commit 1cfb2a5

Browse files
Tetsuo HandaJames Morris
authored andcommitted
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>
1 parent c1a85a0 commit 1cfb2a5

6 files changed

Lines changed: 11 additions & 27 deletions

File tree

‎include/linux/lsm_hooks.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,4 @@ static inline void security_delete_hooks(struct security_hook_list *hooks,
21122112

21132113
extern int lsm_inode_alloc(struct inode *inode);
21142114

2115-
#ifdef CONFIG_SECURITY
2116-
void __init lsm_early_cred(struct cred *cred);
2117-
void __init lsm_early_task(struct task_struct *task);
2118-
#endif
2119-
21202115
#endif /* ! __LINUX_LSM_HOOKS_H */

‎security/apparmor/lsm.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,6 @@ static int __init set_init_ctx(void)
14841484
{
14851485
struct cred *cred = (struct cred *)current->real_cred;
14861486

1487-
lsm_early_cred(cred);
1488-
lsm_early_task(current);
14891487
set_cred_label(cred, aa_get_label(ns_unconfined(root_ns)));
14901488

14911489
return 0;

‎security/security.c‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
278278
kfree(sep);
279279
}
280280

281+
static void __init lsm_early_cred(struct cred *cred);
282+
static void __init lsm_early_task(struct task_struct *task);
283+
281284
static void __init ordered_lsm_init(void)
282285
{
283286
struct lsm_info **lsm;
@@ -312,6 +315,8 @@ static void __init ordered_lsm_init(void)
312315
blob_sizes.lbs_inode, 0,
313316
SLAB_PANIC, NULL);
314317

318+
lsm_early_cred((struct cred *) current->cred);
319+
lsm_early_task(current);
315320
for (lsm = ordered_lsms; *lsm; lsm++)
316321
initialize_lsm(*lsm);
317322

@@ -465,17 +470,12 @@ static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
465470
* lsm_early_cred - during initialization allocate a composite cred blob
466471
* @cred: the cred that needs a blob
467472
*
468-
* Allocate the cred blob for all the modules if it's not already there
473+
* Allocate the cred blob for all the modules
469474
*/
470-
void __init lsm_early_cred(struct cred *cred)
475+
static void __init lsm_early_cred(struct cred *cred)
471476
{
472-
int rc;
477+
int rc = lsm_cred_alloc(cred, GFP_KERNEL);
473478

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);
479479
if (rc)
480480
panic("%s: Early cred alloc failed.\n", __func__);
481481
}
@@ -589,17 +589,12 @@ int lsm_msg_msg_alloc(struct msg_msg *mp)
589589
* lsm_early_task - during initialization allocate a composite task blob
590590
* @task: the task that needs a blob
591591
*
592-
* Allocate the task blob for all the modules if it's not already there
592+
* Allocate the task blob for all the modules
593593
*/
594-
void __init lsm_early_task(struct task_struct *task)
594+
static void __init lsm_early_task(struct task_struct *task)
595595
{
596-
int rc;
596+
int rc = lsm_task_alloc(task);
597597

598-
if (task == NULL)
599-
panic("%s: task cred.\n", __func__);
600-
if (task->security != NULL)
601-
return;
602-
rc = lsm_task_alloc(task);
603598
if (rc)
604599
panic("%s: Early task alloc failed.\n", __func__);
605600
}

‎security/selinux/hooks.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ static void cred_init_security(void)
207207
struct cred *cred = (struct cred *) current->real_cred;
208208
struct task_security_struct *tsec;
209209

210-
lsm_early_cred(cred);
211210
tsec = selinux_cred(cred);
212211
tsec->osid = tsec->sid = SECINITSID_KERNEL;
213212
}

‎security/smack/smack_lsm.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4671,8 +4671,6 @@ static __init int smack_init(void)
46714671
if (!smack_inode_cache)
46724672
return -ENOMEM;
46734673

4674-
lsm_early_cred(cred);
4675-
46764674
/*
46774675
* Set the security state for the initial task.
46784676
*/

‎security/tomoyo/tomoyo.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ static int __init tomoyo_init(void)
566566
/* register ourselves with the security framework */
567567
security_add_hooks(tomoyo_hooks, ARRAY_SIZE(tomoyo_hooks), "tomoyo");
568568
printk(KERN_INFO "TOMOYO Linux initialized\n");
569-
lsm_early_cred(cred);
570569
blob = tomoyo_cred(cred);
571570
*blob = &tomoyo_kernel_domain;
572571
tomoyo_mm_init();

0 commit comments

Comments
 (0)