x86, xsave: remove the redundant access_ok() in setup_rt_frame()
PATCH 1/3 x86, xsave: remove the redundant access_ok() in setup_rt_frame()
save_i387_xstate() is already doing the required access_ok(). Remove the redundant access_ok() before it.
---
arch/x86/kernel/signal_64.c +0 -3
@@ -208,9 +208,6 @@ frame = (void __user *)round_down ( (unsigned long )fp -sizeof (struct rt_sigframe ),16 ) -8 ; -if (!access_ok (VERIFY_WRITE , fp,sizeof (struct _fpstate ))) - goto give_sigsegv; -if (save_i387_xstate (fp) <0 ) err |=-1 ; }else
PATCH 2/3 x86, xsave: clear the user buffer before doing fxsave/xsave
fxsave/xsave instructions will not touch all the bytes in the fxsave/xsave frame. Clear the user buffer before doing fxsave/xsave directly to user buffer during the sigcontext setup.
This is essentially needed in the context of xsave(for example, some of the fields in the xsave header are not touched by the xsave and defined as must be zero).
This will also present uniform and clean context to the user (from which user can safely do fxrstor/xrstor).
---
arch/x86/kernel/xsave.c +6 -0
@@ -92,6 +92,12 @@return 0 ;clear_used_math ();/* trigger finit */ if (task_thread_info (tsk)->status &TS_USEDFPU ) { +/* +* Start with clearing the user buffer. This will present a +* clean context for the bytes not touched by the fxsave/xsave. +*/ +__clear_user (buf, sig_xstate_size); +if (task_thread_info (tsk)->status &TS_XSAVE ) err =xsave_user (buf);else
PATCH 3/3 x86, xsave: use BUG_ON() instead of BUILD_BUG_ON()
In reply to Suresh SiddhaAll these structure sizes are runtime determined. So use a runtime bug check.
---
arch/x86/kernel/xsave.c +1 -2
@@ -82,8 +82,7 @@if (!access_ok (VERIFY_WRITE , buf, sig_xstate_size))return -EACCES ; -BUILD_BUG_ON (sizeof (struct user_i387_struct ) != -sizeof (tsk->thread.xstate->fxsave)); +BUG_ON (sig_xstate_size < xstate_size);if ((unsigned long )buf %64 )printk ("save_i387_xstate: bad fpstate %p\n" , buf);
Ingo Molnar
AppliedRe: [patch 3/3] x86, xsave: use BUG_ON() instead of BUILD_BUG_ON()
Quoted 2 lines · Suresh Siddha
All these structure sizes are runtime determined. So use a runtime bug check.
applied these patches to tip/x86/xsave:
f65bc21: x86, xsave: use BUG_ON() instead of BUILD_BUG_ON()
ed40595: x86, xsave: clear the user buffer before doing fxsave/xsave
ee2b92a: x86, xsave: remove the redundant access_ok() in setup_rt_frame()
thanks Suresh.
Ingo