[v4] kvm: x86: Bounds-check argument to x86_exception_has_error_code
diff mbox series

Message ID 20181023185441.68690-1-jmattson@google.com
State New
Headers show
Series
  • [v4] kvm: x86: Bounds-check argument to x86_exception_has_error_code
Related show

Commit Message

Jim Mattson Oct. 23, 2018, 6:54 p.m. UTC
Only architecturally defined exceptions in the range [0, 31] may have
error codes. The caller to x86_exception_has_error_code() should
ensure that the vector operand is in the range [0, 31].

Note that the one existing call site already does the right thing.

Cc: Marc Orr <marcorr@google.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/x86.h | 2 ++
 1 file changed, 2 insertions(+)

Patch
diff mbox series

diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 224cd0a47568..88dae0225a92 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_ONCE(vector >= 32, "vector 0x%x too large", vector))
+		return false;
 	return (1U << vector) & exception_has_error_code;
 }