linux-stable/arch/x86
Chang S. Bae 6ff29642fd x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly
[ Upstream commit 471f0aa7fa ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-11-04 00:00:30 +09:00
..
boot x86/boot: Don't propagate uninitialized boot_params->cc_blob_address 2022-08-24 09:03:04 +02:00
coco x86/tdx: Handle load_unaligned_zeropad() page-cross to a shared page 2022-06-17 15:37:33 -07:00
configs xen: branch for v6.0-rc3 2022-08-27 15:38:00 -07:00
crypto crypto: x86/polyval - Fix crashes when keys are not 16-byte aligned 2022-11-04 00:00:22 +09:00
entry x86/entry: Fix entry_INT80_compat for Xen PV guests 2022-08-16 10:02:52 +02:00
events perf/x86/intel/lbr: Use setup_clear_cpu_cap() instead of clear_cpu_cap() 2022-11-04 00:00:28 +09:00
hyperv ARM: 2022-08-04 14:59:54 -07:00
ia32
include iommu/vt-d: Allow NVS regions in arch_rmrr_sanity_check() 2022-10-29 10:08:35 +02:00
kernel x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly 2022-11-04 00:00:30 +09:00
kvm KVM: x86: Add compat handler for KVM_X86_SET_MSR_FILTER 2022-10-29 10:08:30 +02:00
lib x86/uaccess: avoid check_object_size() in copy_from_user_nmi() 2022-09-26 12:14:35 -07:00
math-emu
mm x86/mm: disable instrumentations of mm/pgprot.c 2022-09-11 16:22:30 -07:00
net bpf: use bpf_prog_pack for bpf_dispatcher 2022-10-21 12:39:11 +02:00
pci x86/PCI: Revert "x86/PCI: Clip only host bridge windows for E820 regions" 2022-06-17 14:24:14 -05:00
platform Bitmap patches for v6.0-rc1 2022-08-07 17:52:35 -07:00
power
purgatory x86/purgatory: Omit use of bin2c 2022-07-25 10:32:32 +02:00
ras
realmode Intel Trust Domain Extensions 2022-05-23 17:51:12 -07:00
tools
um arch: um: Mark the stack non-executable to fix a binutils warning 2022-09-21 09:11:42 +02:00
video
virt/vmx/tdx
xen x86/entry: Work around Clang __bdos() bug 2022-10-21 12:39:04 +02:00
.gitignore x86/purgatory: Omit use of bin2c 2022-07-25 10:32:32 +02:00
Kbuild
Kconfig x86/Kconfig: Drop check for -mabi=ms for CONFIG_EFI_STUB 2022-10-29 10:08:31 +02:00
Kconfig.assembler
Kconfig.cpu
Kconfig.debug arch: make TRACE_IRQFLAGS_NMI_SUPPORT generic 2022-06-23 15:39:21 +01:00
Makefile asm goto: eradicate CC_HAS_ASM_GOTO 2022-08-21 10:06:28 -07:00
Makefile.um
Makefile_32.cpu