1818 */
1919static int tomoyo_cred_alloc_blank (struct cred * new , gfp_t gfp )
2020{
21- new -> security = NULL ;
21+ struct tomoyo_domain_info * * blob = tomoyo_cred (new );
22+
23+ * blob = NULL ;
2224 return 0 ;
2325}
2426
@@ -34,8 +36,13 @@ static int tomoyo_cred_alloc_blank(struct cred *new, gfp_t gfp)
3436static int tomoyo_cred_prepare (struct cred * new , const struct cred * old ,
3537 gfp_t gfp )
3638{
37- struct tomoyo_domain_info * domain = old -> security ;
38- new -> security = domain ;
39+ struct tomoyo_domain_info * * old_blob = tomoyo_cred (old );
40+ struct tomoyo_domain_info * * new_blob = tomoyo_cred (new );
41+ struct tomoyo_domain_info * domain ;
42+
43+ domain = * old_blob ;
44+ * new_blob = domain ;
45+
3946 if (domain )
4047 atomic_inc (& domain -> users );
4148 return 0 ;
@@ -59,7 +66,9 @@ static void tomoyo_cred_transfer(struct cred *new, const struct cred *old)
5966 */
6067static void tomoyo_cred_free (struct cred * cred )
6168{
62- struct tomoyo_domain_info * domain = cred -> security ;
69+ struct tomoyo_domain_info * * blob = tomoyo_cred (cred );
70+ struct tomoyo_domain_info * domain = * blob ;
71+
6372 if (domain )
6473 atomic_dec (& domain -> users );
6574}
@@ -73,6 +82,9 @@ static void tomoyo_cred_free(struct cred *cred)
7382 */
7483static int tomoyo_bprm_set_creds (struct linux_binprm * bprm )
7584{
85+ struct tomoyo_domain_info * * blob ;
86+ struct tomoyo_domain_info * domain ;
87+
7688 /*
7789 * Do only if this function is called for the first time of an execve
7890 * operation.
@@ -93,13 +105,14 @@ static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)
93105 * stored inside "bprm->cred->security" will be acquired later inside
94106 * tomoyo_find_next_domain().
95107 */
96- atomic_dec (& ((struct tomoyo_domain_info * )
97- bprm -> cred -> security )-> users );
108+ blob = tomoyo_cred (bprm -> cred );
109+ domain = * blob ;
110+ atomic_dec (& domain -> users );
98111 /*
99112 * Tell tomoyo_bprm_check_security() is called for the first time of an
100113 * execve operation.
101114 */
102- bprm -> cred -> security = NULL ;
115+ * blob = NULL ;
103116 return 0 ;
104117}
105118
@@ -112,8 +125,11 @@ static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)
112125 */
113126static int tomoyo_bprm_check_security (struct linux_binprm * bprm )
114127{
115- struct tomoyo_domain_info * domain = bprm -> cred -> security ;
128+ struct tomoyo_domain_info * * blob ;
129+ struct tomoyo_domain_info * domain ;
116130
131+ blob = tomoyo_cred (bprm -> cred );
132+ domain = * blob ;
117133 /*
118134 * Execute permission is checked against pathname passed to do_execve()
119135 * using current domain.
@@ -531,6 +547,8 @@ static struct security_hook_list tomoyo_hooks[] __lsm_ro_after_init = {
531547/* Lock for GC. */
532548DEFINE_SRCU (tomoyo_ss );
533549
550+ int tomoyo_enabled __lsm_ro_after_init = 1 ;
551+
534552/**
535553 * tomoyo_init - Register TOMOYO Linux as a LSM module.
536554 *
@@ -539,17 +557,21 @@ DEFINE_SRCU(tomoyo_ss);
539557static int __init tomoyo_init (void )
540558{
541559 struct cred * cred = (struct cred * ) current_cred ();
560+ struct tomoyo_domain_info * * blob ;
542561
543562 /* register ourselves with the security framework */
544563 security_add_hooks (tomoyo_hooks , ARRAY_SIZE (tomoyo_hooks ), "tomoyo" );
545564 printk (KERN_INFO "TOMOYO Linux initialized\n" );
546- cred -> security = & tomoyo_kernel_domain ;
565+ blob = tomoyo_cred (cred );
566+ * blob = & tomoyo_kernel_domain ;
547567 tomoyo_mm_init ();
568+
548569 return 0 ;
549570}
550571
551572DEFINE_LSM (tomoyo ) = {
552573 .name = "tomoyo" ,
574+ .enabled = & tomoyo_enabled ,
553575 .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE ,
554576 .init = tomoyo_init ,
555577};
0 commit comments