netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3] nfp: flower: Added pointer check and continue
@ 2022-11-18  8:03 Denis Arefev
  2022-11-18 12:43 ` Michal Swiatkowski
  2022-11-22 11:16 ` Leon Romanovsky
  0 siblings, 2 replies; 3+ messages in thread
From: Denis Arefev @ 2022-11-18  8:03 UTC (permalink / raw)
  To: Simon Horman
  Cc: Jakub Kicinski, David S. Miller, oss-drivers, netdev,
	linux-kernel, lvc-project, trufanov, vfh

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

Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: bb9a8d031140 ("nfp: flower: monitor and offload LAG groups")
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
index 63907aeb3884..1aaec4cb9f55 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
@@ -276,7 +276,7 @@ static void nfp_fl_lag_do_work(struct work_struct *work)
 
 	mutex_lock(&lag->lock);
 	list_for_each_entry_safe(entry, storage, &lag->group_list, list) {
-		struct net_device *iter_netdev, **acti_netdevs;
+		struct net_device *iter_netdev, **acti_netdevs = NULL;
 		struct nfp_flower_repr_priv *repr_priv;
 		int active_count = 0, slaves = 0;
 		struct nfp_repr *repr;
@@ -308,6 +308,10 @@ 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
-- 
2.25.1


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

* Re: [PATCH net v3] nfp: flower: Added pointer check and continue
  2022-11-18  8:03 [PATCH net v3] nfp: flower: Added pointer check and continue Denis Arefev
@ 2022-11-18 12:43 ` Michal Swiatkowski
  2022-11-22 11:16 ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Swiatkowski @ 2022-11-18 12:43 UTC (permalink / raw)
  To: Denis Arefev
  Cc: Simon Horman, Jakub Kicinski, David S. Miller, oss-drivers,
	netdev, linux-kernel, lvc-project, trufanov, vfh

On Fri, Nov 18, 2022 at 11:03:17AM +0300, Denis Arefev wrote:
> Return value of a function 'kmalloc_array' is dereferenced at 
> lag_conf.c:347 without checking for null, 
> but it is usually checked for this function.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> Fixes: bb9a8d031140 ("nfp: flower: monitor and offload LAG groups")
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
>  drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> index 63907aeb3884..1aaec4cb9f55 100644
> --- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> +++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> @@ -276,7 +276,7 @@ static void nfp_fl_lag_do_work(struct work_struct *work)
>  
>  	mutex_lock(&lag->lock);
>  	list_for_each_entry_safe(entry, storage, &lag->group_list, list) {
> -		struct net_device *iter_netdev, **acti_netdevs;
> +		struct net_device *iter_netdev, **acti_netdevs = NULL;
Small nit, otherwise looks fine.

I think there is no need to set it to NULL here as it is always set to
return value from kmalloc_array().

Thanks
>  		struct nfp_flower_repr_priv *repr_priv;
>  		int active_count = 0, slaves = 0;
>  		struct nfp_repr *repr;
> @@ -308,6 +308,10 @@ 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
> -- 
> 2.25.1
> 

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

* Re: [PATCH net v3] nfp: flower: Added pointer check and continue
  2022-11-18  8:03 [PATCH net v3] nfp: flower: Added pointer check and continue Denis Arefev
  2022-11-18 12:43 ` Michal Swiatkowski
@ 2022-11-22 11:16 ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2022-11-22 11:16 UTC (permalink / raw)
  To: Denis Arefev
  Cc: Simon Horman, Jakub Kicinski, David S. Miller, oss-drivers,
	netdev, linux-kernel, lvc-project, trufanov, vfh

On Fri, Nov 18, 2022 at 11:03:17AM +0300, Denis Arefev wrote:
> Return value of a function 'kmalloc_array' is dereferenced at 
> lag_conf.c:347 without checking for null, 
> but it is usually checked for this function.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> Fixes: bb9a8d031140 ("nfp: flower: monitor and offload LAG groups")
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
>  drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

<...>

>  		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;

It is usually not good idea to continue after memory allocation fails.
So or add __GFP_NOWARN with a comment why it is safe to continue or bail
out from this loop.

Thanks

> +		}
>  
>  		/* Include sanity check in the loop. It may be that a bond has
>  		 * changed between processing the last notification and the
> -- 
> 2.25.1
> 

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

end of thread, other threads:[~2022-11-22 11:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18  8:03 [PATCH net v3] nfp: flower: Added pointer check and continue Denis Arefev
2022-11-18 12:43 ` Michal Swiatkowski
2022-11-22 11:16 ` Leon Romanovsky

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).