* [Qemu-devel] [PATCH] exec: avoid possible overwriting of mmaped area in qemu_ram_remap
@ 2015-03-25 13:15 Paolo Bonzini
2015-03-26 2:26 ` Gonglei
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2015-03-25 13:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Gonglei
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] exec: avoid possible overwriting of mmaped area in qemu_ram_remap
2015-03-25 13:15 [Qemu-devel] [PATCH] exec: avoid possible overwriting of mmaped area in qemu_ram_remap Paolo Bonzini
@ 2015-03-26 2:26 ` Gonglei
0 siblings, 0 replies; 2+ messages in thread
From: Gonglei @ 2015-03-26 2:26 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel
On 2015/3/25 21:15, Paolo Bonzini wrote:
> 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.
>
Yes, it is.
> 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);
>
Looks good to me, so
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-26 2:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-25 13:15 [Qemu-devel] [PATCH] exec: avoid possible overwriting of mmaped area in qemu_ram_remap Paolo Bonzini
2015-03-26 2:26 ` Gonglei
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).