Skip to contentSkip to conversation

ice: ice_sched: fix an incorrect NULL check on list iterator

PATCH In review Xiaomeng Tong 4 participants 4 messages Mar 27, 2022 – May 3, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: ice_sched: fix an incorrect NULL check on list iterator

The bugs are here:

	if (old_agg_vsi_info)
	if (old_agg_vsi_info && !old_agg_vsi_info->tc_bitmap[0]) {

The list iterator value 'old_agg_vsi_info' will *always* be set and non-NULL by list_for_each_entry_safe(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (old_agg_vsi_info)' will always be true unexpectly).

To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'old_agg_vsi_info' as a dedicated pointer to point to the found element.

Cc stable at vger.kernel.org
Fixes 37c592062b16d ("ice: remove the VSI info from previous agg")
---
 drivers/net/ethernet/intel/ice/ice_sched.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_sched.c +5 -2
index 7947223536e3..fba524148a09 100644
@@ -2757,6 +2757,7 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
 			   u16 vsi_handle, unsigned long *tc_bitmap)
 {
 	struct ice_sched_agg_vsi_info *agg_vsi_info, *old_agg_vsi_info = NULL;
+	struct ice_sched_agg_vsi_info *iter;
 	struct ice_sched_agg_info *agg_info, *old_agg_info;
 	struct ice_hw *hw = pi->hw;
 	int status = 0;
@@ -2774,11 +2775,13 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
 	if (old_agg_info && old_agg_info != agg_info) {
 		struct ice_sched_agg_vsi_info *vtmp;
 
-		list_for_each_entry_safe(old_agg_vsi_info, vtmp,
+		list_for_each_entry_safe(iter, vtmp,
 					 &old_agg_info->agg_vsi_list,
 					 list_entry)
-			if (old_agg_vsi_info->vsi_handle == vsi_handle)
+			if (iter->vsi_handle == vsi_handle) {
+				old_agg_vsi_info = iter;
 				break;
+			}
 	}
 
 	/* check if entry already exist */
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines

-----Original Message-----
From: Xiaomeng Tong <[email protected]>
Sent: Saturday, March 26, 2022 11:44 PM
To: Brandeburg, Jesse <[email protected]>
Cc: Nguyen, Anthony L <[email protected]>; davem at davemloft.net; kuba at kernel.org; pabeni at redhat.com; Raj, Victor <[email protected]>; intel- wired-lan at lists.osuosl.org; netdev at vger.kernel.org; linux- kernel at vger.kernel.org; Xiaomeng Tong <[email protected]>; stable at vger.kernel.org
Subject: [PATCH] ice: ice_sched: fix an incorrect NULL check on list iterator

The bugs are here:

	if (old_agg_vsi_info)
	if (old_agg_vsi_info && !old_agg_vsi_info->tc_bitmap[0]) {

The list iterator value 'old_agg_vsi_info' will *always* be set and non-NULL by list_for_each_entry_safe(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (old_agg_vsi_info)' will always be true unexpectly).

Quoted 4 lines

To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'old_agg_vsi_info' as a dedicated pointer to point to the found element.

Yep. This looks correct to me.

Thanks,
Jake

Quoted 40 lines
Cc stable at vger.kernel.org
Fixes 37c592062b16d ("ice: remove the VSI info from previous agg")
---
 drivers/net/ethernet/intel/ice/ice_sched.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_sched.c +1 -0
index 7947223536e3..fba524148a09 100644
@@ -2757,6 +2757,7 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi,
 u32 agg_id,
 			   u16 vsi_handle, unsigned long *tc_bitmap)
 {
 	struct ice_sched_agg_vsi_info *agg_vsi_info, *old_agg_vsi_info = NULL;
+	struct ice_sched_agg_vsi_info *iter;
 	struct ice_sched_agg_info *agg_info, *old_agg_info;
 	struct ice_hw *hw = pi->hw;
drivers/net/ethernet/intel/ice/ice_sched.c +4 -2
 	int status = 0;
@@ -2774,11 +2775,13 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info
 *pi, u32 agg_id,
 	if (old_agg_info && old_agg_info != agg_info) {
 		struct ice_sched_agg_vsi_info *vtmp;
 
-		list_for_each_entry_safe(old_agg_vsi_info, vtmp,
+		list_for_each_entry_safe(iter, vtmp,
 					 &old_agg_info->agg_vsi_list,
 					 list_entry)
-			if (old_agg_vsi_info->vsi_handle == vsi_handle)
+			if (iter->vsi_handle == vsi_handle) {
+				old_agg_vsi_info = iter;
 				break;
+			}
 	}
 

/* check if entry already exist */
--
2.17.1

Tested-by
#2 lore raw

-----Original Message-----

Quoted 21 lines

From: Xiaomeng Tong <[email protected]>
Sent: Saturday, March 26, 2022 11:44 PM
To: Brandeburg, Jesse <[email protected]>
Cc: Nguyen, Anthony L <[email protected]>;
davem at davemloft.net; kuba at kernel.org; pabeni at redhat.com; Raj, Victor <[email protected]>; intel- wired-lan at lists.osuosl.org; netdev at vger.kernel.org; linux- kernel at vger.kernel.org; Xiaomeng Tong <[email protected]>; stable at vger.kernel.org
Subject: [PATCH] ice: ice_sched: fix an incorrect NULL check on list iterator

The bugs are here:

	if (old_agg_vsi_info)
	if (old_agg_vsi_info && !old_agg_vsi_info->tc_bitmap[0]) {

The list iterator value 'old_agg_vsi_info' will *always* be set and non-NULL by list_for_each_entry_safe(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (old_agg_vsi_info)' will always be true unexpectly).

Quoted 4 lines

To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'old_agg_vsi_info' as a dedicated pointer to point to the found element.

Yep. This looks correct to me.

Quoted 5 lines

Thanks,
Jake

Quoted 7 lines
Cc stable at vger.kernel.org
Fixes 37c592062b16d ("ice: remove the VSI info from previous agg")
---
 drivers/net/ethernet/intel/ice/ice_sched.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Tested-by Gurucharan
#3 lore raw

If the control comes down to the loop then surely the VSI is already part of an aggregator (old). The aggregator vsi list should have that VSI information. My understanding is that if control comes here then you always find a valid entry and matching handle here. If that doesn't happen then we need to debug. The fix is kind of masking this problem.

-Victor

-----Original Message-----
From: G, GurucharanX <[email protected]>
Sent: Monday, May 2, 2022 1:18 AM
To: Keller, Jacob E <[email protected]>; Xiaomeng Tong <[email protected]>; Brandeburg, Jesse <[email protected]>
Cc: netdev at vger.kernel.org; Raj, Victor <[email protected]>; stable at vger.kernel.org; linux-kernel at vger.kernel.org; intel-wired-lan at lists.osuosl.org; kuba at kernel.org; pabeni at redhat.com; davem at davemloft.net
Subject: RE: [PATCH] ice: ice_sched: fix an incorrect NULL check on list iterator

-----Original Message-----

Quoted 21 lines

From: Xiaomeng Tong <[email protected]>
Sent: Saturday, March 26, 2022 11:44 PM
To: Brandeburg, Jesse <[email protected]>
Cc: Nguyen, Anthony L <[email protected]>;
davem at davemloft.net; kuba at kernel.org; pabeni at redhat.com; Raj, Victor <[email protected]>; intel- wired-lan at lists.osuosl.org; netdev at vger.kernel.org; linux- kernel at vger.kernel.org; Xiaomeng Tong <[email protected]>; stable at vger.kernel.org
Subject: [PATCH] ice: ice_sched: fix an incorrect NULL check on list iterator

The bugs are here:

	if (old_agg_vsi_info)
	if (old_agg_vsi_info && !old_agg_vsi_info->tc_bitmap[0]) {

The list iterator value 'old_agg_vsi_info' will *always* be set and non-NULL by list_for_each_entry_safe(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (old_agg_vsi_info)' will always be true unexpectly).

Quoted 4 lines

To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'old_agg_vsi_info' as a dedicated pointer to point to the found element.

Yep. This looks correct to me.

Quoted 5 lines

Thanks,
Jake

Quoted 7 lines
Cc stable at vger.kernel.org
Fixes 37c592062b16d ("ice: remove the VSI info from previous agg")
---
 drivers/net/ethernet/intel/ice/ice_sched.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)