[peterz-queue:sched/core 13/19] kernel/sched/debug.c:453 print_cfs_group_stats() warn: variable dereferenced before check 'se' (see line 444)

From: Dan Carpenter
Date: Mon Sep 13 2021 - 04:49:33 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git sched/core
head: 2dfdb3d20ad50e2ae2cb84cbceb0f0fc75e79e5d
commit: 445d9e8ba05d5e9e4b26956b7fe529223e29d8d1 [13/19] sched: make struct sched_statistics independent of fair sched class
config: x86_64-randconfig-m001-20210910 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
kernel/sched/debug.c:453 print_cfs_group_stats() warn: variable dereferenced before check 'se' (see line 444)

vim +/se +453 kernel/sched/debug.c

3866e845ed5222 kernel/sched/debug.c Steven Rostedt (Red Hat 2016-02-22 439)
ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 440 #ifdef CONFIG_FAIR_GROUP_SCHED
5091faa449ee0b kernel/sched_debug.c Mike Galbraith 2010-11-30 441 static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 442 {
ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 443 struct sched_entity *se = tg->se[cpu];
445d9e8ba05d5e kernel/sched/debug.c Yafang Shao 2021-09-05 @444 struct sched_statistics *stats = __schedstats_from_se(se);
^^
New unchecked dereference.

ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 445
97fb7a0a8944bd kernel/sched/debug.c Ingo Molnar 2018-03-03 446 #define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
445d9e8ba05d5e kernel/sched/debug.c Yafang Shao 2021-09-05 447 #define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", \
445d9e8ba05d5e kernel/sched/debug.c Yafang Shao 2021-09-05 448 #F, (long long)schedstat_val(stats->F))
97fb7a0a8944bd kernel/sched/debug.c Ingo Molnar 2018-03-03 449 #define PN(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
445d9e8ba05d5e kernel/sched/debug.c Yafang Shao 2021-09-05 450 #define PN_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", \
445d9e8ba05d5e kernel/sched/debug.c Yafang Shao 2021-09-05 451 #F, SPLIT_NS((long long)schedstat_val(stats->F)))
ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 452
cd126afe838d7e kernel/sched/debug.c Yuyang Du 2015-07-15 @453 if (!se)
^^^
The old code assumed "se" can be NULL.

18bf2805d9b30c kernel/sched/debug.c Ben Segall 2012-10-04 454 return;
18bf2805d9b30c kernel/sched/debug.c Ben Segall 2012-10-04 455
ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 456 PN(se->exec_start);
ff9b48c3598732 kernel/sched_debug.c Bharata B Rao 2008-11-10 457 PN(se->vruntime);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx