[patch V2 00/14] x86/fpu: Mop up XSAVES and related damage

From: Thomas Gleixner
Date: Sat Jun 05 2021 - 20:32:39 EST


syszbot reported a warnon for XRSTOR raising #GP:

https://lore.kernel.org/r/0000000000004c453905c30f8334@xxxxxxxxxx

with a syzcaller reproducer and a conclusive bisect result. It took a
while to destill a simple C reproducer out of it which allowed to pin point
the root cause: The recent addition of supervisor XSTATEs broke the signal
restore path for the case where the signal handler wreckaged the XSTATE on
stack because it does not sanitize the XSTATE header which causes a
subsequent XRSTOR to fail and #GP.

The following series addresses the problem and fixes related issues which
were found while inspecting the related changes.

V1 of this can be found here:

https://lore.kernel.org/r/20210602095543.149814064@xxxxxxxxxxxxx

Changes vs. V1:

- Address review comments

- Fix the reported fallout (mostly PKRU and PTRACE). The test cases pass
now.

- Address the broken init_fpstate fiddling which was found by deeper
inspection of the PKRU/XSTATE related code.

Thanks,

tglx
---

P.S: I picked up Dave's PKRU series from

https://lore.kernel.org/r/20210603230803.31660AFE@xxxxxxxxxxxxxxxxxx

and adopted it to this pile. The result is here:

https://tglx.de/~tglx/patches-fpu-pkru.tar

There are some fixes at the end which I did no fold back yet and the glibc
PKRU test case with all that applied still fails with:

../sysdeps/unix/sysv/linux/tst-pkey.c:377: numeric comparison failure
left: 1 (0x1); from: result->access_rights[i]
right: 0 (0x0); from: 0
../sysdeps/unix/sysv/linux/tst-pkey.c:382: numeric comparison failure
left: 1 (0x1); from: result2->access_rights[i]
right: 0 (0x0); from: 0
error: 2 test failures

Too tired to analyze that right now, but I wanted to share the work.

---
arch/x86/include/asm/fpu/internal.h | 17 --
arch/x86/include/asm/fpu/xstate.h | 10 -
arch/x86/include/asm/pgtable.h | 6
arch/x86/include/asm/pkeys.h | 11 -
arch/x86/kernel/cpu/bugs.c | 3
arch/x86/kernel/cpu/common.c | 27 +---
arch/x86/kernel/fpu/core.c | 119 ++++++++++++------
arch/x86/kernel/fpu/regset.c | 45 ++----
arch/x86/kernel/fpu/signal.c | 30 +++-
arch/x86/kernel/fpu/xstate.c | 100 +++++----------
arch/x86/kernel/process.c | 14 +-
arch/x86/mm/fault.c | 2
arch/x86/mm/pkeys.c | 31 ++--
b/tools/testing/selftests/x86/corrupt_xstate_header.c | 114 +++++++++++++++++
include/linux/pkeys.h | 2
tools/testing/selftests/x86/Makefile | 3
16 files changed, 334 insertions(+), 200 deletions(-)