Skip to contentSkip to conversation

libsepol/cil: Only expand anonymous category sets in an expression

PATCH In review James Carter 1 participant 2 messages Jul 8, 2021 – Jul 9, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Only expand anonymous category sets in an expression

commit 982ec302b67f3c7f8df667dadb67352b1e4a6d18 (libsepol/cil:
Account for anonymous category sets in an expression) attempted to properly handle anonymous category sets when resolving category expressions. Unfortunately, it did not check whether a category set was actually an anonymous category set and expanded all category sets in an expression. If a category set refers to itself in the expression, then everything from the name of the category set to the end of the expression is ignored.

So, for example, the rule "(categoryset cs (c0 cs c1 c2))", would be equivalent to the rule "(categoryset cs (c0))" as everything from "cs" to the end would be dropped. The secilc-fuzzer found that the rule "(categoryset cat (not cat))" would cause a segfault since "(not)" is not a valid expression and it is assumed to be valid during later evaluation because syntax checking has already been done.

Instead, check whether or not the category set is anonymous before expanding it when resolving an expression.

---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -1
index 145d4e74..933caf9b 100644
@@ -3261,7 +3261,7 @@ int cil_resolve_expr(enum cil_flavor expr_type, struct cil_list *str_expr, struc
 			if (rc != SEPOL_OK) {
 				goto exit;
 			}
-			if (sym_index == CIL_SYM_CATS && NODE(res_datum)->flavor == CIL_CATSET) {
+			if (sym_index == CIL_SYM_CATS && !res_datum->name && NODE(res_datum)->flavor == CIL_CATSET) {
 				struct cil_catset *catset = (struct cil_catset *)res_datum;
 				if (!catset->cats->datum_expr) {
 					rc = cil_resolve_expr(expr_type, catset->cats->str_expr, &catset->cats->datum_expr, parent, extra_args);
Signature · 1 line
2.31.1
#1 lore raw

This patch has been superseded by the patch that also checks for a category set being used in a category range.
Jim

Quoted 42 lines · James Carter

commit 982ec302b67f3c7f8df667dadb67352b1e4a6d18 (libsepol/cil:
Account for anonymous category sets in an expression) attempted to properly handle anonymous category sets when resolving category expressions. Unfortunately, it did not check whether a category set was actually an anonymous category set and expanded all category sets in an expression. If a category set refers to itself in the expression, then everything from the name of the category set to the end of the expression is ignored.

So, for example, the rule "(categoryset cs (c0 cs c1 c2))", would be equivalent to the rule "(categoryset cs (c0))" as everything from "cs" to the end would be dropped. The secilc-fuzzer found that the rule "(categoryset cat (not cat))" would cause a segfault since "(not)" is not a valid expression and it is assumed to be valid during later evaluation because syntax checking has already been done.

Instead, check whether or not the category set is anonymous before expanding it when resolving an expression.

---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -2
index 145d4e74..933caf9b 100644
@@ -3261,7 +3261,7 @@ int cil_resolve_expr(enum cil_flavor expr_type, struct cil_list *str_expr, struc
                        if (rc != SEPOL_OK) {
                                goto exit;
                        }
-                       if (sym_index == CIL_SYM_CATS && NODE(res_datum)->flavor == CIL_CATSET) {
+                       if (sym_index == CIL_SYM_CATS && !res_datum->name && NODE(res_datum)->flavor == CIL_CATSET) {
                                struct cil_catset *catset = (struct cil_catset *)res_datum;
                                if (!catset->cats->datum_expr) {
                                        rc = cil_resolve_expr(expr_type, catset->cats->str_expr, &catset->cats->datum_expr, parent, extra_args);
--

2.31.1