From patchwork Fri Oct 31 21:33:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaro Koskinen X-Patchwork-Id: 405695 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 CFC951400A0 for ; Sat, 1 Nov 2014 08:34:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=jG/fWnte+O3Oi60v71ePWqMZ+KPmxWVnLKIs1ny5/5BbFhq30xviM GGYyjk0p0E2QsNpYe2HoUz/Sixv71owOOvLMfhUxjDoCRwHU0mNvh42RSF/lrA36 BLeVUlhWiJ9EtRXRIy3qYiwVHpfgrZyoZ0YYUSJHFvs9yQzzvU6BV4= 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:from:to:subject:date:message-id; s=default; bh=RF6hU6coMB2ar6R7Dzf20cb2gPA=; b=SUWj6jzvIHLymOd8ZliRWPJz026Y 2jMhYvXnpe74m2M0+UCulPPlfp4K1Nhv4/gPd5kJpZ51c43AQ1yV7UB4aY12rCeI rc+OykkPJuortsNssR8rno+qllEabYZmEhYgczL67mm0kn4DDH79Jo4ZnmT7trSE ZMUmnFq9F/wypzM= Received: (qmail 12919 invoked by alias); 31 Oct 2014 21:34: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 12910 invoked by uid 89); 31 Oct 2014 21:34:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: filtteri2.pp.htv.fi From: Aaro Koskinen To: Carlos O'Donell , GNU C Library , John David Anglin Subject: [PATCH] hppa: avoid NULL dereference of sym_map in elf_machine_rela() Date: Fri, 31 Oct 2014 23:33:51 +0200 Message-Id: <1414791231-30990-1-git-send-email-aaro.koskinen@iki.fi> If sym_map in elf_machine_rela() is NULL, some switch cases in theory could try to dereference it. Avoid those. This fixes the following build failure with GCC 4.9.2: hppa-linux-gnu-gcc -nostdlib -nostartfiles -r -o /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/librtld.map.o '-Wl,-(' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/home/aaro/los/work/parisc/glibc-2.20-build/default/elf/librtld.mapT /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a(dl-addr.os): In function `_dl_addr_inside_object': /home/aaro/git/glibc/elf/dl-addr.c:152: multiple definition of `_dl_addr_inside_object' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os:(.text+0x8b8): first defined here /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a(init-first.os):(.data+0x0): multiple definition of `__libc_multiple_libcs' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os:(.bss+0x7c): first defined here /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a(_itoa.os): In function `_itoa': /home/aaro/git/glibc/stdio-common/_itoa.c:199: multiple definition of `_itoa' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os:(.text+0x5b8): first defined here The build failure is triggered in GCC 4.9 due to "Isolate erroneous paths optimization". References: https://sourceware.org/ml/libc-alpha/2013-11/msg00291.html https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63691 2014-10-31 Aaro Koskinen * sysdeps/hppa/dl-machine.h: Avoid NULL dereference of sym_map in elf_machine_rela(). --- sysdeps/hppa/dl-machine.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h index 9c7471e..6043753 100644 --- a/sysdeps/hppa/dl-machine.h +++ b/sysdeps/hppa/dl-machine.h @@ -587,6 +587,8 @@ elf_machine_rela (struct link_map *map, break; case R_PARISC_DIR21L: + if (sym_map == NULL) + break; { unsigned int insn = *(unsigned int *)reloc_addr; value = sym_map->l_addr + sym->st_value @@ -598,6 +600,8 @@ elf_machine_rela (struct link_map *map, return; case R_PARISC_DIR14R: + if (sym_map == NULL) + break; { unsigned int insn = *(unsigned int *)reloc_addr; value = ((sym_map->l_addr + sym->st_value) & 0x7ff) @@ -686,7 +690,8 @@ elf_machine_rela (struct link_map *map, #if defined USE_TLS && (!defined RTLD_BOOTSTRAP) case R_PARISC_TLS_DTPMOD32: - value = sym_map->l_tls_modid; + if (sym_map != NULL) + value = sym_map->l_tls_modid; break; case R_PARISC_TLS_DTPOFF32: @@ -698,7 +703,7 @@ elf_machine_rela (struct link_map *map, case R_PARISC_TLS_TPREL32: /* The offset is negative, forward from the thread pointer */ - if (sym != NULL) + if (sym != NULL && sym_map != NULL) { CHECK_STATIC_TLS (map, sym_map); value = sym_map->l_tls_offset + sym->st_value + reloc->r_addend;