diff mbox series

[v2] nfp: flower: handle acti_netdevs allocation failure

Message ID 20240308142540.9674-1-duoming@zju.edu.cn (mailing list archive)
State Accepted
Commit 84e95149bd341705f0eca6a7fcb955c548805002
Delegated to: Netdev Maintainers
Headers show
Series [v2] nfp: flower: handle acti_netdevs allocation failure | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 11 maintainers
netdev/build_clang success Errors and warnings before: 956 this patch: 956
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 956 this patch: 956
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-10--00-00 (tests: 888)

Commit Message

Duoming Zhou March 8, 2024, 2:25 p.m. UTC
The kmalloc_array() in nfp_fl_lag_do_work() will return null, if
the physical memory has run out. As a result, if we dereference
the acti_netdevs, the null pointer dereference bugs will happen.

This patch adds a check to judge whether allocation failure occurs.
If it happens, the delayed work will be rescheduled and try again.

Fixes: bb9a8d031140 ("nfp: flower: monitor and offload LAG groups")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
Changes in v2:
  - Remove print warnings on allocation failures.

 drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Louis Peens March 8, 2024, 3:06 p.m. UTC | #1
On Fri, Mar 08, 2024 at 10:25:40PM +0800, Duoming Zhou wrote:
> [Some people who received this message don't often get email from duoming@zju.edu.cn. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> The kmalloc_array() in nfp_fl_lag_do_work() will return null, if
> the physical memory has run out. As a result, if we dereference
> the acti_netdevs, the null pointer dereference bugs will happen.
> 
> This patch adds a check to judge whether allocation failure occurs.
> If it happens, the delayed work will be rescheduled and try again.
> 
> Fixes: bb9a8d031140 ("nfp: flower: monitor and offload LAG groups")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
> Changes in v2:
>   - Remove print warnings on allocation failures.
Thanks Duoming. Just a reminder for next time, it is recommended to add
the tree name to the patch summary ([PATCH net] or [PATCH net-next])
when submitting to netdev. Since this contains a "Fixes" tag it should
probably have been aimed at 'net'.

Reviewed-by: Louis Peens <louis.peens@corigine.com>
> 
>  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 361d7c495e2..2c7bd6e80d9 100644
> --- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> +++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
> @@ -337,6 +337,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
> --
> 2.17.1
>
patchwork-bot+netdevbpf@kernel.org March 11, 2024, 11 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri,  8 Mar 2024 22:25:40 +0800 you wrote:
> The kmalloc_array() in nfp_fl_lag_do_work() will return null, if
> the physical memory has run out. As a result, if we dereference
> the acti_netdevs, the null pointer dereference bugs will happen.
> 
> This patch adds a check to judge whether allocation failure occurs.
> If it happens, the delayed work will be rescheduled and try again.
> 
> [...]

Here is the summary with links:
  - [v2] nfp: flower: handle acti_netdevs allocation failure
    https://git.kernel.org/netdev/net/c/84e95149bd34

You are awesome, thank you!
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 361d7c495e2..2c7bd6e80d9 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c
@@ -337,6 +337,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