]> git.ipfire.org Git - thirdparty/qemu.git/commit
linux-user: Fix qemu brk() to not zero bytes on current page
authorHelge Deller <deller@gmx.de>
Mon, 17 Jul 2023 06:37:17 +0000 (08:37 +0200)
committerMichael Tokarev <mjt@tls.msk.ru>
Mon, 31 Jul 2023 05:52:38 +0000 (08:52 +0300)
commit0102c92a1c2736fc183bd464c1f899c96ca8faea
tree5f7008ace971622c0455f17093711126ef7baa8e
parent5de88d6e1021a8d6de0b70636126c68af0f7232d
linux-user: Fix qemu brk() to not zero bytes on current page

The qemu brk() implementation is too aggressive and cleans remaining bytes
on the current page above the last brk address.

But some existing applications are buggy and read/write bytes above their
current heap address. On a phyiscal machine this does not trigger a
runtime error as long as the access happens on the same page. Additionally
the Linux kernel allocates only full pages and does no zeroing on already
allocated pages, even if the brk address is lowered.

Fix qemu to behave the same way as the kernel does. Do not touch already
allocated pages, and - when running with different page sizes of guest and
host - zero out only those memory areas where the host page size is bigger
than the guest page size.

Signed-off-by: Helge Deller <deller@gmx.de>
Tested-by: "Markus F.X.J. Oberhumer" <markus@oberhumer.com>
Fixes: 86f04735ac ("linux-user: Fix brk() to release pages")
Cc: qemu-stable@nongnu.org
Buglink: https://github.com/upx/upx/issues/683
(cherry picked from commit 15ad98536ad9410fb32ddf1ff09389b677643faa)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
linux-user/syscall.c