I did some research and found that this bug is present since 2003:
- 2003/05/13: https://github.com/qemu/qemu/commit/54936004fddc52c321cb3f9a9a51140e782bed5d#diff-2bf4728e0473404c39c97190bd02b2f8 - https://github.com/qemu/qemu/blob/54936004fddc52c321cb3f9a9a51140e782bed5d/linux-user/mmap.c#L182-L183 - 2008/06/02: https://github.com/qemu/qemu/commit/c8a706fe6242a553960ccc3071a4e75ceba6f3d2#diff-2bf4728e0473404c39c97190bd02b2f8 - https://github.com/qemu/qemu/blob/c8a706fe6242a553960ccc3071a4e75ceba6f3d2/linux-user/mmap.c#L284-L285 - https://github.com/qemu/qemu/blob/c8a706fe6242a553960ccc3071a4e75ceba6f3d2/linux-user/mmap.c#L400-L410
It is present in versions 2.11.2, 2.12.0 and master:
- https://github.com/qemu/qemu/blob/v2.11.2/linux-user/mmap.c#L401-L402 - https://github.com/qemu/qemu/blob/v2.12.0/linux-user/mmap.c#L401-L402 - https://github.com/qemu/qemu/blob/master/linux-user/mmap.c#L400-L401
I think that a possible fix is:
@@ -397,8 +397,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, }
len = TARGET_PAGE_ALIGN(len); - if (len == 0) - goto the_end; + if (len == 0) { + errno = EINVAL; + goto fail; + } real_start = start & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask;
I did some research and found that this bug is present since 2003:
- 2003/05/13: https:/ /github. com/qemu/ qemu/commit/ 54936004fddc52c 321cb3f9a9a5114 0e782bed5d# diff-2bf4728e04 73404c39c97190b d02b2f8 /github. com/qemu/ qemu/blob/ 54936004fddc52c 321cb3f9a9a5114 0e782bed5d/ linux-user/ mmap.c# L182-L183 /github. com/qemu/ qemu/commit/ c8a706fe6242a55 3960ccc3071a4e7 5ceba6f3d2# diff-2bf4728e04 73404c39c97190b d02b2f8 /github. com/qemu/ qemu/blob/ c8a706fe6242a55 3960ccc3071a4e7 5ceba6f3d2/ linux-user/ mmap.c# L284-L285 /github. com/qemu/ qemu/blob/ c8a706fe6242a55 3960ccc3071a4e7 5ceba6f3d2/ linux-user/ mmap.c# L400-L410
- https:/
- 2008/06/02: https:/
- https:/
- https:/
It is present in versions 2.11.2, 2.12.0 and master:
- https:/ /github. com/qemu/ qemu/blob/ v2.11.2/ linux-user/ mmap.c# L401-L402 /github. com/qemu/ qemu/blob/ v2.12.0/ linux-user/ mmap.c# L401-L402 /github. com/qemu/ qemu/blob/ master/ linux-user/ mmap.c# L400-L401
- https:/
- https:/
I think that a possible fix is:
@@ -397,8 +397,10 @@ abi_long target_ mmap(abi_ ulong start, abi_ulong len, int prot,
}
len = TARGET_ PAGE_ALIGN( len); page_mask; page_mask;
- if (len == 0)
- goto the_end;
+ if (len == 0) {
+ errno = EINVAL;
+ goto fail;
+ }
real_start = start & qemu_host_
host_offset = offset & qemu_host_