public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Mathias Krause <minipli@grsecurity.net>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 1/3] KVM: x86: Fix KVM_GET_MSRS stack info leak
Date: Sun, 4 Feb 2024 09:28:07 +0800	[thread overview]
Message-ID: <7b7dacc4-b956-428f-b033-bf75d70de169@intel.com> (raw)
In-Reply-To: <20240203124522.592778-2-minipli@grsecurity.net>

On 2/3/2024 8:45 PM, Mathias Krause wrote:
> Commit 6abe9c1386e5 ("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 12bc2132b15e ("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: 12bc2132b15e ("KVM: X86: Do the same ignore_msrs check for feature msrs")
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

> ---
>   arch/x86/kvm/x86.c | 15 +++++----------
>   1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 363b1c080205..13ec948f3241 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1704,22 +1704,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))
> -			r = 0;
> -	}
> -
> -	if (r)
> -		return r;
> +	if (r == KVM_MSR_RET_INVALID && kvm_msr_ignored_check(index, 0, false))
> +		r = 0;
>   
>   	*data = msr.data;
>   
> -	return 0;
> +	return r;
>   }
>   
>   static bool __kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer)


  reply	other threads:[~2024-02-04  1:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-03 12:45 [PATCH 0/3] KVM: x86 - misc fixes Mathias Krause
2024-02-03 12:45 ` [PATCH 1/3] KVM: x86: Fix KVM_GET_MSRS stack info leak Mathias Krause
2024-02-04  1:28   ` Xiaoyao Li [this message]
2024-02-05 18:42   ` Sean Christopherson
2024-02-06 17:52     ` Mathias Krause
2024-02-03 12:45 ` [PATCH 2/3] KVM: x86: Simplify kvm_vcpu_ioctl_x86_get_debugregs() Mathias Krause
2024-02-04  1:05   ` Xiaoyao Li
2024-02-05 19:53   ` Sean Christopherson
2024-02-06 18:15     ` Mathias Krause
2024-02-06 18:24       ` Sean Christopherson
2024-02-06 18:30         ` Mathias Krause
2024-02-06 18:32     ` Mathias Krause
2024-02-03 12:45 ` [PATCH 3/3] KVM: x86: Fix broken debugregs ABI for 32 bit kernels Mathias Krause
2024-02-05 18:46   ` Sean Christopherson
2024-02-06 18:23     ` Mathias Krause
2024-02-05 19:56 ` [PATCH 0/3] KVM: x86 - misc fixes Sean Christopherson
2024-02-06 18:24   ` Mathias Krause
2024-02-06 18:52 ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b7dacc4-b956-428f-b033-bf75d70de169@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=minipli@grsecurity.net \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox