Commit 42019fc5 authored by Russell King's avatar Russell King

ARM: vfp: use __copy_from_user() when restoring VFP state

__get_user_error() is used as a fast accessor to make copying structure
members in the signal handling path as efficient as possible.  However,
with software PAN and the recent Spectre variant 1, the efficiency is
reduced as these are no longer fast accessors.

In the case of software PAN, it has to switch the domain register around
each access, and with Spectre variant 1, it would have to repeat the
access_ok() check for each access.

Use __copy_from_user() rather than __get_user_err() for individual
members when restoring VFP state.
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
parent c32cd419
...@@ -123,8 +123,8 @@ struct user_vfp_exc; ...@@ -123,8 +123,8 @@ struct user_vfp_exc;
extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *, extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *,
struct user_vfp_exc __user *); struct user_vfp_exc __user *);
extern int vfp_restore_user_hwstate(struct user_vfp __user *, extern int vfp_restore_user_hwstate(struct user_vfp *,
struct user_vfp_exc __user *); struct user_vfp_exc *);
#endif #endif
/* /*
......
...@@ -150,22 +150,18 @@ static int preserve_vfp_context(struct vfp_sigframe __user *frame) ...@@ -150,22 +150,18 @@ static int preserve_vfp_context(struct vfp_sigframe __user *frame)
static int restore_vfp_context(char __user **auxp) static int restore_vfp_context(char __user **auxp)
{ {
struct vfp_sigframe __user *frame = struct vfp_sigframe frame;
(struct vfp_sigframe __user *)*auxp; int err;
unsigned long magic;
unsigned long size;
int err = 0;
__get_user_error(magic, &frame->magic, err);
__get_user_error(size, &frame->size, err);
err = __copy_from_user(&frame, *auxp, sizeof(frame));
if (err) if (err)
return -EFAULT; return err;
if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
if (frame.magic != VFP_MAGIC || frame.size != VFP_STORAGE_SIZE)
return -EINVAL; return -EINVAL;
*auxp += size; *auxp += sizeof(frame);
return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc); return vfp_restore_user_hwstate(&frame.ufp, &frame.ufp_exc);
} }
#endif #endif
......
...@@ -597,13 +597,11 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp, ...@@ -597,13 +597,11 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
} }
/* Sanitise and restore the current VFP state from the provided structures. */ /* Sanitise and restore the current VFP state from the provided structures. */
int vfp_restore_user_hwstate(struct user_vfp __user *ufp, int vfp_restore_user_hwstate(struct user_vfp *ufp, struct user_vfp_exc *ufp_exc)
struct user_vfp_exc __user *ufp_exc)
{ {
struct thread_info *thread = current_thread_info(); struct thread_info *thread = current_thread_info();
struct vfp_hard_struct *hwstate = &thread->vfpstate.hard; struct vfp_hard_struct *hwstate = &thread->vfpstate.hard;
unsigned long fpexc; unsigned long fpexc;
int err = 0;
/* Disable VFP to avoid corrupting the new thread state. */ /* Disable VFP to avoid corrupting the new thread state. */
vfp_flush_hwstate(thread); vfp_flush_hwstate(thread);
...@@ -612,17 +610,16 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp, ...@@ -612,17 +610,16 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp,
* Copy the floating point registers. There can be unused * Copy the floating point registers. There can be unused
* registers see asm/hwcap.h for details. * registers see asm/hwcap.h for details.
*/ */
err |= __copy_from_user(&hwstate->fpregs, &ufp->fpregs, memcpy(&hwstate->fpregs, &ufp->fpregs, sizeof(hwstate->fpregs));
sizeof(hwstate->fpregs));
/* /*
* Copy the status and control register. * Copy the status and control register.
*/ */
__get_user_error(hwstate->fpscr, &ufp->fpscr, err); hwstate->fpscr = ufp->fpscr;
/* /*
* Sanitise and restore the exception registers. * Sanitise and restore the exception registers.
*/ */
__get_user_error(fpexc, &ufp_exc->fpexc, err); fpexc = ufp_exc->fpexc;
/* Ensure the VFP is enabled. */ /* Ensure the VFP is enabled. */
fpexc |= FPEXC_EN; fpexc |= FPEXC_EN;
...@@ -631,10 +628,10 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp, ...@@ -631,10 +628,10 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp,
fpexc &= ~(FPEXC_EX | FPEXC_FP2V); fpexc &= ~(FPEXC_EX | FPEXC_FP2V);
hwstate->fpexc = fpexc; hwstate->fpexc = fpexc;
__get_user_error(hwstate->fpinst, &ufp_exc->fpinst, err); hwstate->fpinst = ufp_exc->fpinst;
__get_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err); hwstate->fpinst2 = ufp_exc->fpinst2;
return err ? -EFAULT : 0; return 0;
} }
/* /*
......
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