From patchwork Thu Apr 6 09:57:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 747676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vzJ6p75BTz9s80 for ; Thu, 6 Apr 2017 19:57:53 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id A8E861028C; Thu, 6 Apr 2017 11:57:49 +0200 (CEST) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from smtprelay.synopsys.com (us01smtprelay-2.synopsys.com [198.182.60.111]) by helium.openadk.org (Postfix) with ESMTPS id 3C7121028C for ; Thu, 6 Apr 2017 11:57:47 +0200 (CEST) Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id EBA3610C08FF; Thu, 6 Apr 2017 02:57:44 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id A7396155; Thu, 6 Apr 2017 02:57:44 -0700 (PDT) Received: from cmiranda-laptop.internal.synopsys.com (cmiranda-laptop.internal.synopsys.com [10.12.64.244]) by mailhost.synopsys.com (Postfix) with ESMTP id E7DF411B; Thu, 6 Apr 2017 02:57:42 -0700 (PDT) From: Cupertino Miranda To: devel@uclibc-ng.org Date: Thu, 6 Apr 2017 11:57:25 +0200 Message-Id: <20170406095725.18604-1-cmiranda@synopsys.com> X-Mailer: git-send-email 2.9.0 Cc: Cupertino.Miranda@synopsys.com, Francois.Bedard@synopsys.com, Vineet.Gupta1@synopsys.com, Alexey.Brodkin@synopsys.com, linux-snps-arc@lists.infradead.org, Claudiu.Zissulescu@synopsys.com Subject: [uclibc-ng-devel] [PATCH] Same iteration variable used for inner and outer loop X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" Inner loop was using same counter variable (i) as the outer loop, therefore making outer loop terminate before it visited all of the ELF program segments. Surrounding code in this inner loop clearly shows the intention that this loop should not affect the outer one, therefore leading me to the conclusion that this should be a bug an not expected code. This bug was detected due to some other bug in ARC binutils that kept setting TEXTREL for any PIE application. Apart from the but, I have also moved the debug message inside of the TEXTREL condition as mprotect is only really called if TELTREL is set. --- ldso/ldso/ldso.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 4e8a49e..a077f20 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -668,12 +668,13 @@ of this helper program; chances are you did not intend to run this program.\n\ * dynamic linking. We can set the protection back * again once we are done. */ - _dl_debug_early("calling mprotect on the application program\n"); /* Now cover the application program. */ if (app_tpnt->dynamic_info[DT_TEXTREL]) { + int j; ElfW(Phdr) *ppnt_outer = ppnt; + _dl_debug_early("calling mprotect on the application program\n"); ppnt = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_val; - for (i = 0; i < auxvt[AT_PHNUM].a_un.a_val; i++, ppnt++) { + for (j = 0; j < auxvt[AT_PHNUM].a_un.a_val; j++, ppnt++) { if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) _dl_mprotect((void *) (DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr) & PAGE_ALIGN), (DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr) & ADDR_ALIGN) +