From owner-svn-src-all@freebsd.org Mon Feb 5 23:35:35 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C8103ED7C8C; Mon, 5 Feb 2018 23:35:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 77B188F9D5; Mon, 5 Feb 2018 23:35:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 68FCE7B56; Mon, 5 Feb 2018 23:35:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w15NZYBg053649; Mon, 5 Feb 2018 23:35:34 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w15NZYpI053647; Mon, 5 Feb 2018 23:35:34 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201802052335.w15NZYpI053647@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Mon, 5 Feb 2018 23:35:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328911 - in head: stand/common sys/kern X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: in head: stand/common sys/kern X-SVN-Commit-Revision: 328911 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Feb 2018 23:35:35 -0000 Author: jhb Date: Mon Feb 5 23:35:33 2018 New Revision: 328911 URL: https://svnweb.freebsd.org/changeset/base/328911 Log: Ignore relocation tables for non-memory-resident sections. As a followup to r328101, ignore relocation tables for ELF object sections that are not memory resident. For modules loaded by the loader, ignore relocation tables whose associated section was not loaded by the loader (sh_addr is zero). For modules loaded at runtime via kldload(2), ignore relocation tables whose associated section is not marked with SHF_ALLOC. Reported by: Mori Hiroki , adrian Tested on: mips, mips64 MFC after: 1 month Sponsored by: DARPA / AFRL Modified: head/stand/common/load_elf_obj.c head/sys/kern/link_elf_obj.c Modified: head/stand/common/load_elf_obj.c ============================================================================== --- head/stand/common/load_elf_obj.c Mon Feb 5 23:29:50 2018 (r328910) +++ head/stand/common/load_elf_obj.c Mon Feb 5 23:35:33 2018 (r328911) @@ -282,6 +282,8 @@ __elfN(obj_loadimage)(struct preloaded_file *fp, elf_f switch (shdr[i].sh_type) { case SHT_REL: case SHT_RELA: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; lastaddr = roundup(lastaddr, shdr[i].sh_addralign); shdr[i].sh_addr = (Elf_Addr)lastaddr; lastaddr += shdr[i].sh_size; Modified: head/sys/kern/link_elf_obj.c ============================================================================== --- head/sys/kern/link_elf_obj.c Mon Feb 5 23:29:50 2018 (r328910) +++ head/sys/kern/link_elf_obj.c Mon Feb 5 23:35:33 2018 (r328911) @@ -272,9 +272,17 @@ link_elf_link_preload(linker_class_t cls, const char * symstrindex = shdr[i].sh_link; break; case SHT_REL: + /* + * Ignore relocation tables for sections not + * loaded by the loader. + */ + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->nreltab++; break; case SHT_RELA: + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->nrelatab++; break; } @@ -398,12 +406,16 @@ link_elf_link_preload(linker_class_t cls, const char * pb++; break; case SHT_REL: + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->reltab[rl].rel = (Elf_Rel *)shdr[i].sh_addr; ef->reltab[rl].nrel = shdr[i].sh_size / sizeof(Elf_Rel); ef->reltab[rl].sec = shdr[i].sh_info; rl++; break; case SHT_RELA: + if (shdr[shdr[i].sh_info].sh_addr == 0) + break; ef->relatab[ra].rela = (Elf_Rela *)shdr[i].sh_addr; ef->relatab[ra].nrela = shdr[i].sh_size / sizeof(Elf_Rela); @@ -620,9 +632,17 @@ link_elf_load_file(linker_class_t cls, const char *fil symstrindex = shdr[i].sh_link; break; case SHT_REL: + /* + * Ignore relocation tables for unallocated + * sections. + */ + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->nreltab++; break; case SHT_RELA: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->nrelatab++; break; case SHT_STRTAB: @@ -880,6 +900,8 @@ link_elf_load_file(linker_class_t cls, const char *fil pb++; break; case SHT_REL: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->reltab[rl].rel = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK); ef->reltab[rl].nrel = shdr[i].sh_size / sizeof(Elf_Rel); @@ -898,6 +920,8 @@ link_elf_load_file(linker_class_t cls, const char *fil rl++; break; case SHT_RELA: + if ((shdr[shdr[i].sh_info].sh_flags & SHF_ALLOC) == 0) + break; ef->relatab[ra].rela = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK); ef->relatab[ra].nrela =