Skip to contentSkip to conversation

libsepol: Fix memory leak in role_dominates_copy_callback

PATCH Superseded Vit Mojzis 3 participants 5 messages Mar 17 – May 12 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 libsepol: Fix memory leak in role_dominates_copy_callback

Free memory allocated by map_ebitmap in case ebitmap_union fails.

Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.

  \#   829|   		return -1;
  \#   830|   	if (ebitmap_union(&new_role->dominates, &mapped))
  \#   831|-> 		return -1;
  \#   832|   	ebitmap_destroy(&mapped);
  \#   833|
---
 libsepol/src/expand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -1
index ed912b57..72804f60 100644
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unused
 
 	if (map_ebitmap(&role->dominates, &mapped, state->rolemap))
 		return -1;
-	if (ebitmap_union(&new_role->dominates, &mapped))
+	if (ebitmap_union(&new_role->dominates, &mapped)) {
+		ebitmap_destroy(&mapped);
 		return -1;
+	}
 	ebitmap_destroy(&mapped);
 
 	return 0;
Signature · 1 line
2.52.0
#1 lore raw
Quoted 10 lines · Vit Mojzis

Free memory allocated by map_ebitmap in case ebitmap_union fails.

Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.

Quoted 6 lines
  \#   829|   		return -1;
  \#   830|   	if (ebitmap_union(&new_role->dominates, &mapped))
  \#   831|-> 		return -1;
  \#   832|   	ebitmap_destroy(&mapped);
  \#   833|

Missing Signed-of-by tag.

Quoted 22 lines
---
 libsepol/src/expand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -1
index ed912b57..72804f60 100644
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unused
 
 	if (map_ebitmap(&role->dominates, &mapped, state->rolemap))
 		return -1;
-	if (ebitmap_union(&new_role->dominates, &mapped))
+	if (ebitmap_union(&new_role->dominates, &mapped)) {
+		ebitmap_destroy(&mapped);
 		return -1;
+	}
 	ebitmap_destroy(&mapped);
 
 	return 0;
Signature · 1 line
2.52.0
author
#2 lore raw

PATCH v2 1/1 libsepol: Fix memory leak in role_dominates_copy_callback

Free memory allocated by map_ebitmap in case ebitmap_union fails.

Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.

  \#   829|   		return -1;
  \#   830|   	if (ebitmap_union(&new_role->dominates, &mapped))
  \#   831|-> 		return -1;
  \#   832|   	ebitmap_destroy(&mapped);
  \#   833|

---
No changes, only added "Signed-off-by".

 libsepol/src/expand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -1
index 5b2b7b03..c7978948 100644
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unused
 
 	if (map_ebitmap(&role->dominates, &mapped, state->rolemap))
 		return -1;
-	if (ebitmap_union(&new_role->dominates, &mapped))
+	if (ebitmap_union(&new_role->dominates, &mapped)) {
+		ebitmap_destroy(&mapped);
 		return -1;
+	}
 	ebitmap_destroy(&mapped);
 
 	return 0;
Signature · 1 line
2.53.0
Acked-by on v2 1/1
#3 lore raw
Quoted 10 lines · Vit Mojzis

Free memory allocated by map_ebitmap in case ebitmap_union fails.

Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.

Quoted 7 lines
  \#   829|   		return -1;
  \#   830|   	if (ebitmap_union(&new_role->dominates, &mapped))
  \#   831|-> 		return -1;
  \#   832|   	ebitmap_destroy(&mapped);
  \#   833|
Quoted 24 lines

---
No changes, only added "Signed-off-by".

 libsepol/src/expand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -1
index 5b2b7b03..c7978948 100644
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unused
 
 	if (map_ebitmap(&role->dominates, &mapped, state->rolemap))
 		return -1;
-	if (ebitmap_union(&new_role->dominates, &mapped))
+	if (ebitmap_union(&new_role->dominates, &mapped)) {
+		ebitmap_destroy(&mapped);
 		return -1;
+	}
 	ebitmap_destroy(&mapped);
 
 	return 0;
Signature · 1 line
2.53.0
#4 lore raw
Quoted 19 lines · Petr Lautrbach
Quoted 16 lines · Vit Mojzis

Free memory allocated by map_ebitmap in case ebitmap_union fails.

Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.

  \#   829|                   return -1;
  \#   830|           if (ebitmap_union(&new_role->dominates, &mapped))
  \#   831|->                 return -1;
  \#   832|           ebitmap_destroy(&mapped);
  \#   833|
Quoted 4 lines
Quoted 1 line

Merged.
Thanks,
Jim

Quoted 26 lines
Quoted 24 lines

---
No changes, only added "Signed-off-by".

 libsepol/src/expand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -2
index 5b2b7b03..c7978948 100644
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unused
 
      if (map_ebitmap(&role->dominates, &mapped, state->rolemap))
              return -1;
-     if (ebitmap_union(&new_role->dominates, &mapped))
+     if (ebitmap_union(&new_role->dominates, &mapped)) {
+             ebitmap_destroy(&mapped);
              return -1;
+     }
      ebitmap_destroy(&mapped);
 
      return 0;
--

2.53.0