@@ -91,21 +91,24 @@ static void audit_cb(struct audit_buffer *ab, void *va)
91
91
/**
92
92
* audit_iface - do audit message for policy unpacking/load/replace/remove
93
93
* @new: profile if it has been allocated (MAYBE NULL)
94
+ * @ns_name: name of the ns the profile is to be loaded to (MAY BE NULL)
94
95
* @name: name of the profile being manipulated (MAYBE NULL)
95
96
* @info: any extra info about the failure (MAYBE NULL)
96
97
* @e: buffer position info
97
98
* @error: error code
98
99
*
99
100
* Returns: %0 or error
100
101
*/
101
- static int audit_iface (struct aa_profile * new , const char * name ,
102
- const char * info , struct aa_ext * e , int error )
102
+ static int audit_iface (struct aa_profile * new , const char * ns_name ,
103
+ const char * name , const char * info , struct aa_ext * e ,
104
+ int error )
103
105
{
104
106
struct aa_profile * profile = __aa_current_profile ();
105
107
struct common_audit_data sa ;
106
108
struct apparmor_audit_data aad = {0 ,};
107
109
sa .type = LSM_AUDIT_DATA_NONE ;
108
110
sa .aad = & aad ;
111
+ aad .iface .ns = ns_name ;
109
112
if (e )
110
113
aad .iface .pos = e -> pos - e -> start ;
111
114
aad .iface .target = new ;
@@ -486,19 +489,32 @@ static bool unpack_rlimits(struct aa_ext *e, struct aa_profile *profile)
486
489
*
487
490
* NOTE: unpack profile sets audit struct if there is a failure
488
491
*/
489
- static struct aa_profile * unpack_profile (struct aa_ext * e )
492
+ static struct aa_profile * unpack_profile (struct aa_ext * e , char * * ns_name )
490
493
{
491
494
struct aa_profile * profile = NULL ;
492
- const char * name = NULL ;
495
+ const char * tmpname , * tmpns = NULL , * name = NULL ;
496
+ size_t ns_len ;
493
497
int i , error = - EPROTO ;
494
498
kernel_cap_t tmpcap ;
495
499
u32 tmp ;
496
500
501
+ * ns_name = NULL ;
502
+
497
503
/* check that we have the right struct being passed */
498
504
if (!unpack_nameX (e , AA_STRUCT , "profile" ))
499
505
goto fail ;
500
506
if (!unpack_str (e , & name , NULL ))
501
507
goto fail ;
508
+ if (* name == '\0' )
509
+ goto fail ;
510
+
511
+ tmpname = aa_splitn_fqname (name , strlen (name ), & tmpns , & ns_len );
512
+ if (tmpns ) {
513
+ * ns_name = kstrndup (tmpns , ns_len , GFP_KERNEL );
514
+ if (!* ns_name )
515
+ goto fail ;
516
+ name = tmpname ;
517
+ }
502
518
503
519
profile = aa_alloc_profile (name , GFP_KERNEL );
504
520
if (!profile )
@@ -646,7 +662,8 @@ static struct aa_profile *unpack_profile(struct aa_ext *e)
646
662
name = NULL ;
647
663
else if (!name )
648
664
name = "unknown" ;
649
- audit_iface (profile , name , "failed to unpack profile" , e , error );
665
+ audit_iface (profile , NULL , name , "failed to unpack profile" , e ,
666
+ error );
650
667
aa_free_profile (profile );
651
668
652
669
return ERR_PTR (error );
@@ -669,7 +686,7 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
669
686
/* get the interface version */
670
687
if (!unpack_u32 (e , & e -> version , "version" )) {
671
688
if (required ) {
672
- audit_iface (NULL , NULL , "invalid profile format" ,
689
+ audit_iface (NULL , NULL , NULL , "invalid profile format" ,
673
690
e , error );
674
691
return error ;
675
692
}
@@ -680,15 +697,21 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
680
697
* Mask off everything that is not kernel abi version
681
698
*/
682
699
if (VERSION_LT (e -> version , v5 ) && VERSION_GT (e -> version , v7 )) {
683
- audit_iface (NULL , NULL , "unsupported interface version" ,
700
+ audit_iface (NULL , NULL , NULL , "unsupported interface version" ,
684
701
e , error );
685
702
return error ;
686
703
}
687
704
688
705
/* read the namespace if present */
689
706
if (unpack_str (e , & name , "namespace" )) {
707
+ if (* name == '\0' ) {
708
+ audit_iface (NULL , NULL , NULL , "invalid namespace name" ,
709
+ e , error );
710
+ return error ;
711
+ }
690
712
if (* ns && strcmp (* ns , name ))
691
- audit_iface (NULL , NULL , "invalid ns change" , e , error );
713
+ audit_iface (NULL , NULL , NULL , "invalid ns change" , e ,
714
+ error );
692
715
else if (!* ns )
693
716
* ns = name ;
694
717
}
@@ -730,7 +753,7 @@ static int verify_profile(struct aa_profile *profile)
730
753
if (profile -> file .dfa &&
731
754
!verify_dfa_xindex (profile -> file .dfa ,
732
755
profile -> file .trans .size )) {
733
- audit_iface (profile , NULL , "Invalid named transition" ,
756
+ audit_iface (profile , NULL , NULL , "Invalid named transition" ,
734
757
NULL , - EPROTO );
735
758
return - EPROTO ;
736
759
}
@@ -744,6 +767,7 @@ void aa_load_ent_free(struct aa_load_ent *ent)
744
767
aa_put_profile (ent -> rename );
745
768
aa_put_profile (ent -> old );
746
769
aa_put_profile (ent -> new );
770
+ kfree (ent -> ns_name );
747
771
kzfree (ent );
748
772
}
749
773
}
@@ -782,13 +806,14 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
782
806
783
807
* ns = NULL ;
784
808
while (e .pos < e .end ) {
809
+ char * ns_name = NULL ;
785
810
void * start ;
786
811
error = verify_header (& e , e .pos == e .start , ns );
787
812
if (error )
788
813
goto fail ;
789
814
790
815
start = e .pos ;
791
- profile = unpack_profile (& e );
816
+ profile = unpack_profile (& e , & ns_name );
792
817
if (IS_ERR (profile )) {
793
818
error = PTR_ERR (profile );
794
819
goto fail ;
@@ -810,6 +835,7 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
810
835
}
811
836
812
837
ent -> new = profile ;
838
+ ent -> ns_name = ns_name ;
813
839
list_add_tail (& ent -> list , lh );
814
840
}
815
841
udata -> abi = e .version & K_ABI_MASK ;
0 commit comments