Skip to contentSkip to conversation

bugfix for graph

PATCH Superseded Min Hu (Connor) 4 participants 15 messages Apr 22, 2021 – Jun 3, 2021

lore
Share & tools
lore
#0 lore raw

cover bugfix for graph

This patchset contains two bugfixes for graph.

HongBo Zheng (2):
graph: fix memory leak
graph: fix dereferencing null pointer

 lib/librte_graph/graph_stats.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 graph: fix memory leak

From: HongBo Zheng <[email protected]>

Fix function 'stats_mem_populate' return without
free dynamic memory referenced by 'stats'.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/librte_graph/graph_stats.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_graph/graph_stats.c +3 -1
index 125e08d..f698bb3 100644
@@ -174,7 +174,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	cluster->stat.hz = rte_get_timer_hz();
 	node = graph_node_id_to_ptr(graph, id);
 	if (node == NULL)
-		SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph %s",
+		SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s",
 			    graph_node->node->name, graph->name);
 	cluster->nodes[cluster->nb_nodes++] = node;
 
@@ -183,6 +183,8 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	*stats_in = stats;
 
 	return 0;
+free:
+	free(stats);
 err:
 	return -rte_errno;
 }
Signature · 1 line
2.7.4
Reviewed-by on v1 1/2
#2 lore raw

Re: [dpdk-dev] [EXT] [PATCH 1/2] graph: fix memory leak

Quoted 52 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 22, 2021 5:22 PM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] [PATCH 1/2] graph: fix memory leak

External Email

----------------------------------------------------------------------
From: HongBo Zheng <[email protected]>

Fix function 'stats_mem_populate' return without free dynamic memory referenced by 'stats'.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/librte_graph/graph_stats.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_graph/graph_stats.c index renamed from lib/librte_graph/graph_stats.c +0 -0

125e08d..f698bb3 100644

lib/librte_graph/graph_stats.c +1 -1
@@ -174,7 +174,7 @@ stats_mem_populate(struct rte_graph_cluster_stats
 **stats_in,
 	cluster->stat.hz = rte_get_timer_hz();
 	node = graph_node_id_to_ptr(graph, id);
 	if (node == NULL)
-		SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph
 %s",
+		SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph
 %s",
lib/librte_graph/graph_stats.c +2 -0
 			    graph_node->node->name, graph->name);
 	cluster->nodes[cluster->nb_nodes++] = node;
@@ -183,6 +183,8 @@ stats_mem_populate(struct rte_graph_cluster_stats
 **stats_in,
 	*stats_in = stats;
 
 	return 0;
+free:
+	free(stats);
 err:
 	return -rte_errno;
Quoted 3 lines

}
--
2.7.4

#3 lore raw

Re: [dpdk-dev] [PATCH 1/2] graph: fix memory leak

In reply to Min Hu (Connor)
Quoted 29 lines · Min Hu (Connor)

From: HongBo Zheng <[email protected]>

Fix function 'stats_mem_populate' return without
free dynamic memory referenced by 'stats'.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/librte_graph/graph_stats.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_graph/graph_stats.c +1 -1
index 125e08d..f698bb3 100644
@@ -174,7 +174,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
        cluster->stat.hz = rte_get_timer_hz();
        node = graph_node_id_to_ptr(graph, id);
        if (node == NULL)
-               SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph %s",
+               SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s",
                            graph_node->node->name, graph->name);
        cluster->nodes[cluster->nb_nodes++] = node;
 

lib/librte_graph/graph_stats.c stats_mem_populate(struct rte_graph_cluster_stats **stats_in, · line 190

Quoted 8 lines
lib/librte_graph/graph_stats.c +2 -0
@@ -183,6 +183,8 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
        *stats_in = stats;
 
        return 0;
+free:
+       free(stats);
 err:
        return -rte_errno;
 }

We have a double free with this change.

If realloc on stats returns the same location, but node lookup fails, stats_in is left untouched and still points at the original stats location.
This location is then freed in the free: label, and later is freed in stats_mem_fini() from caller.

