All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: sched: gred: potential dereference of null pointer
@ 2021-12-09  2:13 Jiasheng Jiang
  2021-12-09  2:36 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-12-09  2:13 UTC (permalink / raw)
  To: jhs, xiyou.wangcong, jiri, davem, kuba
  Cc: netdev, linux-kernel, Jiasheng Jiang

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

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,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: sched: gred: potential dereference of null pointer
  2021-12-09  2:13 [PATCH] net: sched: gred: potential dereference of null pointer Jiasheng Jiang
@ 2021-12-09  2:36 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2021-12-09  2:36 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: jhs, xiyou.wangcong, jiri, davem, netdev, linux-kernel

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,


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-09  2:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09  2:13 [PATCH] net: sched: gred: potential dereference of null pointer Jiasheng Jiang
2021-12-09  2:36 ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.