[v3,1/2] kvm: x86: Bounds-check argument to x86_exception_has_error_code
diff mbox series

Message ID 20181015165742.38393-1-jmattson@google.com
State New
Headers show
Series
  • [v3,1/2] kvm: x86: Bounds-check argument to x86_exception_has_error_code
Related show

Commit Message

Jim Mattson Oct. 15, 2018, 4:57 p.m. UTC
x86_exception_has_error_code should deterministically return false if
its operand is greater than 32.

Fixes: 0447378a4a793 ("kvm: vmx: Nested VM-entry prereqs for event inj.")
Cc: Marc Orr <marcorr@google.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Reviewed-by: Marc Orr <marcorr@google.com>
---
 arch/x86/kvm/x86.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Sean Christopherson Oct. 15, 2018, 5:08 p.m. UTC | #1
On Mon, Oct 15, 2018 at 09:57:41AM -0700, Jim Mattson wrote:
> x86_exception_has_error_code should deterministically return false if
> its operand is greater than 32.

LOL, I hate to be the bearer of bad news, but this should be either
"its operand is greater than 31" or "its operand is greater than or
equal to 32".  Shouldn't require a v4 though.  :)
 
> Fixes: 0447378a4a793 ("kvm: vmx: Nested VM-entry prereqs for event inj.")
> Cc: Marc Orr <marcorr@google.com>
> Cc: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Reviewed-by: Marc Orr <marcorr@google.com>

Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

> ---
>  arch/x86/kvm/x86.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 67b9568613f3..f6965f9734dc 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -116,6 +116,8 @@ static inline bool x86_exception_has_error_code(unsigned int vector)
>  			BIT(NP_VECTOR) | BIT(SS_VECTOR) | BIT(GP_VECTOR) |
>  			BIT(PF_VECTOR) | BIT(AC_VECTOR);
>  
> +	if (WARN_ON_ONCE(vector >= 32))
> +		return false;
>  	return (1U << vector) & exception_has_error_code;
>  }
>  
> -- 
> 2.19.1.331.ge82ca0e54c-goog
>

Patch
diff mbox series

diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 67b9568613f3..f6965f9734dc 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -116,6 +116,8 @@  static inline bool x86_exception_has_error_code(unsigned int vector)
 			BIT(NP_VECTOR) | BIT(SS_VECTOR) | BIT(GP_VECTOR) |
 			BIT(PF_VECTOR) | BIT(AC_VECTOR);
 
+	if (WARN_ON_ONCE(vector >= 32))
+		return false;
 	return (1U << vector) & exception_has_error_code;
 }