Skip to contentSkip to conversation

libsepol: Only apply bounds checking to source types in rules

PATCH In review Stephen Smalley 2 participants 4 messages Apr 28, 2016 – Apr 29, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libsepol: Only apply bounds checking to source types in rules

The current bounds checking of both source and target types requires allowing any domain that has access to the child domain to also have the same permissions to the parent, which is undesirable. Drop the target bounds checking.

Making this change fully functional requires a corresponding kernel change; this change only allows one to build policies that would otherwise violate the bounds checking on target type. The kernel change is required to allow the permissions at runtime.

---
 libsepol/src/hierarchy.c | 26 --------------------------
 1 file changed, 26 deletions(-)
libsepol/src/hierarchy.c +0 -26
index 6f73195..ba65978 100644
@@ -329,32 +329,6 @@ static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p,
 			if (rc) goto exit;
 		}
 	}
-	if (ebitmap_get_bit(&p->attr_type_map[tgt - 1], child - 1)) {
-		avtab_key.target_type = parent;
-		ebitmap_for_each_bit(&p->attr_type_map[src - 1], tnode, i) {
-			if (!ebitmap_node_get_bit(tnode, i))
-				continue;
-			avtab_key.source_type = i + 1;
-			if (avtab_key.source_type == child) {
-				/* Checked above */
-				continue;
-			}
-			d = bounds_not_covered(global_avtab, cur_avtab,
-					       &avtab_key, data);
-			if (!d) continue;
-			td = p->type_val_to_struct[i];
-			if (td && td->bounds) {
-				avtab_key.source_type = td->bounds;
-				d = bounds_not_covered(global_avtab, cur_avtab,
-						       &avtab_key, data);
-				if (!d) continue;
-			}
-			(*numbad)++;
-			rc = bounds_add_bad(handle, i+1, child, class, d, bad);
-			if (rc) goto exit;
-		}
-	}
-
 exit:
 	return rc;
 }
Signature · 1 line
2.5.5
#1 lore raw

PATCH 2/2 libsepol: fix type bounds checking for attributes

The type bounds / hierarchy checker was incorrectly handling rules with attributes as the target type, causing it to trigger violations if the parent type lacked a rule directly to the same attribute even if the parent had all the permissions to the types associated with that attribute. Skip the degenerate case and only check for the individual types.

---
 libsepol/src/hierarchy.c | 2 ++
 1 file changed, 2 insertions(+)
libsepol/src/hierarchy.c +2 -0
index ba65978..79db3a6 100644
@@ -318,6 +318,8 @@ static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p,
 					       &avtab_key, data);
 			if (!d) continue;
 			td = p->type_val_to_struct[i];
+			if (!td || td->flavor == TYPE_ATTRIB)
+				continue;
 			if (td && td->bounds) {
 				avtab_key.target_type = td->bounds;
 				d = bounds_not_covered(global_avtab, cur_avtab,
Signature · 1 line
2.5.5
#2 lore raw

Re: [PATCH 2/2] libsepol: fix type bounds checking for attributes

Quoted 18 lines · Stephen Smalley

The type bounds / hierarchy checker was incorrectly handling rules with attributes as the target type, causing it to trigger violations if the parent type lacked a rule directly to the same attribute even if the parent had all the permissions to the types associated with that attribute. Skip the degenerate case and only check for the individual types.

---
  libsepol/src/hierarchy.c | 2 ++
  1 file changed, 2 insertions(+)
libsepol/src/hierarchy.c +0 -0
index ba65978..79db3a6 100644

libsepol/src/hierarchy.c static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p, · line 325

Quoted 8 lines
libsepol/src/hierarchy.c +2 -0
@@ -318,6 +318,8 @@ static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p,
  					       &avtab_key, data);
  			if (!d) continue;
  			td = p->type_val_to_struct[i];
+			if (!td || td->flavor == TYPE_ATTRIB)
+				continue;
  			if (td && td->bounds) {
  				avtab_key.target_type = td->bounds;
  				d = bounds_not_covered(global_avtab, cur_avtab,

There shouldn't be any attributes here. CIL is wrongly including the attribute itself in the attr_type_map. Patch coming.

Jim

Signature · 2 lines
James Carter <[email protected]>
National Security Agency
#3 lore raw
In reply to Stephen Smalley
Quoted 43 lines · Stephen Smalley

The current bounds checking of both source and target types requires allowing any domain that has access to the child domain to also have the same permissions to the parent, which is undesirable. Drop the target bounds checking.

Making this change fully functional requires a corresponding kernel change; this change only allows one to build policies that would otherwise violate the bounds checking on target type. The kernel change is required to allow the permissions at runtime.

---
  libsepol/src/hierarchy.c | 26 --------------------------
  1 file changed, 26 deletions(-)
libsepol/src/hierarchy.c +0 -19
index 6f73195..ba65978 100644
@@ -329,32 +329,6 @@ static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p,
  			if (rc) goto exit;
  		}
  	}
-	if (ebitmap_get_bit(&p->attr_type_map[tgt - 1], child - 1)) {
-		avtab_key.target_type = parent;
-		ebitmap_for_each_bit(&p->attr_type_map[src - 1], tnode, i) {
-			if (!ebitmap_node_get_bit(tnode, i))
-				continue;
-			avtab_key.source_type = i + 1;
-			if (avtab_key.source_type == child) {
-				/* Checked above */
-				continue;
-			}
-			d = bounds_not_covered(global_avtab, cur_avtab,
-					       &avtab_key, data);
-			if (!d) continue;
-			td = p->type_val_to_struct[i];
-			if (td && td->bounds) {
-				avtab_key.source_type = td->bounds;
-				d = bounds_not_covered(global_avtab, cur_avtab,
-						       &avtab_key, data);
-				if (!d) continue;

libsepol/src/hierarchy.c static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p, · line 334

Quoted 10 lines
libsepol/src/hierarchy.c +0 -7
-			}
-			(*numbad)++;
-			rc = bounds_add_bad(handle, i+1, child, class, d, bad);
-			if (rc) goto exit;
-		}
-	}
-
  exit:
  	return rc;
  }

We also don't need to expand the tgt. I will send a new and improved patch.

Jim

Signature · 2 lines
James Carter <[email protected]>
National Security Agency