diff mbox series

lag_conf: Added pointer check

Message ID 20221115085637.72193-1-arefev@swemel.ru (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series lag_conf: Added pointer check | 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 warning WARNING: Statements should start on a tabstop WARNING: suspect code indent for conditional statements (16, 17)
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Denis Arefev Nov. 15, 2022, 8:56 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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Simon Horman Nov. 15, 2022, 9:22 a.m. UTC | #1
On Tue, Nov 15, 2022 at 11:56:37AM +0300, Denis Arefev wrote:
> [You don't often get email from arefev@swemel.ru. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> 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>

Hi Denis,

thanks for highlighting this problem.

> ---
>  drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 4 +++-
>  1 file changed, 3 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..95ba6e92197d 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;

I don't think it's necessary to set acti_netdevs here as
it is always set before use by the call to kmalloc_array().

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

The indentation here doesn't look right.


Regarding the problem at hand, yes, I agree that it seems
that kmalloc_array() should be checked. But I am concerned that
simply break'ing here may lead to a bad state. And I'd like to ask
for some time to examine this more closely.

>                 /* Include sanity check in the loop. It may be that a bond has
>                  * changed between processing the last notification and the
> --
> 2.25.1
>
Yinjun Zhang Nov. 16, 2022, 1:55 a.m. UTC | #2
On Tue, 15 Nov 2022 11:56:37 +0300, Denis Arefev wrote:
> <...>
> @@ -308,6 +308,8 @@ 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)
> +		 break;

I think we need give other entries and this entry itself one more chance by:
```
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
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..95ba6e92197d 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,8 @@  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)
+		 break;
 
 		/* Include sanity check in the loop. It may be that a bond has
 		 * changed between processing the last notification and the