Skip to content

Commit e9a1cc2

Browse files
Jakob-Koschelanguy11
authored andcommitted
ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg()
The code implicitly assumes that the list iterator finds a correct handle. If 'vsi_handle' is not found the 'old_agg_vsi_info' was pointing to an bogus memory location. For safety a separate list iterator variable should be used to make the != NULL check on 'old_agg_vsi_info' correct under any circumstances. Additionally Linus proposed to avoid any use of the list iterator variable after the loop, in the attempt to move the list iterator variable declaration into the macro to avoid any potential misuse after the loop. Using it in a pointer comparison after the loop is undefined behavior and should be omitted if possible [1]. Fixes: 37c5920 ("ice: remove the VSI info from previous agg") Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel <[email protected]> Tested-by: Arpana Arland <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent 29486b6 commit e9a1cc2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/net/ethernet/intel/ice/ice_sched.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ static int
27882788
ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
27892789
u16 vsi_handle, unsigned long *tc_bitmap)
27902790
{
2791-
struct ice_sched_agg_vsi_info *agg_vsi_info, *old_agg_vsi_info = NULL;
2791+
struct ice_sched_agg_vsi_info *agg_vsi_info, *iter, *old_agg_vsi_info = NULL;
27922792
struct ice_sched_agg_info *agg_info, *old_agg_info;
27932793
struct ice_hw *hw = pi->hw;
27942794
int status = 0;
@@ -2806,11 +2806,13 @@ ice_sched_assoc_vsi_to_agg(struct ice_port_info *pi, u32 agg_id,
28062806
if (old_agg_info && old_agg_info != agg_info) {
28072807
struct ice_sched_agg_vsi_info *vtmp;
28082808

2809-
list_for_each_entry_safe(old_agg_vsi_info, vtmp,
2809+
list_for_each_entry_safe(iter, vtmp,
28102810
&old_agg_info->agg_vsi_list,
28112811
list_entry)
2812-
if (old_agg_vsi_info->vsi_handle == vsi_handle)
2812+
if (iter->vsi_handle == vsi_handle) {
2813+
old_agg_vsi_info = iter;
28132814
break;
2815+
}
28142816
}
28152817

28162818
/* check if entry already exist */

0 commit comments

Comments
 (0)