aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-03-25 14:14:56 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2015-03-26 10:43:54 +0100
commitf18c69cfc554cf9776eb3c35b7510e17541afacb (patch)
tree9718fbc710164140315a97dd83e0d19d6b80f9f2
parent8e7ba4ed3a0b68ab35736c7859fd950f6705e0cf (diff)
exec: avoid possible overwriting of mmaped area in qemu_ram_remap
It is not necessary to munmap an area before remapping it with MAP_FIXED; if the memory region specified by addr and len overlaps pages of any existing mapping, then the overlapped part of the existing mapping will be discarded. On the other hand, if QEMU does munmap the pages, there is a small probability that another mmap sneaks in and catches the just-freed portion of the address space. In effect, munmap followed by mmap(MAP_FIXED) is a use-after-free error, and Coverity flags it as such. Fix it. Reviewed-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--exec.c1
1 files changed, 0 insertions, 1 deletions
diff --git a/exec.c b/exec.c
index 8b922db61..6d1e1e4c7 100644
--- a/exec.c
+++ b/exec.c
@@ -1638,7 +1638,6 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
abort();
} else {
flags = MAP_FIXED;
- munmap(vaddr, length);
if (block->fd >= 0) {
flags |= (block->flags & RAM_SHARED ?
MAP_SHARED : MAP_PRIVATE);