All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] sched: address a potential NULL pointer dereference in the GRED scheduler.
@ 2025-03-07  1:32 kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2025-03-07  1:32 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250304141858.3392957-2-juny24602@gmail.com>
References: <20250304141858.3392957-2-juny24602@gmail.com>
TO: kwqcheii <juny24602@gmail.com>
TO: netdev@vger.kernel.org
CC: kwqcheii <juny24602@gmail.com>

Hi kwqcheii,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.14-rc5 next-20250306]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/kwqcheii/sched-address-a-potential-NULL-pointer-dereference-in-the-GRED-scheduler/20250304-224144
base:   linus/master
patch link:    https://lore.kernel.org/r/20250304141858.3392957-2-juny24602%40gmail.com
patch subject: [PATCH] sched: address a potential NULL pointer dereference in the GRED scheduler.
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r072-20250306 (https://download.01.org/0day-ci/archive/20250307/202503070956.I8Z06FRE-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202503070956.I8Z06FRE-lkp@intel.com/

New smatch warnings:
net/sched/sch_gred.c:330 gred_offload() error: we previously assumed 'opt' could be null (see line 320)

Old smatch warnings:
net/sched/sch_gred.c:474 gred_change_table_def() warn: potential spectre issue 'table->tab' [w]

vim +/opt +330 net/sched/sch_gred.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  310  
890d8d23ec3c9e Jakub Kicinski 2018-11-19  311  static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)
890d8d23ec3c9e Jakub Kicinski 2018-11-19  312  {
890d8d23ec3c9e Jakub Kicinski 2018-11-19  313  	struct gred_sched *table = qdisc_priv(sch);
890d8d23ec3c9e Jakub Kicinski 2018-11-19  314  	struct net_device *dev = qdisc_dev(sch);
f25c0515c52137 Arnd Bergmann  2021-10-26  315  	struct tc_gred_qopt_offload *opt = table->opt;
890d8d23ec3c9e Jakub Kicinski 2018-11-19  316  
890d8d23ec3c9e Jakub Kicinski 2018-11-19  317  	if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
890d8d23ec3c9e Jakub Kicinski 2018-11-19  318  		return;
890d8d23ec3c9e Jakub Kicinski 2018-11-19  319  
8eb926feee9101 kwqcheii       2025-03-04 @320  	if (opt) {
f25c0515c52137 Arnd Bergmann  2021-10-26  321  		memset(opt, 0, sizeof(*opt));
f25c0515c52137 Arnd Bergmann  2021-10-26  322  		opt->command = command;
f25c0515c52137 Arnd Bergmann  2021-10-26  323  		opt->handle = sch->handle;
f25c0515c52137 Arnd Bergmann  2021-10-26  324  		opt->parent = sch->parent;
8eb926feee9101 kwqcheii       2025-03-04  325  	}
f25c0515c52137 Arnd Bergmann  2021-10-26  326  
890d8d23ec3c9e Jakub Kicinski 2018-11-19  327  	if (command == TC_GRED_REPLACE) {
890d8d23ec3c9e Jakub Kicinski 2018-11-19  328  		unsigned int i;
890d8d23ec3c9e Jakub Kicinski 2018-11-19  329  
f25c0515c52137 Arnd Bergmann  2021-10-26 @330  		opt->set.grio_on = gred_rio_mode(table);
f25c0515c52137 Arnd Bergmann  2021-10-26  331  		opt->set.wred_on = gred_wred_mode(table);
f25c0515c52137 Arnd Bergmann  2021-10-26  332  		opt->set.dp_cnt = table->DPs;
f25c0515c52137 Arnd Bergmann  2021-10-26  333  		opt->set.dp_def = table->def;
890d8d23ec3c9e Jakub Kicinski 2018-11-19  334  
890d8d23ec3c9e Jakub Kicinski 2018-11-19  335  		for (i = 0; i < table->DPs; i++) {
890d8d23ec3c9e Jakub Kicinski 2018-11-19  336  			struct gred_sched_data *q = table->tab[i];
890d8d23ec3c9e Jakub Kicinski 2018-11-19  337  
890d8d23ec3c9e Jakub Kicinski 2018-11-19  338  			if (!q)
890d8d23ec3c9e Jakub Kicinski 2018-11-19  339  				continue;
f25c0515c52137 Arnd Bergmann  2021-10-26  340  			opt->set.tab[i].present = true;
f25c0515c52137 Arnd Bergmann  2021-10-26  341  			opt->set.tab[i].limit = q->limit;
f25c0515c52137 Arnd Bergmann  2021-10-26  342  			opt->set.tab[i].prio = q->prio;
f25c0515c52137 Arnd Bergmann  2021-10-26  343  			opt->set.tab[i].min = q->parms.qth_min >> q->parms.Wlog;
f25c0515c52137 Arnd Bergmann  2021-10-26  344  			opt->set.tab[i].max = q->parms.qth_max >> q->parms.Wlog;
f25c0515c52137 Arnd Bergmann  2021-10-26  345  			opt->set.tab[i].is_ecn = gred_use_ecn(q);
f25c0515c52137 Arnd Bergmann  2021-10-26  346  			opt->set.tab[i].is_harddrop = gred_use_harddrop(q);
f25c0515c52137 Arnd Bergmann  2021-10-26  347  			opt->set.tab[i].probability = q->parms.max_P;
f25c0515c52137 Arnd Bergmann  2021-10-26  348  			opt->set.tab[i].backlog = &q->backlog;
890d8d23ec3c9e Jakub Kicinski 2018-11-19  349  		}
f25c0515c52137 Arnd Bergmann  2021-10-26  350  		opt->set.qstats = &sch->qstats;
890d8d23ec3c9e Jakub Kicinski 2018-11-19  351  	}
890d8d23ec3c9e Jakub Kicinski 2018-11-19  352  
f25c0515c52137 Arnd Bergmann  2021-10-26  353  	dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_GRED, opt);
890d8d23ec3c9e Jakub Kicinski 2018-11-19  354  }
890d8d23ec3c9e Jakub Kicinski 2018-11-19  355  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 9+ 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; 9+ 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] 9+ messages in thread
* [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; 9+ 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] 9+ messages in thread

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

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-07  1:32 [PATCH] sched: address a potential NULL pointer dereference in the GRED scheduler kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-03-05 15:57 Jun Yang
2025-02-27 16:04 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

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.