Skip to contentSkip to conversation

libsepol/cil: Don't add constraint if there are no permissions

PATCH In review James Carter 1 participant 3 messages Feb 11, 2022 – Mar 11, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libsepol/cil: Don't add constraint if there are no permissions

Since CIL allows permission expressions, it is possible for the expression to evaluate to no permissions. If this is the case, then don't add the constraint.

---
 libsepol/cil/src/cil_binary.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/cil/src/cil_binary.c +6 -0
index 4ac8ce8d..468fb595 100644
@@ -2823,6 +2823,12 @@ int cil_constrain_to_policydb_helper(policydb_t *pdb, const struct cil_db *db, s
 		goto exit;
 	}
 
+	if (sepol_constrain->permissions == 0) {
+		/* No permissions, so don't insert rule. */
+		free(sepol_constrain);
+		return SEPOL_OK;
+	}
+
 	rc = __cil_constrain_expr_to_sepol_expr(pdb, db, expr, &sepol_expr);
 	if (rc != SEPOL_OK) {
 		goto exit;
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 libsepol: Don't write out constraint if it has no permissions

When writing a conf file or CIL policy out from a kernel binary, do not write out a constraint rule if it has no permissions.

---
 libsepol/src/kernel_to_cil.c  | 3 +++
 libsepol/src/kernel_to_conf.c | 3 +++
 2 files changed, 6 insertions(+)
libsepol/src/kernel_to_cil.c +3 -0
index 693206d2..869f6940 100644
@@ -282,6 +282,9 @@ static int class_constraint_rules_to_strs(struct policydb *pdb, char *classkey,
 	struct strs *strs;
 
 	for (curr = constraint_rules; curr != NULL; curr = curr->next) {
+		if (curr->permissions == 0) {
+			continue;
+		}
 		expr = constraint_expr_to_str(pdb, curr->expr, &is_mls);
 		if (!expr) {
 			rc = -1;
libsepol/src/kernel_to_conf.c +3 -0
index 52b6c60f..3544f73d 100644
@@ -277,6 +277,9 @@ static int class_constraint_rules_to_strs(struct policydb *pdb, char *classkey,
 	int rc = 0;
 
 	for (curr = constraint_rules; curr != NULL; curr = curr->next) {
+		if (curr->permissions == 0) {
+			continue;
+		}
 		expr = constraint_expr_to_str(pdb, curr->expr, &is_mls);
 		if (!expr) {
 			rc = -1;
Signature · 1 line
2.34.1
#2 lore raw
In reply to James Carter
Quoted 6 lines · James Carter

Since CIL allows permission expressions, it is possible for the expression to evaluate to no permissions. If this is the case, then don't add the constraint.

These two patches have been merged.
Jim

Quoted 24 lines
---
 libsepol/cil/src/cil_binary.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/cil/src/cil_binary.c +6 -1
index 4ac8ce8d..468fb595 100644
@@ -2823,6 +2823,12 @@ int cil_constrain_to_policydb_helper(policydb_t *pdb, const struct cil_db *db, s
                goto exit;
        }
 
+       if (sepol_constrain->permissions == 0) {
+               /* No permissions, so don't insert rule. */
+               free(sepol_constrain);
+               return SEPOL_OK;
+       }
+
        rc = __cil_constrain_expr_to_sepol_expr(pdb, db, expr, &sepol_expr);
        if (rc != SEPOL_OK) {
                goto exit;
--

2.34.1