From b61e6af228e890acc341ae21a15b758232899e1b Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Thu, 3 May 2018 12:08:52 +0800 Subject: [PATCH] hv: cpuid: don't reference the crossed array We should consider the boundary condition although we didn't access it. Signed-off-by: Li, Fei1 --- hypervisor/arch/x86/cpuid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c index 1167c4465..ad9e39458 100644 --- a/hypervisor/arch/x86/cpuid.c +++ b/hypervisor/arch/x86/cpuid.c @@ -91,12 +91,13 @@ static inline int set_vcpuid_entry(struct vm *vm, struct vcpuid_entry *tmp; size_t entry_size = sizeof(struct vcpuid_entry); - tmp = &vm->vcpuid_entries[vm->vcpuid_entry_nr++]; - if (vm->vcpuid_entry_nr > MAX_VM_VCPUID_ENTRIES) { + if (vm->vcpuid_entry_nr == MAX_VM_VCPUID_ENTRIES) { pr_err("%s, vcpuid entry over MAX_VM_VCPUID_ENTRIES(%d)\n", __func__, MAX_VM_VCPUID_ENTRIES); return -ENOMEM; } + + tmp = &vm->vcpuid_entries[vm->vcpuid_entry_nr++]; memcpy_s(tmp, entry_size, entry, entry_size); return 0; }