kernel/trace/trace_events_synth.c:436:68: sparse: sparse: incorrect type in argument 2 (different address spaces)

From: kernel test robot
Date: Tue Oct 31 2023 - 12:48:21 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 5a6a09e97199d6600d31383055f9d43fbbcbe86f
commit: 0934ae9977c27133449b6dd8c6213970e7eece38 tracing: Fix reading strings from synthetic events
date: 1 year, 1 month ago
config: x86_64-randconfig-x014-20230805 (https://download.01.org/0day-ci/archive/20231101/202311010013.fm8WTxa5-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/20231101/202311010013.fm8WTxa5-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/202311010013.fm8WTxa5-lkp@xxxxxxxxx/

sparse warnings: (new ones prefixed by >>)
>> kernel/trace/trace_events_synth.c:436:68: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef] __user *unsafe_addr @@ got char *str_val @@
kernel/trace/trace_events_synth.c:436:68: sparse: expected void const [noderef] __user *unsafe_addr
kernel/trace/trace_events_synth.c:436:68: sparse: got char *str_val

vim +436 kernel/trace/trace_events_synth.c

404
405 static unsigned int trace_string(struct synth_trace_event *entry,
406 struct synth_event *event,
407 char *str_val,
408 bool is_dynamic,
409 unsigned int data_size,
410 unsigned int *n_u64)
411 {
412 unsigned int len = 0;
413 char *str_field;
414 int ret;
415
416 if (is_dynamic) {
417 u32 data_offset;
418
419 data_offset = offsetof(typeof(*entry), fields);
420 data_offset += event->n_u64 * sizeof(u64);
421 data_offset += data_size;
422
423 len = kern_fetch_store_strlen((unsigned long)str_val);
424
425 data_offset |= len << 16;
426 *(u32 *)&entry->fields[*n_u64] = data_offset;
427
428 ret = kern_fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry);
429
430 (*n_u64)++;
431 } else {
432 str_field = (char *)&entry->fields[*n_u64];
433
434 #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
435 if ((unsigned long)str_val < TASK_SIZE)
> 436 ret = strncpy_from_user_nofault(str_field, str_val, STR_VAR_LEN_MAX);
437 else
438 #endif
439 ret = strncpy_from_kernel_nofault(str_field, str_val, STR_VAR_LEN_MAX);
440
441 if (ret < 0)
442 strcpy(str_field, FAULT_STRING);
443
444 (*n_u64) += STR_VAR_LEN_MAX / sizeof(u64);
445 }
446
447 return len;
448 }
449

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