Skip to contentSkip to conversation

net/mlx5: fix memleak for resource object

PATCH Superseded Mahmoud Maatuq 4 participants 10 messages Jun 23, 2024 – Jul 4, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: fix memleak for resource object

Coverity issue: 426424

Fixes e78e5408da89 ("net/mlx5: remove cache term from the list utility")
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +4 -1
index d46beffd4c..1010b8e423 100644
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
 		items = *((const struct rte_flow_item **)(ctx->data2));
 		resource->matcher_object = mlx5dr_bwc_matcher_create
 				(resource->group->tbl, resource->priority, items);
-		if (!(resource->matcher_object))
+		if (!(resource->matcher_object)) {
+			mlx5_free(resource);
 			return NULL;
+		}
 #else
+		mlx5_free(resource);
 		return NULL;
 #endif
 	}
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Thank you very much for the fix.

Could you please provide the commit message explaining the problem reported by Coverity and the fix?

Quoted 10 lines

-----Original Message-----
From: Mahmoud Maatuq <[email protected]>
Sent: Sunday, June 23, 2024 12:36
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Mahmoud Maatuq <[email protected]>
Subject: [PATCH] net/mlx5: fix memleak for resource object

Quoted 2 lines

Coverity issue: 426424

Fixes e78e5408da89 ("net/mlx5: remove cache term from the list utility")

The issue was introduced in commit 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure"). Fixes tag should reference that commit.

Quoted 12 lines
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +0 -0
index d46beffd4c..1010b8e423 100644

drivers/net/mlx5/mlx5_flow_dv.c flow_matcher_create_cb(void *tool_ctx, void · line 12014

Quoted 6 lines
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
 *cb_ctx)
                items = *((const struct rte_flow_item **)(ctx->data2));
                resource->matcher_object = mlx5dr_bwc_matcher_create
                                (resource->group->tbl, resource->priority, items);
-               if (!(resource->matcher_object))
+               if (!(resource->matcher_object)) {

While we're at it, could you please remove the parentheses around resource->matcher_object? They're redundant.

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +3 -0
+                       mlx5_free(resource);
                        return NULL;
+               }
 #else
+               mlx5_free(resource);
                return NULL;
 #endif
        }

--
2.43.0

Best regards,
Dariusz Sosnowski

#2 lore raw
Quoted 5 lines · Dariusz Sosnowski

Hi,

Thank you very much for the fix.

Could you please provide the commit message explaining the problem reported by Coverity and the fix?

I thought of doing that, but found Coverity report already explained it, so i was afraid it could be redundant, but I'll add it as a quick explanation

Quoted 11 lines
Quoted 11 lines

-----Original Message-----
From: Mahmoud Maatuq <[email protected]>
Sent: Sunday, June 23, 2024 12:36
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Mahmoud Maatuq <[email protected]>
Subject: [PATCH] net/mlx5: fix memleak for resource object

Quoted 5 lines
Quoted 2 lines

Coverity issue: 426424

Fixes e78e5408da89 ("net/mlx5: remove cache term from the list utility")

The issue was introduced in commit 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure"). Fixes tag should reference that commit.

how to get the proper commit that introduced the issue, as I used git blame to get the above mentioned commit

Quoted 36 lines
Quoted 13 lines
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +0 -0
index d46beffd4c..1010b8e423 100644

drivers/net/mlx5/mlx5_flow_dv.c flow_matcher_create_cb(void *tool_ctx, void · line 12014

Quoted 6 lines
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
 *cb_ctx)
                items = *((const struct rte_flow_item **)(ctx->data2));
                resource->matcher_object = mlx5dr_bwc_matcher_create
                                (resource->group->tbl, resource->priority, items);
-               if (!(resource->matcher_object))
+               if (!(resource->matcher_object)) {

While we're at it, could you please remove the parentheses around resource->matcher_object? They're redundant.

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +3 -0
+                       mlx5_free(resource);
                        return NULL;
+               }
 #else
+               mlx5_free(resource);
                return NULL;
 #endif
        }

--
2.43.0

Best regards,
Dariusz Sosnowski

#3 lore raw
Quoted 13 lines

-----Original Message-----
From: Mahmoud Maatouq <[email protected]>
Sent: Monday, June 24, 2024 21:10
To: Dariusz Sosnowski <[email protected]>
Cc: Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; [email protected]
Subject: Re: [PATCH] net/mlx5: fix memleak for resource object

Quoted 2 lines · Dariusz Sosnowski

Hi,

Quoted 7 lines
Quoted 3 lines

Thank you very much for the fix.

Could you please provide the commit message explaining the problem reported

by Coverity and the fix?

