From patchwork Tue Dec 27 13:01:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dmitry V. Levin" X-Patchwork-Id: 708938 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 3tnwxJ6WdCz9t2T for ; Wed, 28 Dec 2016 00:01:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="lLdvopRr"; 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=HGFd d2qCyXHVBVmtPH/HIGhDKvkiTsnUwXTUoUY3yV6fQk41kP7hPV9tMaLwKfA1ElhP XpXu6AyenMqmbSMlDbldU0j6fVzHEdffvlzWGpvC7A2p9Xm18ZQXVKVhOX4Il5bM 39niUNxEVelch+m+ayhVjSfPAM+U9sdw8ulUeCg= 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=XH6yYgp60u +TBzkwPZU993QqXVI=; b=lLdvopRry7DgooAQXJ2WE3iTLB4/WcqQg5TZrQaOaV 62giQz2WuLZsyLhalCKDLxSvPHMJYO4yW/kSILI+72hMWGBb9qncAjTtT+Yaq5+T fbSICwtNTCKBAYfEZzdYE0A2DGUZFP0LxUn6ESsdOhoYVWndcbGsIQgY5Qd2MZZT k= Received: (qmail 38684 invoked by alias); 27 Dec 2016 13:01:50 -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 38674 invoked by uid 89); 27 Dec 2016 13:01:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1510, remap, H*r:508, link_map X-HELO: vmicros1.altlinux.org Date: Tue, 27 Dec 2016 16:01:44 +0300 From: "Dmitry V. Levin" To: libc-alpha@sourceware.org Subject: [PING] [PATCH] Test for __mprotect failure in _dl_map_segments [BZ #20831] Message-ID: <20161227130144.GC1603@altlinux.org> Mail-Followup-To: libc-alpha@sourceware.org References: <20161116234522.GA8065@altlinux.org> Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161116234522.GA8065@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. --- 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;