Skip to contentSkip to conversation

libsepol/cil: Clear AST node after destroying bad filecon rule

PATCH In review James Carter 1 participant 3 messages Nov 29, 2023 – Dec 12, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Clear AST node after destroying bad filecon rule

Commit fb0a4ce1 (libsepol/cil: Allow paths in filecon rules to be passed as arguments) changed when the new AST node data would be set to point to the new filecon struct when creating a filecon rule. This causes cil_destroy_filecon() to be called twice on the filecon struct if there is an error when creating the filecon rule.

If there is an error when creating a filecon rule, call cil_clear_node() after destroying the filecon struct.

Reported-by oss-fuzz (issue 64385)
---
 libsepol/cil/src/cil_build_ast.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_build_ast.c +1 -0
index be260a31..56dac891 100644
@@ -4197,6 +4197,7 @@ int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, stru
 exit:
 	cil_tree_log(parse_current, CIL_ERR, "Bad filecon declaration");
 	cil_destroy_filecon(filecon);
+	cil_clear_node(ast_node);
 	return rc;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · James Carter

Commit fb0a4ce1 (libsepol/cil: Allow paths in filecon rules to be passed as arguments) changed when the new AST node data would be set to point to the new filecon struct when creating a filecon rule. This causes cil_destroy_filecon() to be called twice on the filecon struct if there is an error when creating the filecon rule.

Quoted 5 lines

If there is an error when creating a filecon rule, call cil_clear_node() after destroying the filecon struct.

Reported-by oss-fuzz (issue 64385)

I plan on merging this patch soon, unless there are any objections. Jim

Quoted 19 lines
---
 libsepol/cil/src/cil_build_ast.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_build_ast.c +1 -1
index be260a31..56dac891 100644
@@ -4197,6 +4197,7 @@ int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, stru
 exit:
        cil_tree_log(parse_current, CIL_ERR, "Bad filecon declaration");
        cil_destroy_filecon(filecon);
+       cil_clear_node(ast_node);
        return rc;
 }
 
--

2.43.0

#2 lore raw
Quoted 9 lines · James Carter
Quoted 7 lines · James Carter

Commit fb0a4ce1 (libsepol/cil: Allow paths in filecon rules to be passed as arguments) changed when the new AST node data would be set to point to the new filecon struct when creating a filecon rule. This causes cil_destroy_filecon() to be called twice on the filecon struct if there is an error when creating the filecon rule.

Quoted 9 lines
Quoted 5 lines

If there is an error when creating a filecon rule, call cil_clear_node() after destroying the filecon struct.

Reported-by oss-fuzz (issue 64385)

I plan on merging this patch soon, unless there are any objections. Jim

This has been merged.
Jim

Quoted 19 lines
Quoted 19 lines
---
 libsepol/cil/src/cil_build_ast.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_build_ast.c +1 -1
index be260a31..56dac891 100644
@@ -4197,6 +4197,7 @@ int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, stru
 exit:
        cil_tree_log(parse_current, CIL_ERR, "Bad filecon declaration");
        cil_destroy_filecon(filecon);
+       cil_clear_node(ast_node);
        return rc;
 }
 
--

2.43.0