diff options
| author | riastradh <riastradh@NetBSD.org> | 2023-06-02 19:09:11 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2023-06-02 19:09:11 +0000 |
| commit | de3d7550b3af629ccae904bcd903f53ec3e5b4d5 (patch) | |
| tree | 7061ada15c137fafd9f004658b2fda61e3850cc1 /tests/libexec | |
| parent | f12a23f2c3d83b202e67485079e0b7608c8e0cdd (diff) | |
ld.elf_so: Test dynamic-then-static abuse via ctor.
XXX pullup-10
Diffstat (limited to 'tests/libexec')
| -rw-r--r-- | tests/libexec/ld.elf_so/Makefile | 3 | ||||
| -rw-r--r-- | tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile | 22 | ||||
| -rw-r--r-- | tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c | 36 | ||||
| -rw-r--r-- | tests/libexec/ld.elf_so/t_tls_extern.c | 19 |
4 files changed, 78 insertions, 2 deletions
diff --git a/tests/libexec/ld.elf_so/Makefile b/tests/libexec/ld.elf_so/Makefile index 575bdd73019..8bcd3648fb5 100644 --- a/tests/libexec/ld.elf_so/Makefile +++ b/tests/libexec/ld.elf_so/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.18 2023/06/02 19:08:48 riastradh Exp $ +# $NetBSD: Makefile,v 1.19 2023/06/02 19:09:11 riastradh Exp $ # NOMAN= # defined @@ -19,6 +19,7 @@ SUBDIR+= helper_onlydef SUBDIR+= .WAIT SUBDIR+= helper_abuse_dynamic SUBDIR+= helper_abuse_static +SUBDIR+= helper_onlyctor_dynamic SUBDIR+= helper_onlyuse_dynamic SUBDIR+= helper_onlyuse_static SUBDIR+= helper_use_dynamic diff --git a/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile b/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile new file mode 100644 index 00000000000..df7cd1f07f8 --- /dev/null +++ b/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile @@ -0,0 +1,22 @@ +# $NetBSD: Makefile,v 1.1 2023/06/02 19:09:11 riastradh Exp $ + +.include <bsd.own.mk> + +LIB= h_onlyctor_dynamic +SRCS= h_onlyctor_dynamic.c + +DEF_DIR!= cd ${.CURDIR}/../helper_onlydef && ${PRINTOBJDIR} +LDADD+= -Wl,-rpath,${TESTSDIR} -L${DEF_DIR} -lh_onlydef + +LIBDIR= ${TESTSBASE}/libexec/ld.elf_so +SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so +SHLIB_MAJOR= 1 + +MKSTATICLIB= no +MKPROFILE= no +MKPICINSTALL= no +MKLINT= no + +NOMAN= # defined + +.include <bsd.lib.mk> diff --git a/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c b/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c new file mode 100644 index 00000000000..4f2b977c862 --- /dev/null +++ b/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c @@ -0,0 +1,36 @@ +/* $NetBSD: h_onlyctor_dynamic.c,v 1.1 2023/06/02 19:09:11 riastradh Exp $ */ + +/*- + * Copyright (c) 2023 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +extern __thread int mysym; /* dynamic */ +int *mysymptr; + +static void __attribute__((constructor)) +init(void) +{ + mysymptr = &mysym; +} diff --git a/tests/libexec/ld.elf_so/t_tls_extern.c b/tests/libexec/ld.elf_so/t_tls_extern.c index d8c569601dd..f291e068eec 100644 --- a/tests/libexec/ld.elf_so/t_tls_extern.c +++ b/tests/libexec/ld.elf_so/t_tls_extern.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_tls_extern.c,v 1.10 2023/06/02 19:08:48 riastradh Exp $ */ +/* $NetBSD: t_tls_extern.c,v 1.11 2023/06/02 19:09:11 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -285,6 +285,22 @@ ATF_TC_BODY(static_usedefnoload, tc) USE_DEF_NOLOAD, /*xfail*/true); } +ATF_TC(onlydef_dynamic_static_ctor); +ATF_TC_HEAD(onlydef_dynamic_static_ctor, tc) +{ + atf_tc_set_md_var(tc, "descr", "definition-only library," + " dynamic load and use in ctor, then static load fails"); +} +ATF_TC_BODY(onlydef_dynamic_static_ctor, tc) +{ + + ATF_REQUIRE_DL(dlopen("libh_onlydef.so", 0)); + ATF_REQUIRE_DL(dlopen("libh_onlyctor_dynamic.so", 0)); + atf_tc_expect_fail("rtld fails to detect dynamic-then-static abuse"); + ATF_CHECK_EQ_MSG(NULL, dlopen("libh_onlyuse_static.so", 0), + "dlopen failed to detect dynamic-then-static abuse"); +} + ATF_TC(onlydef_dynamic_static_eager); ATF_TC_HEAD(onlydef_dynamic_static_eager, tc) { @@ -393,6 +409,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, dynamic_defuse_lazy); ATF_TP_ADD_TC(tp, dynamic_usedef); ATF_TP_ADD_TC(tp, dynamic_usedefnoload); + ATF_TP_ADD_TC(tp, onlydef_dynamic_static_ctor); ATF_TP_ADD_TC(tp, onlydef_dynamic_static_eager); ATF_TP_ADD_TC(tp, onlydef_dynamic_static_lazy); ATF_TP_ADD_TC(tp, onlydef_static_dynamic_eager); |
