@@ -1020,6 +1020,15 @@ bool policydb_class_isvalid(const struct policydb *p, u16 class)
10201020 return true;
10211021}
10221022
1023+ bool policydb_user_isvalid (const struct policydb * p , u32 user )
1024+ {
1025+ if (!user || user > p -> p_roles .nprim )
1026+ return false;
1027+ if (!p -> sym_val_to_name [SYM_USERS ][user - 1 ])
1028+ return false;
1029+ return true;
1030+ }
1031+
10231032bool policydb_role_isvalid (const struct policydb * p , u32 role )
10241033{
10251034 if (!role || role > p -> p_roles .nprim )
@@ -1942,6 +1951,12 @@ static int user_bounds_sanity_check(void *key, void *datum, void *datap)
19421951 return - EINVAL ;
19431952 }
19441953
1954+ if (!policydb_user_isvalid (p , upper -> bounds )) {
1955+ pr_err ("SELinux: user %s: invalid boundary id %d\n" ,
1956+ (char * ) key , upper -> bounds );
1957+ return - EINVAL ;
1958+ }
1959+
19451960 upper = p -> user_val_to_struct [upper -> bounds - 1 ];
19461961 ebitmap_for_each_positive_bit (& user -> roles , node , bit )
19471962 {
@@ -1979,6 +1994,12 @@ static int role_bounds_sanity_check(void *key, void *datum, void *datap)
19791994 return - EINVAL ;
19801995 }
19811996
1997+ if (!policydb_role_isvalid (p , upper -> bounds )) {
1998+ pr_err ("SELinux: role %s: invalid boundary id %d\n" ,
1999+ (char * ) key , upper -> bounds );
2000+ return - EINVAL ;
2001+ }
2002+
19822003 upper = p -> role_val_to_struct [upper -> bounds - 1 ];
19832004 ebitmap_for_each_positive_bit (& role -> types , node , bit )
19842005 {
@@ -2013,9 +2034,13 @@ static int type_bounds_sanity_check(void *key, void *datum, void *datap)
20132034 return - EINVAL ;
20142035 }
20152036
2016- upper = p -> type_val_to_struct [upper -> bounds - 1 ];
2017- BUG_ON (!upper );
2037+ if (!policydb_type_isvalid (p , upper -> bounds )) {
2038+ pr_err ("SELinux: type %s: invalid boundary id %d\n" ,
2039+ (char * ) key , upper -> bounds );
2040+ return - EINVAL ;
2041+ }
20182042
2043+ upper = p -> type_val_to_struct [upper -> bounds - 1 ];
20192044 if (upper -> attribute ) {
20202045 pr_err ("SELinux: type %s: "
20212046 "bounded by attribute %s\n" ,
0 commit comments