Signature · 1 line
David Marchand
#4 lore raw

Re: [dpdk-dev] [PATCH 1/2] graph: fix memory leak

Quoted 32 lines · David Marchand
Quoted 31 lines · Min Hu (Connor)

From: HongBo Zheng <[email protected]>

Fix function 'stats_mem_populate' return without
free dynamic memory referenced by 'stats'.

Fixes af1ae8b6a32c ("graph: implement stats")
---
  lib/librte_graph/graph_stats.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_graph/graph_stats.c +1 -1
index 125e08d..f698bb3 100644
@@ -174,7 +174,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
         cluster->stat.hz = rte_get_timer_hz();
         node = graph_node_id_to_ptr(graph, id);
         if (node == NULL)
-               SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph %s",
+               SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s",
                             graph_node->node->name, graph->name);
         cluster->nodes[cluster->nb_nodes++] = node;
 
@@ -183,6 +183,8 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
         *stats_in = stats;
 
Quoted 9 lines

lib/librte_graph/graph_stats.c stats_mem_populate(struct rte_graph_cluster_stats **stats_in, · line 190

Quoted 6 lines
lib/librte_graph/graph_stats.c +2 -0
         return 0;
+free:
+       free(stats);
  err:
         return -rte_errno;
  }

We have a double free with this change.

Hi, David, I will set "*stats_in " to NULL.
As free(NULL) will just return and will not
result bugs.

Quoted 7 lines

If realloc on stats returns the same location, but node lookup fails, stats_in is left untouched and still points at the original stats location.
This location is then freed in the free: label, and later is freed in stats_mem_fini() from caller.

#5 lore raw

PATCH 2/2 graph: fix dereferencing null pointer

In reply to Min Hu (Connor)

From: HongBo Zheng <[email protected]>

In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/librte_graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_graph/graph_stats.c +1 -1
index f698bb3..bdc8652 100644
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
 	cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
 	stats = realloc(NULL, sz);
-	memset(stats, 0, sz);
 	if (stats) {
+		memset(stats, 0, sz);
 		stats->fn = fn;
 		stats->cluster_node_size = cluster_node_size;
 		stats->max_nodes = 0;
Signature · 1 line
2.7.4
Reviewed-by on v1 2/2
#6 lore raw

Re: [dpdk-dev] [EXT] [PATCH 2/2] graph: fix dereferencing null pointer

Quoted 41 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 22, 2021 5:22 PM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] [PATCH 2/2] graph: fix dereferencing null pointer

External Email

----------------------------------------------------------------------
From: HongBo Zheng <[email protected]>

In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/librte_graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_graph/graph_stats.c index renamed from lib/librte_graph/graph_stats.c +0 -0

f698bb3..bdc8652 100644

lib/librte_graph/graph_stats.c +1 -1
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
 	cluster_node_size = RTE_ALIGN(cluster_node_size,
 RTE_CACHE_LINE_SIZE);
 
 	stats = realloc(NULL, sz);
