Skip to content

Commit f991d17

Browse files
yonghuahwenlingz
authored andcommitted
hv: fix possible buffer overflow in vlapic.c
Possible buffer overflow will happen in vlapic_set_tmr() and vlapic_update_ppr(),this path is to fix them. Tracked-On: #1252 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 2c13ac7 commit f991d17

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ vlapic_set_tmr(struct acrn_vlapic *vlapic, uint32_t vector, bool level)
462462
lapic = &(vlapic->apic_page);
463463
tmrptr = &lapic->tmr[0];
464464
if (level) {
465-
if (!bitmap32_test_and_set_lock((uint16_t)(vector & 0x1fU), &tmrptr[vector >> 5U].v)) {
465+
if (!bitmap32_test_and_set_lock((uint16_t)(vector & 0x1fU), &tmrptr[(vector & 0xffU) >> 5U].v)) {
466466
vcpu_set_eoi_exit_bitmap(vlapic->vcpu, vector);
467467
}
468468
} else {
469-
if (bitmap32_test_and_clear_lock((uint16_t)(vector & 0x1fU), &tmrptr[vector >> 5U].v)) {
469+
if (bitmap32_test_and_clear_lock((uint16_t)(vector & 0x1fU), &tmrptr[(vector & 0xffU) >> 5U].v)) {
470470
vcpu_clear_eoi_exit_bitmap(vlapic->vcpu, vector);
471471
}
472472
}
@@ -875,12 +875,10 @@ vlapic_update_ppr(struct acrn_vlapic *vlapic)
875875
isrptr = &(vlapic->apic_page.isr[0]);
876876
for (vector = 0U; vector < 256U; vector++) {
877877
idx = vector >> 5U;
878-
if ((isrptr[idx].v & (1U << (vector & 0x1fU)))
879-
!= 0U) {
878+
if (((isrptr[idx].v & (1U << (vector & 0x1fU))) != 0U)
879+
&& (i < ISRVEC_STK_SIZE)) {
880880
isrvec = (uint32_t)vlapic->isrvec_stk[i];
881-
if ((i > vlapic->isrvec_stk_top) ||
882-
((i < ISRVEC_STK_SIZE) &&
883-
(isrvec != vector))) {
881+
if ((i > vlapic->isrvec_stk_top) || (isrvec != vector)) {
884882
dump_isrvec_stk(vlapic);
885883
panic("ISR and isrvec_stk out of sync");
886884
}

0 commit comments

Comments
 (0)