Message ID | 20181015164124.225764-1-jmattson@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2,1/2] kvm: x86: Bounds-check argument to x86_exception_has_error_code | expand |
On Mon, Oct 15, 2018 at 09:41:23AM -0700, Jim Mattson wrote: > 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 | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 67b9568613f3..152b20d06a48 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -116,7 +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); > > - return (1U << vector) & exception_has_error_code; > + WARN_ON_ONCE(vector >= 32); > + return vector < 32 && (1U << vector) & exception_has_error_code; WARN_ON_ONCE always returns the condition, even after warning. I.e.: if (WARN_ON_ONCE(vector >= 32)) return false; return (1U << vector) & exception_has_error_code; > } > > static inline bool mmu_is_nested(struct kvm_vcpu *vcpu) > -- > 2.19.1.331.ge82ca0e54c-goog >
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 67b9568613f3..152b20d06a48 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -116,7 +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); - return (1U << vector) & exception_has_error_code; + WARN_ON_ONCE(vector >= 32); + return vector < 32 && (1U << vector) & exception_has_error_code; } static inline bool mmu_is_nested(struct kvm_vcpu *vcpu)