Skip to contentSkip to conversation

net/ice: fix hash flow segmentation fault

dpdk-dev Superseded [email protected] 2 participants 6 messages Mar 3, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

From: Zhu Tao <[email protected]>

Macro rte_errno is not a static value, so it needs to be updated in all error handling code.

Patch 'dc36bd5dfd' mistakenly consider that rte_errno is a constant, which causes the unrecognized flow rule to be marked as recognition success. Later, when the code tried to parse the flow rule, a null pointer caused a segmentation fault.

Fixes dc36bd5dfd ("net/ice: fix flow FDIR/switch memory leak")
---
 drivers/net/ice/ice_hash.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ice/ice_hash.c +10 -4
index d891538bd..e5fb0f344 100644
@@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 			void **meta,
 			struct rte_flow_error *error)
 {
-	int ret = -rte_errno;
+	int ret = 0;
 	struct ice_pattern_match_item *pattern_match_item;
 	struct rss_meta *rss_meta_ptr;
 
@@ -424,12 +424,16 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss supported pattern and find matched pattern. */
 	pattern_match_item = ice_search_pattern_match_item(pattern,
 					array, array_len, error);
-	if (!pattern_match_item)
+	if (!pattern_match_item) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	ret = ice_hash_check_inset(pattern, error);
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	/* Save protocol header to rss_meta. */
 	*meta = rss_meta_ptr;
@@ -439,8 +443,10 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss action. */
 	ret = ice_hash_parse_action(pattern_match_item, actions, meta, error);
 error:
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;
 		rte_free(rss_meta_ptr);
+	}
 	rte_free(pattern_match_item);
 
 	return ret;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 11 lines · On 03/03, [email protected] wrote:

From: Zhu Tao <[email protected]>

Macro rte_errno is not a static value, so it needs to be updated in all error handling code.

Patch 'dc36bd5dfd' mistakenly consider that rte_errno is a constant, which causes the unrecognized flow rule to be marked as recognition success. Later, when the code tried to parse the flow rule, a null pointer caused a segmentation fault.

Fixes dc36bd5dfd ("net/ice: fix flow FDIR/switch memory leak")

It's recommended to have 12 chars length of commit SHA in Fixes line. You can set below git alias for convenience.

git config alias.fixline "log -1 --abbrev=12 --format='Fixes: %h (\"%s\")%nCc: %ae'"

Quoted 24 lines

---
drivers/net/ice/ice_hash.c | 14 ++++++++++----

1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ice/ice_hash.c +1 -1
index d891538bd..e5fb0f344 100644
@@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 			void **meta,
 			struct rte_flow_error *error)
 {
-	int ret = -rte_errno;
+	int ret = 0;
 	struct ice_pattern_match_item *pattern_match_item;
 	struct rss_meta *rss_meta_ptr;
 
@@ -424,12 +424,16 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss supported pattern and find matched pattern. */
 	pattern_match_item = ice_search_pattern_match_item(pattern,
 					array, array_len, error);

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, · line 434

Quoted 10 lines
drivers/net/ice/ice_hash.c +5 -2
-	if (!pattern_match_item)
+	if (!pattern_match_item) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	ret = ice_hash_check_inset(pattern, error);
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;

This seems redundant, since ice_hash_check_inset would return -rte_errno directly.

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, · line 434

Quoted 12 lines
drivers/net/ice/ice_hash.c +1 -0
 		goto error;
+	}
 
 	/* Save protocol header to rss_meta. */
 	*meta = rss_meta_ptr;
@@ -439,8 +443,10 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss action. */
 	ret = ice_hash_parse_action(pattern_match_item, actions, meta, error);

error:

drivers/net/ice/ice_hash.c +2 -1
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;

Ditto.

Quoted 8 lines
		rte_free(rss_meta_ptr);
drivers/net/ice/ice_hash.c +1 -0
+	}
	rte_free(pattern_match_item);

	return ret;
Signature · 1 line
2.17.1
author
#2 lore raw

Hi Xiaolong,

Commit SHA length non-compliance will be modified in V2 patch.
The reason why they did not return immediately after the error is that they need to release the allocated memory after the error, which is released uniformly in error processing, so they did not return directly.

