tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: dlopen interception on libasan



On 11/30/16 15:08, Christos Zoulas wrote:
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.


More this.. (not compile tested)

i.e. should the dynamic linker be searched last and only if we found a weak symbol

Nick
Index: rtld.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.178
diff -u -p -r1.178 rtld.c
--- rtld.c	24 May 2016 20:32:33 -0000	1.178
+++ rtld.c	30 Nov 2016 15:28:47 -0000
@@ -1134,6 +1134,22 @@ do_dlsym(void *handle, const char *name,
 					break;
 				}
 			}
+			/*
+			 * Search the dynamic linker itself, and possibly resolve the
+			 * symbol from there.  This is how the application links to
+			 * dynamic linker services such as dlopen.  Only the values listed
+			 * in the "_rtld_exports" array can be resolved from the dynamic
+			 * linker.
+			 */
+			if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) {
+				rdbg(("Search the dynamic linker itself."));
+				symp = _rtld_symlook_obj(name, hash, &_rtld_objself, flags,
+				    ventry);
+				if (symp != NULL && _rtld_is_exported(symp)) {
+					def = symp;
+					defobj = &_rtld_objself;
+				}
+			}
 			break;
 
 		case (intptr_t)RTLD_DEFAULT:


Home | Main Index | Thread Index | Old Index