From nobody Tue Oct 28 02:12:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151525831292076.47200432248883; Sat, 6 Jan 2018 09:05:12 -0800 (PST) Received: from localhost ([::1]:42537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXruB-0000Pi-T6 for importer@patchew.org; Sat, 06 Jan 2018 12:05:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXrqV-0006Lw-HV for qemu-devel@nongnu.org; Sat, 06 Jan 2018 12:01:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXrqR-0005It-3k for qemu-devel@nongnu.org; Sat, 06 Jan 2018 12:01:23 -0500 Received: from dd7730.kasserver.com ([85.13.132.46]:58275) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXrqQ-0005Ga-Td for qemu-devel@nongnu.org; Sat, 06 Jan 2018 12:01:19 -0500 Received: from dickeberta.xmga2qtle3uutg2tq1cumoxs5h.ax.internal.cloudapp.net (unknown [13.81.53.213]) by dd7730.kasserver.com (Postfix) with ESMTPA id 4E2CC5980D10; Sat, 6 Jan 2018 18:01:16 +0100 (CET) From: Maximilian Riemensberger To: qemu-devel Date: Sat, 6 Jan 2018 17:00:13 +0000 Message-Id: <1515258013-85745-1-git-send-email-riemensberger@cadami.net> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 85.13.132.46 Subject: [Qemu-devel] [PATCH] linux-user/mmap.c: Avoid choosing NULL as start address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maximilian Riemensberger , Peter Maydell , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" mmap() is required by the linux kernel ABI and POSIX to return a non-NULL address when the implementation chooses a start address for the mapping. The current implementation of mmap_find_vma_reserved() can return NULL as start address of a mapping which leads to subsequent crashes inside the guests glibc, e.g. output of qemu-arm-static --strace executing a test binary stx_test: 1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|= 0x20000,-1,0) =3D 0x00000000 1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_sta= ck: Assertion `mem !=3D NULL' failed. This patch fixes mmap_find_vma_reserved() by skipping NULL as start address while searching for a suitable mapping start address. CC: Riku Voipio CC: Laurent Vivier CC: Peter Maydell Signed-off-by: Maximilian Riemensberger --- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 4888f53..20cc5a7 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -221,7 +221,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start= , abi_ulong size) addr =3D end_addr - qemu_host_page_size; =20 while (1) { - if (addr > end_addr) { + if (!addr || addr > end_addr) { if (looped) { return (abi_ulong)-1; } --=20 2.7.4