public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/mseal] elf: Add support to memory sealing for audit modules
@ 2024-06-04 22:58 Adhemerval Zanella
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2024-06-04 22:58 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0f31bbfcd4e9f2cb1933439a1b154c427a3206fb

commit 0f31bbfcd4e9f2cb1933439a1b154c427a3206fb
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 4 14:38:42 2024 -0300

    elf: Add support to memory sealing for audit modules
    
    It is done after the the loading process (instead at loading time
    with RTLD_NODELETE), because the module might be unloaded due
    nexistent or wrong la_version.  It also means that the la_version
    and l_objopen/la_activety might be called without the object memory
    sealed.
    
    Checked on x86_64-linux-gnu.

Diff:
---
 elf/rtld.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/elf/rtld.c b/elf/rtld.c
index 174389e205..de00182d46 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1051,6 +1051,8 @@ static void
 load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
 {
   struct audit_ifaces *last_audit = NULL;
+  struct link_map *l;
+  Lmid_t nsid;
 
   while (true)
     {
@@ -1060,6 +1062,16 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
       load_audit_module (name, &last_audit);
     }
 
+  /* Seal the audit modules and their dependencies.  It is done after the
+     the loading process (instead at loading time with RTLD_NODELETE), because
+     the module might be unloaded (due inexistent or wrong la_version).  */
+  for (nsid = LM_ID_BASE + 1; nsid < GL(dl_nns); nsid++)
+    for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next)
+      {
+	l->l_seal = 1;
+	_dl_mseal_map (l);
+      }
+
   /* Notify audit modules of the initially loaded modules (the main
      program and the dynamic linker itself).  */
   if (GLRO(dl_naudit) > 0)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/azanella/mseal] elf: Add support to memory sealing for audit modules
@ 2024-06-21 14:30 Adhemerval Zanella
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2024-06-21 14:30 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=44cf6547a328cb82b6fb5560503af2b4c2d887d8

commit 44cf6547a328cb82b6fb5560503af2b4c2d887d8
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 4 14:38:42 2024 -0300

    elf: Add support to memory sealing for audit modules
    
    The memory sealing is done after library loading and sanity check
    since an inexistent or wrong la_version might unload the library.
    
    Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Diff:
---
 elf/rtld.c                                      |  4 ++++
 manual/tunables.texi                            |  3 +++
 sysdeps/unix/sysv/linux/Makefile                |  2 ++
 sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c | 23 +++++++++++++++++++++++
 sysdeps/unix/sysv/linux/tst-dl_mseal.c          |  7 +++++--
 5 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/elf/rtld.c b/elf/rtld.c
index 174389e205..62ad1272a4 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1044,6 +1044,10 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
 
   /* Mark the DSO as being used for auditing.  */
   dlmargs.map->l_auditing = 1;
+
+  /* Seal the audit modules and their dependencies.  */
+  dlmargs.map->l_seal = lt_seal_toseal;
+  _dl_mseal_map (dlmargs.map, true);
 }
 
 /* Load all audit modules.  */
diff --git a/manual/tunables.texi b/manual/tunables.texi
index a5cc08ddf2..d15eabc9e8 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -384,6 +384,9 @@ Any library loaded with @code{dlopen} with @code{RTLD_NODELETE} flag.
 @item
 Any runtime library used for process unwind (such as required by @code{backtrace}
 or @code{pthread_exit}).
+
+@item
+All audit modules and their dependencies.
 @end itemize
 
 The tunable accepts three diferent values: @samp{0} where sealing is disabled,
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 808f9e5f8c..ffadb56f05 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -656,9 +656,11 @@ modules-names += \
   lib-tst-dl_mseal-dlopen-2 \
   lib-tst-dl_mseal-dlopen-2-1 \
   lib-tst-dl_mseal-preload \
+  tst-dl_mseal-auditmod \
   # modules-names
 
 $(objpfx)tst-dl_mseal.out: \
+  $(objpfx)tst-dl_mseal-auditmod.so \
   $(objpfx)lib-tst-dl_mseal-preload.so \
   $(objpfx)lib-tst-dl_mseal-1.so \
   $(objpfx)lib-tst-dl_mseal-2.so \
diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c b/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c
new file mode 100644
index 0000000000..d909a1561c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c
@@ -0,0 +1,23 @@
+/* Audit module for tst-dl_mseal test.
+   Copyright (C) 2024 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/>.  */
+
+unsigned int
+la_version (unsigned int v)
+{
+  return v;
+}
diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal.c b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
index da1a3ebe5a..ac60d7342a 100644
--- a/sysdeps/unix/sysv/linux/tst-dl_mseal.c
+++ b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
@@ -35,6 +35,7 @@
 #include <support/xthread.h>
 
 #define LIB_PRELOAD              "lib-tst-dl_mseal-preload.so"
+#define LIB_AUDIT                "tst-dl_mseal-auditmod.so"
 
 #define LIB_NEEDED_1             "lib-tst-dl_mseal-1.so"
 #define LIB_NEEDED_2             "lib-tst-dl_mseal-2.so"
@@ -68,6 +69,7 @@ static const char *expected_sealed_libs[] =
   "ld.so",
   "tst-dl_mseal",
   LIB_PRELOAD,
+  LIB_AUDIT,
   LIB_NEEDED_1,
   LIB_NEEDED_2,
   LIB_DLOPEN_NODELETE,
