Module Name:    src
Committed By:   riastradh
Date:           Fri Jun  2 19:09:12 UTC 2023

Modified Files:
        src/distrib/sets/lists/debug: shl.mi
        src/distrib/sets/lists/tests: shl.mi
        src/tests/libexec/ld.elf_so: Makefile t_tls_extern.c
Added Files:
        src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic: Makefile
            h_onlyctor_dynamic.c

Log Message:
ld.elf_so: Test dynamic-then-static abuse via ctor.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/distrib/sets/lists/debug/shl.mi
cvs rdiff -u -r1.15 -r1.16 src/distrib/sets/lists/tests/shl.mi
cvs rdiff -u -r1.18 -r1.19 src/tests/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.10 -r1.11 src/tests/libexec/ld.elf_so/t_tls_extern.c
cvs rdiff -u -r0 -r1.1 \
    src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile \
    src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/shl.mi
diff -u src/distrib/sets/lists/debug/shl.mi:1.309 src/distrib/sets/lists/debug/shl.mi:1.310
--- src/distrib/sets/lists/debug/shl.mi:1.309	Fri Jun  2 19:08:48 2023
+++ src/distrib/sets/lists/debug/shl.mi	Fri Jun  2 19:09:11 2023
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.309 2023/06/02 19:08:48 riastradh Exp $
+# $NetBSD: shl.mi,v 1.310 2023/06/02 19:09:11 riastradh Exp $
 ./usr/lib/libbfd_g.a						comp-c-debuglib	debuglib,compatfile,binutils
 ./usr/libdata/debug/lib						base-sys-usr	debug,dynamicroot,compatdir
 ./usr/libdata/debug/lib/libavl.so.0.0.debug			comp-zfs-debug	debug,dynamicroot,zfs
@@ -371,6 +371,7 @@
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_dso2.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_dso3.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
+./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_onlyctor_dynamic.so.1.debugtests-libexec-debug	debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_onlydef.so.1.debug		tests-libexec-debug	debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_onlyuse_dynamic.so.1.debug	tests-libexec-debug	debug,compattestfile,atf
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/libh_onlyuse_static.so.1.debug	tests-libexec-debug	debug,compattestfile,atf

Index: src/distrib/sets/lists/tests/shl.mi
diff -u src/distrib/sets/lists/tests/shl.mi:1.15 src/distrib/sets/lists/tests/shl.mi:1.16
--- src/distrib/sets/lists/tests/shl.mi:1.15	Fri Jun  2 19:08:48 2023
+++ src/distrib/sets/lists/tests/shl.mi	Fri Jun  2 19:09:11 2023
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.15 2023/06/02 19:08:48 riastradh Exp $
+# $NetBSD: shl.mi,v 1.16 2023/06/02 19:09:11 riastradh Exp $
 #
 ./usr/tests/lib/csu/h_initfini3_dso.so		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/csu/h_initfini3_dso.so.1	tests-lib-tests		compattestfile,atf
@@ -32,6 +32,8 @@
 ./usr/tests/libexec/ld.elf_so/libh_helper_dso3.so.1				tests-libexec-tests	compattestfile,atf
 ./usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso.so				tests-libexec-tests	compattestfile,atf
 ./usr/tests/libexec/ld.elf_so/libh_helper_ifunc_dso.so.1			tests-libexec-tests	compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_onlyctor_dynamic.so				tests-libexec-tests	compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_onlyctor_dynamic.so.1			tests-libexec-tests	compattestfile,atf
 ./usr/tests/libexec/ld.elf_so/libh_onlydef.so					tests-libexec-tests	compattestfile,atf
 ./usr/tests/libexec/ld.elf_so/libh_onlydef.so.1					tests-libexec-tests	compattestfile,atf
 ./usr/tests/libexec/ld.elf_so/libh_onlyuse_dynamic.so				tests-libexec-tests	compattestfile,atf

Index: src/tests/libexec/ld.elf_so/Makefile
diff -u src/tests/libexec/ld.elf_so/Makefile:1.18 src/tests/libexec/ld.elf_so/Makefile:1.19
--- src/tests/libexec/ld.elf_so/Makefile:1.18	Fri Jun  2 19:08:48 2023
+++ src/tests/libexec/ld.elf_so/Makefile	Fri Jun  2 19:09:11 2023
@@ -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

Index: src/tests/libexec/ld.elf_so/t_tls_extern.c
diff -u src/tests/libexec/ld.elf_so/t_tls_extern.c:1.10 src/tests/libexec/ld.elf_so/t_tls_extern.c:1.11
--- src/tests/libexec/ld.elf_so/t_tls_extern.c:1.10	Fri Jun  2 19:08:48 2023
+++ src/tests/libexec/ld.elf_so/t_tls_extern.c	Fri Jun  2 19:09:11 2023
@@ -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);

Added files:

Index: src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile
diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile:1.1
--- /dev/null	Fri Jun  2 19:09:12 2023
+++ src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile	Fri Jun  2 19:09:11 2023
@@ -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>
Index: src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c
diff -u /dev/null src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c:1.1
--- /dev/null	Fri Jun  2 19:09:12 2023
+++ src/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c	Fri Jun  2 19:09:11 2023
@@ -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;
+}

Reply via email to