From 2073a26f8920ac9c26323122308873d0bcc84be1 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Tue, 17 Jan 2017 11:44:29 +0000 Subject: [PATCH] x86/cpuid: Remove BUG_ON() condition from guest_cpuid() Include a min() against the appropriate ARRAY_SIZE(), and ASSERT() that max_subleaf is within ARRAY_SIZE(). This is more robust to unexpected problems in a release build of Xen. Signed-off-by: Andrew Cooper Reviewed-by: Doug Goldstein Reviewed-by: Jan Beulich --- xen/arch/x86/cpuid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 7b9af1b9cf..076fab30ac 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -856,10 +856,11 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf, switch ( leaf ) { case 0x7: - if ( subleaf > p->feat.max_subleaf ) + ASSERT(p->feat.max_subleaf < ARRAY_SIZE(p->feat.raw)); + if ( subleaf > min_t(uint32_t, p->feat.max_subleaf, + ARRAY_SIZE(p->feat.raw) - 1) ) return; - BUG_ON(subleaf >= ARRAY_SIZE(p->feat.raw)); *res = p->feat.raw[subleaf]; break; -- 2.30.2