446cf2
commit b3fbfe81961a1d14d7b54d1c9757e1f487073bcb
446cf2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
446cf2
Date:   Tue Feb 12 13:51:43 2019 +0100
446cf2
446cf2
    elf: Test for LD_AUDIT module returning zero from la_version [BZ #24122]
446cf2
    
446cf2
    This includes the original test case from commit
446cf2
    8e889c5da3c5981c5a46a93fec02de40131ac5a6 ("elf: Fix LD_AUDIT for
446cf2
    modules with invalid version (BZ#24122)).
446cf2
446cf2
Conflicts:
446cf2
	elf/Makefile
446cf2
	  (Different backport order of tests.)
446cf2
446cf2
diff --git a/elf/Makefile b/elf/Makefile
446cf2
index 6d1962b2e4deb871..4e1356b9172aee02 100644
446cf2
--- a/elf/Makefile
446cf2
+++ b/elf/Makefile
446cf2
@@ -191,6 +191,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
446cf2
 	 tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-noload \
446cf2
 	 tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \
446cf2
 	 tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
446cf2
+	 tst-audit13 \
446cf2
 	 tst-sonamemove-link tst-sonamemove-dlopen tst-initfinilazyfail \
446cf2
 	 tst-dlopenfail tst-dlopenfail-2 \
446cf2
 	 tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen
446cf2
@@ -300,7 +301,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
446cf2
 		tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin \
446cf2
 		tst-main1mod tst-libc_dlvsym-dso tst-absolute-sym-lib \
446cf2
 		tst-absolute-zero-lib tst-big-note-lib \
446cf2
-		tst-sonamemove-linkmod1 \
446cf2
+		tst-audit13mod1 tst-sonamemove-linkmod1 \
446cf2
 		tst-sonamemove-runmod1 tst-sonamemove-runmod2 \
446cf2
 		tst-initlazyfailmod tst-finilazyfailmod \
446cf2
 		tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \
446cf2
@@ -1428,6 +1429,10 @@ tst-audit12-ENV = LD_AUDIT=$(objpfx)tst-auditmod12.so
446cf2
 $(objpfx)tst-audit12mod1.so: $(objpfx)tst-audit12mod2.so
446cf2
 LDFLAGS-tst-audit12mod2.so = -Wl,--version-script=tst-audit12mod2.map
446cf2
 
446cf2
+$(objpfx)tst-audit13.out: $(objpfx)tst-audit13mod1.so
446cf2
+LDFLAGS-tst-audit13mod1.so = -Wl,-z,lazy
446cf2
+tst-audit13-ENV = LD_AUDIT=$(objpfx)tst-audit13mod1.so
446cf2
+
446cf2
 # tst-sonamemove links against an older implementation of the library.
446cf2
 LDFLAGS-tst-sonamemove-linkmod1.so = \
446cf2
   -Wl,--version-script=tst-sonamemove-linkmod1.map \
446cf2
diff --git a/elf/tst-audit13.c b/elf/tst-audit13.c
446cf2
new file mode 100644
446cf2
index 0000000000000000..6f587baf581ce32c
446cf2
--- /dev/null
446cf2
+++ b/elf/tst-audit13.c
446cf2
@@ -0,0 +1,28 @@
446cf2
+/* Check for invalid audit version (BZ#24122).
446cf2
+   Copyright (C) 2019 Free Software Foundation, Inc.
446cf2
+   This file is part of the GNU C Library.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <http://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#include <stdio.h>
446cf2
+
446cf2
+static int
446cf2
+do_test (void)
446cf2
+{
446cf2
+  puts ("plt call");
446cf2
+  return 0;
446cf2
+}
446cf2
+
446cf2
+#include <support/test-driver.c>
446cf2
diff --git a/elf/tst-audit13mod1.c b/elf/tst-audit13mod1.c
446cf2
new file mode 100644
446cf2
index 0000000000000000..cf017e235c7ae030
446cf2
--- /dev/null
446cf2
+++ b/elf/tst-audit13mod1.c
446cf2
@@ -0,0 +1,93 @@
446cf2
+/* Check for invalid audit version (BZ#24122).
446cf2
+   Copyright (C) 2019 Free Software Foundation, Inc.
446cf2
+   This file is part of the GNU C Library.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <http://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#include <link.h>
446cf2
+#include <stdlib.h>
446cf2
+
446cf2
+unsigned int
446cf2
+la_version (unsigned int version)
446cf2
+{
446cf2
+  /* The audit specification says that a version of 0 or a version
446cf2
+     greater than any version supported by the dynamic loader shall
446cf2
+     cause the module to be ignored.  */
446cf2
+  return 0;
446cf2
+}
446cf2
+
446cf2
+void
446cf2
+la_activity (uintptr_t *cookie, unsigned int flag)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+char *
446cf2
+la_objsearch (const char *name, uintptr_t *cookie, unsigned int flag)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+unsigned int
446cf2
+la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t * cookie)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+void
446cf2
+la_preinit (uintptr_t * cookie)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+uintptr_t
446cf2
+#if __ELF_NATIVE_CLASS == 32
446cf2
+la_symbind32 (Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
446cf2
+              uintptr_t *defcook, unsigned int *flags, const char *symname)
446cf2
+#else
446cf2
+la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
446cf2
+              uintptr_t *defcook, unsigned int *flags, const char *symname)
446cf2
+#endif
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+unsigned int
446cf2
+la_objclose (uintptr_t * cookie)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+#include <tst-audit.h>
446cf2
+#if (!defined (pltenter) || !defined (pltexit) || !defined (La_regs) \
446cf2
+     || !defined (La_retval) || !defined (int_retval))
446cf2
+# error "architecture specific code needed in sysdeps/CPU/tst-audit.h"
446cf2
+#endif
446cf2
+
446cf2
+ElfW(Addr)
446cf2
+pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
446cf2
+          uintptr_t *defcook, La_regs *regs, unsigned int *flags,
446cf2
+          const char *symname, long int *framesizep)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}
446cf2
+
446cf2
+unsigned int
446cf2
+pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
446cf2
+         uintptr_t *defcook, const La_regs *inregs, La_retval *outregs,
446cf2
+         const char *symname)
446cf2
+{
446cf2
+  exit (EXIT_FAILURE);
446cf2
+}