From 592d5c75392e1da170050a4999af0618c4865aed Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 26 Sep 2017 13:49:48 -0700 Subject: Skip PT_DYNAMIC segment with p_filesz == 0 [BZ #22101] ELF objects generated with "objcopy --only-keep-debug" have Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align DYNAMIC 0x0+e28 0x0+200e40 0x0+200e40 0x0+ 0x0+1a0 RW 0x8 with 0 file size. ld.so should skip such PT_DYNAMIC segments. Without a PT_DYNAMIC segment the loading of the shared object will fail, and therefore ldd on such objects will also fail instead of crashing. This provides better diagnostics for tooling that is attempting to inspect the invalid shared objects which may just contain debug information. [BZ #22101] * elf/Makefile (tests): Add tst-debug1. ($(objpfx)tst-debug1): New. ($(objpfx)tst-debug1.out): Likewise. ($(objpfx)tst-debug1mod1.so): Likewise. * elf/dl-load.c (_dl_map_object_from_fd): Skip PT_DYNAMIC segment with p_filesz == 0. * elf/tst-debug1.c: New file. Reviewed-by: Carlos O'Donell --- elf/tst-debug1.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 elf/tst-debug1.c (limited to 'elf/tst-debug1.c') diff --git a/elf/tst-debug1.c b/elf/tst-debug1.c new file mode 100644 index 0000000000..aa2f4886bf --- /dev/null +++ b/elf/tst-debug1.c @@ -0,0 +1,34 @@ +/* Unit test for dlopen on ELF object from "objcopy --only-keep-debug". + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +static int +do_test (void) +{ + void *h = dlopen ("tst-debug1mod1.so", RTLD_LAZY); + if (h != NULL) + { + puts ("shouldn't load tst-debug1mod1.so"); + return 1; + } + return 0; +} + +#include -- cgit v1.2.3