sched: address a potential NULL pointer dereference in the GRED scheduler.
Subsystems (3)
PATCH 1/1 sched: address a potential NULL pointer dereference in the GRED scheduler.
If kzalloc in gred_init returns a NULL pointer, the code follows the error handling path, invoking gred_destroy. This, in turn, calls gred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.
--- net/sched/sch_gred.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/sched/sch_gred.c +6 -4
@@ -317,10 +317,12 @@ static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)if (!tc_can_offload (dev) || !dev->netdev_ops->ndo_setup_tc)return ; -memset (opt,0 ,sizeof (*opt)); - opt->command = command; - opt->handle = sch->handle; - opt->parent = sch->parent; +if (opt) { +memset (opt,0 ,sizeof (*opt)); + opt->command = command; + opt->handle = sch->handle; + opt->parent = sch->parent; + }if (command ==TC_GRED_REPLACE ) {unsigned int i;
Signature · 1 line
2.48.1
Quoted 1 line · kwqcheii
If kzalloc in
gred_initreturns a NULL pointer, the code follows the error handling path, invokinggred_destroy. This, in turn, callsgred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.
Thanks for your patch.
Please add your Signed-off-by for your patch, which is a minimum requirement here. You can check Linux kernel development process for more details: https://docs.kernel.org/process/5.Posting.html#before-creating-patches
Also, ./scripts/checkpatch.pl could help you catch issues like this one, it would save you and others a lot of time.
Lastly, if you saw a real crash, please include the kernel stack trace in your patch description. There is a significant difference between a real crash and a theoretical one.
Regards,
Cong
PATCH 1/1 sched: address a potential NULL pointer dereference in the GRED scheduler.
In reply to kwqcheiiIf kzalloc in gred_init returns a NULL pointer, the code follows the error handling path, invoking gred_destroy. This, in turn, calls gred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.
--- net/sched/sch_gred.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/sched/sch_gred.c +6 -4
@@ -317,10 +317,12 @@ static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)if (!tc_can_offload (dev) || !dev->netdev_ops->ndo_setup_tc)return ; -memset (opt,0 ,sizeof (*opt)); - opt->command = command; - opt->handle = sch->handle; - opt->parent = sch->parent; +if (opt) { +memset (opt,0 ,sizeof (*opt)); + opt->command = command; + opt->handle = sch->handle; + opt->parent = sch->parent; + }if (command ==TC_GRED_REPLACE ) {unsigned int i;
Signature · 1 line
2.48.1
Quoted 5 lines · kwqcheii
If kzalloc in
gred_initreturns a NULL pointer, the code follows the error handling path, invokinggred_destroy. This, in turn, callsgred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.Signed-off-by kwqcheii <[email protected]>
Please use your real name for Signed-off-by.
Quoted 12 lines
--- net/sched/sch_gred.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)net/sched/sch_gred.c +0
-0@@ -317,10 +317,12 @@ static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)if (!tc_can_offload (dev) || !dev->netdev_ops->ndo_setup_tc)return ;
net/sched/sch_gred.c static void gred_offload(struct Qdisc *sch, enum tc_gred_command command) · line 325
Quoted 10 lines
net/sched/sch_gred.c +6
-4-memset (opt,0 ,sizeof (*opt)); - opt->command = command; - opt->handle = sch->handle; - opt->parent = sch->parent; +if (opt) { +memset (opt,0 ,sizeof (*opt)); + opt->command = command; + opt->handle = sch->handle; + opt->parent = sch->parent; + }
I think the whole gred_offload() should be skipped when table->opt == NULL, espeically the last call of ->ndo_setup_tc(). Something like:
net/sched/sch_gred.c +2 -1
@@ -913,7 +913,8 @@ static void gred_destroy(struct Qdisc *sch)for (i =0 ; i < table->DPs; i++)gred_destroy_vq (table->tab[i]); -gred_offload (sch,TC_GRED_DESTROY ); +if (table->opt) +gred_offload (sch,TC_GRED_DESTROY );kfree (table->opt); }
What do you think?
Thanks.
PATCH 1/1 sched: address a potential NULL pointer dereference in the GRED scheduler.
If kzalloc in gred_init returns a NULL pointer, the code follows the error handling path, invoking gred_destroy. This, in turn, calls gred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.
--- net/sched/sch_gred.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sched/sch_gred.c +2 -1
@@ -913,7 +913,8 @@ static void gred_destroy(struct Qdisc *sch)for (i =0 ; i < table->DPs; i++)gred_destroy_vq (table->tab[i]); -gred_offload (sch,TC_GRED_DESTROY ); +if (table->opt) +gred_offload (sch,TC_GRED_DESTROY );kfree (table->opt); }
Signature · 1 line
2.48.1
Quoted 6 lines · Jun Yang
If kzalloc in
gred_initreturns a NULL pointer, the code follows the error handling path, invokinggred_destroy. This, in turn, callsgred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.Signed-off-by Jun Yang <[email protected]>
When table->opt is NULL in gred_init(), gred_change_table_def() is not called yet, so it is not necessary to call ->ndo_setup_tc() in gred_offload().
Thanks!
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 5 Mar 2025 23:44:10 +0800 you wrote:
If kzalloc in
gred_initreturns a NULL pointer, the code follows the error handling path, invokinggred_destroy. This, in turn, callsgred_offload, where memset could receive a NULL pointer as input, potentially leading to a kernel crash.Signed-off-by Jun Yang <[email protected]>[...]
Here is the summary with links:
- sched: address a potential NULL pointer dereference in the GRED scheduler.
https://git.kernel.org/netdev/net/c/115ef44a9822
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html