KVM: x86: Fix pkru save/restore when guest CR4.PKE=0, move it to x86.c
authorBabu Moger <babu.moger@amd.com>
Tue, 12 May 2020 23:59:06 +0000 (18:59 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 May 2020 15:46:39 +0000 (17:46 +0200)
commit99e392a4979b97562215596acf7f4eff7ec87ae6
tree83cf32499447b5512466b563e4a568a7417dd056
parent1c3d707d7d12b9f7dc845bcc046451aec25c98ef
KVM: x86: Fix pkru save/restore when guest CR4.PKE=0, move it to x86.c

commit 37486135d3a7b03acc7755b63627a130437f066a upstream.

Though rdpkru and wrpkru are contingent upon CR4.PKE, the PKRU
resource isn't. It can be read with XSAVE and written with XRSTOR.
So, if we don't set the guest PKRU value here(kvm_load_guest_xsave_state),
the guest can read the host value.

In case of kvm_load_host_xsave_state, guest with CR4.PKE clear could
potentially use XRSTOR to change the host PKRU value.

While at it, move pkru state save/restore to common code and the
host_pkru field to kvm_vcpu_arch.  This will let SVM support protection keys.

Cc: stable@vger.kernel.org
Reported-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Message-Id: <158932794619.44260.14508381096663848853.stgit@naples-babu.amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c