kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Add more protection against undefined behavior in rsvd_bits()
Date: Mon, 18 Jan 2021 18:34:19 +0100	[thread overview]
Message-ID: <947f0e1a-c8db-5c68-1e0c-abadd10d92fc@redhat.com> (raw)
In-Reply-To: <20210113204515.3473079-1-seanjc@google.com>

On 13/01/21 21:45, Sean Christopherson wrote:
> Add compile-time asserts in rsvd_bits() to guard against KVM passing in
> garbage hardcoded values, and cap the upper bound at '63' for dynamic
> values to prevent generating a mask that would overflow a u64.
> 
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   arch/x86/kvm/mmu.h | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index 581925e476d6..261be1d2032b 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -44,8 +44,15 @@
>   #define PT32_ROOT_LEVEL 2
>   #define PT32E_ROOT_LEVEL 3
>   
> -static inline u64 rsvd_bits(int s, int e)
> +static __always_inline u64 rsvd_bits(int s, int e)
>   {
> +	BUILD_BUG_ON(__builtin_constant_p(e) && __builtin_constant_p(s) && e < s);
> +
> +	if (__builtin_constant_p(e))
> +		BUILD_BUG_ON(e > 63);
> +	else
> +		e &= 63;
> +
>   	if (e < s)
>   		return 0;
>   
> 

Queued for 5.11, thanks.

Paolo


      reply	other threads:[~2021-01-18 17:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 20:45 [PATCH] KVM: x86: Add more protection against undefined behavior in rsvd_bits() Sean Christopherson
2021-01-18 17:34 ` Paolo Bonzini [this message]

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=947f0e1a-c8db-5c68-1e0c-abadd10d92fc@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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;
as well as URLs for NNTP newsgroup(s).