@@ -91,21 +91,24 @@ static void audit_cb(struct audit_buffer *ab, void *va)
9191/**
9292 * audit_iface - do audit message for policy unpacking/load/replace/remove
9393 * @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)
9495 * @name: name of the profile being manipulated (MAYBE NULL)
9596 * @info: any extra info about the failure (MAYBE NULL)
9697 * @e: buffer position info
9798 * @error: error code
9899 *
99100 * Returns: %0 or error
100101 */
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 )
103105{
104106 struct aa_profile * profile = __aa_current_profile ();
105107 struct common_audit_data sa ;
106108 struct apparmor_audit_data aad = {0 ,};
107109 sa .type = LSM_AUDIT_DATA_NONE ;
108110 sa .aad = & aad ;
111+ aad .iface .ns = ns_name ;
109112 if (e )
110113 aad .iface .pos = e -> pos - e -> start ;
111114 aad .iface .target = new ;
@@ -486,19 +489,32 @@ static bool unpack_rlimits(struct aa_ext *e, struct aa_profile *profile)
486489 *
487490 * NOTE: unpack profile sets audit struct if there is a failure
488491 */
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 )
490493{
491494 struct aa_profile * profile = NULL ;
492- const char * name = NULL ;
495+ const char * tmpname , * tmpns = NULL , * name = NULL ;
496+ size_t ns_len ;
493497 int i , error = - EPROTO ;
494498 kernel_cap_t tmpcap ;
495499 u32 tmp ;
496500
501+ * ns_name = NULL ;
502+
497503 /* check that we have the right struct being passed */
498504 if (!unpack_nameX (e , AA_STRUCT , "profile" ))
499505 goto fail ;
500506 if (!unpack_str (e , & name , NULL ))
501507 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+ }
502518
503519 profile = aa_alloc_profile (name , GFP_KERNEL );
504520 if (!profile )
@@ -646,7 +662,8 @@ static struct aa_profile *unpack_profile(struct aa_ext *e)
646662 name = NULL ;
647663 else if (!name )
648664 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 );
650667 aa_free_profile (profile );
651668
652669 return ERR_PTR (error );
@@ -669,7 +686,7 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
669686 /* get the interface version */
670687 if (!unpack_u32 (e , & e -> version , "version" )) {
671688 if (required ) {
672- audit_iface (NULL , NULL , "invalid profile format" ,
689+ audit_iface (NULL , NULL , NULL , "invalid profile format" ,
673690 e , error );
674691 return error ;
675692 }
@@ -680,15 +697,21 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
680697 * Mask off everything that is not kernel abi version
681698 */
682699 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" ,
684701 e , error );
685702 return error ;
686703 }
687704
688705 /* read the namespace if present */
689706 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+ }
690712 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 );
692715 else if (!* ns )
693716 * ns = name ;
694717 }
@@ -730,7 +753,7 @@ static int verify_profile(struct aa_profile *profile)
730753 if (profile -> file .dfa &&
731754 !verify_dfa_xindex (profile -> file .dfa ,
732755 profile -> file .trans .size )) {
733- audit_iface (profile , NULL , "Invalid named transition" ,
756+ audit_iface (profile , NULL , NULL , "Invalid named transition" ,
734757 NULL , - EPROTO );
735758 return - EPROTO ;
736759 }
@@ -744,6 +767,7 @@ void aa_load_ent_free(struct aa_load_ent *ent)
744767 aa_put_profile (ent -> rename );
745768 aa_put_profile (ent -> old );
746769 aa_put_profile (ent -> new );
770+ kfree (ent -> ns_name );
747771 kzfree (ent );
748772 }
749773}
@@ -782,13 +806,14 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
782806
783807 * ns = NULL ;
784808 while (e .pos < e .end ) {
809+ char * ns_name = NULL ;
785810 void * start ;
786811 error = verify_header (& e , e .pos == e .start , ns );
787812 if (error )
788813 goto fail ;
789814
790815 start = e .pos ;
791- profile = unpack_profile (& e );
816+ profile = unpack_profile (& e , & ns_name );
792817 if (IS_ERR (profile )) {
793818 error = PTR_ERR (profile );
794819 goto fail ;
@@ -810,6 +835,7 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
810835 }
811836
812837 ent -> new = profile ;
838+ ent -> ns_name = ns_name ;
813839 list_add_tail (& ent -> list , lh );
814840 }
815841 udata -> abi = e .version & K_ABI_MASK ;
0 commit comments