From patchwork Tue Sep 25 20:51:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 974738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42KYDz5qZKz9s4s for ; Wed, 26 Sep 2018 06:53:07 +1000 (AEST) Received: from localhost ([::1]:55212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4uKP-0008LM-B6 for incoming@patchwork.ozlabs.org; Tue, 25 Sep 2018 16:53:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4uJW-0008GF-Su for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4uJS-0002G3-0s for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:10 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:46111) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g4uJR-0002F8-7x for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:05 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N2m7Q-1fdMQf2284-0138nM; Tue, 25 Sep 2018 22:51:53 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2018 22:51:27 +0200 Message-Id: <20180925205129.25261-4-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925205129.25261-1-laurent@vivier.eu> References: <20180925205129.25261-1-laurent@vivier.eu> X-Provags-ID: V03:K1:z1HCpHOIocdjodJcQRy1LSws/xBkaQx9BGXX+qbx51VsMfUefHR +fdHF0hj7coAoSS58fho+j8RQSSlFGxkUT9MCv2qtTEzc497euNfOVkgTkul18DJVZHrY4B fk4dPEW5IjEQK3Y70XYfsHgqWtbgRXH4ollcO5PapjiIWmt/x6TfWxaAIbOuSZp2DQ8uHc7 zpQe677M4oaXquYZOADzw== X-UI-Out-Filterresults: notjunk:1; V01:K0:luoLuABJVz4=:Czwf+M3+QYSKHhHypW4jQ0 E+0r7niD9y0sTXgLNw8PAfSwY9KIBn2tfpVifAqCj0MdaczVRF80q1Pa8ZafUvBjdFiRVN2Dw VZ9XmvocMKoDwWzUJzVmyIhcR8e+bioNBLdmI81evhFcoeUv7dbrw6cLcSy9QKHCWyz/r91n2 uhdRDVGDlQk8ghHvVdk9dEC2JxRnDvVM0T6hHt2pOD/l3J2M1uZlX8bVdETn0Ty8jDTRcAJc6 iZIcDTztvCM13CCfrFHumyWasyaWylgKMd5+dI0eLfZ9kKKF1QNcKcGMRp7FYE3DpR6MwuYZK LpI6nbwSk3a1NVWscr9X2/eAf3TQ9Yn9H3TxoKpBmcUAzG94VuBt1L2NVAEG9I/MQzq39MLWT AnSNsJtqojqu8LmG2zY+SlEzarRQCGCnuFh2IZpOZRlpdlUUr7vd4V3kLubZpx8ZY/3a6ow0y l7IqZRyYB2PN//SGy6hXCVv5b3a7WB3AoS4vFad9gl/Q1d+JRUwZJ+iI4vuqSKpE7alP4xD+b 4F2LKWhL4EA9vf5QTMgD3nOvFTVyYt4ZI34CqUwwpk8DqZ+8kCYz/3KgrFJKCygpDN98UMDPV Qjs9AoB7voQnWZoLtFS8SZeUA+Gi1TgJnc0RsMbFRax0f3IGQ8jC75BpxF/8sSoIRGyvk/Ici qh85afJP/sguPmj3DiMEmP+DD1zzLMkrPOsby9Qa4a8bDYhId7Kj0otq7N3ihIZLWbpg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PULL v2 3/5] linux-user: elf: mmap all the target-pages of hostpage for data segment 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: Riku Voipio , Shivaprasad G Bhat , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Shivaprasad G Bhat If the hostpage size is greater than the TARGET_PAGESIZE, the target-pages of size TARGET_PAGESIZE are marked valid only till the length requested during the elfload. The glibc attempts to consume unused space in the last page of data segment(__libc_memalign() in elf/dl-minimal.c). If PT_LOAD p_align is greater than or equal to hostpage size, the GLRO(dl_pagesize) is actually the host pagesize as set in the auxillary vectors. So, there is no explicit mmap request for the remaining target-pages on the last hostpage. The glibc assumes that particular space as available and subsequent attempts to use those addresses lead to crash as the target_mmap has not marked them valid for those target-pages. The issue is seen when trying to chroot to 16.04-x86_64 ubuntu on a PPC64 host where the fork fails to access the thread_id as it is allocated on a page not marked valid. The recent glibc doesn't have checks for thread-id in fork, but the issue can manifest somewhere else, none the less. The fix here is to map all the target-pages of the hostpage during the elfload if the p_align is greater than or equal to hostpage size, for data segment to allow the glibc for proper consumption. Signed-off-by: Shivaprasad G Bhat Reviewed-by: Laurent Vivier Message-Id: <153553435604.51992.5640085189104207249.stgit@lep8c.aus.stglabs.ibm.com> Signed-off-by: Laurent Vivier --- linux-user/elfload.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8638612aec..6ead0d11c6 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1437,7 +1437,10 @@ struct exec #define QMAGIC 0314 /* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE +#define TARGET_ELF_EXEC_PAGESIZE \ + (((eppnt->p_align & ~qemu_host_page_mask) != 0) ? \ + TARGET_PAGE_SIZE : MAX(qemu_host_page_size, TARGET_PAGE_SIZE)) +#define TARGET_ELF_PAGELENGTH(_v) ROUND_UP((_v), TARGET_ELF_EXEC_PAGESIZE) #define TARGET_ELF_PAGESTART(_v) ((_v) & \ ~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1)) #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1)) @@ -2279,7 +2282,7 @@ static void load_elf_image(const char *image_name, int image_fd, for (i = 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt = phdr + i; if (eppnt->p_type == PT_LOAD) { - abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em; + abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; int elf_prot = 0; if (eppnt->p_flags & PF_R) elf_prot = PROT_READ; @@ -2289,8 +2292,9 @@ static void load_elf_image(const char *image_name, int image_fd, vaddr = load_bias + eppnt->p_vaddr; vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); vaddr_ps = TARGET_ELF_PAGESTART(vaddr); + vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); - error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); if (error == -1) {