|
|
71cd55 |
From 4ff514a33e2442ba7dac7e96fc7e371898eed316 Mon Sep 17 00:00:00 2001
|
|
|
71cd55 |
From: James Carter <jwcart2@gmail.com>
|
|
|
71cd55 |
Date: Thu, 24 Jun 2021 15:58:15 -0400
|
|
|
71cd55 |
Subject: [PATCH] libsepol/cil: Only reset AST if optional has a declaration
|
|
|
71cd55 |
|
|
|
71cd55 |
When disabling optionals, the AST needs to be reset only if one
|
|
|
71cd55 |
of the optional blocks being disabled contains a declaration.
|
|
|
71cd55 |
|
|
|
71cd55 |
Call the function cil_tree_subtree_has_decl() for each optional
|
|
|
71cd55 |
block being disabled and only reset the AST if one of them has
|
|
|
71cd55 |
a declaration in it.
|
|
|
71cd55 |
|
|
|
71cd55 |
Signed-off-by: James Carter <jwcart2@gmail.com>
|
|
|
71cd55 |
---
|
|
|
71cd55 |
libsepol/cil/src/cil_resolve_ast.c | 58 +++++++++++++++++-------------
|
|
|
71cd55 |
1 file changed, 34 insertions(+), 24 deletions(-)
|
|
|
71cd55 |
|
|
|
71cd55 |
diff --git a/libsepol/cil/src/cil_resolve_ast.c b/libsepol/cil/src/cil_resolve_ast.c
|
|
|
71cd55 |
index 5245cc1556bd..0ea5b1697dd2 100644
|
|
|
71cd55 |
--- a/libsepol/cil/src/cil_resolve_ast.c
|
|
|
71cd55 |
+++ b/libsepol/cil/src/cil_resolve_ast.c
|
|
|
71cd55 |
@@ -4230,33 +4230,43 @@ int cil_resolve_ast(struct cil_db *db, struct cil_tree_node *current)
|
|
|
71cd55 |
if (changed) {
|
|
|
71cd55 |
struct cil_list_item *item;
|
|
|
71cd55 |
if (pass > CIL_PASS_CALL1) {
|
|
|
71cd55 |
- /* Need to re-resolve because an optional was disabled that contained
|
|
|
71cd55 |
- * one or more declarations. We only need to reset to the call1 pass
|
|
|
71cd55 |
- * because things done in the preceding passes aren't allowed in
|
|
|
71cd55 |
- * optionals, and thus can't be disabled.
|
|
|
71cd55 |
- * Note: set pass to CIL_PASS_CALL1 because the pass++ will increment
|
|
|
71cd55 |
- * it to CIL_PASS_CALL2
|
|
|
71cd55 |
- */
|
|
|
71cd55 |
- cil_log(CIL_INFO, "Resetting declarations\n");
|
|
|
71cd55 |
-
|
|
|
71cd55 |
- if (pass >= CIL_PASS_MISC1) {
|
|
|
71cd55 |
- __cil_ordered_lists_reset(&extra_args.sidorder_lists);
|
|
|
71cd55 |
- __cil_ordered_lists_reset(&extra_args.classorder_lists);
|
|
|
71cd55 |
- __cil_ordered_lists_reset(&extra_args.unordered_classorder_lists);
|
|
|
71cd55 |
- __cil_ordered_lists_reset(&extra_args.catorder_lists);
|
|
|
71cd55 |
- __cil_ordered_lists_reset(&extra_args.sensitivityorder_lists);
|
|
|
71cd55 |
- cil_list_destroy(&db->sidorder, CIL_FALSE);
|
|
|
71cd55 |
- cil_list_destroy(&db->classorder, CIL_FALSE);
|
|
|
71cd55 |
- cil_list_destroy(&db->catorder, CIL_FALSE);
|
|
|
71cd55 |
- cil_list_destroy(&db->sensitivityorder, CIL_FALSE);
|
|
|
71cd55 |
+ int has_decls = CIL_FALSE;
|
|
|
71cd55 |
+
|
|
|
71cd55 |
+ cil_list_for_each(item, extra_args.to_destroy) {
|
|
|
71cd55 |
+ has_decls = cil_tree_subtree_has_decl(item->data);
|
|
|
71cd55 |
+ if (has_decls) {
|
|
|
71cd55 |
+ break;
|
|
|
71cd55 |
+ }
|
|
|
71cd55 |
}
|
|
|
71cd55 |
|
|
|
71cd55 |
- pass = CIL_PASS_CALL1;
|
|
|
71cd55 |
+ if (has_decls) {
|
|
|
71cd55 |
+ /* Need to re-resolve because an optional was disabled that
|
|
|
71cd55 |
+ * contained one or more declarations.
|
|
|
71cd55 |
+ * Everything that needs to be reset comes after the
|
|
|
71cd55 |
+ * CIL_PASS_CALL2 pass. We set pass to CIL_PASS_CALL1 because
|
|
|
71cd55 |
+ * the pass++ will increment it to CIL_PASS_CALL2
|
|
|
71cd55 |
+ */
|
|
|
71cd55 |
+ cil_log(CIL_INFO, "Resetting declarations\n");
|
|
|
71cd55 |
+
|
|
|
71cd55 |
+ if (pass >= CIL_PASS_MISC1) {
|
|
|
71cd55 |
+ __cil_ordered_lists_reset(&extra_args.sidorder_lists);
|
|
|
71cd55 |
+ __cil_ordered_lists_reset(&extra_args.classorder_lists);
|
|
|
71cd55 |
+ __cil_ordered_lists_reset(&extra_args.unordered_classorder_lists);
|
|
|
71cd55 |
+ __cil_ordered_lists_reset(&extra_args.catorder_lists);
|
|
|
71cd55 |
+ __cil_ordered_lists_reset(&extra_args.sensitivityorder_lists);
|
|
|
71cd55 |
+ cil_list_destroy(&db->sidorder, CIL_FALSE);
|
|
|
71cd55 |
+ cil_list_destroy(&db->classorder, CIL_FALSE);
|
|
|
71cd55 |
+ cil_list_destroy(&db->catorder, CIL_FALSE);
|
|
|
71cd55 |
+ cil_list_destroy(&db->sensitivityorder, CIL_FALSE);
|
|
|
71cd55 |
+ }
|
|
|
71cd55 |
|
|
|
71cd55 |
- rc = cil_reset_ast(current);
|
|
|
71cd55 |
- if (rc != SEPOL_OK) {
|
|
|
71cd55 |
- cil_log(CIL_ERR, "Failed to reset declarations\n");
|
|
|
71cd55 |
- goto exit;
|
|
|
71cd55 |
+ pass = CIL_PASS_CALL1;
|
|
|
71cd55 |
+
|
|
|
71cd55 |
+ rc = cil_reset_ast(current);
|
|
|
71cd55 |
+ if (rc != SEPOL_OK) {
|
|
|
71cd55 |
+ cil_log(CIL_ERR, "Failed to reset declarations\n");
|
|
|
71cd55 |
+ goto exit;
|
|
|
71cd55 |
+ }
|
|
|
71cd55 |
}
|
|
|
71cd55 |
}
|
|
|
71cd55 |
cil_list_for_each(item, extra_args.to_destroy) {
|
|
|
71cd55 |
--
|
|
|
71cd55 |
2.32.0
|
|
|
71cd55 |
|