I thought of doing that, but found Coverity report already explained it, so i was afraid it could be redundant, but I'll add it as a quick explanation

Thank you. I'll review v2.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Mahmoud Maatuq <[email protected]>
Sent: Sunday, June 23, 2024 12:36
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan

Azrad

Quoted 8 lines
Quoted 7 lines

<[email protected]>
Cc: [email protected]; Mahmoud Maatuq <[email protected]>
Subject: [PATCH] net/mlx5: fix memleak for resource object

Coverity issue: 426424

Fixes e78e5408da89 ("net/mlx5: remove cache term from the list

utility")

Quoted 6 lines
Quoted 1 line

The issue was introduced in commit 27d171b88031 ("net/mlx5: abstract flow

action and enable reconfigure").

Quoted 1 line

Fixes tag should reference that commit.

how to get the proper commit that introduced the issue, as I used git blame to get the above mentioned commit

I'd say that git blame for the code with the bug is a starting point.
The suspected commit (according to line number) should be verified if it really introduced the issue. For example, in this patch:
- commit e78e5408da89 - modified the API for mlx5 list.
It modified flow_dv_matcher_create_cb function but did not introduce the "if" with missing resource release.
- commit 27d171b88031 - introduced additional resource allocation and clean up was not covered in all code paths.

Quoted 39 lines
Quoted 39 lines
Quoted 15 lines
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_flow_dv.c index d46beffd4c..1010b8e423 100644

drivers/net/mlx5/mlx5_flow_dv.c flow_matcher_create_cb(void *tool_ctx, void · line 12014

Quoted 6 lines
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
 *cb_ctx)
                items = *((const struct rte_flow_item **)(ctx->data2));
                resource->matcher_object = mlx5dr_bwc_matcher_create
                                (resource->group->tbl, resource->priority, items);
-               if (!(resource->matcher_object))
+               if (!(resource->matcher_object)) {

While we're at it, could you please remove the parentheses around resource- matcher_object? They're redundant.

Quoted 10 lines
drivers/net/mlx5/mlx5_flow_dv.c +3 -0
+                       mlx5_free(resource);
                        return NULL;
+               }
 #else
+               mlx5_free(resource);
                return NULL;
 #endif
        }

--
2.43.0

Best regards,
Dariusz Sosnowski

#4 lore raw

PATCH v2 1/1 net/mlx5: fix memleak for resource object

In reply to Mahmoud Maatuq

this makes sure that the allocated resource object is freed for all branches that return NULL

Coverity issue: 426424

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +4 -1
index d46beffd4c..8a0d58cb05 100644
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
 		items = *((const struct rte_flow_item **)(ctx->data2));
 		resource->matcher_object = mlx5dr_bwc_matcher_create
 				(resource->group->tbl, resource->priority, items);
-		if (!(resource->matcher_object))
+		if (!resource->matcher_object) {
+			mlx5_free(resource);
 			return NULL;
+		}
 #else
+		mlx5_free(resource);
 		return NULL;
 #endif
 	}
Signature · 1 line
2.43.0
#5 lore raw

Hi,

Sorry for the delayed review. Just two small comments.

Quoted 9 lines

-----Original Message-----
From: Mahmoud Maatuq <[email protected]>
Sent: Monday, June 24, 2024 21:42
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; Maayan Kashani <[email protected]>
Cc: [email protected]; Mahmoud Maatuq <[email protected]>
Subject: [PATCH v2] net/mlx5: fix memleak for resource object

I think for clarity what resource was leaking, a better title would be:
net/mlx5: fix matcher object memory leak

Quoted 3 lines

this makes sure that the allocated resource object is freed for all branches that return NULL

Typo: s/this/This/
Also, s/allocated resource object/allocated matcher object/ Also, please add a period at the end of the sentence.

Quoted 28 lines

Coverity issue: 426424

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")
---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +4 -1
index d46beffd4c..8a0d58cb05 100644
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
 *cb_ctx)
                items = *((const struct rte_flow_item **)(ctx->data2));
                resource->matcher_object = mlx5dr_bwc_matcher_create
                                (resource->group->tbl, resource->priority, items);
-               if (!(resource->matcher_object))
+               if (!resource->matcher_object) {
+                       mlx5_free(resource);
                        return NULL;
+               }
 #else
+               mlx5_free(resource);
                return NULL;
 #endif
        }
Quoted 2 lines

--
2.43.0

Best regards,
Dariusz Sosnowski

#6 lore raw

PATCH v3 1/1 net/mlx5: fix matcher object memory leak

In reply to Mahmoud Maatuq

This makes sure that the allocated matcher object is freed for all branches that return NULL.

Coverity issue: 426424

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")