BR,
Zhu, Tao

Quoted 94 lines

-----Original Message-----
From: Ye, Xiaolong
Sent: Tuesday, March 3, 2020 11:32 AM
To: Zhu, TaoX <[email protected]>
Cc: Yang, Qiming <[email protected]>; Lu, Wenzhuo <[email protected]>; [email protected]; Su, Simei <[email protected]>; Cao, Yahui <[email protected]>; [email protected]
Subject: Re: [DPDK] net/ice: fix hash flow segmentation fault

Quoted 7 lines · On 03/03, [email protected] wrote:

From: Zhu Tao <[email protected]>

Macro rte_errno is not a static value, so it needs to be updated in all error handling code.

Patch 'dc36bd5dfd' mistakenly consider that rte_errno is a constant, which causes the unrecognized flow rule to be marked as recognition

success.

Quoted 4 lines

Later, when the code tried to parse the flow rule, a null pointer caused a segmentation fault.

Fixes dc36bd5dfd ("net/ice: fix flow FDIR/switch memory leak")

It's recommended to have 12 chars length of commit SHA in Fixes line. You can set below git alias for convenience.

git config alias.fixline "log -1 --abbrev=12 --format='Fixes: %h (\"%s\")%nCc: %ae'"

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused

Quoted 12 lines

---
drivers/net/ice/ice_hash.c | 14 ++++++++++----

1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ice/ice_hash.c +0 -0
index d891538bd..e5fb0f344 100644
@@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused

struct ice_adapter *ad,

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused

