mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 15:05:37 +00:00
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. Backports commit f18c69cfc554cf9776eb3c35b7510e17541afacb from qemu
This commit is contained in:
parent
aad1027c96
commit
71beea204c
|
@ -1242,7 +1242,6 @@ void qemu_ram_remap(struct uc_struct *uc, ram_addr_t addr, ram_addr_t length)
|
|||
;
|
||||
} else {
|
||||
flags = MAP_FIXED;
|
||||
munmap(vaddr, length);
|
||||
if (block->fd >= 0) {
|
||||
flags |= (block->flags & RAM_SHARED ?
|
||||
MAP_SHARED : MAP_PRIVATE);
|
||||
|
|
Loading…
Reference in a new issue