---
v3:
* changed commit message.
* fixed typos
v2:
* fixed Fixes and Cc tags.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +4 -1
index d46beffd4c..8a0d58cb05 100644
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
 		items = *((const struct rte_flow_item **)(ctx->data2));
 		resource->matcher_object = mlx5dr_bwc_matcher_create
 				(resource->group->tbl, resource->priority, items);
-		if (!(resource->matcher_object))
+		if (!resource->matcher_object) {
+			mlx5_free(resource);
 			return NULL;
+		}
 #else
+		mlx5_free(resource);
 		return NULL;
 #endif
 	}

--
2.43.0

Acked-by on v3 1/1
#7 lore raw

RE: [PATCH v3] net/mlx5: fix matcher object memory leak

Hi,

Quoted 52 lines

-----Original Message-----
From: Mahmoud Maatuq <[email protected]>
Sent: Wednesday, July 3, 2024 4:15 AM
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; Maayan Kashani <[email protected]>
Cc: [email protected]; Mahmoud Maatuq <[email protected]>
Subject: [PATCH v3] net/mlx5: fix matcher object memory leak

External email: Use caution opening links or attachments

This makes sure that the allocated matcher object is freed for all branches that return NULL.

Coverity issue: 426424

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable

reconfigure")
Cc: [email protected]

---
v3:
* changed commit message.
* fixed typos
v2:
* fixed Fixes and Cc tags.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_flow_dv.c index d46beffd4c..8a0d58cb05 100644

drivers/net/mlx5/mlx5_flow_dv.c +4 -1
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
 *cb_ctx)
                items = *((const struct rte_flow_item **)(ctx->data2));
                resource->matcher_object = mlx5dr_bwc_matcher_create
                                (resource->group->tbl, resource->priority,
 items);
-               if (!(resource->matcher_object))
+               if (!resource->matcher_object) {
+                       mlx5_free(resource);
                        return NULL;
+               }
 #else
+               mlx5_free(resource);
                return NULL;
 #endif
        }
Quoted 2 lines

--
2.43.0

#8 lore raw

RE: [PATCH v3] net/mlx5: fix matcher object memory leak

Hi,

Quoted 63 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Wednesday, July 3, 2024 10:00
To: Mahmoud Maatuq <[email protected]>; Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>; Maayan Kashani <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v3] net/mlx5: fix matcher object memory leak

Hi,

Quoted 6 lines

-----Original Message-----
From: Mahmoud Maatuq <[email protected]>
Sent: Wednesday, July 3, 2024 4:15 AM
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Bing Zhao <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan

Azrad

Quoted 42 lines

<[email protected]>; Maayan Kashani <[email protected]>
Cc: [email protected]; Mahmoud Maatuq <[email protected]>
Subject: [PATCH v3] net/mlx5: fix matcher object memory leak

External email: Use caution opening links or attachments

This makes sure that the allocated matcher object is freed for all branches that return NULL.

Coverity issue: 426424

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable

reconfigure")
Cc: [email protected]

---
v3:
* changed commit message.
* fixed typos
v2:
* fixed Fixes and Cc tags.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_flow_dv.c index d46beffd4c..8a0d58cb05 100644

drivers/net/mlx5/mlx5_flow_dv.c +3 -1
@@ -12010,9 +12010,12 @@ flow_matcher_create_cb(void *tool_ctx, void
 *cb_ctx)
                items = *((const struct rte_flow_item **)(ctx->data2));
                resource->matcher_object = mlx5dr_bwc_matcher_create
                                (resource->group->tbl,
 resource->priority, items);
-               if (!(resource->matcher_object))
+               if (!resource->matcher_object) {
+                       mlx5_free(resource);
                        return NULL;
+               }
 #else
Quoted 8 lines
Quoted 6 lines
drivers/net/mlx5/mlx5_flow_dv.c +1 -0
+               mlx5_free(resource);
                return NULL;
 #endif
        }

--
2.43.0

Thank you for all the changes and the patch!

Best regards,
Dariusz Sosnowski

#9 lore raw

Re: [PATCH v3] net/mlx5: fix matcher object memory leak

In reply to Mahmoud Maatuq

Hi,

From: Mahmoud Maatuq <[email protected]>
Sent: Tuesday, July 2, 2024 11:14 PM
To: Dariusz Sosnowski; Slava Ovsiienko; Bing Zhao; Ori Kam; Suanming Mou; Matan Azrad; Maayan Kashani
Cc: [email protected]; Mahmoud Maatuq
Subject: [PATCH v3] net/mlx5: fix matcher object memory leak

This makes sure that the allocated matcher object is freed for all branches that return NULL.

Coverity issue: 426424

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh