Hi Charles, kernel test robot noticed the following build warnings: [auto build test WARNING on linus/master] [also build test WARNING on mcgrof/sysctl-next sysctl/sysctl-next v6.13-rc6 next-20250110] [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/Charles-Han/kernel-sysctl-test-Fix-potential-null-dereference-in-sysctl-test/20250110-181004 base: linus/master patch link: https://lore.kernel.org/r/20250110100748.63470-1-hanchunchao%40inspur.com patch subject: [PATCH] kernel/sysctl-test: Fix potential null dereference in sysctl-test config: i386-randconfig-063-20250111 (https://download.01.org/0day-ci/archive/20250111/202501112024.fU1FgDDE-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/20250111/202501112024.fU1FgDDE-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/202501112024.fU1FgDDE-lkp@xxxxxxxxx/ sparse warnings: (new ones prefixed by >>) >> kernel/sysctl-test.c:38:9: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const *value @@ got void [noderef] __user *const __ptr @@ kernel/sysctl-test.c:38:9: sparse: expected void const *value kernel/sysctl-test.c:38:9: sparse: got void [noderef] __user *const __ptr kernel/sysctl-test.c:47:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:47:9: sparse: expected void * kernel/sysctl-test.c:47:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:47:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:47:9: sparse: expected void * kernel/sysctl-test.c:47:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:56:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:56:9: sparse: expected void * kernel/sysctl-test.c:56:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:56:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:56:9: sparse: expected void * kernel/sysctl-test.c:56:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:85:9: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const *value @@ got void [noderef] __user *const __ptr @@ kernel/sysctl-test.c:85:9: sparse: expected void const *value kernel/sysctl-test.c:85:9: sparse: got void [noderef] __user *const __ptr kernel/sysctl-test.c:94:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:94:9: sparse: expected void * kernel/sysctl-test.c:94:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:94:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:94:9: sparse: expected void * kernel/sysctl-test.c:94:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:103:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:103:9: sparse: expected void * kernel/sysctl-test.c:103:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:103:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:103:9: sparse: expected void * kernel/sysctl-test.c:103:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:129:9: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const *value @@ got void [noderef] __user *const __ptr @@ kernel/sysctl-test.c:129:9: sparse: expected void const *value kernel/sysctl-test.c:129:9: sparse: got void [noderef] __user *const __ptr kernel/sysctl-test.c:136:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:136:9: sparse: expected void * kernel/sysctl-test.c:136:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:136:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:136:9: sparse: expected void * kernel/sysctl-test.c:136:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:140:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:140:9: sparse: expected void * kernel/sysctl-test.c:140:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:140:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:140:9: sparse: expected void * kernel/sysctl-test.c:140:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:164:9: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const *value @@ got void [noderef] __user *const __ptr @@ kernel/sysctl-test.c:164:9: sparse: expected void const *value kernel/sysctl-test.c:164:9: sparse: got void [noderef] __user *const __ptr kernel/sysctl-test.c:176:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:176:9: sparse: expected void * kernel/sysctl-test.c:176:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:176:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got void [noderef] __user *buffer @@ kernel/sysctl-test.c:176:9: sparse: expected void * kernel/sysctl-test.c:176:9: sparse: got void [noderef] __user *buffer kernel/sysctl-test.c:206:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:206:9: sparse: expected void * kernel/sysctl-test.c:206:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:206:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:206:9: sparse: expected void * kernel/sysctl-test.c:206:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:237:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:237:9: sparse: expected void * kernel/sysctl-test.c:237:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:237:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:237:9: sparse: expected void * kernel/sysctl-test.c:237:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:269:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:269:9: sparse: expected void * kernel/sysctl-test.c:269:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:269:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:269:9: sparse: expected void * kernel/sysctl-test.c:269:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:300:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:300:9: sparse: expected void * kernel/sysctl-test.c:300:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:300:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:300:9: sparse: expected void * kernel/sysctl-test.c:300:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:341:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:341:9: sparse: expected void * kernel/sysctl-test.c:341:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:341:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:341:9: sparse: expected void * kernel/sysctl-test.c:341:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:374:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:374:9: sparse: expected void * kernel/sysctl-test.c:374:9: sparse: got char [noderef] __user *user_buffer kernel/sysctl-test.c:374:9: sparse: sparse: incorrect type in argument 3 (different address spaces) @@ expected void * @@ got char [noderef] __user *user_buffer @@ kernel/sysctl-test.c:374:9: sparse: expected void * kernel/sysctl-test.c:374:9: sparse: got char [noderef] __user *user_buffer vim +38 kernel/sysctl-test.c 11 12 /* 13 * Test that proc_dointvec will not try to use a NULL .data field even when the 14 * length is non-zero. 15 */ 16 static void sysctl_test_api_dointvec_null_tbl_data(struct kunit *test) 17 { 18 struct ctl_table null_data_table = { 19 .procname = "foo", 20 /* 21 * Here we are testing that proc_dointvec behaves correctly when 22 * we give it a NULL .data field. Normally this would point to a 23 * piece of memory where the value would be stored. 24 */ 25 .data = NULL, 26 .maxlen = sizeof(int), 27 .mode = 0644, 28 .proc_handler = proc_dointvec, 29 .extra1 = SYSCTL_ZERO, 30 .extra2 = SYSCTL_ONE_HUNDRED, 31 }; 32 /* 33 * proc_dointvec expects a buffer in user space, so we allocate one. We 34 * also need to cast it to __user so sparse doesn't get mad. 35 */ 36 void __user *buffer = (void __user *)kunit_kzalloc(test, sizeof(int), 37 GFP_USER); > 38 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); 39 size_t len; 40 loff_t pos; 41 42 /* 43 * We don't care what the starting length is since proc_dointvec should 44 * not try to read because .data is NULL. 45 */ 46 len = 1234; 47 KUNIT_EXPECT_EQ(test, 0, proc_dointvec(&null_data_table, 48 KUNIT_PROC_READ, buffer, &len, 49 &pos)); 50 KUNIT_EXPECT_EQ(test, 0, len); 51 52 /* 53 * See above. 54 */ 55 len = 1234; 56 KUNIT_EXPECT_EQ(test, 0, proc_dointvec(&null_data_table, 57 KUNIT_PROC_WRITE, buffer, &len, 58 &pos)); 59 KUNIT_EXPECT_EQ(test, 0, len); 60 } 61 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki