Skip to contentSkip to conversation

arch/x86/um/signal.c:85:19: sparse: sparse: incorrect type in assignment (different address spaces)

PATCH kernel test robot 1 participant 1 message Oct 27, 2024

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/uml/linux next
head:   d3b08e5f3f2829943342b88d3e2b44fb0ccdccab
commit: 3f17fed2149192c7d3b76a45a6a87b4ff22cd586 [44/50] um: switch to regset API and depend on XSTATE
config: um-randconfig-r123-20241027 (https://download.01.org/0day-ci/archive/20241028/[email protected]/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/20241028/[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]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> arch/x86/um/signal.c:85:19: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct _xstate_64 [noderef] __user *from_fp64 @@     got void * @@
   arch/x86/um/signal.c:85:19: sparse:     expected struct _xstate_64 [noderef] __user *from_fp64
   arch/x86/um/signal.c:85:19: sparse:     got void *
>> arch/x86/um/signal.c:100:38: sparse: sparse: incorrect type in argument 6 (different address spaces) @@     expected void const [noderef] __user *data @@     got void * @@
   arch/x86/um/signal.c:100:38: sparse:     expected void const [noderef] __user *data
   arch/x86/um/signal.c:100:38: sparse:     got void *
   arch/x86/um/signal.c:176:20: sparse: sparse: cast removes address space '__user' of expression
>> arch/x86/um/signal.c:176:17: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct _xstate_64 [noderef] __user *to_fp64 @@     got void * @@
   arch/x86/um/signal.c:176:17: sparse:     expected struct _xstate_64 [noderef] __user *to_fp64
   arch/x86/um/signal.c:176:17: sparse:     got void *
   arch/x86/um/signal.c:201:9: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:201:9: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:201:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __user *ptr @@     got int * @@
   arch/x86/um/signal.c:201:9: sparse:     expected void const volatile [noderef] __user *ptr
   arch/x86/um/signal.c:201:9: sparse:     got int *
   arch/x86/um/signal.c:201:9: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:201:9: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:201:9: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:201:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void [noderef] __user *ptr @@     got int * @@
   arch/x86/um/signal.c:201:9: sparse:     expected void [noderef] __user *ptr
   arch/x86/um/signal.c:201:9: sparse:     got int *
   arch/x86/um/signal.c:242:16: sparse: sparse: cast removes address space '__user' of expression
>> arch/x86/um/signal.c:242:16: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void *__x @@     got void [noderef] __user *[assigned] restorer @@
   arch/x86/um/signal.c:242:16: sparse:     expected void *__x
   arch/x86/um/signal.c:242:16: sparse:     got void [noderef] __user *[assigned] restorer
   arch/x86/um/signal.c:242:16: sparse: sparse: cast removes address space '__user' of expression
>> arch/x86/um/signal.c:242:16: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __user *ptr @@     got void ** @@
   arch/x86/um/signal.c:242:16: sparse:     expected void const volatile [noderef] __user *ptr
   arch/x86/um/signal.c:242:16: sparse:     got void **
   arch/x86/um/signal.c:242:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:242:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:242:16: sparse: sparse: cast removes address space '__user' of expression
>> arch/x86/um/signal.c:242:16: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void [noderef] __user *ptr @@     got void ** @@
   arch/x86/um/signal.c:242:16: sparse:     expected void [noderef] __user *ptr
   arch/x86/um/signal.c:242:16: sparse:     got void **
   arch/x86/um/signal.c:298:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:298:16: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void *__x @@     got void [noderef] __user *[assigned] restorer @@
   arch/x86/um/signal.c:298:16: sparse:     expected void *__x
   arch/x86/um/signal.c:298:16: sparse:     got void [noderef] __user *[assigned] restorer
   arch/x86/um/signal.c:298:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:298:16: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __user *ptr @@     got void ** @@
   arch/x86/um/signal.c:298:16: sparse:     expected void const volatile [noderef] __user *ptr
   arch/x86/um/signal.c:298:16: sparse:     got void **
   arch/x86/um/signal.c:298:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:298:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:298:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:298:16: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void [noderef] __user *ptr @@     got void ** @@
   arch/x86/um/signal.c:298:16: sparse:     expected void [noderef] __user *ptr
   arch/x86/um/signal.c:298:16: sparse:     got void **
   arch/x86/um/signal.c:300:16: sparse: sparse: cast removes address space '__user' of expression
>> arch/x86/um/signal.c:300:16: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void *__x @@     got struct siginfo [noderef] __user * @@
   arch/x86/um/signal.c:300:16: sparse:     expected void *__x
   arch/x86/um/signal.c:300:16: sparse:     got struct siginfo [noderef] __user *
   arch/x86/um/signal.c:300:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:300:16: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __user *ptr @@     got void ** @@
   arch/x86/um/signal.c:300:16: sparse:     expected void const volatile [noderef] __user *ptr
   arch/x86/um/signal.c:300:16: sparse:     got void **
   arch/x86/um/signal.c:300:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:300:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:300:16: sparse: sparse: cast removes address space '__user' of expression
   arch/x86/um/signal.c:300:16: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void [noderef] __user *ptr @@     got void ** @@
   arch/x86/um/signal.c:300:16: sparse:     expected void [noderef] __user *ptr
   arch/x86/um/signal.c:300:16: sparse:     got void **
   arch/x86/um/signal.c:301:16: sparse: sparse: cast removes address space '__user' of expression
>> arch/x86/um/signal.c:301:16: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected void *__x @@     got struct ucontext [noderef] __user * @@

arch/x86/um/signal.c:301:16: sparse: expected void *__x
arch/x86/um/signal.c:301:16: sparse: got struct ucontext [noderef] __user *
arch/x86/um/signal.c:301:16: sparse: sparse: cast removes address space '__user' of expression
arch/x86/um/signal.c:301:16: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const volatile [noderef] __user *ptr @@ got void ** @@
arch/x86/um/signal.c:301:16: sparse: expected void const volatile [noderef] __user *ptr
arch/x86/um/signal.c:301:16: sparse: got void **
arch/x86/um/signal.c:301:16: sparse: sparse: cast removes address space '__user' of expression arch/x86/um/signal.c:301:16: sparse: sparse: cast removes address space '__user' of expression arch/x86/um/signal.c:301:16: sparse: sparse: cast removes address space '__user' of expression
arch/x86/um/signal.c:301:16: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void [noderef] __user *ptr @@ got void ** @@
arch/x86/um/signal.c:301:16: sparse: expected void [noderef] __user *ptr
arch/x86/um/signal.c:301:16: sparse: got void **

vim +85 arch/x86/um/signal.c

    83	
    84	#ifdef CONFIG_X86_32
  > 85		from_fp64 = ((void *)sc.fpstate) + offsetof(struct _fpstate_32, _fxsr_env);
    86	#else
    87		from_fp64 = (void *)sc.fpstate;
    88	#endif
    89	
    90		err = copy_from_user(regs->regs.fp, from_fp64, host_fp_size);
    91		if (err)
    92			return 1;
    93	
    94	#ifdef CONFIG_X86_32
    95		/* Data is duplicated and this copy is the important one */
    96		err = copy_regset_from_user(current,
    97					    task_user_regset_view(current),
    98					    REGSET_FP_LEGACY, 0,
    99					    sizeof(struct user_i387_struct),
 > 100					    (void *)sc.fpstate);
   101		if (err < 0)
   102			return err;
   103	#endif
   104	
   105		return 0;
   106	}
   107	
   108	static int copy_sc_to_user(struct sigcontext __user *to,
   109				   struct _xstate __user *to_fp, struct pt_regs *regs,
   110				   unsigned long mask)
   111	{
   112		struct _xstate_64 __user *to_fp64;
   113		struct sigcontext sc;
   114		struct faultinfo * fi = &current->thread.arch.faultinfo;
   115		int err;
   116		memset(&sc, 0, sizeof(struct sigcontext));
   117	
   118	#define PUTREG(regno, regname) sc.regname = regs->regs.gp[HOST_##regno]
   119	
   120	#ifdef CONFIG_X86_32
   121		PUTREG(GS, gs);
   122		PUTREG(FS, fs);
   123		PUTREG(ES, es);
   124		PUTREG(DS, ds);
   125	#endif
   126		PUTREG(DI, di);
   127		PUTREG(SI, si);
   128		PUTREG(BP, bp);
   129		PUTREG(SP, sp);
   130		PUTREG(BX, bx);
   131		PUTREG(DX, dx);
   132		PUTREG(CX, cx);
   133		PUTREG(AX, ax);
   134	#ifdef CONFIG_X86_64
   135		PUTREG(R8, r8);
   136		PUTREG(R9, r9);
   137		PUTREG(R10, r10);
   138		PUTREG(R11, r11);
   139		PUTREG(R12, r12);
   140		PUTREG(R13, r13);
   141		PUTREG(R14, r14);
   142		PUTREG(R15, r15);
   143	#endif
   144	
   145		sc.cr2 = fi->cr2;
   146		sc.err = fi->error_code;
   147		sc.trapno = fi->trap_no;
   148		PUTREG(IP, ip);
   149		PUTREG(CS, cs);
   150		PUTREG(EFLAGS, flags);
   151	#ifdef CONFIG_X86_32
   152		PUTREG(SP, sp_at_signal);
   153		PUTREG(SS, ss);
   154	#endif
   155	#undef PUTREG
   156		sc.oldmask = mask;
   157		sc.fpstate = (unsigned long)to_fp;
   158	
   159		err = copy_to_user(to, &sc, sizeof(struct sigcontext));
   160		if (err)
   161			return 1;
   162	
   163	#ifdef CONFIG_X86_32
   164		err = copy_regset_to_user(current,
   165					  task_user_regset_view(current),
   166					  REGSET_FP_LEGACY, 0,
   167					  sizeof(struct _fpstate_32), to_fp);
   168		if (err < 0)
   169			return err;
   170	
   171		__put_user(X86_FXSR_MAGIC, &to_fp->fpstate.magic);
   172	
   173		BUILD_BUG_ON(offsetof(struct _xstate, xstate_hdr) !=
   174			     offsetof(struct _xstate_64, xstate_hdr) +
   175				offsetof(struct _fpstate_32, _fxsr_env));
 > 176		to_fp64 = (void *)to_fp + offsetof(struct _fpstate_32, _fxsr_env);
   177	#else
   178		to_fp64 = to_fp;
   179	#endif /* CONFIG_X86_32 */
   180	
   181		if (copy_to_user(to_fp64, regs->regs.fp, host_fp_size))
   182			return 1;
   183	
   184		/*
   185		 * Put magic/size values for userspace. We do not bother to verify them
   186		 * later on, however, userspace needs them should it try to read the
   187		 * XSTATE data. And ptrace does not fill in these parts.
   188		 */
   189		BUILD_BUG_ON(sizeof(int) != FP_XSTATE_MAGIC2_SIZE);
   190	#ifdef CONFIG_X86_32
   191		__put_user(offsetof(struct _fpstate_32, _fxsr_env) +
   192			   host_fp_size + FP_XSTATE_MAGIC2_SIZE,
   193			   &to_fp64->fpstate.sw_reserved.extended_size);
   194	#else
   195		__put_user(host_fp_size + FP_XSTATE_MAGIC2_SIZE,
   196			   &to_fp64->fpstate.sw_reserved.extended_size);
   197	#endif
   198		__put_user(host_fp_size, &to_fp64->fpstate.sw_reserved.xstate_size);
   199	
   200		__put_user(FP_XSTATE_MAGIC1, &to_fp64->fpstate.sw_reserved.magic1);
   201		__put_user(FP_XSTATE_MAGIC2, (int *)((void *)to_fp64 + host_fp_size));
   202	
   203		return 0;
   204	}
   205	
   206	#ifdef CONFIG_X86_32
   207	static int copy_ucontext_to_user(struct ucontext __user *uc,
   208					 struct _xstate __user *fp, sigset_t *set,
   209					 unsigned long sp)
   210	{
   211		int err = 0;
   212	
   213		err |= __save_altstack(&uc->uc_stack, sp);
   214		err |= copy_sc_to_user(&uc->uc_mcontext, fp, &current->thread.regs, 0);
   215		err |= copy_to_user(&uc->uc_sigmask, set, sizeof(*set));
   216		return err;
   217	}
   218	
   219	int setup_signal_stack_sc(unsigned long stack_top, struct ksignal *ksig,
   220				  struct pt_regs *regs, sigset_t *mask)
   221	{
   222		size_t math_size = offsetof(struct _fpstate_32, _fxsr_env) +
   223				   host_fp_size + FP_XSTATE_MAGIC2_SIZE;
   224		struct sigframe __user *frame;
   225		void __user *restorer;
   226		int err = 0, sig = ksig->sig;
   227		unsigned long fp_to;
   228	
   229		/* This is the same calculation as i386 - ((sp + 4) & 15) == 0 */
   230		stack_top = ((stack_top + 4) & -16UL) - 4;
   231		frame = (struct sigframe __user *) stack_top - 1;
   232		if (!access_ok(frame, sizeof(*frame)))
   233			return 1;
   234	
   235		/* Add required space for math frame */
   236		frame = (struct sigframe __user *)((unsigned long)frame - math_size);
   237	
   238		restorer = frame->retcode;
   239		if (ksig->ka.sa.sa_flags & SA_RESTORER)
   240			restorer = ksig->ka.sa.sa_restorer;
   241	
 > 242		err |= __put_user(restorer, (void **)&frame->pretcode);
   243		err |= __put_user(sig, &frame->sig);
   244	
   245		fp_to = (unsigned long)frame + sizeof(*frame);
   246	
   247		err |= copy_sc_to_user(&frame->sc,
   248				       (struct _xstate __user *)fp_to,
   249				       regs, mask->sig[0]);
   250		if (_NSIG_WORDS > 1)
   251			err |= __copy_to_user(&frame->extramask, &mask->sig[1],
   252					      sizeof(frame->extramask));
   253	
   254		/*
   255		 * This is popl %eax ; movl $,%eax ; int $0x80
   256		 *
   257		 * WE DO NOT USE IT ANY MORE! It's only left here for historical
   258		 * reasons and because gdb uses it as a signature to notice
   259		 * signal handler stack frames.
   260		 */
   261		err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
   262		err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
   263		err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));

264
265 if (err)
266 return err;
267
268 PT_REGS_SP(regs) = (unsigned long) frame;
269 PT_REGS_IP(regs) = (unsigned long) ksig->ka.sa.sa_handler;
270 PT_REGS_AX(regs) = (unsigned long) sig;
271 PT_REGS_DX(regs) = (unsigned long) 0;
272 PT_REGS_CX(regs) = (unsigned long) 0;
273 return 0;
274 }
275

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