about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2019-11-02 21:40:26 +0100
committerFlorian Weimer <fweimer@redhat.com>2019-11-02 21:40:26 +0100
commit6a47bd92bf87136b6b7530edd4e7dc88a42ac6ed (patch)
tree1ed35ce6435b77a45c03b14db6141f0c2d981cc1
parent42893aa38fd6041d349ea0427c4d5ccbacd9a2be (diff)
downloadglibc-fw/bug25157.tar.gz
glibc-fw/bug25157.tar.xz
glibc-fw/bug25157.zip
Properly initialize audit cookie for the dynamic loader [BZ #25157] fw/bug25157
The l_audit array is indexed by audit module, not audit function.
-rw-r--r--elf/Makefile15
-rw-r--r--elf/rtld.c14
-rw-r--r--elf/tst-auditmany.c26
-rw-r--r--elf/tst-auditmanymod.h64
-rw-r--r--elf/tst-auditmanymod1.c20
-rw-r--r--elf/tst-auditmanymod2.c20
-rw-r--r--elf/tst-auditmanymod3.c20
-rw-r--r--elf/tst-auditmanymod4.c20
-rw-r--r--elf/tst-auditmanymod5.c20
-rw-r--r--elf/tst-auditmanymod6.c20
-rw-r--r--elf/tst-auditmanymod7.c20
-rw-r--r--elf/tst-auditmanymod8.c20
-rw-r--r--elf/tst-auditmanymod9.c20
13 files changed, 290 insertions, 9 deletions
diff --git a/elf/Makefile b/elf/Makefile
index 5e4cdb494f..06688181e3 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -193,7 +193,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
 	 tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
 	 tst-unwind-ctor tst-unwind-main tst-audit13 \
 	 tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-tlsmodid \
-	 tst-dlopen-self
+	 tst-dlopen-self tst-auditmany
 #	 reldep9
 tests-internal += loadtest unload unload2 circleload1 \
 	 neededtest neededtest2 neededtest3 neededtest4 \
@@ -281,7 +281,10 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
 		tst-main1mod tst-libc_dlvsym-dso tst-absolute-sym-lib \
 		tst-absolute-zero-lib tst-big-note-lib tst-unwind-ctor-lib \
 		tst-audit13mod1 tst-sonamemove-linkmod1 \
-		tst-sonamemove-runmod1 tst-sonamemove-runmod2
+		tst-sonamemove-runmod1 tst-sonamemove-runmod2 \
+		tst-auditmanymod1 tst-auditmanymod2 tst-auditmanymod3 \
+		tst-auditmanymod4 tst-auditmanymod5 tst-auditmanymod6 \
+		tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9
 # Most modules build with _ISOMAC defined, but those filtered out
 # depend on internal headers.
 modules-names-tests = $(filter-out ifuncmod% tst-libc_dlvsym-dso tst-tlsmod%,\
@@ -1426,6 +1429,14 @@ $(objpfx)tst-audit13.out: $(objpfx)tst-audit13mod1.so
 LDFLAGS-tst-audit13mod1.so = -Wl,-z,lazy
 tst-audit13-ENV = LD_AUDIT=$(objpfx)tst-audit13mod1.so
 
+$(objpfx)tst-auditmany.out: $(objpfx)tst-auditmanymod1.so \
+  $(objpfx)tst-auditmanymod2.so $(objpfx)tst-auditmanymod3.so \
+  $(objpfx)tst-auditmanymod4.so $(objpfx)tst-auditmanymod5.so \
+  $(objpfx)tst-auditmanymod6.so $(objpfx)tst-auditmanymod7.so \
+  $(objpfx)tst-auditmanymod8.so	$(objpfx)tst-auditmanymod9.so
+tst-auditmany-ENV = \
+  LD_AUDIT=tst-auditmanymod1.so:tst-auditmanymod2.so:tst-auditmanymod3.so:tst-auditmanymod4.so:tst-auditmanymod5.so:tst-auditmanymod6.so:tst-auditmanymod7.so:tst-auditmanymod8.so:tst-auditmanymod9.so
+
 # 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/rtld.c b/elf/rtld.c
index 8a6e1a11b2..bb7ca4114e 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1008,13 +1008,7 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
 
       /* Store the pointer.  */
       if (err_str == NULL && largs.result != NULL)
-	{
-	  newp->fptr[cnt] = largs.result;
-
-	  /* The dynamic linker link map is statically allocated,
-	     initialize the data now.  */
-	  GL(dl_rtld_map).l_audit[cnt].cookie = (intptr_t) &GL(dl_rtld_map);
-	}
+	newp->fptr[cnt] = largs.result;
       else
 	newp->fptr[cnt] = NULL;
       ++cnt;
@@ -1030,6 +1024,12 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
     *last_audit = GLRO(dl_audit) = &newp->ifaces;
   else
     *last_audit = (*last_audit)->next = &newp->ifaces;
+
+  /* The dynamic linker link map is statically allocated, initialize
+     the data now.  */
+  GL (dl_rtld_map).l_audit[GLRO (dl_naudit)].cookie
+    = (intptr_t) &GL(dl_rtld_map);
+
   ++GLRO(dl_naudit);
 
   /* Mark the DSO as being used for auditing.  */
diff --git a/elf/tst-auditmany.c b/elf/tst-auditmany.c
new file mode 100644
index 0000000000..9d68105b9e
--- /dev/null
+++ b/elf/tst-auditmany.c
@@ -0,0 +1,26 @@
+/* Check cookie initialization for many auditors.  Main program.
+   Copyright (C) 2019 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/>.  */
+
+/* It does not make sense to use the test harness for this test
+   because the testing happens in auditors.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/elf/tst-auditmanymod.h b/elf/tst-auditmanymod.h
new file mode 100644
index 0000000000..d1d89e0843
--- /dev/null
+++ b/elf/tst-auditmanymod.h
@@ -0,0 +1,64 @@
+/* Check cookie initialization for many auditors.  Auditor template.
+   Copyright (C) 2019 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/>.  */
+
+/* The macro MOD must be defined to the number of this auditor (an
+   integer) before including this file.  */
+
+#include <link.h>
+#include <stdio.h>
+#include <unistd.h>
+
+/* Error counter for delayed error reporting.  */
+static int errors;
+
+unsigned int
+la_version (unsigned int version)
+{
+  return version;
+}
+
+unsigned int
+la_objopen (struct link_map *map, Lmid_t lmid,
+            uintptr_t *cookie)
+{
+  struct link_map *cookie_map = (struct link_map *) *cookie;
+  printf ("info: %d, la_objopen: map=%p name=%s cookie=%p:%p diff=%td\n",
+          MOD, map, map->l_name, cookie, cookie_map,
+          (char *) cookie - (char *) map);
+  fflush (stdout);
+  if (map != cookie_map)
+    {
+      printf ("error: %d, la_objopen:"
+              " map address does not match cookie value\n",
+              MOD);
+      fflush (stdout);
+      ++errors;
+    }
+  return 0;
+}
+
+extern unsigned int
+la_objclose (uintptr_t *__cookie)
+{
+  if (errors != 0)
+    {
+      printf ("error: exiting due to previous errors");
+      _exit (1);
+    }
+  return 0;
+}
diff --git a/elf/tst-auditmanymod1.c b/elf/tst-auditmanymod1.c
new file mode 100644
index 0000000000..c7de49d446
--- /dev/null
+++ b/elf/tst-auditmanymod1.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 1.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 1
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod2.c b/elf/tst-auditmanymod2.c
new file mode 100644
index 0000000000..4254f022a1
--- /dev/null
+++ b/elf/tst-auditmanymod2.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 2.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 2
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod3.c b/elf/tst-auditmanymod3.c
new file mode 100644
index 0000000000..ee90f4eb3a
--- /dev/null
+++ b/elf/tst-auditmanymod3.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 3.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 3
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod4.c b/elf/tst-auditmanymod4.c
new file mode 100644
index 0000000000..6379fa1d55
--- /dev/null
+++ b/elf/tst-auditmanymod4.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 4.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 4
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod5.c b/elf/tst-auditmanymod5.c
new file mode 100644
index 0000000000..17c0f617aa
--- /dev/null
+++ b/elf/tst-auditmanymod5.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 5.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 5
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod6.c b/elf/tst-auditmanymod6.c
new file mode 100644
index 0000000000..86bc6801a4
--- /dev/null
+++ b/elf/tst-auditmanymod6.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 6.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 6
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod7.c b/elf/tst-auditmanymod7.c
new file mode 100644
index 0000000000..92b0bf6006
--- /dev/null
+++ b/elf/tst-auditmanymod7.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 7.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 7
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod8.c b/elf/tst-auditmanymod8.c
new file mode 100644
index 0000000000..d42f884d2f
--- /dev/null
+++ b/elf/tst-auditmanymod8.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 8.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 8
+#include "tst-auditmanymod.h"
diff --git a/elf/tst-auditmanymod9.c b/elf/tst-auditmanymod9.c
new file mode 100644
index 0000000000..6bee81d69c
--- /dev/null
+++ b/elf/tst-auditmanymod9.c
@@ -0,0 +1,20 @@
+/* Check cookie initialization for many auditors.  Auditor 9.
+   Copyright (C) 2019 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/>.  */
+
+#define MOD 9
+#include "tst-auditmanymod.h"