-	memset(stats, 0, sz);
 	if (stats) {
+		memset(stats, 0, sz);
 		stats->fn = fn;
 		stats->cluster_node_size = cluster_node_size;
Quoted 3 lines

stats->max_nodes = 0;
--
2.7.4

Acked-by on v1 2/2
#7 lore raw

Re: [dpdk-dev] [PATCH 2/2] graph: fix dereferencing null pointer

In reply to Min Hu (Connor)

lib/librte_graph/graph_stats.c

Quoted 16 lines · Min Hu (Connor)

From: HongBo Zheng <[email protected]>

In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/librte_graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_graph/graph_stats.c +0 -0

The directory name is changed in upstream. Please rebase.

Quoted 16 lines

index f698bb3..bdc8652 100644

lib/librte_graph/graph_stats.c +1 -2
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
        cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
        stats = realloc(NULL, sz);
-       memset(stats, 0, sz);
        if (stats) {
+               memset(stats, 0, sz);
                stats->fn = fn;
                stats->cluster_node_size = cluster_node_size;
                stats->max_nodes = 0;
--

2.7.4

#8 lore raw

v2 cover bugfix for graph

In reply to Min Hu (Connor)

This patchset contains two bugfixes for graph.

HongBo Zheng (2):
graph: fix memory leak
graph: fix dereferencing null pointer

 lib/graph/graph_stats.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

---
v2:
* fix double free.

Signature · 1 line
2.7.4
#9 lore raw

PATCH v2 1/2 graph: fix memory leak

From: HongBo Zheng <[email protected]>

Fix function 'stats_mem_populate' return without
free dynamic memory referenced by 'stats'.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/graph/graph_stats.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/graph/graph_stats.c +4 -1
index 125e08d..30e295d 100644
@@ -165,6 +165,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	stats = realloc(stats, stats->sz + stats->cluster_node_size);
 	if (stats == NULL)
 		SET_ERR_JMP(ENOMEM, err, "Realloc failed");
+	*stats_in = NULL;
 
 	/* Clear the new struct cluster_node area */
 	cluster = RTE_PTR_ADD(stats, stats->sz),
@@ -174,7 +175,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	cluster->stat.hz = rte_get_timer_hz();
 	node = graph_node_id_to_ptr(graph, id);
 	if (node == NULL)
-		SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph %s",
+		SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s",
 			    graph_node->node->name, graph->name);
 	cluster->nodes[cluster->nb_nodes++] = node;
 
@@ -183,6 +184,8 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	*stats_in = stats;
 
 	return 0;
+free:
+	free(stats);
 err:
 	return -rte_errno;
 }
Signature · 1 line
2.7.4
Reviewed-by on v2 1/2
#10 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] graph: fix memory leak

Quoted 11 lines · Min Hu (Connor)

From: HongBo Zheng <[email protected]>

Fix function 'stats_mem_populate' return without
free dynamic memory referenced by 'stats'.

Fixes af1ae8b6a32c ("graph: implement stats")
Signature · 1 line
David Marchand
#11 lore raw

PATCH v2 2/2 graph: fix dereferencing null pointer

In reply to Min Hu (Connor)

From: HongBo Zheng <[email protected]>

In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it.

Fixes af1ae8b6a32c ("graph: implement stats")
---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
index 30e295d..aa70929 100644
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
 	cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
 	stats = realloc(NULL, sz);
-	memset(stats, 0, sz);
 	if (stats) {
+		memset(stats, 0, sz);
 		stats->fn = fn;
 		stats->cluster_node_size = cluster_node_size;
 		stats->max_nodes = 0;
Signature · 1 line
2.7.4
Reviewed-by on v2 2/2
#12 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] graph: fix dereferencing null pointer

Quoted 11 lines · Min Hu (Connor)

From: HongBo Zheng <[email protected]>

In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it.

Fixes af1ae8b6a32c ("graph: implement stats")
Quoted 21 lines
---
 lib/graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -2
index 30e295d..aa70929 100644
@@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
        cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
        stats = realloc(NULL, sz);
-       memset(stats, 0, sz);
        if (stats) {
+               memset(stats, 0, sz);
                stats->fn = fn;
                stats->cluster_node_size = cluster_node_size;
                stats->max_nodes = 0;
--

2.7.4

Reviewed-by on v2 2/2
#13 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] graph: fix dereferencing null pointer

In reply to Min Hu (Connor)
Quoted 11 lines · Min Hu (Connor)

From: HongBo Zheng <[email protected]>

In function 'stats_mem_init', pointer 'stats' should be confirmed not null before memset it.

Fixes af1ae8b6a32c ("graph: implement stats")
Signature · 1 line
David Marchand
#14 lore raw
In reply to Min Hu (Connor)
Quoted 9 lines · Min Hu (Connor)

This patchset contains two bugfixes for graph.

HongBo Zheng (2):
graph: fix memory leak
graph: fix dereferencing null pointer

 lib/graph/graph_stats.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand