* Re: [PATCH v7 14/16] elf: Add la_activity during application exit
@ 2021-12-27 5:13 jma14
2021-12-27 13:20 ` Adhemerval Zanella
0 siblings, 1 reply; 4+ messages in thread
From: jma14 @ 2021-12-27 5:13 UTC (permalink / raw)
To: Florian Weimer, Adhemerval Zanella; +Cc: John Mellor-Crummey, libc-alpha
On December 24, 2021 11:50:54 AM CST, Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
> * Adhemerval Zanella:
>
>> la_activity is not called during application exit, even though
>> la_objclose is.
>>
>> Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
>
> Still looks good, thanks.
I still have a concern with this patch, the included test does not
actually test the fix, it passes even without the changes in dl-fini.c.
I believe these two checks suffice to test the new functionality:
- la_objclose should be called after la_activity(LA_ACT_DELETE) for
the closed object's namespace. (Since dlclose is not used in this
test, AFAICT la_objclose is only called during program termination.)
- la_activity(LA_ACT_CONSISTENT) should be the last callback
received for every namespace.
-Jonathon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v7 14/16] elf: Add la_activity during application exit 2021-12-27 5:13 [PATCH v7 14/16] elf: Add la_activity during application exit jma14 @ 2021-12-27 13:20 ` Adhemerval Zanella 0 siblings, 0 replies; 4+ messages in thread From: Adhemerval Zanella @ 2021-12-27 13:20 UTC (permalink / raw) To: jma14, Florian Weimer; +Cc: John Mellor-Crummey, libc-alpha On 27/12/2021 02:13, jma14 wrote: > > On December 24, 2021 11:50:54 AM CST, Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> wrote: >> * Adhemerval Zanella: >> >>> la_activity is not called during application exit, even though >>> la_objclose is. >>> >>> Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. >> >> Still looks good, thanks. > > I still have a concern with this patch, the included test does not actually test the fix, it passes even without the changes in dl-fini.c. I just noticed that the audit module does not really implement the la_activity. > > I believe these two checks suffice to test the new functionality: > - la_objclose should be called after la_activity(LA_ACT_DELETE) for the closed object's namespace. (Since dlclose is not used in this test, AFAICT la_objclose is only called during program termination.) > - la_activity(LA_ACT_CONSISTENT) should be the last callback received for every namespace. Yeah, that's what I have in mind as well. I will send an updated version. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v7 00/16] Multiple rtld-audit fixes @ 2021-12-22 13:26 Adhemerval Zanella 2021-12-22 13:27 ` [PATCH v7 14/16] elf: Add la_activity during application exit Adhemerval Zanella 0 siblings, 1 reply; 4+ messages in thread From: Adhemerval Zanella @ 2021-12-22 13:26 UTC (permalink / raw) To: libc-alpha, fweimer; +Cc: John Mellor-Crummey, Ben Woodard This patchset fixes most of the rtld-audit issues brought by John Mellor-Crummey [1] while trying to use it along with the HPCToolkit. This should cover all the issues listed as 'Tier 1' [2] (the aarch64 SVE requires additional work, so it is postpone to 2.36) and also most of the 'Tier2' issue (BZ#28096 inclusive) which prevents the use of some glibc function that uses TLS internally on the audit module. There is also some point brough by John Melloc-Crummey documents that I don't have a straighforward answer so I haven't added on this patchset: 1 la_activity(LA_ACT_ADD) is never called for auditor namespaces, even though la_objopen and la_activity(LA_ACT_CONSISTENT) are. There is no easy solution for this: we need at least to load the *first* auditor to actually issue the la_activity(LA_ACT_ADD). It means that it would *only* work for subsequent audit modules, and adding this specific semantic is confusing and does not really improve things (it only helps when multiple audit modules are used). 2. la_objopen is called for the main binary and for ld.so before the first la_activity(LA_ACT_ADD) call. This contradicts the pattern found in a successful dlopen (where la_activity(LA_ACT_ADD) precedes la_objopen). The constrain here is we need to handle DT_AUDIT and DT_DEPAUDIT dynamic tags, which means we need to first load the executable in memory to parse the required audit modules. So we need to first parse the dynamic audit tags, load the audit modules, and then load the object itself. 3. For non-PIE executables the base address listed in link_map->l_addr for the main application binary is 0, even though dladdr is able to recover the correct offset. La_objopen is affected by this. This would require to change an internal semantic for link_map->l_addr. This is not straighfoward and I am not sure about the direct gains. I have checked the patches on x86_64, i686, aarch64, armv7, powerpc64, powerpc64le, and powerpc. [1] https://sourceware.org/pipermail/libc-alpha/2021-June/127636.html [2] https://docs.google.com/document/d/1dVaDBdzySecxQqD6hLLzDrEF18M1UtjDna9gL5BWWI0/edit# [3] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/ld-audit-fixes Changes from v6: - Dropped SVE, main application on main_map l_name, and Run constructors if executable has a soname of a dependency patches. - Bumped LAV_VERSION to 2 on la_symbind bind-now support. - Added extension pointer on aarch64 fix. - Moved the refactor patch at the start of the set. - Changed _dl_audit_objsearch interface. Changes from v5: - Fixed build with --enable-profiling=yes. - Moved la_activity (LA_ACT_ADD) *after* _dl_add_to_namespace_list() for BZ#28062 fix. - Fixed powerpc64 ELFv1 OPD toc setup for bind-now. - Fixed testsuite issues for ia64. - Removed LA_SYMB_BINDNOW now that LA_SYMB_NOPLTENTER and LA_SYMB_NOPLTEXIT is passed for bind-now. Changes from v4: - Added a fix for constructors if executable has a soname of a dependency - Rebased against master. Changes from v3 - Added a aarch64 SVE RFC patch. - Fixed an issue with bind-now fix on powerpc64 ELFv1. - Rebased against master. Changes from v2 - Refactored rtld-audit code to move common come to dl-audit.c. - Issue audit la_objopen() for vDSO. - Isseu la_activity during application exit. - Issue la_symbind() for bind-now (BZ #23734). - Fix runtime linker auditing on aarch64 (BZ #26643) Changes from v1 - Fixed -fstack-protector-all tst-auditmod17. - Simplify the _dl_call_libc_early_init call the 'Fix audit regression' patch. - Remove symbind check fr BZ#15333. - Added the BZ#28096 fix. Adhemerval Zanella (15): elf: Add _dl_audit_objopen elf: Add _dl_audit_activity_map and _dl_audit_activity_nsid elf: Add _dl_audit_objsearch elf: Add _dl_audit_objclose elf: Add _dl_audit_symbind_alt and _dl_audit_symbind elf: Add _dl_audit_preinit elf: Add _dl_audit_pltenter elf: Add _dl_audit_pltexit elf: Avoid unnecessary slowdown from profiling with audit (BZ#15533) elf: Add audit tests for modules with TLSDESC elf: Do not fail for failed dlmopen on audit modules (BZ #28061) elf: Fix initial-exec TLS access on audit modules (BZ #28096) elf: Issue audit la_objopen for vDSO elf: Add la_activity during application exit elf: Issue la_symbind for bind-now (BZ #23734) Ben Woodard (1): elf: Fix runtime linker auditing on aarch64 (BZ #26643) NEWS | 7 + bits/link_lavcurrent.h | 2 +- csu/libc-start.c | 23 +- elf/Makefile | 147 ++++++++- elf/Versions | 1 + elf/dl-audit.c | 385 ++++++++++++++++++++++ elf/dl-close.c | 67 +--- elf/dl-fini.c | 25 +- elf/dl-load.c | 107 ++---- elf/dl-object.c | 20 +- elf/dl-open.c | 22 +- elf/dl-reloc.c | 20 +- elf/dl-runtime.c | 252 ++------------ elf/dl-support.c | 8 + elf/dl-sym-post.h | 47 +-- elf/dl-tls.c | 16 +- elf/do-rel.h | 57 +++- elf/rtld.c | 73 +--- elf/setup-vdso.h | 2 +- elf/sotruss-lib.c | 6 + elf/tst-audit-tlsdesc-dlopen.c | 67 ++++ elf/tst-audit-tlsdesc-mod1.c | 41 +++ elf/tst-audit-tlsdesc-mod2.c | 33 ++ elf/tst-audit-tlsdesc.c | 60 ++++ elf/tst-audit19a.c | 38 +++ elf/tst-audit19b.c | 94 ++++++ elf/tst-audit19bmod.c | 23 ++ elf/tst-audit20.c | 25 ++ elf/tst-audit21.c | 42 +++ elf/tst-audit22.c | 124 +++++++ elf/tst-audit23.c | 173 ++++++++++ elf/tst-audit23mod.c | 23 ++ elf/tst-audit24a.c | 36 ++ elf/tst-audit24amod1.c | 31 ++ elf/tst-audit24amod2.c | 25 ++ elf/tst-audit24b.c | 37 +++ elf/tst-audit24bmod1.c | 31 ++ elf/tst-audit24bmod2.c | 23 ++ elf/tst-audit24c.c | 2 + elf/tst-audit24d.c | 36 ++ elf/tst-audit24dmod1.c | 33 ++ elf/tst-audit24dmod2.c | 28 ++ elf/tst-audit24dmod3.c | 31 ++ elf/tst-audit24dmod4.c | 25 ++ elf/tst-audit25a.c | 127 +++++++ elf/tst-audit25b.c | 128 +++++++ elf/tst-audit25mod1.c | 30 ++ elf/tst-audit25mod2.c | 30 ++ elf/tst-audit25mod3.c | 22 ++ elf/tst-audit25mod4.c | 22 ++ elf/tst-auditmod-tlsdesc.c | 25 ++ elf/tst-auditmod19a.c | 25 ++ elf/tst-auditmod19b.c | 46 +++ elf/tst-auditmod20.c | 57 ++++ elf/tst-auditmod21a.c | 80 +++++ elf/tst-auditmod21b.c | 22 ++ elf/tst-auditmod22.c | 51 +++ elf/tst-auditmod23.c | 69 ++++ elf/tst-auditmod24.h | 29 ++ elf/tst-auditmod24a.c | 114 +++++++ elf/tst-auditmod24b.c | 104 ++++++ elf/tst-auditmod24c.c | 3 + elf/tst-auditmod24d.c | 120 +++++++ elf/tst-auditmod25.c | 79 +++++ include/dlfcn.h | 2 + include/link.h | 4 + sysdeps/aarch64/Makefile | 20 ++ sysdeps/aarch64/bits/link.h | 26 +- sysdeps/aarch64/dl-audit-check.h | 28 ++ sysdeps/aarch64/dl-link.sym | 6 +- sysdeps/aarch64/dl-trampoline.S | 99 ++++-- sysdeps/aarch64/tst-audit26.c | 37 +++ sysdeps/aarch64/tst-audit26mod.c | 33 ++ sysdeps/aarch64/tst-audit26mod.h | 50 +++ sysdeps/aarch64/tst-audit27.c | 64 ++++ sysdeps/aarch64/tst-audit27mod.c | 95 ++++++ sysdeps/aarch64/tst-audit27mod.h | 67 ++++ sysdeps/aarch64/tst-auditmod26.c | 103 ++++++ sysdeps/aarch64/tst-auditmod27.c | 180 ++++++++++ sysdeps/alpha/dl-trampoline.S | 8 +- sysdeps/arm/dl-machine-rel.h | 2 + sysdeps/arm/dl-trampoline.S | 2 +- sysdeps/generic/dl-audit-check.h | 23 ++ sysdeps/generic/dl-fixup-attribute.h | 24 ++ sysdeps/generic/dl-lookupcfg.h | 3 + sysdeps/generic/dl-machine-rel.h | 2 + sysdeps/generic/ldsodefs.h | 52 +++ sysdeps/hppa/dl-lookupcfg.h | 3 + sysdeps/hppa/dl-runtime.c | 2 +- sysdeps/hppa/dl-trampoline.S | 6 +- sysdeps/i386/dl-fixup-attribute.h | 30 ++ sysdeps/i386/dl-machine-rel.h | 2 + sysdeps/i386/dl-machine.h | 23 -- sysdeps/i386/dl-trampoline.S | 2 +- sysdeps/ia64/dl-lookupcfg.h | 3 + sysdeps/ia64/dl-trampoline.S | 16 +- sysdeps/m68k/dl-trampoline.S | 2 +- sysdeps/mips/dl-machine-rel.h | 1 + sysdeps/powerpc/dl-lookupcfg.h | 39 +++ sysdeps/powerpc/powerpc64/dl-trampoline.S | 4 +- sysdeps/s390/s390-32/dl-trampoline.h | 4 +- sysdeps/s390/s390-64/dl-trampoline.h | 2 +- sysdeps/sh/dl-trampoline.S | 4 +- sysdeps/sparc/sparc32/dl-trampoline.S | 2 +- sysdeps/sparc/sparc64/dl-trampoline.S | 2 +- sysdeps/x86_64/dl-runtime.h | 2 +- sysdeps/x86_64/dl-trampoline.h | 6 +- 107 files changed, 3978 insertions(+), 658 deletions(-) create mode 100644 elf/dl-audit.c create mode 100644 elf/tst-audit-tlsdesc-dlopen.c create mode 100644 elf/tst-audit-tlsdesc-mod1.c create mode 100644 elf/tst-audit-tlsdesc-mod2.c create mode 100644 elf/tst-audit-tlsdesc.c create mode 100644 elf/tst-audit19a.c create mode 100644 elf/tst-audit19b.c create mode 100644 elf/tst-audit19bmod.c create mode 100644 elf/tst-audit20.c create mode 100644 elf/tst-audit21.c create mode 100644 elf/tst-audit22.c create mode 100644 elf/tst-audit23.c create mode 100644 elf/tst-audit23mod.c create mode 100644 elf/tst-audit24a.c create mode 100644 elf/tst-audit24amod1.c create mode 100644 elf/tst-audit24amod2.c create mode 100644 elf/tst-audit24b.c create mode 100644 elf/tst-audit24bmod1.c create mode 100644 elf/tst-audit24bmod2.c create mode 100644 elf/tst-audit24c.c create mode 100644 elf/tst-audit24d.c create mode 100644 elf/tst-audit24dmod1.c create mode 100644 elf/tst-audit24dmod2.c create mode 100644 elf/tst-audit24dmod3.c create mode 100644 elf/tst-audit24dmod4.c create mode 100644 elf/tst-audit25a.c create mode 100644 elf/tst-audit25b.c create mode 100644 elf/tst-audit25mod1.c create mode 100644 elf/tst-audit25mod2.c create mode 100644 elf/tst-audit25mod3.c create mode 100644 elf/tst-audit25mod4.c create mode 100644 elf/tst-auditmod-tlsdesc.c create mode 100644 elf/tst-auditmod19a.c create mode 100644 elf/tst-auditmod19b.c create mode 100644 elf/tst-auditmod20.c create mode 100644 elf/tst-auditmod21a.c create mode 100644 elf/tst-auditmod21b.c create mode 100644 elf/tst-auditmod22.c create mode 100644 elf/tst-auditmod23.c create mode 100644 elf/tst-auditmod24.h create mode 100644 elf/tst-auditmod24a.c create mode 100644 elf/tst-auditmod24b.c create mode 100644 elf/tst-auditmod24c.c create mode 100644 elf/tst-auditmod24d.c create mode 100644 elf/tst-auditmod25.c create mode 100644 sysdeps/aarch64/dl-audit-check.h create mode 100644 sysdeps/aarch64/tst-audit26.c create mode 100644 sysdeps/aarch64/tst-audit26mod.c create mode 100644 sysdeps/aarch64/tst-audit26mod.h create mode 100644 sysdeps/aarch64/tst-audit27.c create mode 100644 sysdeps/aarch64/tst-audit27mod.c create mode 100644 sysdeps/aarch64/tst-audit27mod.h create mode 100644 sysdeps/aarch64/tst-auditmod26.c create mode 100644 sysdeps/aarch64/tst-auditmod27.c create mode 100644 sysdeps/generic/dl-audit-check.h create mode 100644 sysdeps/generic/dl-fixup-attribute.h create mode 100644 sysdeps/i386/dl-fixup-attribute.h create mode 100644 sysdeps/powerpc/dl-lookupcfg.h -- 2.32.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v7 14/16] elf: Add la_activity during application exit 2021-12-22 13:26 [PATCH v7 00/16] Multiple rtld-audit fixes Adhemerval Zanella @ 2021-12-22 13:27 ` Adhemerval Zanella 2021-12-24 17:50 ` Florian Weimer 0 siblings, 1 reply; 4+ messages in thread From: Adhemerval Zanella @ 2021-12-22 13:27 UTC (permalink / raw) To: libc-alpha, fweimer; +Cc: John Mellor-Crummey, Ben Woodard la_activity is not called during application exit, even though la_objclose is. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. --- elf/Makefile | 8 +- elf/dl-fini.c | 9 +++ elf/tst-audit23.c | 173 +++++++++++++++++++++++++++++++++++++++++++ elf/tst-audit23mod.c | 23 ++++++ elf/tst-auditmod23.c | 69 +++++++++++++++++ 5 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 elf/tst-audit23.c create mode 100644 elf/tst-audit23mod.c create mode 100644 elf/tst-auditmod23.c diff --git a/elf/Makefile b/elf/Makefile index 47305d3bde..3a521ae89e 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -235,7 +235,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-audit20 \ tst-audit21 \ tst-audit22 \ - tst-rtld-run-static \ + tst-audit23 \ # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -389,6 +389,8 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-auditmod21a \ tst-auditmod21b \ tst-auditmod22 \ + tst-auditmod23 \ + tst-audit23mod \ # Most modules build with _ISOMAC defined, but those filtered out # depend on internal headers. @@ -1612,6 +1614,10 @@ tst-audit21-ENV = LD_AUDIT=$(objpfx)tst-auditmod21a.so $(objpfx)tst-audit22.out: $(objpfx)tst-auditmod22.so tst-audit22-ARGS = -- $(host-test-program-cmd) +$(objpfx)tst-audit23.out: $(objpfx)tst-auditmod23.so \ + $(objpfx)tst-audit23mod.so +tst-audit23-ARGS = -- $(host-test-program-cmd) + # tst-sonamemove links against an older implementation of the library. LDFLAGS-tst-sonamemove-linkmod1.so = \ -Wl,--version-script=tst-sonamemove-linkmod1.map \ diff --git a/elf/dl-fini.c b/elf/dl-fini.c index b789cfb9f2..81b4f4119a 100644 --- a/elf/dl-fini.c +++ b/elf/dl-fini.c @@ -64,6 +64,10 @@ _dl_fini (void) __rtld_lock_unlock_recursive (GL(dl_load_lock)); else { +#ifdef SHARED + /* Auditing checkpoint: we will start deleting objects. */ + _dl_audit_activity_nsid (ns, LA_ACT_DELETE); +#endif /* Now we can allocate an array to hold all the pointers and copy the pointers in. */ struct link_map *maps[nloaded]; @@ -153,6 +157,11 @@ _dl_fini (void) /* Correct the previous increment. */ --l->l_direct_opencount; } + +#ifdef SHARED + /* Auditing checkpoint: we will start deleting objects. */ + _dl_audit_activity_nsid (ns, LA_ACT_CONSISTENT); +#endif } } diff --git a/elf/tst-audit23.c b/elf/tst-audit23.c new file mode 100644 index 0000000000..653cbcc360 --- /dev/null +++ b/elf/tst-audit23.c @@ -0,0 +1,173 @@ +/* Check DT_AUDIT la_objopen and la_objclose for all objects. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <getopt.h> +#include <limits.h> +#include <inttypes.h> +#include <gnu/lib-names.h> +#include <string.h> +#include <stdlib.h> +#include <support/capture_subprocess.h> +#include <support/check.h> +#include <support/xstdio.h> +#include <support/xdlfcn.h> +#include <support/support.h> + +static int restart; +#define CMDLINE_OPTIONS \ + { "restart", no_argument, &restart, 1 }, + +static int +handle_restart (void) +{ + xdlopen ("tst-audit23mod.so", RTLD_NOW); + xdlmopen (LM_ID_NEWLM, LIBC_SO, RTLD_NOW); + + return 0; +} + +static inline bool +startswith (const char *str, const char *pre) +{ + size_t lenpre = strlen (pre); + size_t lenstr = strlen (str); + return lenstr >= lenpre && memcmp (pre, str, lenpre) == 0; +} + +static inline bool +is_vdso (const char *str) +{ + return startswith (str, "linux-gate") + || startswith (str, "linux-vdso"); +} + +static int +do_test (int argc, char *argv[]) +{ + /* We must have either: + - One our fource parameters left if called initially: + + path to ld.so optional + + "--library-path" optional + + the library path optional + + the application name */ + if (restart) + return handle_restart (); + + char *spargv[9]; + int i = 0; + for (; i < argc - 1; i++) + spargv[i] = argv[i + 1]; + spargv[i++] = (char *) "--direct"; + spargv[i++] = (char *) "--restart"; + spargv[i] = NULL; + + setenv ("LD_AUDIT", "tst-auditmod23.so", 0); + struct support_capture_subprocess result + = support_capture_subprogram (spargv[0], spargv); + support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr); + + + /* We expect la_objopen/la_objclose for the objects: + 1. executable + 2. loader + 3. libc.so + 4. tst-audit23mod.so + 5. libc.so (LM_ID_NEWLM). + 6. vdso (optional and ignored). */ + enum { max_objs = 6 }; + struct la_obj_t + { + char *lname; + uintptr_t laddr; + Lmid_t lmid; + bool closed; + } objs[max_objs] = { [0 ... max_objs-1] = { .closed = false } }; + size_t nobjs = 0; + + FILE *out = fmemopen (result.err.buffer, result.err.length, "r"); + TEST_VERIFY (out != NULL); + char *buffer = NULL; + size_t buffer_length = 0; + while (xgetline (&buffer, &buffer_length, out)) + { + enum { LA_OBJOPEN, LA_OBJCLOSE} mode; + ptrdiff_t offset; + if (startswith (buffer, "la_objopen: ")) + { + offset = strlen ("la_objopen: "); + mode = LA_OBJOPEN; + } + else if (startswith (buffer, "la_objclose: ")) + { + offset = strlen ("la_objclose: "); + mode = LA_OBJCLOSE; + } + else + continue; + + char *lname; + uintptr_t laddr; + Lmid_t lmid; + int r = sscanf (buffer + offset, "%ms %"SCNxPTR" %ld", &lname, &laddr, + &lmid); + TEST_COMPARE (r, 3); + + if (mode == LA_OBJOPEN) + { + /* la_objclose is not triggered by vDSO because glibc does not + unload it. */ + if (is_vdso (lname)) + continue; + if (nobjs == max_objs) + FAIL_EXIT1 ("non expected la_objopen: %s %"PRIxPTR" %ld", + lname, laddr, lmid); + objs[nobjs].lname = lname; + objs[nobjs].laddr = laddr; + objs[nobjs].lmid = lmid; + objs[nobjs].closed = false; + nobjs++; + } + else if (mode == LA_OBJCLOSE) + { + for (size_t i = 0; i < nobjs; i++) + { + if (strcmp (lname, objs[i].lname) == 0 && lmid == objs[i].lmid) + { + TEST_COMPARE (objs[i].closed, false); + objs[i].closed = true; + break; + } + } + } + } + + for (size_t i = 0; i < nobjs; i++) + { + TEST_COMPARE (objs[i].closed, true); + free (objs[i].lname); + } + + free (buffer); + xfclose (out); + + return 0; +} + +#define TEST_FUNCTION_ARGV do_test +#include <support/test-driver.c> diff --git a/elf/tst-audit23mod.c b/elf/tst-audit23mod.c new file mode 100644 index 0000000000..4ca66cf772 --- /dev/null +++ b/elf/tst-audit23mod.c @@ -0,0 +1,23 @@ +/* Extra modules for tst-audit23 + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +int +foo (void) +{ + return 0; +} diff --git a/elf/tst-auditmod23.c b/elf/tst-auditmod23.c new file mode 100644 index 0000000000..56a3dbf801 --- /dev/null +++ b/elf/tst-auditmod23.c @@ -0,0 +1,69 @@ +/* Audit modules loaded by tst-audit23. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <link.h> +#include <inttypes.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/auxv.h> + +unsigned int +la_version (unsigned int version) +{ + return LAV_CURRENT; +} + +struct map_desc_t +{ + char *lname; + uintptr_t laddr; + Lmid_t lmid; +}; + +unsigned int +la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie) +{ + const char *l_name = map->l_name[0] == '\0' ? "mainapp" : map->l_name; + fprintf (stderr, "%s: %s %"PRIxPTR" %ld\n", __func__, + l_name, map->l_addr, lmid); + + struct map_desc_t *map_desc = malloc (sizeof (struct map_desc_t)); + if (map_desc == NULL) + abort (); + + map_desc->lname = strdup (l_name); + map_desc->laddr = map->l_addr; + map_desc->lmid = lmid; + + *cookie = (uintptr_t) map_desc; + + return 0; +} + +unsigned int +la_objclose (uintptr_t *cookie) +{ + struct map_desc_t *map_desc = (struct map_desc_t *) *cookie; + fprintf (stderr, "%s: %s %"PRIxPTR" %ld\n", __func__, + map_desc->lname, map_desc->laddr, map_desc->lmid); + free (map_desc->lname); + free (map_desc); + + return 0; +} -- 2.32.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v7 14/16] elf: Add la_activity during application exit 2021-12-22 13:27 ` [PATCH v7 14/16] elf: Add la_activity during application exit Adhemerval Zanella @ 2021-12-24 17:50 ` Florian Weimer 0 siblings, 0 replies; 4+ messages in thread From: Florian Weimer @ 2021-12-24 17:50 UTC (permalink / raw) To: Adhemerval Zanella; +Cc: libc-alpha, John Mellor-Crummey, Ben Woodard * Adhemerval Zanella: > la_activity is not called during application exit, even though > la_objclose is. > > Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Still looks good, thanks. Reviewed-by: Florian Weimer <fweimer@redhat.com> Florian ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-27 13:20 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-12-27 5:13 [PATCH v7 14/16] elf: Add la_activity during application exit jma14 2021-12-27 13:20 ` Adhemerval Zanella -- strict thread matches above, loose matches on Subject: below -- 2021-12-22 13:26 [PATCH v7 00/16] Multiple rtld-audit fixes Adhemerval Zanella 2021-12-22 13:27 ` [PATCH v7 14/16] elf: Add la_activity during application exit Adhemerval Zanella 2021-12-24 17:50 ` Florian Weimer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).