kernel/trace/bpf_trace.c:2254:21: sparse: sparse: dereference of noderef expression

From: kernel test robot
Date: Wed Dec 27 2023 - 12:18:54 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fbafc3e621c3f4ded43720fdb1d6ce1728ec664e
commit: 0236fec57a15dc2a068dfe4488e0c2ab4559b1ec bpf: Resolve symbols with ftrace_lookup_symbols for kprobe multi link
date: 1 year, 8 months ago
config: i386-randconfig-061-20231101 (https://download.01.org/0day-ci/archive/20231228/202312280124.W09SBhfq-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231228/202312280124.W09SBhfq-lkp@xxxxxxxxx/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 <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312280124.W09SBhfq-lkp@xxxxxxxxx/

sparse warnings: (new ones prefixed by >>)
>> kernel/trace/bpf_trace.c:2254:21: sparse: sparse: dereference of noderef expression
kernel/trace/bpf_trace.c:2258:66: sparse: sparse: dereference of noderef expression

vim +2254 kernel/trace/bpf_trace.c

2236
2237 static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt)
2238 {
2239 unsigned long __user usymbol;
2240 const char **syms = NULL;
2241 char *buf = NULL, *p;
2242 int err = -ENOMEM;
2243 unsigned int i;
2244
2245 syms = kvmalloc(cnt * sizeof(*syms), GFP_KERNEL);
2246 if (!syms)
2247 goto error;
2248
2249 buf = kvmalloc(cnt * KSYM_NAME_LEN, GFP_KERNEL);
2250 if (!buf)
2251 goto error;
2252
2253 for (p = buf, i = 0; i < cnt; i++) {
> 2254 if (__get_user(usymbol, usyms + i)) {
2255 err = -EFAULT;
2256 goto error;
2257 }
2258 err = strncpy_from_user(p, (const char __user *) usymbol, KSYM_NAME_LEN);
2259 if (err == KSYM_NAME_LEN)
2260 err = -E2BIG;
2261 if (err < 0)
2262 goto error;
2263 syms[i] = p;
2264 p += err + 1;
2265 }
2266
2267 us->syms = syms;
2268 us->buf = buf;
2269 return 0;
2270
2271 error:
2272 if (err) {
2273 kvfree(syms);
2274 kvfree(buf);
2275 }
2276 return err;
2277 }
2278

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