Skip to contentSkip to conversation

lag_conf: Added pointer check and continue

PATCH Superseded Denis Arefev 3 participants 4 messages Nov 16, 2022 – Nov 18, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lag_conf: Added pointer check and continue

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.

---
 drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/netronome/nfp/flower/lag_conf.c +5 -1
index 63907aeb3884..1aaec4cb9f55 100644
@@ -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
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Denis Arefev

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.

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

drivers/net/ethernet/netronome/nfp/flower/lag_conf.c static void nfp_fl_lag_do_work(struct work_struct *work) · line 279

Quoted 10 lines
drivers/net/ethernet/netronome/nfp/flower/lag_conf.c +1 -1
index 63907aeb3884..1aaec4cb9f55 100644
@@ -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.

...

#2 lore raw
Quoted 5 lines · Simon Horman
Quoted 4 lines · Denis Arefev

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.

Quoted 8 lines
Quoted 3 lines

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

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.

Quoted 28 lines

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

drivers/net/ethernet/netronome/nfp/flower/lag_conf.c static void nfp_fl_lag_do_work(struct work_struct *work) · line 279

Quoted 10 lines
drivers/net/ethernet/netronome/nfp/flower/lag_conf.c +1 -1
index 63907aeb3884..1aaec4cb9f55 100644
@@ -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.

...

maintainer
#3 lore raw
In reply to Simon Horman
Quoted 3 lines · 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")