From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gonglei <arei.gonglei@huawei.com>
Subject: [Qemu-devel] [PATCH] exec: avoid possible overwriting of mmaped area in qemu_ram_remap
Date: Wed, 25 Mar 2015 14:15:52 +0100 [thread overview]
Message-ID: <1427289352-6680-1-git-send-email-pbonzini@redhat.com> (raw)
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.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
Please review. :)
exec.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/exec.c b/exec.c
index 8b922db..6d1e1e4 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);
--
2.3.3
next reply other threads:[~2015-03-25 13:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-25 13:15 Paolo Bonzini [this message]
2015-03-26 2:26 ` [Qemu-devel] [PATCH] exec: avoid possible overwriting of mmaped area in qemu_ram_remap Gonglei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1427289352-6680-1-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).