Netdev List
 help / color / mirror / Atom feed
* [PATCH] sched: address a potential NULL pointer dereference in the GRED scheduler.
@ 2025-02-27 16:04 kwqcheii
  2025-02-27 18:26 ` Cong Wang
  2025-03-04 14:18 ` kwqcheii
  0 siblings, 2 replies; 8+ messages in thread
From: kwqcheii @ 2025-02-27 16:04 UTC (permalink / raw)
  To: netdev; +Cc: kwqcheii

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

diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index ab6234b4fcd5..fa643e5709bd 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -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;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* Re: [PATCH] sched: address a potential NULL pointer dereference in the GRED scheduler.
@ 2025-03-05 15:57 Jun Yang
  0 siblings, 0 replies; 8+ messages in thread
From: Jun Yang @ 2025-03-05 15:57 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: juny24602, netdev

On Wed, Mar 5, 2025 at 4:05 AM Cong Wang <xiyou.wangcong@gmail.com> wrote:
> I think the whole gred_offload() should be skipped when table->opt ==
> NULL, espeically the last call of ->ndo_setup_tc(). Something like:

Thank you for your review. I have updated the part with my name.
I don't quite understand why the code would send a TC_SETUP_QDISC_GRED command during destroy. I haven't found the function that handles this command, so this part of the code should not produce side effects. Adding a check on the outer layer would indeed be safer. I have already modified this part of the patch.


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

end of thread, other threads:[~2025-03-07  0:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 16:04 [PATCH] sched: address a potential NULL pointer dereference in the GRED scheduler kwqcheii
2025-02-27 18:26 ` Cong Wang
2025-03-04 14:18 ` kwqcheii
2025-03-04 20:05   ` Cong Wang
2025-03-05 15:44     ` Jun Yang
2025-03-05 18:22       ` Cong Wang
2025-03-07  0:50       ` patchwork-bot+netdevbpf
  -- strict thread matches above, loose matches on Subject: below --
2025-03-05 15:57 Jun Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox