> From: "Theo de Raadt" <dera...@openbsd.org> > Date: Sun, 03 Mar 2024 08:20:33 -0700 > > It almost feels as if libc.so equivelancy should be closer to > _dl_find_shlib(), > > (in particular, meaning searchpath[0] in _dl_find_shlib() coming > from lpath in _dl_load_shlib() > > Is testing for this in loader.c not the right place, and that > code should be moved to a deeper place, reached by more variations?
Yes, the diff below would make more sense. Anyway, probably something to do after the next release? > The thing that would break is if someone dlopen() of > "libc.so.not-a-system-library", and that is a real .so but not a real > full libc; imagine it just contains 1 stub function which isn't a > system call. it would now fail to load that stub function. So maybe > it is better if we force the applications to request "libc.so". Index: libexec/ld.so/library_subr.c =================================================================== RCS file: /cvs/src/libexec/ld.so/library_subr.c,v retrieving revision 1.55 diff -u -p -r1.55 library_subr.c --- libexec/ld.so/library_subr.c 27 Apr 2023 12:27:56 -0000 1.55 +++ libexec/ld.so/library_subr.c 3 Mar 2024 16:44:33 -0000 @@ -321,6 +321,11 @@ _dl_load_shlib(const char *libname, elf_ try_any_minor = 0; ignore_hints = 0; + if (_dl_strncmp(libname, "libc.so.", 8) == 0) { + if (_dl_libcname) + libname = _dl_libcname; + } + if (_dl_strchr(libname, '/')) { char *paths[2]; char *lpath, *lname; Index: libexec/ld.so/loader.c =================================================================== RCS file: /cvs/src/libexec/ld.so/loader.c,v retrieving revision 1.223 diff -u -p -r1.223 loader.c --- libexec/ld.so/loader.c 22 Jan 2024 02:08:31 -0000 1.223 +++ libexec/ld.so/loader.c 3 Mar 2024 16:44:33 -0000 @@ -406,10 +406,6 @@ _dl_load_dep_libs(elf_object_t *object, liblist[randomlist[loop]].dynp->d_un.d_val; DL_DEB(("loading: %s required by %s\n", libname, dynobj->load_name)); - if (_dl_strncmp(libname, "libc.so.", 8) == 0) { - if (_dl_libcname) - libname = _dl_libcname; - } depobj = _dl_load_shlib(libname, dynobj, OBJTYPE_LIB, depflags, nodelete); if (depobj == 0) { Index: libexec/ld.so/resolve.h =================================================================== RCS file: /cvs/src/libexec/ld.so/resolve.h,v retrieving revision 1.107 diff -u -p -r1.107 resolve.h --- libexec/ld.so/resolve.h 16 Jan 2024 19:07:31 -0000 1.107 +++ libexec/ld.so/resolve.h 3 Mar 2024 16:44:33 -0000 @@ -376,6 +376,7 @@ extern char **_dl_libpath; extern int _dl_bindnow; extern int _dl_traceld; extern int _dl_debug; +extern const char *_dl_libcname; extern char *_dl_preload; extern char *_dl_tracefmt1;