]> git.proxmox.com Git - mirror_qemu.git/commitdiff
exec: Fix bounce buffer allocation in address_space_map()
authorKevin Wolf <kwolf@redhat.com>
Mon, 22 Jul 2013 12:30:23 +0000 (14:30 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 28 Oct 2013 16:34:42 +0000 (17:34 +0100)
This fixes a regression introduced by commit e3127ae0c, which kept the
allocation size of the bounce buffer limited to one page in order to
avoid unbounded allocations (as explained in the commit message of
6d16c2f88), but broke the reporting of the shortened bounce buffer to
the caller. The caller therefore assumes that the full requested size
was provided and causes memory corruption when writing beyond the end of
the actually allocated buffer.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
exec.c

diff --git a/exec.c b/exec.c
index 2e31ffcb2c17e798073bfe561480a2301a2fee8e..b453713bdbde08e11610c9bdc7476dbda8168ada 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -2099,7 +2099,9 @@ void *address_space_map(AddressSpace *as,
         if (bounce.buffer) {
             return NULL;
         }
-        bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, TARGET_PAGE_SIZE);
+        /* Avoid unbounded allocations */
+        l = MIN(l, TARGET_PAGE_SIZE);
+        bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, l);
         bounce.addr = addr;
         bounce.len = l;