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 <andrew.coop...@citrix.com>
---
CC: Jan Beulich <jbeul...@suse.com>
---
 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 7b9af1b..076fab3 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.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to