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