This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
PATCH: BZ #14370: Check mismatched TLS/non-TLS symbols
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 4 Sep 2012 15:19:20 -0700
- Subject: PATCH: BZ #14370: Check mismatched TLS/non-TLS symbols
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
Mismatched TLS/non-TLS symbols from poorly built DSO may crash ld.so.
This patch adds check for mismatched TLS/non-TLS symbols. Performance
impact is tool small to be visible for glibc build/check on ia32, x86-64
and x32. OK to install?
Thanks.
H.J.
---
ChangeLog | 6 ++++++
elf/dl-lookup.c | 25 +++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 5411be3..838c607 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-09-04 H.J. Lu <hongjiu.lu@intel.com>
+
+ [BZ #14370]
+ * elf/dl-lookup.c (_dl_lookup_symbol_x): Check mismatched
+ TLS/non-TLS symbols.
+
2012-09-04 Florian Weimer <fweimer@redhat.com>
* stdlib/tst-secure-getenv.c (alternative_main): Only warn on SGID
diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
index e7f7148..85bfb51 100644
--- a/elf/dl-lookup.c
+++ b/elf/dl-lookup.c
@@ -840,6 +840,31 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map,
? undef_map->l_scope : symbol_scope,
version, type_class, flags, skip_map);
+ if (__builtin_expect (*ref != NULL, 1)
+ && (__builtin_expect (ELFW(ST_TYPE) (current_value.s->st_info) == STT_TLS, 0)
+ || __builtin_expect (ELFW(ST_TYPE) ((*ref)->st_info) == STT_TLS, 0))
+ && __builtin_expect (ELFW(ST_TYPE) (current_value.s->st_info) !=
+ ELFW(ST_TYPE) ((*ref)->st_info), 1))
+ {
+ const char *reference_name = undef_map ? undef_map->l_name : "";
+ const char *definition_name = (current_value.m->l_name[0]
+ ? current_value.m->l_name
+ : rtld_progname);
+ _dl_signal_cerror (0, (reference_name[0]
+ ? reference_name
+ : (rtld_progname ?: "<main program>")),
+ N_("symbol lookup error"),
+ make_string ((ELFW(ST_TYPE) ((*ref)->st_info) == STT_TLS
+ ? "TLS" : "non-TLS"),
+ " definition `", undef_name,
+ "' mismatches ",
+ (ELFW(ST_TYPE) (current_value.s->st_info) == STT_TLS
+ ? "TLS" : "non-TLS"),
+ " reference in ", definition_name));
+ *ref = NULL;
+ return 0;
+ }
+
/* The object is used. */
if (__builtin_expect (current_value.m->l_used == 0, 0))
current_value.m->l_used = 1;
--
1.7.11.4