Skip to content

Commit ccf5624

Browse files
lyan3lijinxia
authored andcommitted
hv:irq: avoid out-of-range access to irq_alloc_bitmap[]
Logically, out-of-range access won't happen at these places. However, it depends on the behaviour of other codes. This commit makes changes to explicitly eliminate the possibility in these functions. Tracked-On: #1235 Signed-off-by: Yan, Like <like.yan@intel.com>
1 parent 4a038d1 commit ccf5624

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

hypervisor/arch/x86/irq.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ uint32_t alloc_irq_num(uint32_t req_irq)
4141
if (irq == IRQ_INVALID) {
4242
/* if no valid irq num given, find a free one */
4343
irq = ffz64_ex(irq_alloc_bitmap, NR_IRQS);
44-
irq = (irq == NR_IRQS) ? IRQ_INVALID : irq;
4544
}
4645

47-
if (irq != IRQ_INVALID) {
46+
if (irq >= NR_IRQS) {
47+
irq = IRQ_INVALID;
48+
} else {
4849
bitmap_set_nolock((uint16_t)(irq & 0x3FU),
49-
irq_alloc_bitmap + (irq >> 6U));
50+
irq_alloc_bitmap + (irq >> 6U));
5051
}
5152
spinlock_irqrestore_release(&irq_alloc_spinlock, rflags);
5253
return irq;
@@ -323,7 +324,13 @@ void dispatch_interrupt(struct intr_excp_ctx *ctx)
323324
uint32_t irq = vector_to_irq[vr];
324325
struct irq_desc *desc;
325326

326-
if (irq == IRQ_INVALID) {
327+
/* The value from vector_to_irq[] must be:
328+
* IRQ_INVALID, which means the vector is not allocated;
329+
* or
330+
* < NR_IRQS, which is the irq number it bound with;
331+
* Any other value means there is something wrong.
332+
*/
333+
if (irq == IRQ_INVALID || irq >= NR_IRQS) {
327334
goto ERR;
328335
}
329336

0 commit comments

Comments
 (0)