@@ -3818,6 +3818,38 @@ static int cil_defaultrange_to_policydb(policydb_t *pdb, struct cil_defaultrange
38183818 return SEPOL_ERR ;
38193819}
38203820
3821+ static int cil_segregateattributes_to_policydb (policydb_t * pdb , const struct cil_segregateattributes * sattrs )
3822+ {
3823+ segregate_attributes_rule_t * sattr ;
3824+ struct cil_list_item * curr ;
3825+ type_datum_t * sepol_type ;
3826+ int rc = SEPOL_ERR ;
3827+
3828+ sattr = cil_malloc (sizeof (segregate_attributes_rule_t ));
3829+ ebitmap_init (& sattr -> attrs );
3830+
3831+ cil_list_for_each (curr , sattrs -> datum_expr ) {
3832+ rc = __cil_get_sepol_type_datum (pdb , DATUM (curr -> data ), & sepol_type );
3833+ if (rc != SEPOL_OK ) goto exit ;
3834+
3835+ if (ebitmap_set_bit (& sattr -> attrs , sepol_type -> s .value - 1 , 1 )) {
3836+ goto exit ;
3837+ }
3838+ }
3839+
3840+ sattr -> next = pdb -> segregate_attributes ;
3841+ pdb -> segregate_attributes = sattr ;
3842+
3843+ return SEPOL_OK ;
3844+
3845+ exit :
3846+ if (sattr ) {
3847+ ebitmap_destroy (& sattr -> attrs );
3848+ free (sattr );
3849+ }
3850+ return rc ;
3851+ }
3852+
38213853static int __cil_node_to_policydb (struct cil_tree_node * node , void * extra_args )
38223854{
38233855 int rc = SEPOL_OK ;
@@ -3960,6 +3992,9 @@ static int __cil_node_to_policydb(struct cil_tree_node *node, void *extra_args)
39603992 case CIL_DEFAULTRANGE :
39613993 rc = cil_defaultrange_to_policydb (pdb , node -> data );
39623994 break ;
3995+ case CIL_SEGREGATEATTRIBUTES :
3996+ rc = cil_segregateattributes_to_policydb (pdb , node -> data );
3997+ break ;
39633998 default :
39643999 break ;
39654000 }
@@ -4890,6 +4925,42 @@ static int cil_check_neverallows(const struct cil_db *db, policydb_t *pdb, struc
48904925 return rc ;
48914926}
48924927
4928+ static int cil_check_segregateattributes (const policydb_t * pdb , int * violation )
4929+ {
4930+ const segregate_attributes_rule_t * sattr ;
4931+
4932+ for (sattr = pdb -> segregate_attributes ; sattr ; sattr = sattr -> next ) {
4933+ ebitmap_node_t * first_node ;
4934+ unsigned int first_bit ;
4935+
4936+ ebitmap_for_each_positive_bit (& sattr -> attrs , first_node , first_bit ) {
4937+ ebitmap_node_t * second_node ;
4938+ unsigned int second_bit ;
4939+
4940+ ebitmap_for_each_positive_bit_after (& sattr -> attrs , second_node , second_bit , first_node , first_bit ) {
4941+ ebitmap_t attr_union ;
4942+ ebitmap_node_t * type_node ;
4943+ unsigned int type_bit ;
4944+
4945+ if (ebitmap_and (& attr_union , & pdb -> attr_type_map [first_bit ], & pdb -> attr_type_map [second_bit ]))
4946+ return SEPOL_ERR ;
4947+
4948+ ebitmap_for_each_positive_bit (& attr_union , type_node , type_bit ) {
4949+ cil_log (CIL_ERR , "Segregate Attributes violation, type %s associated with attributes %s and %s\n" ,
4950+ pdb -> p_type_val_to_name [type_bit ],
4951+ pdb -> p_type_val_to_name [first_bit ],
4952+ pdb -> p_type_val_to_name [second_bit ]);
4953+ * violation = CIL_TRUE ;
4954+ }
4955+
4956+ ebitmap_destroy (& attr_union );
4957+ }
4958+ }
4959+ }
4960+
4961+ return SEPOL_OK ;
4962+ }
4963+
48934964static struct cil_list * cil_classperms_from_sepol (policydb_t * pdb , uint16_t class , uint32_t data , struct cil_class * class_value_to_cil [], struct cil_perm * * perm_value_to_cil [])
48944965{
48954966 struct cil_classperms * cp ;
@@ -5160,6 +5231,10 @@ int cil_binary_create_allocated_pdb(const struct cil_db *db, sepol_policydb_t *p
51605231 rc = cil_check_neverallows (db , pdb , neverallows , & violation );
51615232 if (rc != SEPOL_OK ) goto exit ;
51625233
5234+ cil_log (CIL_INFO , "Checking Segregate Attributes\n" );
5235+ rc = cil_check_segregateattributes (pdb , & violation );
5236+ if (rc != SEPOL_OK ) goto exit ;
5237+
51635238 cil_log (CIL_INFO , "Checking User Bounds\n" );
51645239 rc = bounds_check_users (NULL , pdb );
51655240 if (rc ) {
0 commit comments