linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] x86/pkeys: PKRU manipulation bug fixes and cleanups
@ 2021-05-27 23:51 Dave Hansen
  2021-05-27 23:51 ` [PATCH 1/5] x86/pkeys: move read_pkru() and write_pkru() Dave Hansen
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Dave Hansen @ 2021-05-27 23:51 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, Dave Hansen, tglx, mingo, bp, x86, luto, shuah,
	babu.moger, dave.kleikamp, linuxram, bauerman

Andy Lutomirski recently noted a probable bug in write_pkru(), but
it was unclear if it was user-visible.  A recent bug report in
related code[1] forced me to take a look.

Basically, manipulation of XSAVE state is too unstructured.
get_xsave_addr() gives callers the impression they can read and
write XSAVE state when there are a lot of pitfalls, like updates
to xstate.features bits.

As a result, more than one call site screws up the modification
of PKRU in the XSAVE buffer.  This series fixes that problem up
and also hopefully carves out a less error-prone path that can
be reused for other XSAVE features.

This series:
 * Moves the PKRU manipulation to a more appropriate location,
   away from the page table code
 * Wraps get_xsave_addr() with more structured, less error-prone
   interfaces.
 * Conditionally hides a pkey debugfs file, eliminating the need
   for new runtime checks to work with the new interface.
 * Add a selftest to make it more likely to catch bugs like this
   in the future.  This improved selftest catches this issue on
   Intel CPUs.  Without the improvement, it only triggers on AMD.

This has been lightly tested so far.  It probably needs a
tested-by from at least the AMD folks before anyone applies it.

1. https://lore.kernel.org/linux-kselftest/b2e0324a-9125-bb34-9e76-81817df27c48@amd.com/

--

 arch/x86/include/asm/fpu/internal.h          |    8 -
 arch/x86/include/asm/fpu/xstate.h            |  130 +++++++++++++++++++++++++++
 arch/x86/include/asm/pgtable.h               |   29 ------
 arch/x86/include/asm/processor.h             |    7 +
 arch/x86/kernel/cpu/common.c                 |    6 -
 arch/x86/kernel/fpu/xstate.c                 |    2 
 arch/x86/kernel/process_64.c                 |    1 
 arch/x86/kvm/svm/sev.c                       |    1 
 arch/x86/kvm/x86.c                           |    1 
 arch/x86/mm/pkeys.c                          |   13 +-
 tools/testing/selftests/vm/Makefile          |    4 
 tools/testing/selftests/vm/pkey-x86.h        |    1 
 tools/testing/selftests/vm/protection_keys.c |   73 +++++++++++++++
 13 files changed, 227 insertions(+), 49 deletions(-)

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Babu Moger <babu.moger@amd.com>
Cc: Dave Kleikamp <dave.kleikamp@oracle.com>
Cc: Ram Pai <linuxram@us.ibm.com>
Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-06-01 22:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 23:51 [PATCH 0/5] x86/pkeys: PKRU manipulation bug fixes and cleanups Dave Hansen
2021-05-27 23:51 ` [PATCH 1/5] x86/pkeys: move read_pkru() and write_pkru() Dave Hansen
2021-05-27 23:51 ` [PATCH 2/5] x86/pkeys: rename write_pkru() Dave Hansen
2021-05-27 23:51 ` [PATCH 3/5] x86/pkeys: skip 'init_pkru' debugfs file creation when pkeys not supported Dave Hansen
2021-05-27 23:51 ` [PATCH 4/5] x86/pkeys: replace PKRU modification infrastructure Dave Hansen
2021-05-28  1:17   ` Mika Penttilä
2021-05-28 17:00   ` Dave Kleikamp
2021-06-01 21:54   ` Babu Moger
2021-06-01 22:43     ` Dave Kleikamp
2021-06-01 22:49       ` Dave Hansen
2021-05-27 23:51 ` [PATCH 5/5] selftests/vm/pkeys: exercise x86 XSAVE init state Dave Hansen
2021-05-28 15:32 ` [PATCH 0/5] x86/pkeys: PKRU manipulation bug fixes and cleanups Thomas Gleixner
2021-05-28 16:11   ` Dave Hansen
2021-05-28 17:13     ` Andy Lutomirski
2021-05-28 17:19       ` Thomas Gleixner
2021-05-28 17:19     ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).