tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: dlopen interception on libasan
In article <583EE75A.8050205%netbsd.org@localhost>,
Nick Hudson <skrll%netbsd.org@localhost> wrote:
>On 11/30/16 14:37, Christos Zoulas wrote:
>> On Nov 30, 7:34am, skrll%netbsd.org@localhost (Nick Hudson) wrote:
>>
>
>[incorrect test deleted]
>
>> You did not define dlopen() in your own shared object; libasan needs to
>> do that to override the default definition. This is not the right test.
>
>OK, so... add something like
>
>https://nxr.netbsd.org/xref/src/libexec/ld.elf_so/symbol.c#565
>
>to
>
> https://nxr.netbsd.org/xref/src/libexec/ld.elf_so/rtld.c#1125
>
You mean changing the behavior of RTLD_NEXT, to look at the dynamic linker
first? I think I like your idea better since it hides the dlopen from ld.so
implementation detail. What do others think?
christos
Index: rtld.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.178
diff -u -u -r1.178 rtld.c
--- rtld.c 24 May 2016 20:32:33 -0000 1.178
+++ rtld.c 30 Nov 2016 15:07:03 -0000
@@ -1123,6 +1123,17 @@
break;
case (intptr_t)RTLD_NEXT: /* Objects after callers */
+ /*
+ * Emulate the lookup path for the default symbol
+ * search to resolve dlopen and friends from rtld
+ */
+ def = _rtld_symlook_obj(name, hash, &_rtld_objself,
+ flags, ventry);
+ if (def != NULL && _rtld_is_exported(def)) {
+ defobj = &_rtld_objself;
+ break;
+ }
+ /* did not find it in rtld, proceed as usual */
obj = obj->next;
/*FALLTHROUGH*/
Index: rtld.h
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.h,v
retrieving revision 1.125
diff -u -u -r1.125 rtld.h
--- rtld.h 14 Jun 2016 13:06:41 -0000 1.125
+++ rtld.h 30 Nov 2016 15:07:03 -0000
@@ -416,6 +416,7 @@
Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int);
/* symbol.c */
+bool _rtld_is_exported(const Elf_Sym *);
unsigned long _rtld_elf_hash(const char *);
const Elf_Sym *_rtld_symlook_obj(const char *, unsigned long,
const Obj_Entry *, u_int, const Ver_Entry *);
Index: symbol.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/symbol.c,v
retrieving revision 1.65
diff -u -u -r1.65 symbol.c
--- symbol.c 10 Aug 2014 23:35:26 -0000 1.65
+++ symbol.c 30 Nov 2016 15:07:04 -0000
@@ -80,7 +80,7 @@
return false;
}
-static bool
+bool
_rtld_is_exported(const Elf_Sym *def)
{
static const fptr_t _rtld_exports[] = {
Home |
Main Index |
Thread Index |
Old Index