From patchwork Thu May 18 08:28:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 69575 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E701386D634 for ; Thu, 18 May 2023 08:31:52 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from forward102b.mail.yandex.net (forward102b.mail.yandex.net [IPv6:2a02:6b8:c02:900:1:45:d181:d102]) by sourceware.org (Postfix) with ESMTPS id AB2D4385770F for ; Thu, 18 May 2023 08:29:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB2D4385770F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1186:0:640:38cb:0]) by forward102b.mail.yandex.net (Yandex) with ESMTP id 573986002F for ; Thu, 18 May 2023 11:29:37 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id XTYe39MDZ0U0-HPvlXc7W; Thu, 18 May 2023 11:29:36 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1684398577; bh=ubu1ZoxOk1wyv26aata4LmhupVgv5iNiorgC21pdxiQ=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=TYgpKsVKYEKhdrbSd4OS72OvUgFjPxXwPPTdiKYx7/OV17fIpgMtfe7GPmsu3InxM 77cpkZtiotb19+BaMfr57ViFdzPKTVoomnP4zpy5goKYXZGtUCho2LwrgmTCnhMgRY bHZLtY9l2B2B8p3ESCxrztQqDw9KHhw5IUyaMvyU= Authentication-Results: mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 02/14] use initial mmap also for ET_EXEC Date: Thu, 18 May 2023 13:28:42 +0500 Message-Id: <20230518082854.3903342-3-stsp2@yandex.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230518082854.3903342-1-stsp2@yandex.ru> References: <20230518082854.3903342-1-stsp2@yandex.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This allows to replace the further anonymous mmaps with mprotect. Which, in turn, will allow to split the protection stage in the subsequent patches. The test-suite was run on x86_64/64 and showed no regressions. Signed-off-by: Stas Sergeev --- elf/dl-map-segments.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h index ed7675cabf..6a6127f773 100644 --- a/elf/dl-map-segments.h +++ b/elf/dl-map-segments.h @@ -129,7 +129,12 @@ _dl_map_segments (struct link_map *l, int fd, else { /* Remember which part of the address space this object uses. */ - l->l_map_start = c->mapstart + l->l_addr; + l->l_map_start = (ElfW(Addr)) __mmap ((caddr_t) l->l_addr + c->mapstart, + maplength, PROT_NONE, + MAP_ANON|MAP_PRIVATE|MAP_FIXED, + -1, 0); + if (__glibc_unlikely ((void *) l->l_map_start == MAP_FAILED)) + return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT; l->l_map_end = l->l_map_start + maplength; l->l_contiguous = !has_holes; } @@ -182,13 +187,11 @@ _dl_map_segments (struct link_map *l, int fd, if (zeroend > zeropage) { - /* Map the remaining zero pages in from the zero fill FD. */ - caddr_t mapat; - mapat = __mmap ((caddr_t) zeropage, zeroend - zeropage, - c->prot, MAP_ANON|MAP_PRIVATE|MAP_FIXED, - -1, 0); - if (__glibc_unlikely (mapat == MAP_FAILED)) - return DL_MAP_SEGMENTS_ERROR_MAP_ZERO_FILL; + /* Protect the remaining zero pages. */ + if (__glibc_unlikely (__mprotect ((caddr_t) zeropage, + zeroend - zeropage, + c->prot) < 0)) + return DL_MAP_SEGMENTS_ERROR_MPROTECT; } }