diff mbox series

[v2] lag_conf: Added pointer check and continue

Message ID 20221116081336.83373-1-arefev@swemel.ru (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v2] lag_conf: Added pointer check and continue | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 8 maintainers not CCed: louis.peens@corigine.com Julia.Lawall@inria.fr pabeni@redhat.com walter.heymans@corigine.com edumazet@google.com simon.horman@corigine.com oss-drivers@corigine.com yanguo.li@corigine.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Denis Arefev Nov. 16, 2022, 8:13 a.m. UTC
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.

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

Comments

Simon Horman Nov. 16, 2022, 9:39 a.m. UTC | #1
On Wed, Nov 16, 2022 at 11:13:36AM +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.
> 
> Signed-off-by: Denis Arefev <arefev@swemel.ru>

Thanks Denis,

I'll let me colleague Yinjun review the functional change,
although, based on his earlier feedback, it does look good to me.

From my side I have two nits:

1. I think the patch prefix should be 'nfp: flower:'
   i.e., the patch subject should be more like
   [PATCH v2] nfp: flower: handle allocation failure in LAG delayed work

2. Inline, below.

Kind regards,
Simon

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

2. I don't think it is necessary (or therefore desirable)
   to initialise acti_netdevs to NULL.
   As far as I can tell the variable is already always
   set before being used.

...
Simon Horman Nov. 16, 2022, 10:35 a.m. UTC | #2
On Wed, Nov 16, 2022 at 10:40:00AM +0100, Simon Horman wrote:
> On Wed, Nov 16, 2022 at 11:13:36AM +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.
> > 
> > Signed-off-by: Denis Arefev <arefev@swemel.ru>
> 
> Thanks Denis,
> 
> I'll let me colleague Yinjun review the functional change,
> although, based on his earlier feedback, it does look good to me.

I confirmed with Yinjun that he is happy with the patch,
other than the comments that I made.

> From my side I have two nits:
> 
> 1. I think the patch prefix should be 'nfp: flower:'
>    i.e., the patch subject should be more like
>    [PATCH v2] nfp: flower: handle allocation failure in LAG delayed work
> 
> 2. Inline, below.
> 
> Kind regards,
> Simon
> 
> > 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;
> 
> 2. I don't think it is necessary (or therefore desirable)
>    to initialise acti_netdevs to NULL.
>    As far as I can tell the variable is already always
>    set before being used.
> 
> ...
Jakub Kicinski Nov. 18, 2022, 3:47 a.m. UTC | #3
On Wed, 16 Nov 2022 10:39:54 +0100 Simon Horman wrote:
> 1. I think the patch prefix should be 'nfp: flower:'
>    i.e., the patch subject should be more like
>    [PATCH v2] nfp: flower: handle allocation failure in LAG delayed work

One more note here, please add the tree name to the prefix:
  [PATCH net v2] ...
and a fixes tag right above the sign-off:

Fixes: bb9a8d031140 ("nfp: flower: monitor and offload LAG groups")
diff mbox series

Patch

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