Fixes and improvements for FPU handling on x86:

  - Prevent sigaltstack out of bounds writes. The kernel unconditionally
    writes the FPU state to the alternate stack without checking whether
    the stack is large enough to accomodate it.

    Check the alternate stack size before doing so and in case it's too
    small force a SIGSEGV instead of silently corrupting user space data.

  - MINSIGSTKZ and SIGSTKSZ are constants in signal.h and have never been
    updated despite the fact that the FPU state which is stored on the
    signal stack has grown over time which causes trouble in the field
    when AVX512 is available on a CPU. The kernel does not expose the
    minimum requirements for the alternate stack size depending on the
    available and enabled CPU features.

    ARM already added an aux vector AT_MINSIGSTKSZ for the same reason.
    Add it to x86 as well

  - A major cleanup of the x86 FPU code. The recent discoveries of XSTATE
    related issues unearthed quite some inconsistencies, duplicated code
    and other issues.

    The fine granular overhaul addresses this, makes the code more robust
    and maintainable, which allows to integrate upcoming XSTATE related
    features in sane ways.
x86/fpu/xstate: Clear xstate header in copy_xstate_to_uabi_buf() again

The change which made copy_xstate_to_uabi_buf() usable for
[x]fpregs_get() removed the zeroing of the header which means the
header, which is copied to user space later, contains except for the
xfeatures member, random stack content.

Add the memset() back to zero it before usage.

Fixes: eb6f51723f03 ("x86/fpu: Make copy_xstate_to_kernel() usable for [x]fpregs_get()")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/875yy3wb8h.ffs@nanos.tec.linutronix.de
1 file changed