linux-stable/arch/x86/kernel/fpu
Chang S. Bae 471f0aa7fa x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly
When an extended state component is not present in fpstate, but in init
state, the function copies from init_fpstate via copy_feature().

But, dynamic states are not present in init_fpstate because of all-zeros
init states. Then retrieving them from init_fpstate will explode like this:

 BUG: kernel NULL pointer dereference, address: 0000000000000000
 ...
 RIP: 0010:memcpy_erms+0x6/0x10
  ? __copy_xstate_to_uabi_buf+0x381/0x870
  fpu_copy_guest_fpstate_to_uabi+0x28/0x80
  kvm_arch_vcpu_ioctl+0x14c/0x1460 [kvm]
  ? __this_cpu_preempt_check+0x13/0x20
  ? vmx_vcpu_put+0x2e/0x260 [kvm_intel]
  kvm_vcpu_ioctl+0xea/0x6b0 [kvm]
  ? kvm_vcpu_ioctl+0xea/0x6b0 [kvm]
  ? __fget_light+0xd4/0x130
  __x64_sys_ioctl+0xe3/0x910
  ? debug_smp_processor_id+0x17/0x20
  ? fpregs_assert_state_consistent+0x27/0x50
  do_syscall_64+0x3f/0x90
  entry_SYSCALL_64_after_hwframe+0x63/0xcd

Adjust the 'mask' to zero out the userspace buffer for the features that
are not available both from fpstate and from init_fpstate.

The dynamic features depend on the compacted XSAVE format. Ensure it is
enabled before reading XCOMP_BV in init_fpstate.

Fixes: 2308ee57d9 ("x86/fpu/amx: Enable the AMX feature in 64-bit mode")
Reported-by: Yuan Yao <yuan.yao@intel.com>
Suggested-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Tested-by: Yuan Yao <yuan.yao@intel.com>
Link: https://lore.kernel.org/lkml/BYAPR11MB3717EDEF2351C958F2C86EED95259@BYAPR11MB3717.namprd11.prod.outlook.com/
Link: https://lkml.kernel.org/r/20221021185844.13472-1-chang.seok.bae@intel.com
2022-10-21 15:22:09 -07:00
..
bugs.c x86/fpu: Replace the includes of fpu/internal.h 2021-10-20 15:27:29 +02:00
context.h x86/fpu: Update XFD state where required 2021-10-26 10:53:02 +02:00
core.c x86/fpu: Add a helper to prepare AMX state for low-power CPU idle 2022-07-19 18:46:15 +02:00
init.c x86/fpu: Configure init_fpstate attributes orderly 2022-10-17 15:44:25 +02:00
internal.h x86/fpu/signal: Prepare for variable sigframe length 2021-10-26 10:18:09 +02:00
legacy.h x86/fpu: Remove .fixup usage 2021-12-11 09:09:48 +01:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
regset.c x86/ptrace: Fix xfpregs_set()'s incorrect xmm clearing 2022-02-18 11:23:21 +01:00
signal.c x86/fpu/signal: Initialize sw_bytes in save_xstate_epilog() 2021-11-30 15:13:47 -08:00
xstate.c x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly 2022-10-21 15:22:09 -07:00
xstate.h x86/fpu/xsave: Support XSAVEC in the kernel 2022-04-25 15:05:37 +02:00