From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id 605AD3890433 for ; Mon, 4 Jan 2021 19:25:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 605AD3890433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 979505E2; Mon, 4 Jan 2021 20:25:06 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pi0mhApYFwoR; Mon, 4 Jan 2021 20:25:06 +0100 (CET) Received: from function.youpi.perso.aquilenet.fr (lfbn-bor-1-56-204.w90-50.abo.wanadoo.fr [90.50.148.204]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 08EFC573; Mon, 4 Jan 2021 20:25:05 +0100 (CET) Received: from samy by function.youpi.perso.aquilenet.fr with local (Exim 4.94) (envelope-from ) id 1kwVTU-000ErO-PX; Mon, 04 Jan 2021 20:25:04 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] hurd: Fix mmap(!MAP_FIXED) on bogus address Date: Mon, 4 Jan 2021 20:25:04 +0100 Message-Id: <20210104192504.57079-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jan 2021 19:25:10 -0000 In the !MAP_FIXED case, when a bogus address is given mmap should pick up a valide address rather than returning EINVAL: Posix only talks about EINVAL for the MAP_FIXED case. This fixes long-running ghc processes. --- sysdeps/mach/hurd/mmap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c index ed8faadee8..ea0e61d571 100644 --- a/sysdeps/mach/hurd/mmap.c +++ b/sysdeps/mach/hurd/mmap.c @@ -127,9 +127,9 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) vmprot, VM_PROT_ALL, (flags & MAP_SHARED) ? VM_INHERIT_SHARE : VM_INHERIT_COPY); - if (err == KERN_NO_SPACE) + if (flags & MAP_FIXED) { - if (flags & MAP_FIXED) + if (err == KERN_NO_SPACE) { /* XXX this is not atomic as it is in unix! */ /* The region is already allocated; deallocate it first. */ @@ -143,7 +143,10 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) (flags & MAP_SHARED) ? VM_INHERIT_SHARE : VM_INHERIT_COPY); } - else if (mapaddr != 0) + } + else + { + if (mapaddr != 0 && (err == KERN_NO_SPACE || err == KERN_INVALID_ADDRESS)) err = __vm_map (__mach_task_self (), &mapaddr, (vm_size_t) len, (vm_address_t) 0, 1, memobj, (vm_offset_t) offset, -- 2.29.2