lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALCETrWQJtv6f1zYnWSiPe7qFUx4znthbysVC9NJ-88YqP5-eg@mail.gmail.com>
Date:   Tue, 16 Jun 2020 09:53:39 -0700
From:   Andy Lutomirski <luto@...capital.net>
To:     Borislav Petkov <bp@...en8.de>
Cc:     x86-ml <x86@...nel.org>, jpa@...nelbug.mail.kapsi.fi,
        Dave Hansen <dave.hansen@...el.com>,
        "H. Peter Anvin" <hpa@...or.com>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        lkml <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86/fpu: Reset MXCSR to default in kernel_fpu_begin()

On Tue, Jun 16, 2020 at 2:53 AM Borislav Petkov <bp@...en8.de> wrote:
>
> Ok,
>
> here's the fix first so that it goes in. I'll hammer on the test case later.

Does the 32-bit case need FNINIT?

>
> ---
> From: Petteri Aimonen <jpa@....mail.kapsi.fi>
>
> Previously, kernel floating point code would run with the MXCSR control
> register value last set by userland code by the thread that was active
> on the CPU core just before kernel call. This could affect calculation
> results if rounding mode was changed, or a crash if a FPU/SIMD exception
> was unmasked.
>
> Restore MXCSR to the kernel's default value.
>
>  [ bp: Carve out from a bigger patch by Petteri, add feature check. ]
>
> Signed-off-by: Petteri Aimonen <jpa@....mail.kapsi.fi>
> Signed-off-by: Borislav Petkov <bp@...e.de>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=207979
> ---
>  arch/x86/include/asm/fpu/internal.h | 5 +++++
>  arch/x86/kernel/fpu/core.c          | 3 +++
>  2 files changed, 8 insertions(+)
>
> diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
> index 42159f45bf9c..845e7481ab77 100644
> --- a/arch/x86/include/asm/fpu/internal.h
> +++ b/arch/x86/include/asm/fpu/internal.h
> @@ -623,6 +623,11 @@ static inline void switch_fpu_finish(struct fpu *new_fpu)
>   * MXCSR and XCR definitions:
>   */
>
> +static inline void ldmxcsr(u32 mxcsr)
> +{
> +       asm volatile("ldmxcsr %0" :: "m" (mxcsr));
> +}
> +
>  extern unsigned int mxcsr_feature_mask;
>
>  #define XCR_XFEATURE_ENABLED_MASK      0x00000000
> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
> index 06c818967bb6..f398fedc590a 100644
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -101,6 +101,9 @@ void kernel_fpu_begin(void)
>                 copy_fpregs_to_fpstate(&current->thread.fpu);
>         }
>         __cpu_invalidate_fpregs_state();
> +
> +       if (boot_cpu_has(X86_FEATURE_XMM))
> +               ldmxcsr(MXCSR_DEFAULT);
>  }
>  EXPORT_SYMBOL_GPL(kernel_fpu_begin);
>
> --
> 2.21.0
>
>
> --
> Regards/Gruss,
>     Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette



-- 
Andy Lutomirski
AMA Capital Management, LLC

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