@@ -247,11 +249,12 @@ do_test (int argc, char *argv[])
   spargv[i++] = (char *) "--restart";
   spargv[i] = NULL;
 
-  char *envvarss[3];
+  char *envvarss[4];
   envvarss[0] = (char *) "GLIBC_TUNABLES=glibc.rtld.seal=2";
 #ifndef TEST_STATIC
   envvarss[1] = (char *) "LD_PRELOAD=" LIB_PRELOAD;
-  envvarss[2] = NULL;
+  envvarss[2] = (char *) "LD_AUDIT=" LIB_AUDIT,
+  envvarss[3] = NULL;
 #else
   envvarss[1] = NULL;
 #endif

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/azanella/mseal] elf: Add support to memory sealing for audit modules
@ 2024-06-19 13:05 Adhemerval Zanella
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella @ 2024-06-19 13:05 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2fe393dd1768a6b027c848a494285c29ad577bf0

commit 2fe393dd1768a6b027c848a494285c29ad577bf0
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 4 14:38:42 2024 -0300

    elf: Add support to memory sealing for audit modules
    
    The memory sealing is done after library loading and sanity check
    since an inexistent or wrong la_version might unload the library.
    
    Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Diff:
---
 elf/rtld.c                                      |  4 ++++
 manual/tunables.texi                            |  3 +++
 sysdeps/unix/sysv/linux/Makefile                |  2 ++
 sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c | 23 +++++++++++++++++++++++
 sysdeps/unix/sysv/linux/tst-dl_mseal.c          |  7 +++++--
 5 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/elf/rtld.c b/elf/rtld.c
index 174389e205..62ad1272a4 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1044,6 +1044,10 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
 
   /* Mark the DSO as being used for auditing.  */
   dlmargs.map->l_auditing = 1;
+
+  /* Seal the audit modules and their dependencies.  */
+  dlmargs.map->l_seal = lt_seal_toseal;
+  _dl_mseal_map (dlmargs.map, true);
 }
 
 /* Load all audit modules.  */
diff --git a/manual/tunables.texi b/manual/tunables.texi
index a5cc08ddf2..d15eabc9e8 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -384,6 +384,9 @@ Any library loaded with @code{dlopen} with @code{RTLD_NODELETE} flag.
 @item
 Any runtime library used for process unwind (such as required by @code{backtrace}
 or @code{pthread_exit}).
+
+@item
+All audit modules and their dependencies.
 @end itemize
 
 The tunable accepts three diferent values: @samp{0} where sealing is disabled,
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 922511b4a1..f11aff84f5 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -656,9 +656,11 @@ modules-names += \
   lib-tst-dl_mseal-dlopen-2 \
   lib-tst-dl_mseal-dlopen-2-1 \
   lib-tst-dl_mseal-preload \
+  tst-dl_mseal-auditmod \
   # modules-names
 
 $(objpfx)tst-dl_mseal.out: \
+  $(objpfx)tst-dl_mseal-auditmod.so \
   $(objpfx)lib-tst-dl_mseal-preload.so \
   $(objpfx)lib-tst-dl_mseal-1.so \
   $(objpfx)lib-tst-dl_mseal-2.so \
diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c b/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c
new file mode 100644
index 0000000000..d909a1561c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c
@@ -0,0 +1,23 @@
+/* Audit module for tst-dl_mseal test.
+   Copyright (C) 2024 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/>.  */
+
+unsigned int
+la_version (unsigned int v)
+{
+  return v;
+}
diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal.c b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
index da1a3ebe5a..ac60d7342a 100644
--- a/sysdeps/unix/sysv/linux/tst-dl_mseal.c
+++ b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
@@ -35,6 +35,7 @@
 #include <support/xthread.h>
 
 #define LIB_PRELOAD              "lib-tst-dl_mseal-preload.so"
+#define LIB_AUDIT                "tst-dl_mseal-auditmod.so"
 
 #define LIB_NEEDED_1             "lib-tst-dl_mseal-1.so"
 #define LIB_NEEDED_2             "lib-tst-dl_mseal-2.so"
@@ -68,6 +69,7 @@ static const char *expected_sealed_libs[] =
   "ld.so",
   "tst-dl_mseal",
   LIB_PRELOAD,
+  LIB_AUDIT,
   LIB_NEEDED_1,
   LIB_NEEDED_2,
   LIB_DLOPEN_NODELETE,
@@ -247,11 +249,12 @@ do_test (int argc, char *argv[])
   spargv[i++] = (char *) "--restart";
   spargv[i] = NULL;
 
-  char *envvarss[3];
+  char *envvarss[4];
   envvarss[0] = (char *) "GLIBC_TUNABLES=glibc.rtld.seal=2";
 #ifndef TEST_STATIC
   envvarss[1] = (char *) "LD_PRELOAD=" LIB_PRELOAD;
-  envvarss[2] = NULL;
+  envvarss[2] = (char *) "LD_AUDIT=" LIB_AUDIT,
+  envvarss[3] = NULL;
 #else
   envvarss[1] = NULL;
 #endif

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-21 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 22:58 [glibc/azanella/mseal] elf: Add support to memory sealing for audit modules Adhemerval Zanella
2024-06-19 13:05 Adhemerval Zanella
2024-06-21 14:30 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).