|
|
c5d972 |
Added $(libdl) to $(objpfx)tst-audit-tlsdesc-dlopen in elf/Makefile
|
|
|
c5d972 |
since we still need $(libdl) in RHEL8.
|
|
|
c5d972 |
|
|
|
c5d972 |
commit d1b38173c9255b1a4ae00018ad9b35404a7c74d0
|
|
|
c5d972 |
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
c5d972 |
Date: Wed Jun 30 15:51:31 2021 -0300
|
|
|
c5d972 |
|
|
|
c5d972 |
elf: Add audit tests for modules with TLSDESC
|
|
|
c5d972 |
|
|
|
c5d972 |
Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
|
|
|
c5d972 |
|
|
|
c5d972 |
Reviewed-by: Florian Weimer <fweimer@redhat.com>
|
|
|
c5d972 |
|
|
|
c5d972 |
diff --git a/elf/Makefile b/elf/Makefile
|
|
|
c5d972 |
index 0cc03ffe2984ee50..d8d9734df0fea9a8 100644
|
|
|
c5d972 |
--- a/elf/Makefile
|
|
|
c5d972 |
+++ b/elf/Makefile
|
|
|
c5d972 |
@@ -375,6 +375,22 @@ modules-names += tst-gnu2-tls1mod
|
|
|
c5d972 |
$(objpfx)tst-gnu2-tls1: $(objpfx)tst-gnu2-tls1mod.so
|
|
|
c5d972 |
tst-gnu2-tls1mod.so-no-z-defs = yes
|
|
|
c5d972 |
CFLAGS-tst-gnu2-tls1mod.c += -mtls-dialect=gnu2
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+tests += tst-audit-tlsdesc tst-audit-tlsdesc-dlopen
|
|
|
c5d972 |
+modules-names += tst-audit-tlsdesc-mod1 tst-audit-tlsdesc-mod2 tst-auditmod-tlsdesc
|
|
|
c5d972 |
+$(objpfx)tst-audit-tlsdesc: $(objpfx)tst-audit-tlsdesc-mod1.so \
|
|
|
c5d972 |
+ $(objpfx)tst-audit-tlsdesc-mod2.so \
|
|
|
c5d972 |
+ $(shared-thread-library)
|
|
|
c5d972 |
+CFLAGS-tst-audit-tlsdesc-mod1.c += -mtls-dialect=gnu2
|
|
|
c5d972 |
+CFLAGS-tst-audit-tlsdesc-mod2.c += -mtls-dialect=gnu2
|
|
|
c5d972 |
+$(objpfx)tst-audit-tlsdesc-dlopen: $(shared-thread-library) $(libdl)
|
|
|
c5d972 |
+$(objpfx)tst-audit-tlsdesc-dlopen.out: $(objpfx)tst-audit-tlsdesc-mod1.so \
|
|
|
c5d972 |
+ $(objpfx)tst-audit-tlsdesc-mod2.so
|
|
|
c5d972 |
+$(objpfx)tst-audit-tlsdesc-mod1.so: $(objpfx)tst-audit-tlsdesc-mod2.so
|
|
|
c5d972 |
+$(objpfx)tst-audit-tlsdesc.out: $(objpfx)tst-auditmod-tlsdesc.so
|
|
|
c5d972 |
+tst-audit-tlsdesc-ENV = LD_AUDIT=$(objpfx)tst-auditmod-tlsdesc.so
|
|
|
c5d972 |
+$(objpfx)tst-audit-tlsdesc-dlopen.out: $(objpfx)tst-auditmod-tlsdesc.so
|
|
|
c5d972 |
+tst-audit-tlsdesc-dlopen-ENV = LD_AUDIT=$(objpfx)tst-auditmod-tlsdesc.so
|
|
|
c5d972 |
endif
|
|
|
c5d972 |
ifeq (yes,$(have-protected-data))
|
|
|
c5d972 |
modules-names += tst-protected1moda tst-protected1modb
|
|
|
c5d972 |
diff --git a/elf/tst-audit-tlsdesc-dlopen.c b/elf/tst-audit-tlsdesc-dlopen.c
|
|
|
c5d972 |
new file mode 100644
|
|
|
c5d972 |
index 0000000000000000..9c16bb087aca1b77
|
|
|
c5d972 |
--- /dev/null
|
|
|
c5d972 |
+++ b/elf/tst-audit-tlsdesc-dlopen.c
|
|
|
c5d972 |
@@ -0,0 +1,67 @@
|
|
|
c5d972 |
+/* DT_AUDIT with modules with TLSDESC.
|
|
|
c5d972 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
c5d972 |
+ This file is part of the GNU C Library.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
c5d972 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
c5d972 |
+ License as published by the Free Software Foundation; either
|
|
|
c5d972 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
c5d972 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c5d972 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c5d972 |
+ Lesser General Public License for more details.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
c5d972 |
+ License along with the GNU C Library; if not, see
|
|
|
c5d972 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+#include <support/check.h>
|
|
|
c5d972 |
+#include <support/xthread.h>
|
|
|
c5d972 |
+#include <support/xdlfcn.h>
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+static void *
|
|
|
c5d972 |
+thr_func (void *mod)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ int* (*get_global1)(void) = xdlsym (mod, "get_global1");
|
|
|
c5d972 |
+ int* (*get_global2)(void) = xdlsym (mod, "get_global2");
|
|
|
c5d972 |
+ void (*set_global2)(int) = xdlsym (mod, "set_global2");
|
|
|
c5d972 |
+ int* (*get_local1)(void) = xdlsym (mod, "get_local1");
|
|
|
c5d972 |
+ int* (*get_local2)(void) = xdlsym (mod, "get_local2");
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ int *global1 = get_global1 ();
|
|
|
c5d972 |
+ TEST_COMPARE (*global1, 0);
|
|
|
c5d972 |
+ ++*global1;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ int *global2 = get_global2 ();
|
|
|
c5d972 |
+ TEST_COMPARE (*global2, 0);
|
|
|
c5d972 |
+ ++*global2;
|
|
|
c5d972 |
+ TEST_COMPARE (*global2, 1);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ set_global2 (10);
|
|
|
c5d972 |
+ TEST_COMPARE (*global2, 10);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ int *local1 = get_local1 ();
|
|
|
c5d972 |
+ TEST_COMPARE (*local1, 0);
|
|
|
c5d972 |
+ ++*local1;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ int *local2 = get_local2 ();
|
|
|
c5d972 |
+ TEST_COMPARE (*local2, 0);
|
|
|
c5d972 |
+ ++*local2;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ return 0;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+static int
|
|
|
c5d972 |
+do_test (void)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ void *mod = xdlopen ("tst-audit-tlsdesc-mod1.so", RTLD_LAZY);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ pthread_t thr = xpthread_create (NULL, thr_func, mod);
|
|
|
c5d972 |
+ void *r = xpthread_join (thr);
|
|
|
c5d972 |
+ TEST_VERIFY (r == NULL);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ return 0;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+#include <support/test-driver.c>
|
|
|
c5d972 |
diff --git a/elf/tst-audit-tlsdesc-mod1.c b/elf/tst-audit-tlsdesc-mod1.c
|
|
|
c5d972 |
new file mode 100644
|
|
|
c5d972 |
index 0000000000000000..61c7dd99a2fb5e28
|
|
|
c5d972 |
--- /dev/null
|
|
|
c5d972 |
+++ b/elf/tst-audit-tlsdesc-mod1.c
|
|
|
c5d972 |
@@ -0,0 +1,41 @@
|
|
|
c5d972 |
+/* DT_AUDIT with modules with TLSDESC.
|
|
|
c5d972 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
c5d972 |
+ This file is part of the GNU C Library.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
c5d972 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
c5d972 |
+ License as published by the Free Software Foundation; either
|
|
|
c5d972 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
c5d972 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c5d972 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c5d972 |
+ Lesser General Public License for more details.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
c5d972 |
+ License along with the GNU C Library; if not, see
|
|
|
c5d972 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+__thread int global1;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+int *
|
|
|
c5d972 |
+get_global1 (void)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ return &global1;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+static __thread int local1;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+void *
|
|
|
c5d972 |
+get_local1 (void)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ return &local1;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+extern __thread int global2;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+void
|
|
|
c5d972 |
+set_global2 (int v)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ global2 = v;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
diff --git a/elf/tst-audit-tlsdesc-mod2.c b/elf/tst-audit-tlsdesc-mod2.c
|
|
|
c5d972 |
new file mode 100644
|
|
|
c5d972 |
index 0000000000000000..28aef635f688ee03
|
|
|
c5d972 |
--- /dev/null
|
|
|
c5d972 |
+++ b/elf/tst-audit-tlsdesc-mod2.c
|
|
|
c5d972 |
@@ -0,0 +1,33 @@
|
|
|
c5d972 |
+/* DT_AUDIT with modules with TLSDESC.
|
|
|
c5d972 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
c5d972 |
+ This file is part of the GNU C Library.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
c5d972 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
c5d972 |
+ License as published by the Free Software Foundation; either
|
|
|
c5d972 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
c5d972 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c5d972 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c5d972 |
+ Lesser General Public License for more details.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
c5d972 |
+ License along with the GNU C Library; if not, see
|
|
|
c5d972 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+__thread int global2;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+int *
|
|
|
c5d972 |
+get_global2 (void)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ return &global2;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+static __thread int local2;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+void *
|
|
|
c5d972 |
+get_local2 (void)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ return &local2;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
diff --git a/elf/tst-audit-tlsdesc.c b/elf/tst-audit-tlsdesc.c
|
|
|
c5d972 |
new file mode 100644
|
|
|
c5d972 |
index 0000000000000000..3c8be81c95528f47
|
|
|
c5d972 |
--- /dev/null
|
|
|
c5d972 |
+++ b/elf/tst-audit-tlsdesc.c
|
|
|
c5d972 |
@@ -0,0 +1,60 @@
|
|
|
c5d972 |
+/* DT_AUDIT with modules with TLSDESC.
|
|
|
c5d972 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
c5d972 |
+ This file is part of the GNU C Library.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
c5d972 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
c5d972 |
+ License as published by the Free Software Foundation; either
|
|
|
c5d972 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
c5d972 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c5d972 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c5d972 |
+ Lesser General Public License for more details.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
c5d972 |
+ License along with the GNU C Library; if not, see
|
|
|
c5d972 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+#include <support/check.h>
|
|
|
c5d972 |
+#include <support/xthread.h>
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+extern __thread int global1;
|
|
|
c5d972 |
+extern __thread int global2;
|
|
|
c5d972 |
+void *get_local1 (void);
|
|
|
c5d972 |
+void set_global2 (int v);
|
|
|
c5d972 |
+void *get_local2 (void);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+static void *
|
|
|
c5d972 |
+thr_func (void *clousure)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ TEST_COMPARE (global1, 0);
|
|
|
c5d972 |
+ ++global1;
|
|
|
c5d972 |
+ TEST_COMPARE (global2, 0);
|
|
|
c5d972 |
+ ++global2;
|
|
|
c5d972 |
+ TEST_COMPARE (global2, 1);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ set_global2 (10);
|
|
|
c5d972 |
+ TEST_COMPARE (global2, 10);
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ int *local1 = get_local1 ();
|
|
|
c5d972 |
+ TEST_COMPARE (*local1, 0);
|
|
|
c5d972 |
+ ++*local1;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ int *local2 = get_local2 ();
|
|
|
c5d972 |
+ TEST_COMPARE (*local2, 0);
|
|
|
c5d972 |
+ ++*local2;
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ return 0;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+static int
|
|
|
c5d972 |
+do_test (void)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ pthread_t thr = xpthread_create (NULL, thr_func, NULL);
|
|
|
c5d972 |
+ void *r = xpthread_join (thr);
|
|
|
c5d972 |
+ TEST_VERIFY (r == NULL);
|
|
|
c5d972 |
+ return 0;
|
|
|
c5d972 |
+}
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+#include <support/test-driver.c>
|
|
|
c5d972 |
diff --git a/elf/tst-auditmod-tlsdesc.c b/elf/tst-auditmod-tlsdesc.c
|
|
|
c5d972 |
new file mode 100644
|
|
|
c5d972 |
index 0000000000000000..e4b835d1f1fb6f73
|
|
|
c5d972 |
--- /dev/null
|
|
|
c5d972 |
+++ b/elf/tst-auditmod-tlsdesc.c
|
|
|
c5d972 |
@@ -0,0 +1,25 @@
|
|
|
c5d972 |
+/* DT_AUDIT with modules with TLSDESC.
|
|
|
c5d972 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
c5d972 |
+ This file is part of the GNU C Library.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
c5d972 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
c5d972 |
+ License as published by the Free Software Foundation; either
|
|
|
c5d972 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
c5d972 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c5d972 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c5d972 |
+ Lesser General Public License for more details.
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
c5d972 |
+ License along with the GNU C Library; if not, see
|
|
|
c5d972 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+#include <link.h>
|
|
|
c5d972 |
+
|
|
|
c5d972 |
+unsigned int
|
|
|
c5d972 |
+la_version (unsigned int version)
|
|
|
c5d972 |
+{
|
|
|
c5d972 |
+ return LAV_CURRENT;
|
|
|
c5d972 |
+}
|