[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/12] ioapic: use irq number instead of vector in io
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 12/12] ioapic: use irq number instead of vector in ioapic_eoi_broadcast |
Date: |
Fri, 5 Jul 2019 22:23:22 +0200 |
From: Li Qiang <address@hidden>
When emulating irqchip in qemu, such as following command:
x86_64-softmmu/qemu-system-x86_64 -m 1024 -smp 4 -hda /home/test/test.img
-machine kernel-irqchip=off --enable-kvm -vnc :0 -device edu -monitor stdio
We will get a crash with following asan output:
(qemu) /home/test/qemu5/qemu/hw/intc/ioapic.c:266:27: runtime error: index 35
out of bounds for type 'int [24]'
=================================================================
==113504==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x61b000003114 at pc 0x5579e3c7a80f bp 0x7fd004bf8c10 sp 0x7fd004bf8c00
WRITE of size 4 at 0x61b000003114 thread T4
#0 0x5579e3c7a80e in ioapic_eoi_broadcast
/home/test/qemu5/qemu/hw/intc/ioapic.c:266
#1 0x5579e3c6f480 in apic_eoi /home/test/qemu5/qemu/hw/intc/apic.c:428
#2 0x5579e3c720a7 in apic_mem_write /home/test/qemu5/qemu/hw/intc/apic.c:802
#3 0x5579e3b1e31a in memory_region_write_accessor
/home/test/qemu5/qemu/memory.c:503
#4 0x5579e3b1e6a2 in access_with_adjusted_size
/home/test/qemu5/qemu/memory.c:569
#5 0x5579e3b28d77 in memory_region_dispatch_write
/home/test/qemu5/qemu/memory.c:1497
#6 0x5579e3a1b36b in flatview_write_continue
/home/test/qemu5/qemu/exec.c:3323
#7 0x5579e3a1b633 in flatview_write /home/test/qemu5/qemu/exec.c:3362
#8 0x5579e3a1bcb1 in address_space_write /home/test/qemu5/qemu/exec.c:3452
#9 0x5579e3a1bd03 in address_space_rw /home/test/qemu5/qemu/exec.c:3463
#10 0x5579e3b8b979 in kvm_cpu_exec
/home/test/qemu5/qemu/accel/kvm/kvm-all.c:2045
#11 0x5579e3ae4499 in qemu_kvm_cpu_thread_fn
/home/test/qemu5/qemu/cpus.c:1287
#12 0x5579e4cbdb9f in qemu_thread_start util/qemu-thread-posix.c:502
#13 0x7fd0146376da in start_thread
(/lib/x86_64-linux-gnu/libpthread.so.0+0x76da)
#14 0x7fd01436088e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x12188e
This is because in ioapic_eoi_broadcast function, we uses 'vector' to
index the 's->irq_eoi'. To fix this, we should uses the irq number.
Signed-off-by: Li Qiang <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
---
hw/intc/ioapic.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
index db9e518..c408749 100644
--- a/hw/intc/ioapic.c
+++ b/hw/intc/ioapic.c
@@ -245,8 +245,8 @@ void ioapic_eoi_broadcast(int vector)
s->ioredtbl[n] = entry & ~IOAPIC_LVT_REMOTE_IRR;
if (!(entry & IOAPIC_LVT_MASKED) && (s->irr & (1 << n))) {
- ++s->irq_eoi[vector];
- if (s->irq_eoi[vector] >= SUCCESSIVE_IRQ_MAX_COUNT) {
+ ++s->irq_eoi[n];
+ if (s->irq_eoi[n] >= SUCCESSIVE_IRQ_MAX_COUNT) {
/*
* Real hardware does not deliver the interrupt immediately
* during eoi broadcast, and this lets a buggy guest make
@@ -254,16 +254,16 @@ void ioapic_eoi_broadcast(int vector)
* level-triggered interrupt. Emulate this behavior if we
* detect an interrupt storm.
*/
- s->irq_eoi[vector] = 0;
+ s->irq_eoi[n] = 0;
timer_mod_anticipate(s->delayed_ioapic_service_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
+
NANOSECONDS_PER_SECOND / 100);
- trace_ioapic_eoi_delayed_reassert(vector);
+ trace_ioapic_eoi_delayed_reassert(n);
} else {
ioapic_service(s);
}
} else {
- s->irq_eoi[vector] = 0;
+ s->irq_eoi[n] = 0;
}
}
}
--
1.8.3.1
- [Qemu-devel] [PULL 01/12] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size(), (continued)
- [Qemu-devel] [PULL 01/12] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size(), Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 07/12] target/i386: fix feature check in hyperv-stub.c, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 05/12] intel_iommu: Fix unexpected unmaps during global unmap, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 02/12] checkpatch: do not warn for multiline parenthesized returned value, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 04/12] intel_iommu: Fix incorrect "end" for vtd_address_space_unmap, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 11/12] hw/i386: Fix linker error when ISAPC is disabled, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 09/12] target/i386: kvm: Fix when nested state is needed for migration, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 10/12] Makefile: generate header file with the list of devices enabled, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 06/12] ioapic: clear irq_eoi when updating the ioapic redirect table entry, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 03/12] i386/kvm: Fix build with -m32, Paolo Bonzini, 2019/07/05
- [Qemu-devel] [PULL 12/12] ioapic: use irq number instead of vector in ioapic_eoi_broadcast,
Paolo Bonzini <=
- [Qemu-devel] [PULL 08/12] minikconf: do not include variables from MINIKCONF_ARGS in config-all-devices.mak, Paolo Bonzini, 2019/07/05
- Re: [Qemu-devel] [PULL 00/12] Misc bugfixes for QEMU hard freeze, Peter Maydell, 2019/07/08