diff mbox series

net: sched: gred: potential dereference of null pointer

Message ID 20211209021346.2004600-1-jiasheng@iscas.ac.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: sched: gred: potential dereference of null pointer | 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 fail 1 blamed authors not CCed: eric.dumazet@gmail.com; 1 maintainers not CCed: eric.dumazet@gmail.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/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiasheng Jiang Dec. 9, 2021, 2:13 a.m. UTC
The return value of kzalloc() needs to be checked.
To avoid use of null pointer in gred_change_vq() in case
of the failure of alloc.

Fixes: 869aa41044b0 ("sch_gred: prefer GFP_KERNEL allocations")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 net/sched/sch_gred.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jakub Kicinski Dec. 9, 2021, 2:36 a.m. UTC | #1
On Thu,  9 Dec 2021 10:13:46 +0800 Jiasheng Jiang wrote:
> The return value of kzalloc() needs to be checked.
> To avoid use of null pointer in gred_change_vq() in case
> of the failure of alloc.
> 
> Fixes: 869aa41044b0 ("sch_gred: prefer GFP_KERNEL allocations")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>

I don't see how. Please explain in more detail. gred_change_vq() gets 
a pointer to a pointer and checks if its values is NULL.

> diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
> index f4132dc25ac0..c0d355281baf 100644
> --- a/net/sched/sch_gred.c
> +++ b/net/sched/sch_gred.c
> @@ -697,6 +697,8 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt,
>  	}
>  
>  	prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);
> +	if (!prealloc)
> +		return -ENOMEM;
>  	sch_tree_lock(sch);
>  
>  	err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P, &prealloc,
diff mbox series

Patch

diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index f4132dc25ac0..c0d355281baf 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -697,6 +697,8 @@  static int gred_change(struct Qdisc *sch, struct nlattr *opt,
 	}
 
 	prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);
+	if (!prealloc)
+		return -ENOMEM;
 	sch_tree_lock(sch);
 
 	err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P, &prealloc,