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: 18693 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;