Skip to contentSkip to conversation

kernel/kthread.c:1570 param_get_namefmt() warn: variable dereferenced before check 'param' (see line 1567)

PATCH New Dan Carpenter 1 participant 1 message Sep 8, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 12/12 kernel/kthread.c:1570 param_get_namefmt() warn: variable dereferenced before check 'param' (see line 1567)

tree:   https://github.com/qais-yousef/linux sched-setscheduler-hide
head:   557fb1e21399de5f674beb93fa6793adce124cc2
commit: 557fb1e21399de5f674beb93fa6793adce124cc2 [12/12] kthread: Implement parameter handling logic
config: x86_64-randconfig-161-20230907 (https://download.01.org/0day-ci/archive/20230908/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230908/[email protected]/reproduce)

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
kernel/kthread.c:1570 param_get_namefmt() warn: variable dereferenced before check 'param' (see line 1567) kernel/kthread.c:1794 param_set_sched_util_min() warn: ignoring unreachable code.

vim +/param +1570 kernel/kthread.c

557fb1e21399de5f Qais Yousef 2023-08-27  1562  static int param_get_namefmt(char *buffer, int len,
557fb1e21399de5f Qais Yousef 2023-08-27  1563  			     const char *name, const char *param)
557fb1e21399de5f Qais Yousef 2023-08-27  1564  {
557fb1e21399de5f Qais Yousef 2023-08-27  1565  	int namelen = strlen(name);
557fb1e21399de5f Qais Yousef 2023-08-27  1566  	int kthreadlen = strlen("kthread.");
557fb1e21399de5f Qais Yousef 2023-08-27 @1567  	int paramlen = strlen(param);
                                                                      ^^^^^

Dereferenced

557fb1e21399de5f Qais Yousef 2023-08-27 1568 int size = namelen - kthreadlen - paramlen;
557fb1e21399de5f Qais Yousef 2023-08-27 1569
557fb1e21399de5f Qais Yousef 2023-08-27 @1570 if (!namelen || !param || size > len)

                                                                 ^^^^^

Checked too late.

557fb1e21399de5f Qais Yousef 2023-08-27  1571  		return -EINVAL;
557fb1e21399de5f Qais Yousef 2023-08-27  1572  
557fb1e21399de5f Qais Yousef 2023-08-27  1573  	strlcpy(buffer, name + kthreadlen, size);
557fb1e21399de5f Qais Yousef 2023-08-27  1574  
557fb1e21399de5f Qais Yousef 2023-08-27  1575  	return 0;
557fb1e21399de5f Qais Yousef 2023-08-27  1576  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki