From: Fangrui Song <maskray@google.com>
To: libc-alpha@sourceware.org
Subject: [PATCH] elf: Remove fallback to the start of DT_STRTAB for dladdr
Date: Sun, 1 May 2022 14:50:49 -0700 [thread overview]
Message-ID: <20220501215049.2143788-1-maskray@google.com> (raw)
When neither DT_HASH nor DT_GNU_HASH is present, the code scans
[DT_SYMTAB, DT_STRTAB). However, there is no guarantee that .dynstr
immediately follows .dynsym (e.g. lld typically places .gnu.version
after .dynsym).
In the absence of a hash table, symbol lookup will always fail
(map->l_nbuckets == 0), so it seems appropriate to just bail out.
---
elf/dl-addr.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/elf/dl-addr.c b/elf/dl-addr.c
index e3c5598e1a..6f5f8eac5c 100644
--- a/elf/dl-addr.c
+++ b/elf/dl-addr.c
@@ -71,18 +71,10 @@ determine_info (const ElfW(Addr) addr, struct link_map *match, Dl_info *info,
}
}
}
- else
+ else if (match->l_info[DT_HASH] != NULL)
{
- const ElfW(Sym) *symtabend;
- if (match->l_info[DT_HASH] != NULL)
- symtabend = (symtab
- + ((Elf_Symndx *) D_PTR (match, l_info[DT_HASH]))[1]);
- else
- /* There is no direct way to determine the number of symbols in the
- dynamic symbol table and no hash table is present. The ELF
- binary is ill-formed but what shall we do? Use the beginning of
- the string table which generally follows the symbol table. */
- symtabend = (const ElfW(Sym) *) strtab;
+ const ElfW (Sym) *symtabend
+ = (symtab + ((Elf_Symndx *) D_PTR (match, l_info[DT_HASH]))[1]);
for (; (void *) symtab < (void *) symtabend; ++symtab)
if ((ELFW(ST_BIND) (symtab->st_info) == STB_GLOBAL
@@ -96,6 +88,7 @@ determine_info (const ElfW(Addr) addr, struct link_map *match, Dl_info *info,
&& symtab->st_name < strtabsize)
matchsym = (ElfW(Sym) *) symtab;
}
+ /* In the absence of a hash table, as if the object has no symbol. */
if (mapp)
*mapp = match;
--
2.36.0.464.gb9c8b46e94-goog
next reply other threads:[~2022-05-01 21:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-01 21:50 Fangrui Song [this message]
2022-05-02 6:56 ` Florian Weimer
2022-05-02 7:04 ` Fangrui Song
2022-05-02 7:21 ` Florian Weimer
2022-05-02 7:30 ` Fangrui Song
2022-05-02 8:26 ` Florian Weimer
2022-05-02 8:34 ` Florian Weimer
2022-05-02 16:06 ` Fangrui Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220501215049.2143788-1-maskray@google.com \
--to=maskray@google.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).