@@ -85,9 +85,9 @@ static void audit_cb(struct audit_buffer *ab, void *va)
85
85
audit_log_format (ab , " ns=" );
86
86
audit_log_untrustedstring (ab , aad (sa )-> iface .ns );
87
87
}
88
- if (aad (sa )-> iface . name ) {
88
+ if (aad (sa )-> name ) {
89
89
audit_log_format (ab , " name=" );
90
- audit_log_untrustedstring (ab , aad (sa )-> iface . name );
90
+ audit_log_untrustedstring (ab , aad (sa )-> name );
91
91
}
92
92
if (aad (sa )-> iface .pos )
93
93
audit_log_format (ab , " offset=%ld" , aad (sa )-> iface .pos );
@@ -114,9 +114,9 @@ static int audit_iface(struct aa_profile *new, const char *ns_name,
114
114
aad (& sa )-> iface .pos = e -> pos - e -> start ;
115
115
aad (& sa )-> iface .ns = ns_name ;
116
116
if (new )
117
- aad (& sa )-> iface . name = new -> base .hname ;
117
+ aad (& sa )-> name = new -> base .hname ;
118
118
else
119
- aad (& sa )-> iface . name = name ;
119
+ aad (& sa )-> name = name ;
120
120
aad (& sa )-> info = info ;
121
121
aad (& sa )-> error = error ;
122
122
@@ -583,6 +583,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
583
583
{
584
584
struct aa_profile * profile = NULL ;
585
585
const char * tmpname , * tmpns = NULL , * name = NULL ;
586
+ const char * info = "failed to unpack profile" ;
586
587
size_t ns_len ;
587
588
struct rhashtable_params params = { 0 };
588
589
char * key = NULL ;
@@ -604,8 +605,10 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
604
605
tmpname = aa_splitn_fqname (name , strlen (name ), & tmpns , & ns_len );
605
606
if (tmpns ) {
606
607
* ns_name = kstrndup (tmpns , ns_len , GFP_KERNEL );
607
- if (!* ns_name )
608
+ if (!* ns_name ) {
609
+ info = "out of memory" ;
608
610
goto fail ;
611
+ }
609
612
name = tmpname ;
610
613
}
611
614
@@ -624,21 +627,27 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
624
627
if (IS_ERR (profile -> xmatch )) {
625
628
error = PTR_ERR (profile -> xmatch );
626
629
profile -> xmatch = NULL ;
630
+ info = "bad xmatch" ;
627
631
goto fail ;
628
632
}
629
633
/* xmatch_len is not optional if xmatch is set */
630
634
if (profile -> xmatch ) {
631
- if (!unpack_u32 (e , & tmp , NULL ))
635
+ if (!unpack_u32 (e , & tmp , NULL )) {
636
+ info = "missing xmatch len" ;
632
637
goto fail ;
638
+ }
633
639
profile -> xmatch_len = tmp ;
634
640
}
635
641
636
642
/* disconnected attachment string is optional */
637
643
(void ) unpack_str (e , & profile -> disconnected , "disconnected" );
638
644
639
645
/* per profile debug flags (complain, audit) */
640
- if (!unpack_nameX (e , AA_STRUCT , "flags" ))
646
+ if (!unpack_nameX (e , AA_STRUCT , "flags" )) {
647
+ info = "profile missing flags" ;
641
648
goto fail ;
649
+ }
650
+ info = "failed to unpack profile flags" ;
642
651
if (!unpack_u32 (e , & tmp , NULL ))
643
652
goto fail ;
644
653
if (tmp & PACKED_FLAG_HAT )
@@ -667,6 +676,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
667
676
/* set a default value if path_flags field is not present */
668
677
profile -> path_flags = PATH_MEDIATE_DELETED ;
669
678
679
+ info = "failed to unpack profile capabilities" ;
670
680
if (!unpack_u32 (e , & (profile -> caps .allow .cap [0 ]), NULL ))
671
681
goto fail ;
672
682
if (!unpack_u32 (e , & (profile -> caps .audit .cap [0 ]), NULL ))
@@ -676,6 +686,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
676
686
if (!unpack_u32 (e , & tmpcap .cap [0 ], NULL ))
677
687
goto fail ;
678
688
689
+ info = "failed to unpack upper profile capabilities" ;
679
690
if (unpack_nameX (e , AA_STRUCT , "caps64" )) {
680
691
/* optional upper half of 64 bit caps */
681
692
if (!unpack_u32 (e , & (profile -> caps .allow .cap [1 ]), NULL ))
@@ -690,6 +701,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
690
701
goto fail ;
691
702
}
692
703
704
+ info = "failed to unpack extended profile capabilities" ;
693
705
if (unpack_nameX (e , AA_STRUCT , "capsx" )) {
694
706
/* optional extended caps mediation mask */
695
707
if (!unpack_u32 (e , & (profile -> caps .extended .cap [0 ]), NULL ))
@@ -700,11 +712,14 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
700
712
goto fail ;
701
713
}
702
714
703
- if (!unpack_rlimits (e , profile ))
715
+ if (!unpack_rlimits (e , profile )) {
716
+ info = "failed to unpack profile rlimits" ;
704
717
goto fail ;
718
+ }
705
719
706
720
if (unpack_nameX (e , AA_STRUCT , "policydb" )) {
707
721
/* generic policy dfa - optional and may be NULL */
722
+ info = "failed to unpack policydb" ;
708
723
profile -> policy .dfa = unpack_dfa (e );
709
724
if (IS_ERR (profile -> policy .dfa )) {
710
725
error = PTR_ERR (profile -> policy .dfa );
@@ -734,6 +749,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
734
749
if (IS_ERR (profile -> file .dfa )) {
735
750
error = PTR_ERR (profile -> file .dfa );
736
751
profile -> file .dfa = NULL ;
752
+ info = "failed to unpack profile file rules" ;
737
753
goto fail ;
738
754
} else if (profile -> file .dfa ) {
739
755
if (!unpack_u32 (e , & profile -> file .start , "dfa_start" ))
@@ -746,10 +762,13 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
746
762
} else
747
763
profile -> file .dfa = aa_get_dfa (nulldfa );
748
764
749
- if (!unpack_trans_table (e , profile ))
765
+ if (!unpack_trans_table (e , profile )) {
766
+ info = "failed to unpack profile transition table" ;
750
767
goto fail ;
768
+ }
751
769
752
770
if (unpack_nameX (e , AA_STRUCT , "data" )) {
771
+ info = "out of memory" ;
753
772
profile -> data = kzalloc (sizeof (* profile -> data ), GFP_KERNEL );
754
773
if (!profile -> data )
755
774
goto fail ;
@@ -761,8 +780,10 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
761
780
params .hashfn = strhash ;
762
781
params .obj_cmpfn = datacmp ;
763
782
764
- if (rhashtable_init (profile -> data , & params ))
783
+ if (rhashtable_init (profile -> data , & params )) {
784
+ info = "failed to init key, value hash table" ;
765
785
goto fail ;
786
+ }
766
787
767
788
while (unpack_strdup (e , & key , NULL )) {
768
789
data = kzalloc (sizeof (* data ), GFP_KERNEL );
@@ -784,12 +805,16 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
784
805
profile -> data -> p );
785
806
}
786
807
787
- if (!unpack_nameX (e , AA_STRUCTEND , NULL ))
808
+ if (!unpack_nameX (e , AA_STRUCTEND , NULL )) {
809
+ info = "failed to unpack end of key, value data table" ;
788
810
goto fail ;
811
+ }
789
812
}
790
813
791
- if (!unpack_nameX (e , AA_STRUCTEND , NULL ))
814
+ if (!unpack_nameX (e , AA_STRUCTEND , NULL )) {
815
+ info = "failed to unpack end of profile" ;
792
816
goto fail ;
817
+ }
793
818
794
819
return profile ;
795
820
@@ -798,8 +823,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
798
823
name = NULL ;
799
824
else if (!name )
800
825
name = "unknown" ;
801
- audit_iface (profile , NULL , name , "failed to unpack profile" , e ,
802
- error );
826
+ audit_iface (profile , NULL , name , info , e , error );
803
827
aa_free_profile (profile );
804
828
805
829
return ERR_PTR (error );
0 commit comments