Re: [patch 0/8] x86/fpu: Mop up XSAVES and related damage

From: Yu, Yu-cheng
Date: Wed Jun 02 2021 - 17:28:05 EST


On 6/2/2021 2:55 AM, Thomas Gleixner wrote:
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.

Thanks to Andy and Dave for working on this with me!

Thanks,

tglx
---
arch/x86/include/asm/fpu/xstate.h | 4
arch/x86/kernel/fpu/core.c | 62 ++++++---
arch/x86/kernel/fpu/regset.c | 43 ++----
arch/x86/kernel/fpu/signal.c | 30 +++-
arch/x86/kernel/fpu/xstate.c | 95 +++++----------
b/tools/testing/selftests/x86/corrupt_xstate_header.c | 114 ++++++++++++++++++
tools/testing/selftests/x86/Makefile | 3
7 files changed, 234 insertions(+), 117 deletions(-)


With the series applied, glibc pkey test fails sometimes. I will try to find out the cause.

The test:

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/tst-pkey.c

The output:

error: ../sysdeps/unix/sysv/linux/tst-pkey.c:161: not true: !check_page_access (i, false)
error: ../sysdeps/unix/sysv/linux/tst-pkey.c:162: not true: !check_page_access (i, true)
error: ../sysdeps/unix/sysv/linux/tst-pkey.c:161: not true: !check_page_access (i, false)
error: ../sysdeps/unix/sysv/linux/tst-pkey.c:162: not true: !check_page_access (i, true)
error: ../sysdeps/unix/sysv/linux/tst-pkey.c:161: not true: !check_page_access (i, false)
error: ../sysdeps/unix/sysv/linux/tst-pkey.c:162: not true: !check_page_access (i, true)
../sysdeps/unix/sysv/linux/tst-pkey.c:238: numeric comparison failure
left: 0 (0x0); from: result->access_rights[i]
right: 1 (0x1); from: PKEY_DISABLE_ACCESS
../sysdeps/unix/sysv/linux/tst-pkey.c:238: numeric comparison failure
left: 0 (0x0); from: result->access_rights[i]
right: 1 (0x1); from: PKEY_DISABLE_ACCESS
../sysdeps/unix/sysv/linux/tst-pkey.c:238: numeric comparison failure
left: 0 (0x0); from: result->access_rights[i]
right: 1 (0x1); from: PKEY_DISABLE_ACCESS
../sysdeps/unix/sysv/linux/tst-pkey.c:242: numeric comparison failure
left: 0 (0x0); from: result->access_rights[i]
right: 1 (0x1); from: PKEY_DISABLE_ACCESS
../sysdeps/unix/sysv/linux/tst-pkey.c:242: numeric comparison failure
left: 0 (0x0); from: result->access_rights[i]
right: 1 (0x1); from: PKEY_DISABLE_ACCESS
../sysdeps/unix/sysv/linux/tst-pkey.c:242: numeric comparison failure
left: 0 (0x0); from: result->access_rights[i]
right: 1 (0x1); from: PKEY_DISABLE_ACCESS
error: 12 test failures