From ac0bf8bd587a5b9e19f4a39d87b26bc7e63e0f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Tue, 11 May 2021 14:41:02 -0300 Subject: [PATCH] qemu: restore mremap-efault patch. This was deleted in b393370212519d8bbba57b50293380124a06bbbb, but was still necessary. Without it, qemu in user mode has the wrong return value for mremap, which leads to infinite looping in some situations (afaik only with musl). This could be observed with qemu-user-static when crossbuilding webkit2gtk for armv*-musl, where strace(1) showed infinite looping: mremap(0x6525a000, 4096, 8192, 0^C) = -1 ENOMEM (Out of memory) The command being used was: /usr/bin/qemu-arm-static -L /usr/arm-linux-musleabihf -E LD_LIBRARY_PATH=/usr/arm-linux-musleabihf/usr/lib:.libs: /builddir/webkitgtk-2.32.1/build/Source/WebKit/tmp-introspecth0go8pvu/WebKit2-4.0 --introspect-dump=/builddir/webkitgtk-2.32.1/build/Source/WebKit/tmp-introspecth0go8pvu/functions.txt,/builddir/webkitgtk-2.32.1/build/Source/WebKit/tmp-introspecth0go8pvu/dump.xml --- srcpkgs/qemu/patches/mmap-mremap-efault.patch | 42 +++++++++++++++++++ srcpkgs/qemu/template | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 srcpkgs/qemu/patches/mmap-mremap-efault.patch diff --git a/srcpkgs/qemu/patches/mmap-mremap-efault.patch b/srcpkgs/qemu/patches/mmap-mremap-efault.patch new file mode 100644 index 00000000000..be58a46df66 --- /dev/null +++ b/srcpkgs/qemu/patches/mmap-mremap-efault.patch @@ -0,0 +1,42 @@ +Source: @pullmoll +Upstream: no +Reason: errno=EFAULT when the address passed to mremap(2) is not valid + +See Rich Felker's comment at https://www.openwall.com/lists/musl/2017/06/21/2 for +why we need to return errno as described in man mremap(2) from qemu-user-static. +Also speed up the loop when checking for increasing the mappings size to go +in steps of TARGET_PAGE_SIZE and OR-in a check for the very last byte of the range. +diff --git linux-user/mmap.c linux-user/mmap.c +index 7e3b245..1e8d0f1 100644 +--- linux-user/mmap.c ++++ linux-user/mmap.c +@@ -738,7 +738,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, + !guest_range_valid_untagged(new_addr, new_size)) || + ((flags & MREMAP_MAYMOVE) == 0 && + !guest_range_valid_untagged(old_addr, new_size))) { +- errno = ENOMEM; ++ errno = EFAULT; + return -1; + } + +@@ -775,9 +775,10 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, + abi_ulong addr; + for (addr = old_addr + old_size; + addr < old_addr + new_size; +- addr++) { ++ addr += TARGET_PAGE_SIZE) { + prot |= page_get_flags(addr); + } ++ prot |= page_get_flags(old_addr + new_size - 1); + } + if (prot == 0) { + host_addr = mremap(g2h_untagged(old_addr), +@@ -796,7 +797,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, + } + } + } else { +- errno = ENOMEM; ++ errno = EFAULT; + host_addr = MAP_FAILED; + } + } diff --git a/srcpkgs/qemu/template b/srcpkgs/qemu/template index 75f57bac755..0fadb41f609 100644 --- a/srcpkgs/qemu/template +++ b/srcpkgs/qemu/template @@ -2,7 +2,7 @@ # This package should be updated together with qemu-user-static pkgname=qemu version=6.0.0 -revision=1 +revision=2 build_style=configure hostmakedepends="gettext pkg-config perl python3 automake libtool flex python3-Sphinx texinfo ninja"