|
|
c5d972 |
commit aee6e90f93e285016b6cd9c8bd00402c19ba271b
|
|
|
c5d972 |
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
c5d972 |
Date: Mon Jul 19 15:47:51 2021 -0300
|
|
|
c5d972 |
|
|
|
c5d972 |
elf: Add _dl_audit_objopen
|
|
|
c5d972 |
|
|
|
c5d972 |
It consolidates the code required to call la_objopen audit callback.
|
|
|
c5d972 |
|
|
|
c5d972 |
Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
|
|
|
c5d972 |
|
|
|
c5d972 |
Reviewed-by: Florian Weimer <fweimer@redhat.com>
|
|
|
c5d972 |
|
|
|
c5d972 |
Conflicts:
|
|
|
c5d972 |
elf/Makefile
|
|
|
c5d972 |
|
|
|
c5d972 |
diff --git a/elf/Makefile b/elf/Makefile
|
|
|
c5d972 |
index 2312184692433313..08a32a712a34f2cc 100644
|
|
|
c5d972 |
--- a/elf/Makefile
|
|
|
c5d972 |
+++ b/elf/Makefile
|
|
|
c5d972 |
@@ -64,7 +64,8 @@ elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
|
|
|
c5d972 |
# interpreter and operating independent of libc.
|
|
|
c5d972 |
rtld-routines = rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \
|
|
|
c5d972 |
dl-error-minimal dl-conflict dl-hwcaps dl-hwcaps_split dl-hwcaps-subdirs \
|
|
|
c5d972 |
- dl-usage dl-diagnostics dl-diagnostics-kernel dl-diagnostics-cpu
|
|
|
c5d972 |
+ dl-usage dl-diagnostics dl-diagnostics-kernel dl-diagnostics-cpu \
|
|
|
c5d972 |
+ dl-audit
|
|
|
c5d972 |
all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
|
|
|
c5d972 |
|
|
|
c5d972 |
CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
|
|
|
c5d972 |
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
|
|
|
c5d972 |
new file mode 100644
|
|
|
c5d972 |
index 0000000000000000..4066dfe85146b9d4
|
|
|
c5d972 |
--- /dev/null
|
|
|
c5d972 |
+++ b/elf/dl-audit.c
|
|
|
c5d972 |
@@ -0,0 +1,39 @@
|
|
|
c5d972 |
+/* Audit common functions.
|
|
|
c5d972 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
c5d972 |
+ This file is part of the GNU C Library.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
c5d972 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
c5d972 |
+ License as published by the Free Software Foundation; either
|
|
|
c5d972 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
c5d972 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c5d972 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c5d972 |
+ Lesser General Public License for more details.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
c5d972 |
+ License along with the GNU C Library; if not, see
|
|
|
c5d972 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+#include <ldsodefs.h>
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+void
|
|
|
c5d972 |
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ if (__glibc_likely (GLRO(dl_naudit) == 0))
|
|
|
c5d972 |
+ return;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ struct audit_ifaces *afct = GLRO(dl_audit);
|
|
|
c5d972 |
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
|
|
|
c5d972 |
+ {
|
|
|
c5d972 |
+ if (afct->objopen != NULL)
|
|
|
c5d972 |
+ {
|
|
|
c5d972 |
+ struct auditstate *state = link_map_audit_state (l, cnt);
|
|
|
c5d972 |
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
|
|
|
c5d972 |
+ l->l_audit_any_plt |= state->bindflags != 0;
|
|
|
c5d972 |
+ }
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ afct = afct->next;
|
|
|
c5d972 |
+ }
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
diff --git a/elf/dl-load.c b/elf/dl-load.c
|
|
|
c5d972 |
index de5aef5777045da5..c11b1d1781e9b40b 100644
|
|
|
c5d972 |
--- a/elf/dl-load.c
|
|
|
c5d972 |
+++ b/elf/dl-load.c
|
|
|
c5d972 |
@@ -1436,22 +1436,8 @@ cannot enable executable stack as shared object requires");
|
|
|
c5d972 |
|
|
|
c5d972 |
#ifdef SHARED
|
|
|
c5d972 |
/* Auditing checkpoint: we have a new object. */
|
|
|
c5d972 |
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
|
|
|
c5d972 |
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
|
|
|
c5d972 |
- {
|
|
|
c5d972 |
- struct audit_ifaces *afct = GLRO(dl_audit);
|
|
|
c5d972 |
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
|
|
|
c5d972 |
- {
|
|
|
c5d972 |
- if (afct->objopen != NULL)
|
|
|
c5d972 |
- {
|
|
|
c5d972 |
- struct auditstate *state = link_map_audit_state (l, cnt);
|
|
|
c5d972 |
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
|
|
|
c5d972 |
- l->l_audit_any_plt |= state->bindflags != 0;
|
|
|
c5d972 |
- }
|
|
|
c5d972 |
-
|
|
|
c5d972 |
- afct = afct->next;
|
|
|
c5d972 |
- }
|
|
|
c5d972 |
- }
|
|
|
c5d972 |
+ if (!GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
|
|
|
c5d972 |
+ _dl_audit_objopen (l, nsid);
|
|
|
c5d972 |
#endif
|
|
|
c5d972 |
|
|
|
c5d972 |
return l;
|
|
|
c5d972 |
diff --git a/elf/rtld.c b/elf/rtld.c
|
|
|
c5d972 |
index f3836b8a78faaf27..1982e42390760e0a 100644
|
|
|
c5d972 |
--- a/elf/rtld.c
|
|
|
c5d972 |
+++ b/elf/rtld.c
|
|
|
c5d972 |
@@ -1075,25 +1075,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
|
|
|
c5d972 |
dlmargs.map->l_auditing = 1;
|
|
|
c5d972 |
}
|
|
|
c5d972 |
|
|
|
c5d972 |
-/* Notify the the audit modules that the object MAP has already been
|
|
|
c5d972 |
- loaded. */
|
|
|
c5d972 |
-static void
|
|
|
c5d972 |
-notify_audit_modules_of_loaded_object (struct link_map *map)
|
|
|
c5d972 |
-{
|
|
|
c5d972 |
- struct audit_ifaces *afct = GLRO(dl_audit);
|
|
|
c5d972 |
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
|
|
|
c5d972 |
- {
|
|
|
c5d972 |
- if (afct->objopen != NULL)
|
|
|
c5d972 |
- {
|
|
|
c5d972 |
- struct auditstate *state = link_map_audit_state (map, cnt);
|
|
|
c5d972 |
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
|
|
|
c5d972 |
- map->l_audit_any_plt |= state->bindflags != 0;
|
|
|
c5d972 |
- }
|
|
|
c5d972 |
-
|
|
|
c5d972 |
- afct = afct->next;
|
|
|
c5d972 |
- }
|
|
|
c5d972 |
-}
|
|
|
c5d972 |
-
|
|
|
c5d972 |
/* Load all audit modules. */
|
|
|
c5d972 |
static void
|
|
|
c5d972 |
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
|
|
|
c5d972 |
@@ -1112,8 +1093,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
|
|
|
c5d972 |
program and the dynamic linker itself). */
|
|
|
c5d972 |
if (GLRO(dl_naudit) > 0)
|
|
|
c5d972 |
{
|
|
|
c5d972 |
- notify_audit_modules_of_loaded_object (main_map);
|
|
|
c5d972 |
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
|
|
|
c5d972 |
+ _dl_audit_objopen (main_map, LM_ID_BASE);
|
|
|
c5d972 |
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE);
|
|
|
c5d972 |
}
|
|
|
c5d972 |
}
|
|
|
c5d972 |
|
|
|
c5d972 |
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
|
|
|
c5d972 |
index 2dd6f0c3c4aaaef5..410f070e28b74bdf 100644
|
|
|
c5d972 |
--- a/sysdeps/generic/ldsodefs.h
|
|
|
c5d972 |
+++ b/sysdeps/generic/ldsodefs.h
|
|
|
c5d972 |
@@ -1268,6 +1268,11 @@ link_map_audit_state (struct link_map *l, size_t index)
|
|
|
c5d972 |
{
|
|
|
c5d972 |
return &l->l_audit[index];
|
|
|
c5d972 |
}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+/* Call the la_objopen from the audit modules for the link_map L on the
|
|
|
c5d972 |
+ namespace identification NSID. */
|
|
|
c5d972 |
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid)
|
|
|
c5d972 |
+ attribute_hidden;
|
|
|
c5d972 |
#endif /* SHARED */
|
|
|
c5d972 |
|
|
|
c5d972 |
__END_DECLS
|