Skip to contentSkip to conversation

libsepol/cil: Fix detected RESOURCE_LEAK (CWE-772)

PATCH In review Petr Lautrbach 2 participants 3 messages Sep 9, 2021 – Sep 13, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Fix detected RESOURCE_LEAK (CWE-772)

libsepol/cil/src/cil_binary.c:4823: alloc_arg: "bounds_check_type" allocates memory that is stored into "bad". libsepol/cil/src/cil_binary.c:4840: var_assign: Assigning: "cur" = "bad". libsepol/cil/src/cil_binary.c:4844: noescape: Resource "cur" is not freed or pointed-to in "cil_avrule_from_sepol". libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "cur" going out of scope leaks the storage it points to. libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "bad" going out of scope leaks the storage it points to.

---
 libsepol/cil/src/cil_binary.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -0
index 43c37fc24686..4a80cb562424 100644
@@ -4842,6 +4842,7 @@ static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void
 				rc = cil_avrule_from_sepol(pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);
 				if (rc != SEPOL_OK) {
 					cil_log(CIL_ERR, "Failed to convert sepol avrule to CIL\n");
+					bounds_destroy_bad(bad);
 					goto exit;
 				}
 				__cil_print_rule("  ", "allow", &target);
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Petr Lautrbach

libsepol/cil/src/cil_binary.c:4823: alloc_arg: "bounds_check_type" allocates memory that is stored into "bad". libsepol/cil/src/cil_binary.c:4840: var_assign: Assigning: "cur" = "bad". libsepol/cil/src/cil_binary.c:4844: noescape: Resource "cur" is not freed or pointed-to in "cil_avrule_from_sepol". libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "cur" going out of scope leaks the storage it points to. libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "bad" going out of scope leaks the storage it points to.

Quoted 19 lines
---
 libsepol/cil/src/cil_binary.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -1
index 43c37fc24686..4a80cb562424 100644
@@ -4842,6 +4842,7 @@ static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void
                                rc = cil_avrule_from_sepol(pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);
                                if (rc != SEPOL_OK) {
                                        cil_log(CIL_ERR, "Failed to convert sepol avrule to CIL\n");
+                                       bounds_destroy_bad(bad);
                                        goto exit;
                                }
                                __cil_print_rule("  ", "allow", &target);
--

2.32.0

#2 lore raw
Quoted 11 lines · James Carter
Quoted 8 lines · Petr Lautrbach

libsepol/cil/src/cil_binary.c:4823: alloc_arg: "bounds_check_type" allocates memory that is stored into "bad". libsepol/cil/src/cil_binary.c:4840: var_assign: Assigning: "cur" = "bad". libsepol/cil/src/cil_binary.c:4844: noescape: Resource "cur" is not freed or pointed-to in "cil_avrule_from_sepol". libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "cur" going out of scope leaks the storage it points to. libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "bad" going out of scope leaks the storage it points to.

Merged.

Quoted 19 lines
Quoted 19 lines
---
 libsepol/cil/src/cil_binary.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -1
index 43c37fc24686..4a80cb562424 100644
@@ -4842,6 +4842,7 @@ static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void
                                rc = cil_avrule_from_sepol(pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);
                                if (rc != SEPOL_OK) {
                                        cil_log(CIL_ERR, "Failed to convert sepol avrule to CIL\n");
+                                       bounds_destroy_bad(bad);
                                        goto exit;
                                }
                                __cil_print_rule("  ", "allow", &target);
--

2.32.0