Skip to contentSkip to conversation

net/ice: fix null pointer dereferences

PATCH Superseded Wenwu Ma 2 participants 5 messages Mar 1, 2024 – Mar 4, 2024 Network drivers

lore
Share & tools
lore

Wenwu Ma

author
#0 lore raw

PATCH 1/1 net/ice: fix null pointer dereferences

This patch fixes two null pointer dereferences detected by coverity scan.

Coverity issue: 414096

Fixes 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")
---
 drivers/net/ice/ice_tm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ice/ice_tm.c +8 -2
index fbab0b8808..e10ac855f9 100644
@@ -616,7 +616,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MAX_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+		else
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth");
 		return -EINVAL;
 	}
 
@@ -630,7 +633,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MIN_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+		else
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 29 lines · Wenwu Ma

This patch fixes two null pointer dereferences detected by coverity scan.

Coverity issue: 414096

Fixes 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")
---
 drivers/net/ice/ice_tm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ice/ice_tm.c +4 -1
index fbab0b8808..e10ac855f9 100644
@@ -616,7 +616,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MAX_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+		else
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth");
 		return -EINVAL;
 	}
 
@@ -630,7 +633,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MIN_BW,

drivers/net/ice/ice_tm.c static int ice_set_node_rate(struct ice_hw *hw, · line 642

Quoted 10 lines
drivers/net/ice/ice_tm.c +4 -1
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+		else
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth");
 		return -EINVAL;
 	}
 

Hi Wenwu,

I'm not sure that this is the best fix here, since the error message doesn't seem particularly useful without the node id. Looking at the code, this is a static function, so non-public, and only called in three places in rte_tm.c: from ice_cfg_hw_node, ice_do_hierarchy_commit and ice_reset_nolead_nodes. In all three cases, failure of this function is immediately followed by a more specific error message from the calling function. Therefore, I think we can solve the coverity problem by just deleting the error prints from here completely, and let the callers manage error reporting.

What do you think?

/Bruce

author
#2 lore raw
Quoted 65 lines

-----Original Message-----
From: Richardson, Bruce <[email protected]>
Sent: Friday, March 1, 2024 6:35 PM
To: Ma, WenwuX <[email protected]>
Cc: [email protected]; Jiale, SongX <[email protected]>
Subject: Re: [PATCH] net/ice: fix null pointer dereferences

Quoted 16 lines · Wenwu Ma

This patch fixes two null pointer dereferences detected by coverity scan.

Coverity issue: 414096

Fixes 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")
---
 drivers/net/ice/ice_tm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ice/ice_tm.c index renamed from drivers/net/ice/ice_tm.c +0 -0

fbab0b8808..e10ac855f9 100644

drivers/net/ice/ice_tm.c static int ice_set_node_rate(struct ice_hw *hw, · line 619

Quoted 4 lines
drivers/net/ice/ice_tm.c +0 -1
@@ -616,7 +616,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MAX_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for

node %u", tm_node->id);

drivers/net/ice/ice_tm.c static int ice_set_node_rate(struct ice_hw *hw, · line 620

Quoted 2 lines
drivers/net/ice/ice_tm.c +2 -0
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth for

node %u", tm_node->id);

drivers/net/ice/ice_tm.c static int ice_set_node_rate(struct ice_hw *hw, · line 633

Quoted 10 lines
drivers/net/ice/ice_tm.c +2 -1
+		else
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth");
 		return -EINVAL;
 	}
 
@@ -630,7 +633,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MIN_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for

node %u", tm_node->id);

drivers/net/ice/ice_tm.c static int ice_set_node_rate(struct ice_hw *hw, · line 637

Quoted 2 lines
drivers/net/ice/ice_tm.c +2 -0
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth for

node %u", tm_node->id);

drivers/net/ice/ice_tm.c static int ice_set_node_rate(struct ice_hw *hw, · line 642

Quoted 5 lines
drivers/net/ice/ice_tm.c +2 -0
+		else
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth");
 		return -EINVAL;
 	}
 

Hi Wenwu,

I'm not sure that this is the best fix here, since the error message doesn't seem particularly useful without the node id. Looking at the code, this is a static function, so non-public, and only called in three places in rte_tm.c: from ice_cfg_hw_node, ice_do_hierarchy_commit and ice_reset_nolead_nodes. In all three cases, failure of this function is immediately followed by a more specific error message from the calling function. Therefore, I think we can solve the coverity problem by just deleting the error prints from here completely, and let the callers manage error reporting.

Quoted 2 lines

What do you think?

Ok, I will submit a new patch later.

Quoted 1 line

/Bruce

author
#3 lore raw

PATCH v2 1/1 net/ice: fix null pointer dereferences

In reply to Wenwu Ma

This patch fixes two null pointer dereferences detected by coverity scan.

Coverity issue: 414096

Fixes 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")

---
v2:
- deleting rather than modifying the prints that
cause null pointer dereferences

---
 drivers/net/ice/ice_tm.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/ice/ice_tm.c +2 -6
index fbab0b8808..17f0ca0ce0 100644
@@ -615,10 +615,8 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   sched_node,
 					   ICE_MAX_BW,
 					   rate);
-	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+	if (status)
 		return -EINVAL;
-	}
 
 	if (reset || committed == 0)
 		rate = ICE_SCHED_DFLT_BW;
@@ -629,10 +627,8 @@ static int ice_set_node_rate(struct ice_hw *hw,
 					   sched_node,
 					   ICE_MIN_BW,
 					   rate);
-	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+	if (status)
 		return -EINVAL;
-	}
 
 	return 0;
 }
Signature · 1 line
2.25.1