]> git.proxmox.com Git - qemu.git/commitdiff
memory: assert that PhysPageEntry's ptr does not overflow
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 May 2013 09:30:23 +0000 (11:30 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 May 2013 16:42:30 +0000 (18:42 +0200)
While sized to 15 bits in PhysPageEntry, the ptr field is ORed into the
iotlb entries together with a page-aligned pointer.  The ptr field must
not overflow into this page-aligned value, assert that it is smaller than
the page size.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
exec.c

diff --git a/exec.c b/exec.c
index 1355661963f657f9c5d392214314cfa0d557f880..8562fcac9c654032651ddefa04e69c46177f331d 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -713,6 +713,12 @@ static void destroy_all_mappings(AddressSpaceDispatch *d)
 
 static uint16_t phys_section_add(MemoryRegionSection *section)
 {
+    /* The physical section number is ORed with a page-aligned
+     * pointer to produce the iotlb entries.  Thus it should
+     * never overflow into the page-aligned value.
+     */
+    assert(phys_sections_nb < TARGET_PAGE_SIZE);
+
     if (phys_sections_nb == phys_sections_nb_alloc) {
         phys_sections_nb_alloc = MAX(phys_sections_nb_alloc * 2, 16);
         phys_sections = g_renew(MemoryRegionSection, phys_sections,