Quoted 9 lines
drivers/net/ice/ice_hash.c +1 -1
 			void **meta,
 			struct rte_flow_error *error)
 {
-	int ret = -rte_errno;
+	int ret = 0;
 	struct ice_pattern_match_item *pattern_match_item;
 	struct rss_meta *rss_meta_ptr;
 
@@ -424,12 +424,16 @@ ice_hash_parse_pattern_action(__rte_unused

struct ice_adapter *ad,

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, · line 434

Quoted 13 lines
drivers/net/ice/ice_hash.c +5 -2
 	/* Check rss supported pattern and find matched pattern. */
 	pattern_match_item = ice_search_pattern_match_item(pattern,
 					array, array_len, error);
-	if (!pattern_match_item)
+	if (!pattern_match_item) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	ret = ice_hash_check_inset(pattern, error);
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;

This seems redundant, since ice_hash_check_inset would return -rte_errno directly.

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused

Quoted 6 lines
drivers/net/ice/ice_hash.c +1 -0
 		goto error;
+	}
 
 	/* Save protocol header to rss_meta. */
 	*meta = rss_meta_ptr;
@@ -439,8 +443,10 @@ ice_hash_parse_pattern_action(__rte_unused

struct ice_adapter *ad,

drivers/net/ice/ice_hash.c ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad, · line 434

Quoted 7 lines
drivers/net/ice/ice_hash.c +0 -0
 	/* Check rss action. */
 	ret = ice_hash_parse_action(pattern_match_item, actions, meta,
 error);

error:

drivers/net/ice/ice_hash.c +2 -1
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;

Ditto.

Quoted 8 lines
		rte_free(rss_meta_ptr);
drivers/net/ice/ice_hash.c +1 -0
+	}
	rte_free(pattern_match_item);

	return ret;

--
2.17.1

#3 lore raw

PATCH v2 1/1 net/ice: fix hash flow segmentation fault

In reply to [email protected]

From: Zhu Tao <[email protected]>

Macro rte_errno is not a static value, so it needs to be updated in all error handling code.

Patch 'dc36bd5dfdeb' mistakenly consider that rte_errno is a constant, which causes the unrecognized flow rule to be marked as recognition success. Later, when the code tried to parse the flow rule, a null pointer caused a segmentation fault.

Fixes dc36bd5dfdeb ("net/ice: fix flow FDIR/switch memory leak")

---
v2 Changes:

Commit message: Use 12 chars length of commit SHA in Fixes line.

 drivers/net/ice/ice_hash.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ice/ice_hash.c +10 -4
index d891538bd..e5fb0f344 100644
@@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 			void **meta,
 			struct rte_flow_error *error)
 {
-	int ret = -rte_errno;
+	int ret = 0;
 	struct ice_pattern_match_item *pattern_match_item;
 	struct rss_meta *rss_meta_ptr;
 
@@ -424,12 +424,16 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss supported pattern and find matched pattern. */
 	pattern_match_item = ice_search_pattern_match_item(pattern,
 					array, array_len, error);
-	if (!pattern_match_item)
+	if (!pattern_match_item) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	ret = ice_hash_check_inset(pattern, error);
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	/* Save protocol header to rss_meta. */
 	*meta = rss_meta_ptr;
@@ -439,8 +443,10 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss action. */
 	ret = ice_hash_parse_action(pattern_match_item, actions, meta, error);
 error:
-	if (ret)
+	if (ret) {
+		ret = -rte_errno;
 		rte_free(rss_meta_ptr);
+	}
 	rte_free(pattern_match_item);
 
 	return ret;
Signature · 1 line
2.17.1
#4 lore raw

PATCH v3 1/1 net/ice: fix hash flow segmentation fault

In reply to [email protected]

From: Zhu Tao <[email protected]>

Macro rte_errno is not a static value, so it needs to be updated in all error handling code.

Patch 'dc36bd5dfdeb' mistakenly consider that rte_errno is a constant, which causes the unrecognized flow rule to be marked as recognition success. Later, when the code tried to parse the flow rule, a null pointer caused a segmentation fault.

Fixes dc36bd5dfdeb ("net/ice: fix flow FDIR/switch memory leak")

---
v3 Changes:

Commit message: Use 12 chars length of commit SHA in Fixes line.

 Code: Delete redundant assignment codes.

v2 Changes:

Commit message: Use 12 chars length of commit SHA in Fixes line.

 drivers/net/ice/ice_hash.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ice/ice_hash.c +4 -2
index d891538bd..0e9c3c4e5 100644
@@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 			void **meta,
 			struct rte_flow_error *error)
 {
-	int ret = -rte_errno;
+	int ret = 0;
 	struct ice_pattern_match_item *pattern_match_item;
 	struct rss_meta *rss_meta_ptr;
 
@@ -424,8 +424,10 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss supported pattern and find matched pattern. */
 	pattern_match_item = ice_search_pattern_match_item(pattern,
 					array, array_len, error);
-	if (!pattern_match_item)
+	if (!pattern_match_item) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	ret = ice_hash_check_inset(pattern, error);
 	if (ret)
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1 Applied
#5 lore raw
Quoted 55 lines · On 03/03, [email protected] wrote:

From: Zhu Tao <[email protected]>

Macro rte_errno is not a static value, so it needs to be updated in all error handling code.

Patch 'dc36bd5dfdeb' mistakenly consider that rte_errno is a constant, which causes the unrecognized flow rule to be marked as recognition success. Later, when the code tried to parse the flow rule, a null pointer caused a segmentation fault.

Fixes dc36bd5dfdeb ("net/ice: fix flow FDIR/switch memory leak")

---
v3 Changes:

Commit message: Use 12 chars length of commit SHA in Fixes line.

Code: Delete redundant assignment codes.

v2 Changes:

Commit message: Use 12 chars length of commit SHA in Fixes line.

drivers/net/ice/ice_hash.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ice/ice_hash.c +4 -2
index d891538bd..0e9c3c4e5 100644
@@ -409,7 +409,7 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 			void **meta,
 			struct rte_flow_error *error)
 {
-	int ret = -rte_errno;
+	int ret = 0;
 	struct ice_pattern_match_item *pattern_match_item;
 	struct rss_meta *rss_meta_ptr;
 
@@ -424,8 +424,10 @@ ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
 	/* Check rss supported pattern and find matched pattern. */
 	pattern_match_item = ice_search_pattern_match_item(pattern,
 					array, array_len, error);
-	if (!pattern_match_item)
+	if (!pattern_match_item) {
+		ret = -rte_errno;
 		goto error;
+	}
 
 	ret = ice_hash_check_inset(pattern, error);
 	if (ret)
Signature · 1 line
2.17.1

Applied to dpdk-next-net-intel, Thanks.