Commit 89833fab authored by Jann Horn's avatar Jann Horn Committed by Borislav Petkov

x86/fpu: Fix __user annotations

In save_xstate_epilog(), use __user when type-casting userspace
pointers.

In setup_sigcontext() and x32_setup_rt_frame(), cast the userspace
pointers to 'unsigned long __user *' before writing into them. These
pointers are originally '__u32 __user *' or '__u64 __user *', causing
sparse to complain when a userspace pointer is written into them. The
casts are okay because the pointers always point to pointer-sized
values.

Thanks to Luc Van Oostenryck and Al Viro for explaining this to me.
Signed-off-by: default avatarJann Horn <jannh@google.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Mukesh Ojha <mojha@codeaurora.org>
Cc: Qiaowei Ren <qiaowei.ren@intel.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190329214652.258477-3-jannh@google.com
parent 79a3aaa7
...@@ -92,13 +92,13 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame) ...@@ -92,13 +92,13 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
return err; return err;
err |= __put_user(FP_XSTATE_MAGIC2, err |= __put_user(FP_XSTATE_MAGIC2,
(__u32 *)(buf + fpu_user_xstate_size)); (__u32 __user *)(buf + fpu_user_xstate_size));
/* /*
* Read the xfeatures which we copied (directly from the cpu or * Read the xfeatures which we copied (directly from the cpu or
* from the state in task struct) to the user buffers. * from the state in task struct) to the user buffers.
*/ */
err |= __get_user(xfeatures, (__u32 *)&x->header.xfeatures); err |= __get_user(xfeatures, (__u32 __user *)&x->header.xfeatures);
/* /*
* For legacy compatible, we always set FP/SSE bits in the bit * For legacy compatible, we always set FP/SSE bits in the bit
...@@ -113,7 +113,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame) ...@@ -113,7 +113,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
*/ */
xfeatures |= XFEATURE_MASK_FPSSE; xfeatures |= XFEATURE_MASK_FPSSE;
err |= __put_user(xfeatures, (__u32 *)&x->header.xfeatures); err |= __put_user(xfeatures, (__u32 __user *)&x->header.xfeatures);
return err; return err;
} }
......
...@@ -206,7 +206,7 @@ int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, ...@@ -206,7 +206,7 @@ int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
put_user_ex(regs->ss, &sc->ss); put_user_ex(regs->ss, &sc->ss);
#endif /* CONFIG_X86_32 */ #endif /* CONFIG_X86_32 */
put_user_ex(fpstate, &sc->fpstate); put_user_ex(fpstate, (unsigned long __user *)&sc->fpstate);
/* non-iBCS2 extensions.. */ /* non-iBCS2 extensions.. */
put_user_ex(mask, &sc->oldmask); put_user_ex(mask, &sc->oldmask);
...@@ -569,7 +569,7 @@ static int x32_setup_rt_frame(struct ksignal *ksig, ...@@ -569,7 +569,7 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
restorer = NULL; restorer = NULL;
err |= -EFAULT; err |= -EFAULT;
} }
put_user_ex(restorer, &frame->pretcode); put_user_ex(restorer, (unsigned long __user *)&frame->pretcode);
} put_user_catch(err); } put_user_catch(err);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate, err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment