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