[PATCH] net: sched: gred: potential dereference of null pointer

Subsystems: networking [general], tc subsystem, the rest

STALE1767d

2 messages, 2 authors, 2021-12-09 · open the first message on its own page

[PATCH] net: sched: gred: potential dereference of null pointer

From: Jiasheng Jiang <hidden>
Date: 2021-12-09 02:14:24

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 <redacted>
---
 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

Re: [PATCH] net: sched: gred: potential dereference of null pointer

From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-12-09 02:36:15

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 <redacted>
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.
quoted hunk
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,

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help