lkml.org 
[lkml]   [2021]   [Jun]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[tip: x86/fpu] x86/fpu/signal: Sanitize copy_user_to_fpregs_zeroing()
    The following commit has been merged into the x86/fpu branch of tip:

    Commit-ID: cdcec1b77001e7f2cd10dccfc6d9b6d5d3f1f3ea
    Gitweb: https://git.kernel.org/tip/cdcec1b77001e7f2cd10dccfc6d9b6d5d3f1f3ea
    Author: Thomas Gleixner <tglx@linutronix.de>
    AuthorDate: Wed, 23 Jun 2021 14:02:28 +02:00
    Committer: Borislav Petkov <bp@suse.de>
    CommitterDate: Wed, 23 Jun 2021 20:03:15 +02:00

    x86/fpu/signal: Sanitize copy_user_to_fpregs_zeroing()

    Now that user_xfeatures is correctly set when xsave is enabled, remove
    the duplicated initialization of components.

    Rename the function while at it.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Reviewed-by: Borislav Petkov <bp@suse.de>
    Link: https://lkml.kernel.org/r/20210623121457.377341297@linutronix.de
    ---
    arch/x86/kernel/fpu/signal.c | 36 ++++++++++++++---------------------
    1 file changed, 15 insertions(+), 21 deletions(-)

    diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
    index d552410..a1a7013 100644
    --- a/arch/x86/kernel/fpu/signal.c
    +++ b/arch/x86/kernel/fpu/signal.c
    @@ -251,33 +251,27 @@ sanitize_restored_user_xstate(union fpregs_state *state,
    }

    /*
    - * Restore the extended state if present. Otherwise, restore the FP/SSE state.
    + * Restore the FPU state directly from the userspace signal frame.
    */
    -static int copy_user_to_fpregs_zeroing(void __user *buf, u64 xbv, int fx_only)
    +static int restore_fpregs_from_user(void __user *buf, u64 xrestore, bool fx_only)
    {
    - u64 init_bv;
    - int r;
    -
    if (use_xsave()) {
    - if (fx_only) {
    - init_bv = xfeatures_mask_uabi() & ~XFEATURE_MASK_FPSSE;
    + u64 init_bv = xfeatures_mask_uabi() & ~xrestore;
    + int ret;

    - r = fxrstor_from_user_sigframe(buf);
    - if (!r)
    - os_xrstor(&init_fpstate.xsave, init_bv);
    - return r;
    - } else {
    - init_bv = xfeatures_mask_uabi() & ~xbv;
    -
    - r = xrstor_from_user_sigframe(buf, xbv);
    - if (!r && unlikely(init_bv))
    - os_xrstor(&init_fpstate.xsave, init_bv);
    - return r;
    - }
    + if (likely(!fx_only))
    + ret = xrstor_from_user_sigframe(buf, xrestore);
    + else
    + ret = fxrstor_from_user_sigframe(buf);
    +
    + if (!ret && unlikely(init_bv))
    + os_xrstor(&init_fpstate.xsave, init_bv);
    + return ret;
    } else if (use_fxsr()) {
    return fxrstor_from_user_sigframe(buf);
    - } else
    + } else {
    return frstor_from_user_sigframe(buf);
    + }
    }

    static int __fpu_restore_sig(void __user *buf, void __user *buf_fx,
    @@ -314,7 +308,7 @@ static int __fpu_restore_sig(void __user *buf, void __user *buf_fx,
    */
    fpregs_lock();
    pagefault_disable();
    - ret = copy_user_to_fpregs_zeroing(buf_fx, user_xfeatures, fx_only);
    + ret = restore_fpregs_from_user(buf_fx, user_xfeatures, fx_only);
    pagefault_enable();
    if (!ret) {

    \
     
     \ /
      Last update: 2021-06-24 00:09    [W:2.248 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site