Skip to contentSkip to conversation

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

PATCH In review Vit Mojzis 2 participants 3 messages Apr 30, 2024 – May 2, 2024 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

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

libsepol-3.6/cil/src/cil_binary.c:902: alloc_fn: Storage is returned from allocation function "cil_malloc". libsepol-3.6/cil/src/cil_binary.c:902: var_assign: Assigning: "mls_level" = storage returned from "cil_malloc(24UL)". libsepol-3.6/cil/src/cil_binary.c:903: noescape: Resource "mls_level" is not freed or pointed-to in "mls_level_init". libsepol-3.6/cil/src/cil_binary.c:905: noescape: Resource "mls_level" is not freed or pointed-to in "mls_level_cpy". libsepol-3.6/cil/src/cil_binary.c:919: leaked_storage: Variable "mls_level" 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 95bd18ba..c8144a5a 100644
@@ -904,6 +904,7 @@ static int cil_sensalias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alia
 
 	rc = mls_level_cpy(mls_level, sepol_level->level);
 	if (rc != SEPOL_OK) {
+		free(mls_level);
 		goto exit;
 	}
 	sepol_alias->level = mls_level;
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Vit Mojzis

libsepol-3.6/cil/src/cil_binary.c:902: alloc_fn: Storage is returned from allocation function "cil_malloc". libsepol-3.6/cil/src/cil_binary.c:902: var_assign: Assigning: "mls_level" = storage returned from "cil_malloc(24UL)". libsepol-3.6/cil/src/cil_binary.c:903: noescape: Resource "mls_level" is not freed or pointed-to in "mls_level_init". libsepol-3.6/cil/src/cil_binary.c:905: noescape: Resource "mls_level" is not freed or pointed-to in "mls_level_cpy". libsepol-3.6/cil/src/cil_binary.c:919: leaked_storage: Variable "mls_level" going out of scope leaks the storage it points to.

Quoted 20 lines
---
 libsepol/cil/src/cil_binary.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -1
index 95bd18ba..c8144a5a 100644
@@ -904,6 +904,7 @@ static int cil_sensalias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alia
 
        rc = mls_level_cpy(mls_level, sepol_level->level);
        if (rc != SEPOL_OK) {
+               free(mls_level);
                goto exit;
        }
        sepol_alias->level = mls_level;
--

2.43.0

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

libsepol-3.6/cil/src/cil_binary.c:902: alloc_fn: Storage is returned from allocation function "cil_malloc". libsepol-3.6/cil/src/cil_binary.c:902: var_assign: Assigning: "mls_level" = storage returned from "cil_malloc(24UL)". libsepol-3.6/cil/src/cil_binary.c:903: noescape: Resource "mls_level" is not freed or pointed-to in "mls_level_init". libsepol-3.6/cil/src/cil_binary.c:905: noescape: Resource "mls_level" is not freed or pointed-to in "mls_level_cpy". libsepol-3.6/cil/src/cil_binary.c:919: leaked_storage: Variable "mls_level" going out of scope leaks the storage it points to.

Quoted 4 lines
Quoted 1 line

Merged.
Thanks,
Jim

Quoted 20 lines
Quoted 20 lines
---
 libsepol/cil/src/cil_binary.c | 1 +
 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -1
index 95bd18ba..c8144a5a 100644
@@ -904,6 +904,7 @@ static int cil_sensalias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alia
 
        rc = mls_level_cpy(mls_level, sepol_level->level);
        if (rc != SEPOL_OK) {
+               free(mls_level);
                goto exit;
        }
        sepol_alias->level = mls_level;
--

2.43.0