From patchwork Mon Mar 20 19:35:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dmitry V. Levin" X-Patchwork-Id: 741150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vn5lv6xR4z9ryv for ; Tue, 21 Mar 2017 06:36:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="r4NRhl2d"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=tKgT +23mBTgVm1LrTnT2iQBhmufu1B5SFgfWzPVB0Ql2ARMG+XWk1YNviw5+lV8Rk0bL 5YEy0HEO6tKUlJXIPviQpA0fdkKaoOyYZhT8h6uvfWtd5N6OF5uFGmbezawij0AC C2YSS498JYuWz6/uSTAId3Ej/z5lZZ/E0DTV3RU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=PTybj5hyLb Jte2K7S0suB0gdhoo=; b=r4NRhl2diwVzjs3TGrViZQPLryEso228dIXIlqgEXy PySolgK2ccw9J3f3AqUizQ1Phc5s1sqPwMynV3UXX90TFwqC1TBw9eOd5ATNS36c E+7CZpOGijeDVSDEuFYYlutERsZO4THedNNlPZjKoO628+pMD39LrOBFEhk5PixP 8= Received: (qmail 79052 invoked by alias); 20 Mar 2017 19:36:03 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 79027 invoked by uid 89); 20 Mar 2017 19:36:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*r:508, inaccessible X-HELO: vmicros1.altlinux.org Date: Mon, 20 Mar 2017 22:35:58 +0300 From: "Dmitry V. Levin" To: libc-alpha@sourceware.org Subject: [PING v2] [PATCH] Test for __mprotect failure in _dl_map_segments [BZ #20831] Message-ID: <20170320193558.GB26547@altlinux.org> Mail-Followup-To: libc-alpha@sourceware.org References: <20161116234522.GA8065@altlinux.org> <20161227130144.GC1603@altlinux.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161227130144.GC1603@altlinux.org> * elf/dl-map-segments.h (_dl_map_segments): Test for failure of __mprotect to change protection on the excess portion to disallow all access. --- I understand the patch is trivial, but anyway, there is a bug and it has to be fixed. If there are no comments, I'd push it rather than go on with these ping reposts. --- ChangeLog | 7 +++++++ elf/dl-map-segments.h | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h index e583f64..3dc030b 100644 --- a/elf/dl-map-segments.h +++ b/elf/dl-map-segments.h @@ -64,14 +64,19 @@ _dl_map_segments (struct link_map *l, int fd, l->l_addr = l->l_map_start - c->mapstart; if (has_holes) - /* Change protection on the excess portion to disallow all access; - the portions we do not remap later will be inaccessible as if - unallocated. Then jump into the normal segment-mapping loop to - handle the portion of the segment past the end of the file - mapping. */ - __mprotect ((caddr_t) (l->l_addr + c->mapend), - loadcmds[nloadcmds - 1].mapstart - c->mapend, - PROT_NONE); + { + /* Change protection on the excess portion to disallow all access; + the portions we do not remap later will be inaccessible as if + unallocated. Then jump into the normal segment-mapping loop to + handle the portion of the segment past the end of the file + mapping. */ + int rc; + rc = __mprotect ((caddr_t) (l->l_addr + c->mapend), + loadcmds[nloadcmds - 1].mapstart - c->mapend, + PROT_NONE); + if (__glibc_unlikely (rc < 0)) + return DL_MAP_SEGMENTS_ERROR_MPROTECT; + } l->l_contiguous = 1;