Commit dc86f610 authored by Mathias Krause's avatar Mathias Krause Committed by hanliyang
Browse files

KVM: x86: Fix KVM_GET_MSRS stack info leak

mainline inclusion
from mainline-v6.8-rc5
commit 3376ca3f1a2075eaa23c5576c47d04d7e8a4adda
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I98WPG

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3376ca3f1a2075eaa23c5576c47d04d7e8a4adda



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

Commit 6abe9c13 ("KVM: X86: Move ignore_msrs handling upper the
stack") changed the 'ignore_msrs' handling, including sanitizing return
values to the caller. This was fine until commit 12bc2132 ("KVM:
X86: Do the same ignore_msrs check for feature msrs") which allowed
non-existing feature MSRs to be ignored, i.e. to not generate an error
on the ioctl() level. It even tried to preserve the sanitization of the
return value. However, the logic is flawed, as '*data' will be
overwritten again with the uninitialized stack value of msr.data.

Fix this by simplifying the logic and always initializing msr.data,
vanishing the need for an additional error exit path.

Fixes: 12bc2132 ("KVM: X86: Do the same ignore_msrs check for feature msrs")
Signed-off-by: default avatarMathias Krause <minipli@grsecurity.net>
Reviewed-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20240203124522.592778-2-minipli@grsecurity.net


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 31348363
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -1755,22 +1755,17 @@ static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
	struct kvm_msr_entry msr;
	int r;

	/* Unconditionally clear the output for simplicity */
	msr.data = 0;
	msr.index = index;
	r = kvm_get_msr_feature(&msr);

	if (r == KVM_MSR_RET_INVALID) {
		/* Unconditionally clear the output for simplicity */
		*data = 0;
		if (kvm_msr_ignored_check(index, 0, false))
	if (r == KVM_MSR_RET_INVALID && kvm_msr_ignored_check(index, 0, false))
		r = 0;
	}

	if (r)
		return r;

	*data = msr.data;

	return 0;
	return r;
}

static bool __kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer)