lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210622222504.E8874E6D@viggo.jf.intel.com>
Date:   Tue, 22 Jun 2021 15:25:04 -0700
From:   Dave Hansen <dave.hansen@...ux.intel.com>
To:     linux-mm@...ck.org
Cc:     linux-kernel@...r.kernel.org,
        Dave Hansen <dave.hansen@...ux.intel.com>, tglx@...utronix.de,
        mingo@...hat.com, bp@...en8.de, x86@...nel.org, luto@...nel.org
Subject: [RFC][PATCH 5/8] x86/fpu: XSAVE buffer access routine rename


From: Dave Hansen <dave.hansen@...ux.intel.com>

get_xsave_addr() sounds like it works on generic XSAVE buffers.  It
does not.  It only works on kernel XSAVE buffers which are part of the
FPU fpstate.

Give it a better name: get_fpstate_addr().  Also add warnings to it in
case non-fpstate features are requested (NULL should be returned for
these, but WARN() anyway).

Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Borislav Petkov <bp@...en8.de>
Cc: x86@...nel.org
Cc: Andy Lutomirski <luto@...nel.org>
---

 b/arch/x86/include/asm/fpu/xstate.h |    2 +-
 b/arch/x86/kernel/fpu/xstate.c      |   11 ++++++-----
 b/arch/x86/kvm/x86.c                |    8 ++++----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff -puN arch/x86/include/asm/fpu/xstate.h~get_xsave_addr-warning arch/x86/include/asm/fpu/xstate.h
--- a/arch/x86/include/asm/fpu/xstate.h~get_xsave_addr-warning	2021-06-22 14:49:11.268051751 -0700
+++ b/arch/x86/include/asm/fpu/xstate.h	2021-06-22 14:49:11.279051751 -0700
@@ -134,7 +134,7 @@ extern u64 xstate_fx_sw_bytes[USER_XSTAT
 extern void __init update_regset_xstate_info(unsigned int size,
 					     u64 xstate_mask);
 
-void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
+void *get_fpstate_addr(struct xregs_state *xsave, int xfeature_nr);
 int xfeature_size(int xfeature_nr);
 int copy_uabi_from_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf);
 int copy_sigframe_from_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf);
diff -puN arch/x86/kernel/fpu/xstate.c~get_xsave_addr-warning arch/x86/kernel/fpu/xstate.c
--- a/arch/x86/kernel/fpu/xstate.c~get_xsave_addr-warning	2021-06-22 14:49:11.270051751 -0700
+++ b/arch/x86/kernel/fpu/xstate.c	2021-06-22 14:49:11.279051751 -0700
@@ -878,7 +878,8 @@ static void *__raw_xsave_addr(struct xre
 }
 /*
  * Given the xsave area and a state inside, this function returns the
- * address of the state.
+ * address of the state.  This only works on kernel fpstate, not on
+ * generic buffers created with XSAVE*.
  *
  * This is the API that is called to get xstate address in either
  * standard format or compacted format of xsave area.
@@ -894,7 +895,7 @@ static void *__raw_xsave_addr(struct xre
  *	address of the state in the xsave area, or NULL if the
  *	field is not present in the xsave buffer.
  */
-void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
+void *get_fpstate_addr(struct xregs_state *xsave, int xfeature_nr)
 {
 	/*
 	 * Do we even *have* xsave state?
@@ -906,8 +907,8 @@ void *get_xsave_addr(struct xregs_state
 	 * We should not ever be requesting features that we
 	 * have not enabled.
 	 */
-	WARN_ONCE(!(xfeatures_mask_all & BIT_ULL(xfeature_nr)),
-		  "get of unsupported state");
+	WARN_ONCE(!(xfeatures_mask_fpstate() & BIT_ULL(xfeature_nr)),
+		  "get of unsupported fpstate");
 	/*
 	 * This assumes the last 'xsave*' instruction to
 	 * have requested that 'xfeature_nr' be saved.
@@ -924,7 +925,7 @@ void *get_xsave_addr(struct xregs_state
 
 	return __raw_xsave_addr(xsave, xfeature_nr);
 }
-EXPORT_SYMBOL_GPL(get_xsave_addr);
+EXPORT_SYMBOL_GPL(get_fpstate_addr);
 
 #ifdef CONFIG_ARCH_HAS_PKEYS
 
diff -puN arch/x86/kvm/x86.c~get_xsave_addr-warning arch/x86/kvm/x86.c
--- a/arch/x86/kvm/x86.c~get_xsave_addr-warning	2021-06-22 14:49:11.274051751 -0700
+++ b/arch/x86/kvm/x86.c	2021-06-22 14:49:11.284051751 -0700
@@ -4602,7 +4602,7 @@ static void fill_xsave(u8 *dest, struct
 			memcpy(dest + offset, &vcpu->arch.pkru,
 			       sizeof(vcpu->arch.pkru));
 		} else {
-			src = get_xsave_addr(xsave, xfeature_nr);
+			src = get_fpstate_addr(xsave, xfeature_nr);
 			if (src)
 				memcpy(dest + offset, src, size);
 		}
@@ -4645,7 +4645,7 @@ static void load_xsave(struct kvm_vcpu *
 			memcpy(&vcpu->arch.pkru, src + offset,
 			       sizeof(vcpu->arch.pkru));
 		} else {
-			void *dest = get_xsave_addr(xsave, xfeature_nr);
+			void *dest = get_fpstate_addr(xsave, xfeature_nr);
 
 			if (dest)
 				memcpy(dest, src + offset, size);
@@ -10479,11 +10479,11 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcp
 		 */
 		if (init_event)
 			kvm_put_guest_fpu(vcpu);
-		mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave,
+		mpx_state_buffer = get_fpstate_addr(&vcpu->arch.guest_fpu->state.xsave,
 					XFEATURE_BNDREGS);
 		if (mpx_state_buffer)
 			memset(mpx_state_buffer, 0, sizeof(struct mpx_bndreg_state));
-		mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave,
+		mpx_state_buffer = get_fpstate_addr(&vcpu->arch.guest_fpu->state.xsave,
 					XFEATURE_BNDCSR);
 		if (mpx_state_buffer)
 			memset(mpx_state_buffer, 0, sizeof(struct mpx_bndcsr));
_

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