public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen
@ 2021-07-30 19:24 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-07-30 19:24 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1d8988e9df095a1521f97d47c8ba63fcb8fbd761
commit 1d8988e9df095a1521f97d47c8ba63fcb8fbd761
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jul 19 15:47:51 2021 -0300
elf: Add _dl_audit_objopen
It consolidates the code required to call la_objopen() audit callback.
No function change, checked on x86_64-linux-gnu.
Diff:
---
elf/Makefile | 3 ++-
elf/dl-audit.c | 42 ++++++++++++++++++++++++++++++++++++++++++
elf/dl-load.c | 17 +----------------
elf/rtld.c | 23 ++---------------------
sysdeps/generic/ldsodefs.h | 5 +++++
5 files changed, 52 insertions(+), 38 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 78ab9f2228..c6c97efd8c 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -35,7 +35,8 @@ dl-routines = $(addprefix dl-,load lookup object reloc deps \
execstack open close trampoline \
exception sort-maps lookup-direct \
call-libc-early-init write \
- thread_gscope_wait tls_init_tp)
+ thread_gscope_wait tls_init_tp \
+ audit)
ifeq (yes,$(use-ldconfig))
dl-routines += dl-cache
endif
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
new file mode 100644
index 0000000000..24d8557f18
--- /dev/null
+++ b/elf/dl-audit.c
@@ -0,0 +1,42 @@
+/* Audit common functions.
+ 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 <ldsodefs.h>
+
+#ifdef SHARED
+void
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit)
+{
+ if (__glibc_likely (GLRO(dl_naudit) == 0)
+ || (check_audit && GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing))
+ return;
+
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objopen != NULL)
+ {
+ struct auditstate *state = link_map_audit_state (l, cnt);
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
+ l->l_audit_any_plt |= state->bindflags != 0;
+ }
+
+ afct = afct->next;
+ }
+}
+#endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 433a59191a..c0b68638c0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1512,22 +1512,7 @@ cannot enable executable stack as shared object requires");
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
- {
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (l, cnt);
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
- l->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
- }
+ _dl_audit_objopen (l, nsid, true);
#endif
return l;
diff --git a/elf/rtld.c b/elf/rtld.c
index 1312378b5f..8008570f82 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1057,25 +1057,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
dlmargs.map->l_dont_set_tls_static = 1;
}
-/* Notify the the audit modules that the object MAP has already been
- loaded. */
-static void
-notify_audit_modules_of_loaded_object (struct link_map *map)
-{
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (map, cnt);
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
- map->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
-}
-
/* Load all audit modules. */
static void
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
@@ -1094,8 +1075,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
program and the dynamic linker itself). */
if (GLRO(dl_naudit) > 0)
{
- notify_audit_modules_of_loaded_object (main_map);
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+ _dl_audit_objopen (main_map, LM_ID_BASE, false);
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE, false);
}
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9c15259236..3432bcd693 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1346,6 +1346,11 @@ link_map_audit_state (struct link_map *l, size_t index)
return &base[index];
}
}
+
+/* Call the la_objopen() from the audit modules for the link_map L on the
+ namespace identification NSID. If CHECK_AUDIT is set it will also check
+ if main mapping of the namespace is an audit modules. */
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit);
#endif /* SHARED */
#if PTHREAD_IN_LIBC && defined SHARED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen
@ 2021-11-16 13:57 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-11-16 13:57 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c2d1ea99dbb8459a4a60af351a9116f1dca0f5b0
commit c2d1ea99dbb8459a4a60af351a9116f1dca0f5b0
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jul 19 15:47:51 2021 -0300
elf: Add _dl_audit_objopen
It consolidates the code required to call la_objopen() audit callback.
Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
Diff:
---
elf/Makefile | 2 +-
elf/dl-audit.c | 42 ++++++++++++++++++++++++++++++++++++++++++
elf/dl-load.c | 17 +----------------
elf/rtld.c | 23 ++---------------------
sysdeps/generic/ldsodefs.h | 5 +++++
5 files changed, 51 insertions(+), 38 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 8f3e3a3602..80ed31edbe 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -36,7 +36,7 @@ dl-routines = $(addprefix dl-,load lookup object reloc deps \
exception sort-maps lookup-direct \
call-libc-early-init write \
thread_gscope_wait tls_init_tp \
- debug-symbols minimal-malloc)
+ debug-symbols minimal-malloc audit)
ifeq (yes,$(use-ldconfig))
dl-routines += dl-cache
endif
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
new file mode 100644
index 0000000000..24d8557f18
--- /dev/null
+++ b/elf/dl-audit.c
@@ -0,0 +1,42 @@
+/* Audit common functions.
+ 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 <ldsodefs.h>
+
+#ifdef SHARED
+void
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit)
+{
+ if (__glibc_likely (GLRO(dl_naudit) == 0)
+ || (check_audit && GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing))
+ return;
+
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objopen != NULL)
+ {
+ struct auditstate *state = link_map_audit_state (l, cnt);
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
+ l->l_audit_any_plt |= state->bindflags != 0;
+ }
+
+ afct = afct->next;
+ }
+}
+#endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 240b5efb45..09e87f5a25 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1519,22 +1519,7 @@ cannot enable executable stack as shared object requires");
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
- {
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (l, cnt);
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
- l->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
- }
+ _dl_audit_objopen (l, nsid, true);
#endif
return l;
diff --git a/elf/rtld.c b/elf/rtld.c
index be2d5d8e74..647f476957 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1063,25 +1063,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
dlmargs.map->l_auditing = 1;
}
-/* Notify the the audit modules that the object MAP has already been
- loaded. */
-static void
-notify_audit_modules_of_loaded_object (struct link_map *map)
-{
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (map, cnt);
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
- map->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
-}
-
/* Load all audit modules. */
static void
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
@@ -1100,8 +1081,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
program and the dynamic linker itself). */
if (GLRO(dl_naudit) > 0)
{
- notify_audit_modules_of_loaded_object (main_map);
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+ _dl_audit_objopen (main_map, LM_ID_BASE, false);
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE, false);
}
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 1318c36dce..dec592bf53 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1391,6 +1391,11 @@ link_map_audit_state (struct link_map *l, size_t index)
return &base[index];
}
}
+
+/* Call the la_objopen() from the audit modules for the link_map L on the
+ namespace identification NSID. If CHECK_AUDIT is set it will also check
+ if main mapping of the namespace is a audit modules. */
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit);
#endif /* SHARED */
#if PTHREAD_IN_LIBC && defined SHARED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen
@ 2021-11-09 18:18 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-11-09 18:18 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bb59db16c11b8e322d3133462e8d6036ad69e55f
commit bb59db16c11b8e322d3133462e8d6036ad69e55f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jul 19 15:47:51 2021 -0300
elf: Add _dl_audit_objopen
It consolidates the code required to call la_objopen() audit callback.
Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
Diff:
---
elf/Makefile | 2 +-
elf/dl-audit.c | 42 ++++++++++++++++++++++++++++++++++++++++++
elf/dl-load.c | 17 +----------------
elf/rtld.c | 23 ++---------------------
sysdeps/generic/ldsodefs.h | 5 +++++
5 files changed, 51 insertions(+), 38 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index db61ab5fe6..f685831913 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -36,7 +36,7 @@ dl-routines = $(addprefix dl-,load lookup object reloc deps \
exception sort-maps lookup-direct \
call-libc-early-init write \
thread_gscope_wait tls_init_tp \
- debug-symbols minimal-malloc)
+ debug-symbols minimal-malloc audit)
ifeq (yes,$(use-ldconfig))
dl-routines += dl-cache
endif
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
new file mode 100644
index 0000000000..24d8557f18
--- /dev/null
+++ b/elf/dl-audit.c
@@ -0,0 +1,42 @@
+/* Audit common functions.
+ 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 <ldsodefs.h>
+
+#ifdef SHARED
+void
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit)
+{
+ if (__glibc_likely (GLRO(dl_naudit) == 0)
+ || (check_audit && GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing))
+ return;
+
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objopen != NULL)
+ {
+ struct auditstate *state = link_map_audit_state (l, cnt);
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
+ l->l_audit_any_plt |= state->bindflags != 0;
+ }
+
+ afct = afct->next;
+ }
+}
+#endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 72298776f6..572378e0ca 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1520,22 +1520,7 @@ cannot enable executable stack as shared object requires");
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
- {
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (l, cnt);
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
- l->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
- }
+ _dl_audit_objopen (l, nsid, true);
#endif
return l;
diff --git a/elf/rtld.c b/elf/rtld.c
index db1817655f..7179c71188 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1059,25 +1059,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
dlmargs.map->l_dont_set_tls_static = 1;
}
-/* Notify the the audit modules that the object MAP has already been
- loaded. */
-static void
-notify_audit_modules_of_loaded_object (struct link_map *map)
-{
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (map, cnt);
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
- map->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
-}
-
/* Load all audit modules. */
static void
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
@@ -1096,8 +1077,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
program and the dynamic linker itself). */
if (GLRO(dl_naudit) > 0)
{
- notify_audit_modules_of_loaded_object (main_map);
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+ _dl_audit_objopen (main_map, LM_ID_BASE, false);
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE, false);
}
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 1318c36dce..dec592bf53 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1391,6 +1391,11 @@ link_map_audit_state (struct link_map *l, size_t index)
return &base[index];
}
}
+
+/* Call the la_objopen() from the audit modules for the link_map L on the
+ namespace identification NSID. If CHECK_AUDIT is set it will also check
+ if main mapping of the namespace is a audit modules. */
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit);
#endif /* SHARED */
#if PTHREAD_IN_LIBC && defined SHARED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen
@ 2021-09-10 18:25 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-09-10 18:25 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dad33a2c8719a02bc157338310714e13408b72af
commit dad33a2c8719a02bc157338310714e13408b72af
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jul 19 15:47:51 2021 -0300
elf: Add _dl_audit_objopen
It consolidates the code required to call la_objopen() audit callback.
Diff:
---
elf/Makefile | 3 ++-
elf/dl-audit.c | 42 ++++++++++++++++++++++++++++++++++++++++++
elf/dl-load.c | 17 +----------------
elf/rtld.c | 23 ++---------------------
sysdeps/generic/ldsodefs.h | 5 +++++
5 files changed, 52 insertions(+), 38 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 4240bf6f9b..4006233c10 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -35,7 +35,8 @@ dl-routines = $(addprefix dl-,load lookup object reloc deps \
execstack open close trampoline \
exception sort-maps lookup-direct \
call-libc-early-init write \
- thread_gscope_wait tls_init_tp)
+ thread_gscope_wait tls_init_tp \
+ audit)
ifeq (yes,$(use-ldconfig))
dl-routines += dl-cache
endif
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
new file mode 100644
index 0000000000..24d8557f18
--- /dev/null
+++ b/elf/dl-audit.c
@@ -0,0 +1,42 @@
+/* Audit common functions.
+ 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 <ldsodefs.h>
+
+#ifdef SHARED
+void
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit)
+{
+ if (__glibc_likely (GLRO(dl_naudit) == 0)
+ || (check_audit && GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing))
+ return;
+
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objopen != NULL)
+ {
+ struct auditstate *state = link_map_audit_state (l, cnt);
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
+ l->l_audit_any_plt |= state->bindflags != 0;
+ }
+
+ afct = afct->next;
+ }
+}
+#endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 433a59191a..c0b68638c0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1512,22 +1512,7 @@ cannot enable executable stack as shared object requires");
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
- {
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (l, cnt);
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
- l->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
- }
+ _dl_audit_objopen (l, nsid, true);
#endif
return l;
diff --git a/elf/rtld.c b/elf/rtld.c
index 6ad4cedfb5..ca510fc3c8 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1057,25 +1057,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
dlmargs.map->l_dont_set_tls_static = 1;
}
-/* Notify the the audit modules that the object MAP has already been
- loaded. */
-static void
-notify_audit_modules_of_loaded_object (struct link_map *map)
-{
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (map, cnt);
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
- map->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
-}
-
/* Load all audit modules. */
static void
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
@@ -1094,8 +1075,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
program and the dynamic linker itself). */
if (GLRO(dl_naudit) > 0)
{
- notify_audit_modules_of_loaded_object (main_map);
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+ _dl_audit_objopen (main_map, LM_ID_BASE, false);
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE, false);
}
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9c15259236..7eb3ad8ff9 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1346,6 +1346,11 @@ link_map_audit_state (struct link_map *l, size_t index)
return &base[index];
}
}
+
+/* Call the la_objopen() from the audit modules for the link_map L on the
+ namespace identification NSID. If CHECK_AUDIT is set it will also check
+ if main mapping of the namespace is a audit modules. */
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit);
#endif /* SHARED */
#if PTHREAD_IN_LIBC && defined SHARED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen
@ 2021-08-04 20:53 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-04 20:53 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a3503e54dd624d6481c7e81c2d507aeea69973d4
commit a3503e54dd624d6481c7e81c2d507aeea69973d4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jul 19 15:47:51 2021 -0300
elf: Add _dl_audit_objopen
It consolidates the code required to call la_objopen() audit callback.
Diff:
---
elf/Makefile | 3 ++-
elf/dl-audit.c | 42 ++++++++++++++++++++++++++++++++++++++++++
elf/dl-load.c | 17 +----------------
elf/rtld.c | 23 ++---------------------
sysdeps/generic/ldsodefs.h | 5 +++++
5 files changed, 52 insertions(+), 38 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 78ab9f2228..c6c97efd8c 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -35,7 +35,8 @@ dl-routines = $(addprefix dl-,load lookup object reloc deps \
execstack open close trampoline \
exception sort-maps lookup-direct \
call-libc-early-init write \
- thread_gscope_wait tls_init_tp)
+ thread_gscope_wait tls_init_tp \
+ audit)
ifeq (yes,$(use-ldconfig))
dl-routines += dl-cache
endif
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
new file mode 100644
index 0000000000..24d8557f18
--- /dev/null
+++ b/elf/dl-audit.c
@@ -0,0 +1,42 @@
+/* Audit common functions.
+ 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 <ldsodefs.h>
+
+#ifdef SHARED
+void
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit)
+{
+ if (__glibc_likely (GLRO(dl_naudit) == 0)
+ || (check_audit && GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing))
+ return;
+
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objopen != NULL)
+ {
+ struct auditstate *state = link_map_audit_state (l, cnt);
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
+ l->l_audit_any_plt |= state->bindflags != 0;
+ }
+
+ afct = afct->next;
+ }
+}
+#endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 433a59191a..c0b68638c0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1512,22 +1512,7 @@ cannot enable executable stack as shared object requires");
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
- {
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (l, cnt);
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
- l->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
- }
+ _dl_audit_objopen (l, nsid, true);
#endif
return l;
diff --git a/elf/rtld.c b/elf/rtld.c
index 1312378b5f..8008570f82 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1057,25 +1057,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
dlmargs.map->l_dont_set_tls_static = 1;
}
-/* Notify the the audit modules that the object MAP has already been
- loaded. */
-static void
-notify_audit_modules_of_loaded_object (struct link_map *map)
-{
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (map, cnt);
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
- map->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
-}
-
/* Load all audit modules. */
static void
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
@@ -1094,8 +1075,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
program and the dynamic linker itself). */
if (GLRO(dl_naudit) > 0)
{
- notify_audit_modules_of_loaded_object (main_map);
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+ _dl_audit_objopen (main_map, LM_ID_BASE, false);
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE, false);
}
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9c15259236..7eb3ad8ff9 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1346,6 +1346,11 @@ link_map_audit_state (struct link_map *l, size_t index)
return &base[index];
}
}
+
+/* Call the la_objopen() from the audit modules for the link_map L on the
+ namespace identification NSID. If CHECK_AUDIT is set it will also check
+ if main mapping of the namespace is a audit modules. */
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit);
#endif /* SHARED */
#if PTHREAD_IN_LIBC && defined SHARED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen
@ 2021-08-04 17:47 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-04 17:47 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=65863938eafa186b8a27f1c781d981ebfd70d006
commit 65863938eafa186b8a27f1c781d981ebfd70d006
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Mon Jul 19 15:47:51 2021 -0300
elf: Add _dl_audit_objopen
It consolidates the code required to call la_objopen() audit callback.
Diff:
---
elf/Makefile | 3 ++-
elf/dl-audit.c | 42 ++++++++++++++++++++++++++++++++++++++++++
elf/dl-load.c | 17 +----------------
elf/rtld.c | 23 ++---------------------
sysdeps/generic/ldsodefs.h | 5 +++++
5 files changed, 52 insertions(+), 38 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 78ab9f2228..c6c97efd8c 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -35,7 +35,8 @@ dl-routines = $(addprefix dl-,load lookup object reloc deps \
execstack open close trampoline \
exception sort-maps lookup-direct \
call-libc-early-init write \
- thread_gscope_wait tls_init_tp)
+ thread_gscope_wait tls_init_tp \
+ audit)
ifeq (yes,$(use-ldconfig))
dl-routines += dl-cache
endif
diff --git a/elf/dl-audit.c b/elf/dl-audit.c
new file mode 100644
index 0000000000..24d8557f18
--- /dev/null
+++ b/elf/dl-audit.c
@@ -0,0 +1,42 @@
+/* Audit common functions.
+ 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 <ldsodefs.h>
+
+#ifdef SHARED
+void
+_dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit)
+{
+ if (__glibc_likely (GLRO(dl_naudit) == 0)
+ || (check_audit && GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing))
+ return;
+
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ if (afct->objopen != NULL)
+ {
+ struct auditstate *state = link_map_audit_state (l, cnt);
+ state->bindflags = afct->objopen (l, nsid, &state->cookie);
+ l->l_audit_any_plt |= state->bindflags != 0;
+ }
+
+ afct = afct->next;
+ }
+}
+#endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 433a59191a..c0b68638c0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1512,22 +1512,7 @@ cannot enable executable stack as shared object requires");
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0)
- && !GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing)
- {
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (l, cnt);
- state->bindflags = afct->objopen (l, nsid, &state->cookie);
- l->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
- }
+ _dl_audit_objopen (l, nsid, true);
#endif
return l;
diff --git a/elf/rtld.c b/elf/rtld.c
index 1312378b5f..8008570f82 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1057,25 +1057,6 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
dlmargs.map->l_dont_set_tls_static = 1;
}
-/* Notify the the audit modules that the object MAP has already been
- loaded. */
-static void
-notify_audit_modules_of_loaded_object (struct link_map *map)
-{
- struct audit_ifaces *afct = GLRO(dl_audit);
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- if (afct->objopen != NULL)
- {
- struct auditstate *state = link_map_audit_state (map, cnt);
- state->bindflags = afct->objopen (map, LM_ID_BASE, &state->cookie);
- map->l_audit_any_plt |= state->bindflags != 0;
- }
-
- afct = afct->next;
- }
-}
-
/* Load all audit modules. */
static void
load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
@@ -1094,8 +1075,8 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
program and the dynamic linker itself). */
if (GLRO(dl_naudit) > 0)
{
- notify_audit_modules_of_loaded_object (main_map);
- notify_audit_modules_of_loaded_object (&GL(dl_rtld_map));
+ _dl_audit_objopen (main_map, LM_ID_BASE, false);
+ _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE, false);
}
}
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9c15259236..7eb3ad8ff9 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1346,6 +1346,11 @@ link_map_audit_state (struct link_map *l, size_t index)
return &base[index];
}
}
+
+/* Call the la_objopen() from the audit modules for the link_map L on the
+ namespace identification NSID. If CHECK_AUDIT is set it will also check
+ if main mapping of the namespace is a audit modules. */
+void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit);
#endif /* SHARED */
#if PTHREAD_IN_LIBC && defined SHARED
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-16 13:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 19:24 [glibc/azanella/ld-audit-fixes] elf: Add _dl_audit_objopen Adhemerval Zanella
2021-08-04 17:47 Adhemerval Zanella
2021-08-04 20:53 Adhemerval Zanella
2021-09-10 18:25 Adhemerval Zanella
2021-11-09 18:18 Adhemerval Zanella
2021-11-16 13:57 Adhemerval Zanella
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).