From a3fedff4d1373f9f3dc6959857a5d8ef2fb85eba Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 6 May 2013 19:59:29 +0000 Subject: [PATCH] Fixed handling of DT_SONAME: - add function to add name aliases for shared libraries loaded XXX[1]: we don't add a name during load time, only when DT_SONAME is present. - search already loaded objects in load_by_name for an already loaded object that matches our name and return it. - add missing initialization and cleanup for obj->names XXX[2]: should we make them SIMPLEQ? - Add XXX in rtld.c about getting the name of an object. NB: This makes the jdk work again without resorting to a hack of putting the build path of libjvm.so into the run path (which is a security problem). XXX: Pullup-6? --- libexec/ld.elf_so/headers.c | 11 ++++++++--- libexec/ld.elf_so/load.c | 12 +++++++++--- libexec/ld.elf_so/map_object.c | 10 ++++++++-- libexec/ld.elf_so/rtld.c | 5 +++-- libexec/ld.elf_so/rtld.h | 3 ++- libexec/ld.elf_so/symver.c | 18 ++++++++++++++++-- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/libexec/ld.elf_so/headers.c b/libexec/ld.elf_so/headers.c index 8b57c75f8d07..42241ca14901 100644 --- a/libexec/ld.elf_so/headers.c +++ b/libexec/ld.elf_so/headers.c @@ -1,4 +1,4 @@ -/* $NetBSD: headers.c,v 1.50 2013/05/06 08:02:20 skrll Exp $ */ +/* $NetBSD: headers.c,v 1.51 2013/05/06 19:59:29 christos Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include #ifndef lint -__RCSID("$NetBSD: headers.c,v 1.50 2013/05/06 08:02:20 skrll Exp $"); +__RCSID("$NetBSD: headers.c,v 1.51 2013/05/06 19:59:29 christos Exp $"); #endif /* not lint */ #include @@ -68,6 +68,7 @@ _rtld_digest_dynamic(const char *execname, Obj_Entry *obj) { Elf_Dyn *dynp; Needed_Entry **needed_tail = &obj->needed; + const Elf_Dyn *dyn_soname = NULL; const Elf_Dyn *dyn_rpath = NULL; bool use_pltrel = false; bool use_pltrela = false; @@ -222,7 +223,7 @@ _rtld_digest_dynamic(const char *execname, Obj_Entry *obj) break; case DT_SONAME: - /* Not used by the dynamic linker. */ + dyn_soname = dynp; break; case DT_INIT: @@ -358,6 +359,10 @@ _rtld_digest_dynamic(const char *execname, Obj_Entry *obj) _rtld_add_paths(execname, &obj->rpaths, obj->strtab + dyn_rpath->d_un.d_val); } + if (dyn_soname != NULL) { + _rtld_object_add_name(obj, obj->strtab + + dyn_soname->d_un.d_val); + } } /* diff --git a/libexec/ld.elf_so/load.c b/libexec/ld.elf_so/load.c index 02653c78ddb1..8a25eb663134 100644 --- a/libexec/ld.elf_so/load.c +++ b/libexec/ld.elf_so/load.c @@ -1,4 +1,4 @@ -/* $NetBSD: load.c,v 1.43 2013/05/06 08:02:20 skrll Exp $ */ +/* $NetBSD: load.c,v 1.44 2013/05/06 19:59:30 christos Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include #ifndef lint -__RCSID("$NetBSD: load.c,v 1.43 2013/05/06 08:02:20 skrll Exp $"); +__RCSID("$NetBSD: load.c,v 1.44 2013/05/06 19:59:30 christos Exp $"); #endif /* not lint */ #include @@ -199,7 +199,7 @@ _rtld_load_by_name(const char *name, Obj_Entry *obj, Needed_Entry **needed, int flags) { Library_Xform *x = _rtld_xforms; - Obj_Entry *o = NULL; + Obj_Entry *o; size_t j; ssize_t i; bool got = false; @@ -210,6 +210,12 @@ _rtld_load_by_name(const char *name, Obj_Entry *obj, Needed_Entry **needed, } val; dbg(("load by name %s %p", name, x)); + for (o = _rtld_objlist->next; o != NULL; o = o->next) + if (_rtld_object_match_name(o, name)) { + (*needed)->obj = o; + return true; + } + for (; x; x = x->next) { if (strcmp(x->name, name) != 0) continue; diff --git a/libexec/ld.elf_so/map_object.c b/libexec/ld.elf_so/map_object.c index 3571cc2e3286..01b6bae984dd 100644 --- a/libexec/ld.elf_so/map_object.c +++ b/libexec/ld.elf_so/map_object.c @@ -1,4 +1,4 @@ -/* $NetBSD: map_object.c,v 1.48 2013/05/06 08:02:20 skrll Exp $ */ +/* $NetBSD: map_object.c,v 1.49 2013/05/06 19:59:30 christos Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -34,7 +34,7 @@ #include #ifndef lint -__RCSID("$NetBSD: map_object.c,v 1.48 2013/05/06 08:02:20 skrll Exp $"); +__RCSID("$NetBSD: map_object.c,v 1.49 2013/05/06 19:59:30 christos Exp $"); #endif /* not lint */ #include @@ -432,6 +432,11 @@ _rtld_obj_free(Obj_Entry *obj) obj->needed = needed->next; xfree(needed); } + while (!STAILQ_EMPTY(&obj->names)) { + Name_Entry *entry = STAILQ_FIRST(&obj->names); + STAILQ_REMOVE_HEAD(&obj->names, link); + free(entry); + } while ((elm = SIMPLEQ_FIRST(&obj->dldags)) != NULL) { SIMPLEQ_REMOVE_HEAD(&obj->dldags, link); xfree(elm); @@ -454,6 +459,7 @@ _rtld_obj_new(void) Obj_Entry *obj; obj = CNEW(Obj_Entry); + STAILQ_INIT(&obj->names); SIMPLEQ_INIT(&obj->dldags); SIMPLEQ_INIT(&obj->dagmembers); return obj; diff --git a/libexec/ld.elf_so/rtld.c b/libexec/ld.elf_so/rtld.c index 31dcf2dd6987..9b34667f4d1e 100644 --- a/libexec/ld.elf_so/rtld.c +++ b/libexec/ld.elf_so/rtld.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.c,v 1.165 2013/05/06 08:02:20 skrll Exp $ */ +/* $NetBSD: rtld.c,v 1.166 2013/05/06 19:59:30 christos Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include #ifndef lint -__RCSID("$NetBSD: rtld.c,v 1.165 2013/05/06 08:02:20 skrll Exp $"); +__RCSID("$NetBSD: rtld.c,v 1.166 2013/05/06 19:59:30 christos Exp $"); #endif /* not lint */ #include @@ -1372,6 +1372,7 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *pa for (obj = _rtld_objlist; obj != NULL; obj = obj->next) { phdr_info.dlpi_addr = (Elf_Addr)obj->relocbase; + /* XXX: wrong but not fixing it yet */ phdr_info.dlpi_name = STAILQ_FIRST(&obj->names) ? STAILQ_FIRST(&obj->names)->name : obj->path; phdr_info.dlpi_phdr = obj->phdr; diff --git a/libexec/ld.elf_so/rtld.h b/libexec/ld.elf_so/rtld.h index 47e34bdcf7fc..968f8914c644 100644 --- a/libexec/ld.elf_so/rtld.h +++ b/libexec/ld.elf_so/rtld.h @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.h,v 1.114 2013/05/06 08:02:20 skrll Exp $ */ +/* $NetBSD: rtld.h,v 1.115 2013/05/06 19:59:30 christos Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -425,6 +425,7 @@ void _rtld_combreloc_reset(const Obj_Entry *); #endif /* symver.c */ +void _rtld_object_add_name(Obj_Entry *, const char *); int _rtld_object_match_name(const Obj_Entry *, const char *); int _rtld_verify_object_versions(Obj_Entry *); diff --git a/libexec/ld.elf_so/symver.c b/libexec/ld.elf_so/symver.c index 4d4e463647a9..c8c795ea2beb 100644 --- a/libexec/ld.elf_so/symver.c +++ b/libexec/ld.elf_so/symver.c @@ -1,4 +1,4 @@ -/* $NetBSD: symver.c,v 1.1 2011/06/25 05:45:12 nonaka Exp $ */ +/* $NetBSD: symver.c,v 1.2 2013/05/06 19:59:30 christos Exp $ */ /*- * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra. @@ -59,7 +59,7 @@ */ #include -__RCSID("$NetBSD: symver.c,v 1.1 2011/06/25 05:45:12 nonaka Exp $"); +__RCSID("$NetBSD: symver.c,v 1.2 2013/05/06 19:59:30 christos Exp $"); #include #include @@ -68,6 +68,20 @@ __RCSID("$NetBSD: symver.c,v 1.1 2011/06/25 05:45:12 nonaka Exp $"); #include "debug.h" #include "rtld.h" +void +_rtld_object_add_name(Obj_Entry *obj, const char *name) +{ + Name_Entry *entry; + size_t len; + + len = strlen(name); + entry = xmalloc(sizeof(Name_Entry) + len); + + if (entry != NULL) { + strcpy(entry->name, name); + STAILQ_INSERT_TAIL(&obj->names, entry, link); + } +} int _rtld_object_match_name(const Obj_Entry *obj, const char *name)