@@ -81,19 +81,20 @@ static inline aa_state_t match_component(struct aa_profile *profile,
81
81
struct aa_profile * tp ,
82
82
bool stack , aa_state_t state )
83
83
{
84
+ struct aa_ruleset * rules = & profile -> rules ;
84
85
const char * ns_name ;
85
86
86
87
if (stack )
87
- state = aa_dfa_match (profile -> file .dfa , state , "&" );
88
+ state = aa_dfa_match (rules -> file .dfa , state , "&" );
88
89
if (profile -> ns == tp -> ns )
89
- return aa_dfa_match (profile -> file .dfa , state , tp -> base .hname );
90
+ return aa_dfa_match (rules -> file .dfa , state , tp -> base .hname );
90
91
91
92
/* try matching with namespace name and then profile */
92
93
ns_name = aa_ns_name (profile -> ns , tp -> ns , true);
93
- state = aa_dfa_match_len (profile -> file .dfa , state , ":" , 1 );
94
- state = aa_dfa_match (profile -> file .dfa , state , ns_name );
95
- state = aa_dfa_match_len (profile -> file .dfa , state , ":" , 1 );
96
- return aa_dfa_match (profile -> file .dfa , state , tp -> base .hname );
94
+ state = aa_dfa_match_len (rules -> file .dfa , state , ":" , 1 );
95
+ state = aa_dfa_match (rules -> file .dfa , state , ns_name );
96
+ state = aa_dfa_match_len (rules -> file .dfa , state , ":" , 1 );
97
+ return aa_dfa_match (rules -> file .dfa , state , tp -> base .hname );
97
98
}
98
99
99
100
/**
@@ -117,6 +118,7 @@ static int label_compound_match(struct aa_profile *profile,
117
118
aa_state_t state , bool subns , u32 request ,
118
119
struct aa_perms * perms )
119
120
{
121
+ struct aa_ruleset * rules = & profile -> rules ;
120
122
struct aa_profile * tp ;
121
123
struct label_it i ;
122
124
struct path_cond cond = { };
@@ -139,12 +141,12 @@ static int label_compound_match(struct aa_profile *profile,
139
141
label_for_each_cont (i , label , tp ) {
140
142
if (!aa_ns_visible (profile -> ns , tp -> ns , subns ))
141
143
continue ;
142
- state = aa_dfa_match (profile -> file .dfa , state , "//&" );
144
+ state = aa_dfa_match (rules -> file .dfa , state , "//&" );
143
145
state = match_component (profile , tp , false, state );
144
146
if (!state )
145
147
goto fail ;
146
148
}
147
- * perms = * (aa_lookup_fperms (& (profile -> file ), state , & cond ));
149
+ * perms = * (aa_lookup_fperms (& (rules -> file ), state , & cond ));
148
150
aa_apply_modes_to_perms (profile , perms );
149
151
if ((perms -> allow & request ) != request )
150
152
return - EACCES ;
@@ -177,6 +179,7 @@ static int label_components_match(struct aa_profile *profile,
177
179
aa_state_t start , bool subns , u32 request ,
178
180
struct aa_perms * perms )
179
181
{
182
+ struct aa_ruleset * rules = & profile -> rules ;
180
183
struct aa_profile * tp ;
181
184
struct label_it i ;
182
185
struct aa_perms tmp ;
@@ -197,7 +200,7 @@ static int label_components_match(struct aa_profile *profile,
197
200
return 0 ;
198
201
199
202
next :
200
- tmp = * (aa_lookup_fperms (& (profile -> file ), state , & cond ));
203
+ tmp = * (aa_lookup_fperms (& (rules -> file ), state , & cond ));
201
204
aa_apply_modes_to_perms (profile , & tmp );
202
205
aa_perms_accum (perms , & tmp );
203
206
label_for_each_cont (i , label , tp ) {
@@ -206,7 +209,7 @@ static int label_components_match(struct aa_profile *profile,
206
209
state = match_component (profile , tp , stack , start );
207
210
if (!state )
208
211
goto fail ;
209
- tmp = * (aa_lookup_fperms (& (profile -> file ), state , & cond ));
212
+ tmp = * (aa_lookup_fperms (& (rules -> file ), state , & cond ));
210
213
aa_apply_modes_to_perms (profile , & tmp );
211
214
aa_perms_accum (perms , & tmp );
212
215
}
@@ -296,18 +299,19 @@ static int aa_xattrs_match(const struct linux_binprm *bprm,
296
299
ssize_t size ;
297
300
struct dentry * d ;
298
301
char * value = NULL ;
299
- int value_size = 0 , ret = profile -> xattr_count ;
302
+ struct aa_attachment * attach = & profile -> attach ;
303
+ int value_size = 0 , ret = attach -> xattr_count ;
300
304
301
- if (!bprm || !profile -> xattr_count )
305
+ if (!bprm || !attach -> xattr_count )
302
306
return 0 ;
303
307
might_sleep ();
304
308
305
309
/* transition from exec match to xattr set */
306
- state = aa_dfa_outofband_transition (profile -> xmatch .dfa , state );
310
+ state = aa_dfa_outofband_transition (attach -> xmatch .dfa , state );
307
311
d = bprm -> file -> f_path .dentry ;
308
312
309
- for (i = 0 ; i < profile -> xattr_count ; i ++ ) {
310
- size = vfs_getxattr_alloc (& init_user_ns , d , profile -> xattrs [i ],
313
+ for (i = 0 ; i < attach -> xattr_count ; i ++ ) {
314
+ size = vfs_getxattr_alloc (& init_user_ns , d , attach -> xattrs [i ],
311
315
& value , value_size , GFP_KERNEL );
312
316
if (size >= 0 ) {
313
317
u32 index , perm ;
@@ -317,20 +321,20 @@ static int aa_xattrs_match(const struct linux_binprm *bprm,
317
321
* that not present xattr can be distinguished from a 0
318
322
* length value or rule that matches any value
319
323
*/
320
- state = aa_dfa_null_transition (profile -> xmatch .dfa ,
324
+ state = aa_dfa_null_transition (attach -> xmatch .dfa ,
321
325
state );
322
326
/* Check xattr value */
323
- state = aa_dfa_match_len (profile -> xmatch .dfa , state ,
327
+ state = aa_dfa_match_len (attach -> xmatch .dfa , state ,
324
328
value , size );
325
- index = ACCEPT_TABLE (profile -> xmatch .dfa )[state ];
326
- perm = profile -> xmatch .perms [index ].allow ;
329
+ index = ACCEPT_TABLE (attach -> xmatch .dfa )[state ];
330
+ perm = attach -> xmatch .perms [index ].allow ;
327
331
if (!(perm & MAY_EXEC )) {
328
332
ret = - EINVAL ;
329
333
goto out ;
330
334
}
331
335
}
332
336
/* transition to next element */
333
- state = aa_dfa_outofband_transition (profile -> xmatch .dfa , state );
337
+ state = aa_dfa_outofband_transition (attach -> xmatch .dfa , state );
334
338
if (size < 0 ) {
335
339
/*
336
340
* No xattr match, so verify if transition to
@@ -382,6 +386,8 @@ static struct aa_label *find_attach(const struct linux_binprm *bprm,
382
386
rcu_read_lock ();
383
387
restart :
384
388
list_for_each_entry_rcu (profile , head , base .list ) {
389
+ struct aa_attachment * attach = & profile -> attach ;
390
+
385
391
if (profile -> label .flags & FLAG_NULL &&
386
392
& profile -> label == ns_unconfined (profile -> ns ))
387
393
continue ;
@@ -397,24 +403,24 @@ static struct aa_label *find_attach(const struct linux_binprm *bprm,
397
403
* as another profile, signal a conflict and refuse to
398
404
* match.
399
405
*/
400
- if (profile -> xmatch .dfa ) {
406
+ if (attach -> xmatch .dfa ) {
401
407
unsigned int count ;
402
408
aa_state_t state ;
403
409
u32 index , perm ;
404
410
405
- state = aa_dfa_leftmatch (profile -> xmatch .dfa ,
406
- profile -> xmatch .start [AA_CLASS_XMATCH ],
411
+ state = aa_dfa_leftmatch (attach -> xmatch .dfa ,
412
+ attach -> xmatch .start [AA_CLASS_XMATCH ],
407
413
name , & count );
408
- index = ACCEPT_TABLE (profile -> xmatch .dfa )[state ];
409
- perm = profile -> xmatch .perms [index ].allow ;
414
+ index = ACCEPT_TABLE (attach -> xmatch .dfa )[state ];
415
+ perm = attach -> xmatch .perms [index ].allow ;
410
416
/* any accepting state means a valid match. */
411
417
if (perm & MAY_EXEC ) {
412
418
int ret = 0 ;
413
419
414
420
if (count < candidate_len )
415
421
continue ;
416
422
417
- if (bprm && profile -> xattr_count ) {
423
+ if (bprm && attach -> xattr_count ) {
418
424
long rev = READ_ONCE (ns -> revision );
419
425
420
426
if (!aa_get_profile_not0 (profile ))
@@ -453,7 +459,7 @@ static struct aa_label *find_attach(const struct linux_binprm *bprm,
453
459
* xattrs, or a longer match
454
460
*/
455
461
candidate = profile ;
456
- candidate_len = max (count , profile -> xmatch_len );
462
+ candidate_len = max (count , attach -> xmatch_len );
457
463
candidate_xattrs = ret ;
458
464
conflict = false;
459
465
}
@@ -497,6 +503,7 @@ static const char *next_name(int xtype, const char *name)
497
503
struct aa_label * x_table_lookup (struct aa_profile * profile , u32 xindex ,
498
504
const char * * name )
499
505
{
506
+ struct aa_ruleset * rules = & profile -> rules ;
500
507
struct aa_label * label = NULL ;
501
508
u32 xtype = xindex & AA_X_TYPE_MASK ;
502
509
int index = xindex & AA_X_INDEX_MASK ;
@@ -507,7 +514,7 @@ struct aa_label *x_table_lookup(struct aa_profile *profile, u32 xindex,
507
514
/* TODO: move lookup parsing to unpack time so this is a straight
508
515
* index into the resultant label
509
516
*/
510
- for (* name = profile -> file .trans .table [index ]; !label && * name ;
517
+ for (* name = rules -> file .trans .table [index ]; !label && * name ;
511
518
* name = next_name (xtype , * name )) {
512
519
if (xindex & AA_X_CHILD ) {
513
520
struct aa_profile * new_profile ;
@@ -546,6 +553,7 @@ static struct aa_label *x_to_label(struct aa_profile *profile,
546
553
const char * * lookupname ,
547
554
const char * * info )
548
555
{
556
+ struct aa_ruleset * rules = & profile -> rules ;
549
557
struct aa_label * new = NULL ;
550
558
struct aa_ns * ns = profile -> ns ;
551
559
u32 xtype = xindex & AA_X_TYPE_MASK ;
@@ -558,7 +566,7 @@ static struct aa_label *x_to_label(struct aa_profile *profile,
558
566
break ;
559
567
case AA_X_TABLE :
560
568
/* TODO: fix when perm mapping done at unload */
561
- stack = profile -> file .trans .table [xindex & AA_X_INDEX_MASK ];
569
+ stack = rules -> file .trans .table [xindex & AA_X_INDEX_MASK ];
562
570
if (* stack != '&' ) {
563
571
/* released by caller */
564
572
new = x_table_lookup (profile , xindex , lookupname );
@@ -612,9 +620,10 @@ static struct aa_label *profile_transition(struct aa_profile *profile,
612
620
char * buffer , struct path_cond * cond ,
613
621
bool * secure_exec )
614
622
{
623
+ struct aa_ruleset * rules = & profile -> rules ;
615
624
struct aa_label * new = NULL ;
616
625
const char * info = NULL , * name = NULL , * target = NULL ;
617
- aa_state_t state = profile -> file .start [AA_CLASS_FILE ];
626
+ aa_state_t state = rules -> file .start [AA_CLASS_FILE ];
618
627
struct aa_perms perms = {};
619
628
bool nonewprivs = false;
620
629
int error = 0 ;
@@ -648,7 +657,7 @@ static struct aa_label *profile_transition(struct aa_profile *profile,
648
657
}
649
658
650
659
/* find exec permissions for name */
651
- state = aa_str_perms (& (profile -> file ), state , name , cond , & perms );
660
+ state = aa_str_perms (& (rules -> file ), state , name , cond , & perms );
652
661
if (perms .allow & MAY_EXEC ) {
653
662
/* exec permission determine how to transition */
654
663
new = x_to_label (profile , bprm , name , perms .xindex , & target ,
@@ -710,7 +719,8 @@ static int profile_onexec(struct aa_profile *profile, struct aa_label *onexec,
710
719
char * buffer , struct path_cond * cond ,
711
720
bool * secure_exec )
712
721
{
713
- aa_state_t state = profile -> file .start [AA_CLASS_FILE ];
722
+ struct aa_ruleset * rules = & profile -> rules ;
723
+ aa_state_t state = rules -> file .start [AA_CLASS_FILE ];
714
724
struct aa_perms perms = {};
715
725
const char * xname = NULL , * info = "change_profile onexec" ;
716
726
int error = - EACCES ;
@@ -743,7 +753,7 @@ static int profile_onexec(struct aa_profile *profile, struct aa_label *onexec,
743
753
}
744
754
745
755
/* find exec permissions for name */
746
- state = aa_str_perms (& (profile -> file ), state , xname , cond , & perms );
756
+ state = aa_str_perms (& (rules -> file ), state , xname , cond , & perms );
747
757
if (!(perms .allow & AA_MAY_ONEXEC )) {
748
758
info = "no change_onexec valid for executable" ;
749
759
goto audit ;
@@ -752,7 +762,7 @@ static int profile_onexec(struct aa_profile *profile, struct aa_label *onexec,
752
762
* onexec permission is linked to exec with a standard pairing
753
763
* exec\0change_profile
754
764
*/
755
- state = aa_dfa_null_transition (profile -> file .dfa , state );
765
+ state = aa_dfa_null_transition (rules -> file .dfa , state );
756
766
error = change_profile_perms (profile , onexec , stack , AA_MAY_ONEXEC ,
757
767
state , & perms );
758
768
if (error ) {
@@ -1249,12 +1259,13 @@ static int change_profile_perms_wrapper(const char *op, const char *name,
1249
1259
struct aa_label * target , bool stack ,
1250
1260
u32 request , struct aa_perms * perms )
1251
1261
{
1262
+ struct aa_ruleset * rules = & profile -> rules ;
1252
1263
const char * info = NULL ;
1253
1264
int error = 0 ;
1254
1265
1255
1266
if (!error )
1256
1267
error = change_profile_perms (profile , target , stack , request ,
1257
- profile -> file .start [AA_CLASS_FILE ],
1268
+ rules -> file .start [AA_CLASS_FILE ],
1258
1269
perms );
1259
1270
if (error )
1260
1271
error = aa_audit_file (profile , perms , op , request , name ,
0 commit comments