Commit bf184b49 authored by hanliyang's avatar hanliyang
Browse files

KVM: SVM: CSV: Fix the vm_size even if CSV3 feature is unsupported on Hygon CPUs

hygon inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBGDLQ


CVE: NA

---------------------------

Assume the userspace request CSV3's KVM ioctl interface on Hygon CPUs
before C86-4G, the vm_size if as value sizeof(struct kvm_svm), and
functions for the CSV3's KVM ioctl interface try to check whether the
guest is a CSV3 guest by access the structure as below:

  struct kvm_csv_info {
  	......
  	bool csv3_active;
  	......
  };

  struct kvm_svm_csv {
  	struct kvm_svm kvm_svm;
  	struct kvm_csv_info csv_info;
  };

But the csv_info field of struct kvm_svm_csv will not be allocated, the
functions for the CSV3's KVM ioctl interface will not get value of
csv3_active field of struct kvm_csv_info.

Always fix the vm_size in csv_init() to address the above issue.

Fixes: a87600ec ("KVM: SVM: CSV: Add KVM_CSV3_INIT command")
Fixes: e23a88d6 ("KVM: SVM: CSV: Add KVM_CSV3_LAUNCH_ENCRYPT_DATA command")
Fixes: 3f0c982b ("KVM: SVM: CSV: Add KVM_CSV3_LAUNCH_ENCRYPT_VMCB command")
Fixes: 9080aa62 ("KVM: SVM: CSV: Manage CSV3 guest's nested page table")
Fixes: ef841260 ("KVM: SVM: CSV: Add KVM_CSV3_SEND_ENCRYPT_DATA command")
Fixes: fca88def ("KVM: SVM: CSV: Add KVM_CSV3_SEND_ENCRYPT_CONTEXT command")
Fixes: 80ab300b ("KVM: SVM: CSV: Add KVM_CSV3_RECEIVE_ENCRYPT_DATA command")
Fixes: f11dc54e ("KVM: SVM: CSV: Add KVM_CSV3_RECEIVE_ENCRYPT_CONTEXT command")
Fixes: c97c1d01 ("KVM: SVM: CSV: Add ioctl API to unpin shared pages of CSV3 guest")
Signed-off-by: default avatarhanliyang <hanliyang@hygon.cn>
parent 1e381fff
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2709,14 +2709,13 @@ void __init csv_init(struct kvm_x86_ops *ops)

	memcpy(&csv_x86_ops, ops, sizeof(struct kvm_x86_ops));

	ops->vm_size = sizeof(struct kvm_svm_csv);
	ops->mem_enc_ioctl = csv_mem_enc_ioctl;
	ops->vm_attestation = csv_vm_attestation;
	ops->control_pre_system_reset = csv_control_pre_system_reset;
	ops->control_post_system_reset = csv_control_post_system_reset;

	if (boot_cpu_has(X86_FEATURE_SEV_ES) && boot_cpu_has(X86_FEATURE_CSV3)) {
		ops->vm_size = sizeof(struct kvm_svm_csv);

		ops->vm_destroy = csv_vm_destroy;
		ops->handle_exit = csv_handle_exit;
		ops->guest_memory_reclaimed = csv_guest_memory_reclaimed;