netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfp: flower: Added pointer check and continue.
@ 2023-11-17 12:57 Denis Arefev
  2023-11-17 14:27 ` Louis Peens
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Arefev @ 2023-11-17 12:57 UTC (permalink / raw)
  To: Louis Peens
  Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
	oss-drivers, netdev, linux-kernel, lvc-project

Return value of a function 'kmalloc_array' is dereferenced at
lag_conf.c without checking for null, but it is usually
checked for this function.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
index 88d6d992e7d0..8cc6cce73283 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
@@ -339,6 +339,11 @@ static void nfp_fl_lag_do_work(struct work_struct *work)
 		acti_netdevs = kmalloc_array(entry->slave_cnt,
 					     sizeof(*acti_netdevs), GFP_KERNEL);
 
+		if (!acti_netdevs) {
+			schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY);
+			continue;
+		}
+
 		/* Include sanity check in the loop. It may be that a bond has
 		 * changed between processing the last notification and the
 		 * work queue triggering. If the number of slaves has changed
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfp: flower: Added pointer check and continue.
  2023-11-17 12:57 [PATCH] nfp: flower: Added pointer check and continue Denis Arefev
@ 2023-11-17 14:27 ` Louis Peens
  2023-11-19  4:22   ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Louis Peens @ 2023-11-17 14:27 UTC (permalink / raw)
  To: Denis Arefev
  Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
	oss-drivers, netdev, linux-kernel, lvc-project

On Fri, Nov 17, 2023 at 03:57:01PM +0300, Denis Arefev wrote:
> 
> Return value of a function 'kmalloc_array' is dereferenced at
> lag_conf.c without checking for null, but it is usually
> checked for this function.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
>  drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> index 88d6d992e7d0..8cc6cce73283 100644
> --- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> +++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> @@ -339,6 +339,11 @@ static void nfp_fl_lag_do_work(struct work_struct *work)
>                 acti_netdevs = kmalloc_array(entry->slave_cnt,
>                                              sizeof(*acti_netdevs), GFP_KERNEL);
> 
> +               if (!acti_netdevs) {
> +                       schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY);
> +                       continue;
> +               }
> +
Thanks for reporting this Denis, it definitely seems to be an oversight.
Would you mind adding a 'nfp_flower_cmsg_warn' here as well, so that
this case does not go undetected? Maybe something like "cannot
allocate memory for group processing" can work.

>                 /* Include sanity check in the loop. It may be that a bond has
>                  * changed between processing the last notification and the
>                  * work queue triggering. If the number of slaves has changed
> --
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfp: flower: Added pointer check and continue.
  2023-11-17 14:27 ` Louis Peens
@ 2023-11-19  4:22   ` Jakub Kicinski
  2023-11-20  7:04     ` Louis Peens
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2023-11-19  4:22 UTC (permalink / raw)
  To: Louis Peens
  Cc: Denis Arefev, David S. Miller, Eric Dumazet, Paolo Abeni,
	oss-drivers, netdev, linux-kernel, lvc-project

On Fri, 17 Nov 2023 16:27:17 +0200 Louis Peens wrote:
> >                 acti_netdevs = kmalloc_array(entry->slave_cnt,
> >                                              sizeof(*acti_netdevs), GFP_KERNEL);
> > 

Unnecessary new line, please remove it.
There should be no empty lines between call and error check.

> > +               if (!acti_netdevs) {
> > +                       schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY);
> > +                       continue;
> > +               }
> > +  
> Thanks for reporting this Denis, it definitely seems to be an oversight.
> Would you mind adding a 'nfp_flower_cmsg_warn' here as well, so that
> this case does not go undetected? Maybe something like "cannot
> allocate memory for group processing" can work.

There's a checkpatch check against printing warnings on allocation
failures. Kernel will complain loudly on OOM, anyway, there's no need
for a local print.
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nfp: flower: Added pointer check and continue.
  2023-11-19  4:22   ` Jakub Kicinski
@ 2023-11-20  7:04     ` Louis Peens
  0 siblings, 0 replies; 4+ messages in thread
From: Louis Peens @ 2023-11-20  7:04 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Denis Arefev, David S. Miller, Eric Dumazet, Paolo Abeni,
	oss-drivers, netdev, linux-kernel, lvc-project

On Sat, Nov 18, 2023 at 08:22:07PM -0800, Jakub Kicinski wrote:
> On Fri, 17 Nov 2023 16:27:17 +0200 Louis Peens wrote:
> > >                 acti_netdevs = kmalloc_array(entry->slave_cnt,
> > >                                              sizeof(*acti_netdevs), GFP_KERNEL);
> > > 
> 
> Unnecessary new line, please remove it.
> There should be no empty lines between call and error check.
> 
> > > +               if (!acti_netdevs) {
> > > +                       schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY);
> > > +                       continue;
> > > +               }
> > > +  
> > Thanks for reporting this Denis, it definitely seems to be an oversight.
> > Would you mind adding a 'nfp_flower_cmsg_warn' here as well, so that
> > this case does not go undetected? Maybe something like "cannot
> > allocate memory for group processing" can work.
> 
> There's a checkpatch check against printing warnings on allocation
> failures. Kernel will complain loudly on OOM, anyway, there's no need
> for a local print.
Ah, thanks Jakub, I did not know that this is frowned upon. But I have
not thought about OOM - it would indeed not be a silent failure.

In that case I would be quite happy to add my Ack to v2 with the newline
comment addressed.
> -- 
> pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-20  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 12:57 [PATCH] nfp: flower: Added pointer check and continue Denis Arefev
2023-11-17 14:27 ` Louis Peens
2023-11-19  4:22   ` Jakub Kicinski
2023-11-20  7:04     ` Louis Peens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).