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: 747677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vzJ764zFhz9s80 for ; Thu, 6 Apr 2017 19:58:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jBplvdgQ"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=QSOqg/AWHRAqLw9+71SVyN2T8w1v4G7FUJyoredbbrI=; b=jBp lvdgQWuUuR6zN8/7ovLfnaPmGVvgUIiUP3n31xjh7GstroZ3iY/+rIlJGdldbGqSoSpXhWhvgoRaO 2xvRSv4hYmqnzEOYV4T5fm2G0JX2gLf5yUzmYWWc3PSMq0S3lC1iIw/y9wfvnnBF94NV3GJ8muGKy n+S3vRYbhcby+cIAI3elShky7jTgxtTjLu9fS+0CeaPIGEhtdxoL7avoxRrZYgL+4yC+8WFvV8GsS MLTPbBjXMAhVnZeJP2vl7NMpkEbKXTbp6QF+Hhijg1hpDSbrmYu2EgUJjr4gwkavBUg4xHSOeCZM/ E+3nFuxIsVeag9r1NNK8bLzaQutsJ0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cw4B7-0001At-Ds; Thu, 06 Apr 2017 09:58:09 +0000 Received: from smtprelay2.synopsys.com ([198.182.60.111] helo=smtprelay.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cw4B4-00018h-Nj for linux-snps-arc@lists.infradead.org; Thu, 06 Apr 2017 09:58:08 +0000 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 Subject: [PATCH] Same iteration variable used for inner and outer loop 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170406_025806_775767_26D343EE X-CRM114-Status: UNSURE ( 9.03 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.60.111 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [198.182.60.111 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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) +