diff mbox series

[RFC,2/8] x86/fpu: hook up PKRU into signal user ABIs

Message ID 20210622222459.9C76B034@viggo.jf.intel.com (mailing list archive)
State New
Headers show
Series x86/pkeys: remove PKRU from kernel XSAVE buffer | expand

Commit Message

Dave Hansen June 22, 2021, 10:24 p.m. UTC
From: Dave Hansen <dave.hansen@linux.intel.com>

One nice thing about having PKRU be XSAVE-managed is that it gets naturally
exposed into the XSAVE-using ABIs.  Now that XSAVE will not be used to
manage PKRU, these ABIs need to be manually enabled to deal with PKRU.

For signals (the restore_hwregs_from_user() path), it's quite
straightforward.  restore_hwregs_from_user() will update PKRU in from
the user signal buffer.  Ensure that PKRU is shuffled into the thread
storage.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
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>
---

 b/arch/x86/kernel/fpu/signal.c |    7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff -puN arch/x86/kernel/fpu/signal.c~fpu-sig-stash-pkru arch/x86/kernel/fpu/signal.c
--- a/arch/x86/kernel/fpu/signal.c~fpu-sig-stash-pkru	2021-06-22 14:49:07.899051760 -0700
+++ b/arch/x86/kernel/fpu/signal.c	2021-06-22 14:49:07.903051760 -0700
@@ -233,6 +233,13 @@  static int restore_hwregs_from_user(void
 
 		if (!ret && unlikely(init_bv))
 			os_xrstor(&init_fpstate.xsave, init_bv);
+
+		/*
+		 * PKRU may have been modified by XRSTOR,
+		 * save the possibly updated value:
+		 */
+		current->thread.pkru = read_pkru();
+
 		return ret;
 	} else if (use_fxsr()) {
 		return fxrstor_from_user_sigframe(buf);