Skip to contentSkip to conversation

libsepol/cil: Do not skip macros when resolving until later passes

PATCH In review James Carter 3 participants 3 messages Sep 29, 2021 – Oct 6, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Do not skip macros when resolving until later passes

Since only tunableifs need to be resolved in a macro before the macro is copied for each call, macros were being skipped after resolving tunableifs. Statments not allowed to be in macros would be found during the pass that resolved tunableifs. Unfortunately, in-statments are resolved after tunableifs and they can be used to add statements to macros that are not allowed.

Instead, do not skip macros until after the pass that resolves in- statements that are to be resolved after block inheritance. This allows blocks, blockinherits, blockabstracts, and macros that were added by an in-statement to be found and an error reported.

This bug was found by the secilc-fuzzer.

---
 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 2cf94368..e97a9f46 100644
@@ -3946,7 +3946,7 @@ int __cil_resolve_ast_node_helper(struct cil_tree_node *node, uint32_t *finished
 	}
 
 	if (node->flavor == CIL_MACRO) {
-		if (pass != CIL_PASS_TIF) {
+		if (pass > CIL_PASS_IN_AFTER) {
 			*finished = CIL_TREE_SKIP_HEAD;
 			rc = SEPOL_OK;
 			goto exit;
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · James Carter

Since only tunableifs need to be resolved in a macro before the macro is copied for each call, macros were being skipped after resolving tunableifs. Statments not allowed to be in macros would be found during the pass that resolved tunableifs. Unfortunately, in-statments are resolved after tunableifs and they can be used to add statements to macros that are not allowed.

Quoted 8 lines

Instead, do not skip macros until after the pass that resolves in- statements that are to be resolved after block inheritance. This allows blocks, blockinherits, blockabstracts, and macros that were added by an in-statement to be found and an error reported.

This bug was found by the secilc-fuzzer.

I confirm this fixes the issue reported in
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36466&q=selinux&can=2
which can be reproduced by the following policy:

(macro MACRO ())
(in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO)
...
repeated at least 4000 times

Thanks,
Nicolas

Quoted 20 lines
---
 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 2cf94368..e97a9f46 100644
@@ -3946,7 +3946,7 @@ int __cil_resolve_ast_node_helper(struct cil_tree_node *node, uint32_t *finished
        }
 
        if (node->flavor == CIL_MACRO) {
-               if (pass != CIL_PASS_TIF) {
+               if (pass > CIL_PASS_IN_AFTER) {
                        *finished = CIL_TREE_SKIP_HEAD;
                        rc = SEPOL_OK;
                        goto exit;
--

2.31.1

#2 lore raw
Quoted 32 lines · Nicolas Iooss
Quoted 8 lines · James Carter

Since only tunableifs need to be resolved in a macro before the macro is copied for each call, macros were being skipped after resolving tunableifs. Statments not allowed to be in macros would be found during the pass that resolved tunableifs. Unfortunately, in-statments are resolved after tunableifs and they can be used to add statements to macros that are not allowed.

Quoted 8 lines

Instead, do not skip macros until after the pass that resolves in- statements that are to be resolved after block inheritance. This allows blocks, blockinherits, blockabstracts, and macros that were added by an in-statement to be found and an error reported.

This bug was found by the secilc-fuzzer.

I confirm this fixes the issue reported in
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36466&q=selinux&can=2
which can be reproduced by the following policy:

(macro MACRO ())
(in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO) (in MACRO (blockinherit BLOCK)) (call MACRO)
...
repeated at least 4000 times

Quoted 2 lines

Merged. Thanks!

Quoted 20 lines
Quoted 20 lines
---
 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 2cf94368..e97a9f46 100644
@@ -3946,7 +3946,7 @@ int __cil_resolve_ast_node_helper(struct cil_tree_node *node, uint32_t *finished
        }
 
        if (node->flavor == CIL_MACRO) {
-               if (pass != CIL_PASS_TIF) {
+               if (pass > CIL_PASS_IN_AFTER) {
                        *finished = CIL_TREE_SKIP_HEAD;
                        rc = SEPOL_OK;
                        goto exit;
--

2.31.1