diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2023-08-15 06:26:35 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2023-08-15 06:26:35 +0000 |
commit | c3afb56359011bcb089e92c3ecf863467c31e5fe (patch) | |
tree | 707b737d4db283d0943b7f7c0ec22a7dbd3b40a3 /libexec | |
parent | 275fac441839da83552c2608b542ff82b462526d (diff) |
Improve handling of dlopen(RTLD_TRACE) aka ldd, of a library that
is already loaded:
* add a 'trace' argument to _dl_show_objects() and exit the
walk-the-objects loop if you hit that traced object
* in dlopen(), pass the trace object to _dl_show_objects()
* also, invoke _dl_show_objects() + exit if the object was
already opened
* pass NULL to _dl_show_objects() for all the other calls
* oh hey, _dl_tracelib is now superfluous: _dl_show_objects()
should do the walk-the-objects loop only if trace is not NULL.
Problem noted by gnezdo@
ok millert@
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/dlfcn.c | 22 | ||||
-rw-r--r-- | libexec/ld.so/loader.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/resolve.h | 5 | ||||
-rw-r--r-- | libexec/ld.so/util.h | 3 |
4 files changed, 21 insertions, 13 deletions
diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c index 3b3dbdb8360..2aee958d316 100644 --- a/libexec/ld.so/dlfcn.c +++ b/libexec/ld.so/dlfcn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dlfcn.c,v 1.114 2023/07/08 14:09:43 jasper Exp $ */ +/* $OpenBSD: dlfcn.c,v 1.115 2023/08/15 06:26:34 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -39,7 +39,6 @@ #include "archdep.h" int _dl_errno; -static int _dl_tracelib; static int _dl_real_close(void *handle); static lock_cb *_dl_thread_fnc = NULL; @@ -72,7 +71,6 @@ dlopen(const char *libname, int flags) if ((flags & RTLD_TRACE) == RTLD_TRACE) { _dl_traceld = 1; - _dl_tracelib = 1; } DL_DEB(("dlopen: loading: %s\n", libname)); @@ -110,6 +108,11 @@ dlopen(const char *libname, int flags) /* if opened but grpsym_vec has not been filled in */ if (object->grpsym_vec.len == 0) _dl_cache_grpsym_list_setup(object); + if (_dl_traceld) { + _dl_show_objects(object); + _dl_unload_shlib(object); + _dl_exit(0); + } goto loaded; } @@ -126,7 +129,7 @@ dlopen(const char *libname, int flags) int err; DL_DEB(("tail %s\n", object->load_name )); if (_dl_traceld) { - _dl_show_objects(); + _dl_show_objects(object); _dl_unload_shlib(object); _dl_exit(0); } @@ -250,7 +253,7 @@ dlctl(void *handle, int command, void *data) break; } case 0x20: - _dl_show_objects(); + _dl_show_objects(NULL); retval = 0; break; case 0x21: @@ -486,7 +489,7 @@ _dl_tracefmt(int fd, elf_object_t *object, const char *fmt1, const char *fmt2, } void -_dl_show_objects(void) +_dl_show_objects(elf_object_t *trace) { elf_object_t *object; char *objtypename; @@ -514,12 +517,15 @@ _dl_show_objects(void) _dl_dprintf(outputfd, "\tStart %s End %s Type Open Ref GrpRef Name\n", pad, pad); - if (_dl_tracelib) { - for (; object != NULL; object = object->next) + if (trace != NULL) { + for (; object != NULL; object = object->next) { + if (object == trace) + break; if (object->obj_type == OBJTYPE_LDR) { object = object->next; break; } + } } for (; object != NULL; object = object->next) { diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index 7a32013d948..52e7b03e945 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.213 2023/07/08 14:09:43 jasper Exp $ */ +/* $OpenBSD: loader.c,v 1.214 2023/08/15 06:26:34 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -701,7 +701,7 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) if (_dl_debug || _dl_traceld) { if (_dl_traceld) _dl_pledge("stdio rpath", NULL); - _dl_show_objects(); + _dl_show_objects(NULL); } DL_DEB(("dynamic loading done, %s.\n", diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 19e8bea4b98..d32279d15f8 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.104 2023/01/29 20:30:56 gnezdo Exp $ */ +/* $OpenBSD: resolve.h,v 1.105 2023/08/15 06:26:34 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -347,6 +347,9 @@ void _dl_trace_setup(char **) __boot; void _dl_trace_object_setup(elf_object_t *); int _dl_trace_plt(const elf_object_t *, const char *); +/* dlfcn.c */ +void _dl_show_objects(elf_object_t *_object); + /* tib.c */ void _dl_allocate_tls_offsets(void) __boot; void _dl_allocate_first_tib(void) __boot; diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h index d2f47baf1d7..6a91472028c 100644 --- a/libexec/ld.so/util.h +++ b/libexec/ld.so/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.38 2023/01/29 20:30:21 gnezdo Exp $ */ +/* $OpenBSD: util.h,v 1.39 2023/08/15 06:26:34 guenther Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <millert@openbsd.org> @@ -59,7 +59,6 @@ size_t _dl_strlcat(char *dst, const char *src, size_t siz); void _dl_printf(const char *fmt, ...); void _dl_vprintf(const char *fmt, va_list ap); void _dl_dprintf(int, const char *fmt, ...); -void _dl_show_objects(void); void _dl_arc4randombuf(void *, size_t); u_int32_t _dl_arc4random(void); ssize_t _dl_write(int fd, const char* buf, size_t len); |