* [PATCH net] ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg()
@ 2023-03-13 16:31 Jakob Koschel
2023-03-13 18:26 ` [Intel-wired-lan] " Paul Menzel
2023-03-14 18:50 ` Tony Nguyen
0 siblings, 2 replies; 3+ messages in thread
From: Jakob Koschel @ 2023-03-13 16:31 UTC (permalink / raw)
To: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: intel-wired-lan, netdev, linux-kernel, Pietro Borrello,
Cristiano Giuffrida, Bos, H.J.,
Jakob Koschel
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 comparision after the loop is undefined
behavior and should be omitted if possible [1].
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jkl820.git@gmail.com>
---
drivers/net/ethernet/intel/ice/ice_sched.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c
index 4eca8d195ef0..b7682de0ae05 100644
--- a/drivers/net/ethernet/intel/ice/ice_sched.c
+++ b/drivers/net/ethernet/intel/ice/ice_sched.c
@@ -2788,7 +2788,7 @@ static int
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 *agg_vsi_info, *iter, *old_agg_vsi_info = NULL;
struct ice_sched_agg_info *agg_info, *old_agg_info;
struct ice_hw *hw = pi->hw;
int status = 0;
@@ -2806,11 +2806,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 */
---
base-commit: eeac8ede17557680855031c6f305ece2378af326
change-id: 20230301-ice-fix-invalid-iterator-found-check-0a3e5b43dfb3
Best regards,
--
Jakob Koschel <jkl820.git@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Intel-wired-lan] [PATCH net] ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg()
2023-03-13 16:31 [PATCH net] ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg() Jakob Koschel
@ 2023-03-13 18:26 ` Paul Menzel
2023-03-14 18:50 ` Tony Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Paul Menzel @ 2023-03-13 18:26 UTC (permalink / raw)
To: Jakob Koschel
Cc: Jesse Brandeburg, Tony Nguyen, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, Pietro Borrello,
linux-kernel, Bos, H.J.,
Cristiano Giuffrida, intel-wired-lan
Dear Jakob,
Thank you for the patch.
Am 13.03.23 um 17:31 schrieb Jakob Koschel:
> 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 comparision after the loop is undefined
compar*i*son
> behavior and should be omitted if possible [1].
(It took me a short time to find the reference number at the end of the
URL.)
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
> Signed-off-by: Jakob Koschel <jkl820.git@gmail.com>
> ---
> drivers/net/ethernet/intel/ice/ice_sched.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c
> index 4eca8d195ef0..b7682de0ae05 100644
> --- a/drivers/net/ethernet/intel/ice/ice_sched.c
> +++ b/drivers/net/ethernet/intel/ice/ice_sched.c
> @@ -2788,7 +2788,7 @@ static int
> 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 *agg_vsi_info, *iter, *old_agg_vsi_info = NULL;
> struct ice_sched_agg_info *agg_info, *old_agg_info;
> struct ice_hw *hw = pi->hw;
> int status = 0;
> @@ -2806,11 +2806,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 */
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Kind regards,
Paul
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg()
2023-03-13 16:31 [PATCH net] ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg() Jakob Koschel
2023-03-13 18:26 ` [Intel-wired-lan] " Paul Menzel
@ 2023-03-14 18:50 ` Tony Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Tony Nguyen @ 2023-03-14 18:50 UTC (permalink / raw)
To: Jakob Koschel, Jesse Brandeburg, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: intel-wired-lan, netdev, linux-kernel, Pietro Borrello,
Cristiano Giuffrida, Bos, H.J.
On 3/13/2023 9:31 AM, Jakob Koschel wrote:
> 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 comparision after the loop is undefined
> behavior and should be omitted if possible [1].
>
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
> Signed-off-by: Jakob Koschel <jkl820.git@gmail.com>
The patch looks fine, however, for net patches, could you please include
a Fixes: tag.
Thanks,
Tony
> ---
> drivers/net/ethernet/intel/ice/ice_sched.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c
> index 4eca8d195ef0..b7682de0ae05 100644
> --- a/drivers/net/ethernet/intel/ice/ice_sched.c
> +++ b/drivers/net/ethernet/intel/ice/ice_sched.c
> @@ -2788,7 +2788,7 @@ static int
> 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 *agg_vsi_info, *iter, *old_agg_vsi_info = NULL;
> struct ice_sched_agg_info *agg_info, *old_agg_info;
> struct ice_hw *hw = pi->hw;
> int status = 0;
> @@ -2806,11 +2806,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 */
>
> ---
> base-commit: eeac8ede17557680855031c6f305ece2378af326
> change-id: 20230301-ice-fix-invalid-iterator-found-check-0a3e5b43dfb3
>
> Best regards,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-14 18:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 16:31 [PATCH net] ice: fix invalid check for empty list in ice_sched_assoc_vsi_to_agg() Jakob Koschel
2023-03-13 18:26 ` [Intel-wired-lan] " Paul Menzel
2023-03-14 18:50 ` Tony Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®