From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1039) id E9BAB3858439; Tue, 19 Jul 2022 16:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9BAB3858439 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: H.J. Lu To: bfd-cvs@sourceware.org Subject: [binutils-gdb/binutils-2_38-branch] x86: Properly check invalid relocation against protected symbol X-Act-Checkin: binutils-gdb X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/binutils-2_38-branch X-Git-Oldrev: 730a2af40f3e17bb168e29817b40f00a2c90bd56 X-Git-Newrev: 19892fedb7b7e9129d76a0c48b26721d4973fb20 Message-Id: <20220719161232.E9BAB3858439@sourceware.org> Date: Tue, 19 Jul 2022 16:12:32 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jul 2022 16:12:33 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D19892fedb7b7= e9129d76a0c48b26721d4973fb20 commit 19892fedb7b7e9129d76a0c48b26721d4973fb20 Author: H.J. Lu Date: Mon Jul 18 11:44:32 2022 -0700 x86: Properly check invalid relocation against protected symbol =20 Only check invalid relocation against protected symbol defined in shared object. =20 bfd/ =20 PR ld/29377 * elf32-i386.c (elf_i386_scan_relocs): Only check invalid relocation against protected symbol defined in shared object. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. =20 ld/ =20 PR ld/29377 * testsuite/ld-elf/linux-x86.exp: Run PR ld/29377 tests. * testsuite/ld-elf/pr29377a.c: New file. * testsuite/ld-elf/pr29377b.c: Likewise. =20 (cherry picked from commit bd0736124c20950ac353f01e5029b7cb5d8a7010) =20 ld: Pass -nostdlib to compiler with -r =20 Pass -nostdlib to compiler with -r to avoid unnecessary .o file and libraries. =20 PR ld/29377 * testsuite/ld-elf/linux-x86.exp: Pass -nostdlib with -r. =20 (cherry picked from commit 76e4fa70e79ee959c0e11eaacd4cf863291b1ddb) Diff: --- bfd/elf32-i386.c | 2 ++ bfd/elf64-x86-64.c | 2 ++ ld/testsuite/ld-elf/linux-x86.exp | 16 ++++++++++++++++ ld/testsuite/ld-elf/pr29377a.c | 5 +++++ ld/testsuite/ld-elf/pr29377b.c | 10 ++++++++++ 5 files changed, 35 insertions(+) diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 3bc710096aa..94a23bf30a0 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1811,6 +1811,8 @@ elf_i386_scan_relocs (bfd *abfd, if (h->pointer_equality_needed && h->type =3D=3D STT_FUNC && eh->def_protected + && !SYMBOL_DEFINED_NON_SHARED_P (h) + && h->def_dynamic && elf_has_indirect_extern_access (h->root.u.def.section->owner)) { /* Disallow non-canonical reference to canonical diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 16229b39dca..970379dea3b 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -2254,6 +2254,8 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_in= fo *info, if (h->pointer_equality_needed && h->type =3D=3D STT_FUNC && eh->def_protected + && !SYMBOL_DEFINED_NON_SHARED_P (h) + && h->def_dynamic && elf_has_indirect_extern_access (h->root.u.def.section->owner)) { /* Disallow non-canonical reference to canonical diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-= x86.exp index 2e0cbd37f17..a3eb56809b1 100644 --- a/ld/testsuite/ld-elf/linux-x86.exp +++ b/ld/testsuite/ld-elf/linux-x86.exp @@ -134,6 +134,22 @@ run_cc_link_tests [list \ {{readelf {--dyn-syms -W} pr28158.rd} {nm -D pr28158.nd}} \ "pr28158" \ ] \ + [list \ + "Build pr29377.o" \ + "-r -nostdlib -Wl,-z,noexecstack" \ + "" \ + {pr29377a.c indirect-extern-access.S} \ + {} \ + "pr29377.o" \ + ] \ + [list \ + "Build pr29377" \ + "$NOPIE_LDFLAGS tmpdir/pr29377.o" \ + "-fPIC" \ + {pr29377b.c} \ + {} \ + "pr29377" \ + ] \ ] =20 run_ld_link_exec_tests [list \ diff --git a/ld/testsuite/ld-elf/pr29377a.c b/ld/testsuite/ld-elf/pr29377a.c new file mode 100644 index 00000000000..41d9545e3bf --- /dev/null +++ b/ld/testsuite/ld-elf/pr29377a.c @@ -0,0 +1,5 @@ +__attribute__ ((visibility ("protected"))) +void +foo (void) +{ +} diff --git a/ld/testsuite/ld-elf/pr29377b.c b/ld/testsuite/ld-elf/pr29377b.c new file mode 100644 index 00000000000..3cf163b25b4 --- /dev/null +++ b/ld/testsuite/ld-elf/pr29377b.c @@ -0,0 +1,10 @@ +extern void foo (void); + +void (*foo_p) (void); + +int +main () +{ + foo_p =3D foo; + return 0; +}