hv:Check pcpu number to avoid overflow

-- check pcpu number in several functions
   to avoid overflow
-- rename pcpu_id to pcpu_num in local_parse_madt

Tracked-On: #861
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Li, Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Mingqiang Chi 2018-10-24 13:32:13 +08:00 committed by Xie, Nanlin
parent 672583a091
commit 3eb45b9bf6
3 changed files with 8 additions and 14 deletions

View File

@ -308,7 +308,7 @@ static void init_percpu_data_area(void)
alloc_phy_cpu_data(pcpu_num); alloc_phy_cpu_data(pcpu_num);
for (i = 0U; i < pcpu_num; i++) { for (i = 0U; (i < pcpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) {
per_cpu(lapic_id, i) = lapic_id_array[i]; per_cpu(lapic_id, i) = lapic_id_array[i];
} }
} }
@ -592,7 +592,7 @@ static uint16_t get_cpu_id_from_lapic_id(uint32_t lapic_id)
{ {
uint16_t i; uint16_t i;
for (i = 0U; i < phys_cpu_num; i++) { for (i = 0U; (i < phys_cpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) {
if (per_cpu(lapic_id, i) == lapic_id) { if (per_cpu(lapic_id, i) == lapic_id) {
return i; return i;
} }

View File

@ -229,7 +229,7 @@ static void *get_acpi_tbl(const char *sig)
static uint16_t static uint16_t
local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM]) local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
{ {
uint16_t pcpu_id = 0U; uint16_t pcpu_num = 0U;
struct acpi_madt_local_apic *processor; struct acpi_madt_local_apic *processor;
struct acpi_table_madt *madt_ptr; struct acpi_table_madt *madt_ptr;
void *first; void *first;
@ -249,16 +249,10 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) { if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) {
processor = (struct acpi_madt_local_apic *)entry; processor = (struct acpi_madt_local_apic *)entry;
if ((processor->lapic_flags & ACPI_MADT_ENABLED) != 0U) { if ((processor->lapic_flags & ACPI_MADT_ENABLED) != 0U) {
lapic_id_array[pcpu_id] = processor->id; if (pcpu_num < CONFIG_MAX_PCPU_NUM) {
pcpu_id++; lapic_id_array[pcpu_num] = processor->id;
/*
* set the pcpu_num as 0U to indicate the
* potential overflow
*/
if (pcpu_id >= CONFIG_MAX_PCPU_NUM) {
pcpu_id = 0U;
break;
} }
pcpu_num++;
} }
} }
@ -266,7 +260,7 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
(((uint64_t)entry) + entry->length); (((uint64_t)entry) + entry->length);
} }
return pcpu_id; return pcpu_num;
} }
/* The lapic_id info gotten from madt will be returned in lapic_id_array */ /* The lapic_id info gotten from madt will be returned in lapic_id_array */

View File

@ -77,7 +77,7 @@ void init_logmsg(uint32_t flags)
logmsg.seq = 0; logmsg.seq = 0;
/* allocate sbuf for log before sos booting */ /* allocate sbuf for log before sos booting */
for (pcpu_id = 0U; pcpu_id < phys_cpu_num; pcpu_id++) { for (pcpu_id = 0U; (pcpu_id < phys_cpu_num) && (pcpu_id < CONFIG_MAX_PCPU_NUM); pcpu_id++) {
alloc_earlylog_sbuf(pcpu_id); alloc_earlylog_sbuf(pcpu_id);
} }
} }