Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src ld.elf_so: Test dynamic-then-static abuse via ctor.
details: https://anonhg.NetBSD.org/src/rev/8f2cae116fe2
branches: trunk
changeset: 376138:8f2cae116fe2
user: riastradh <riastradh%NetBSD.org@localhost>
date: Fri Jun 02 19:09:11 2023 +0000
description:
ld.elf_so: Test dynamic-then-static abuse via ctor.
XXX pullup-10
diffstat:
distrib/sets/lists/debug/shl.mi | 3 +-
distrib/sets/lists/tests/shl.mi | 4 +-
tests/libexec/ld.elf_so/Makefile | 3 +-
tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile | 22 ++++++
tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c | 36 ++++++++++
tests/libexec/ld.elf_so/t_tls_extern.c | 19 +++++-
6 files changed, 83 insertions(+), 4 deletions(-)
diffs (158 lines):
diff -r 67b2283af2d6 -r 8f2cae116fe2 distrib/sets/lists/debug/shl.mi
--- a/distrib/sets/lists/debug/shl.mi Fri Jun 02 19:08:48 2023 +0000
+++ b/distrib/sets/lists/debug/shl.mi Fri Jun 02 19:09:11 2023 +0000
@@ -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
diff -r 67b2283af2d6 -r 8f2cae116fe2 distrib/sets/lists/tests/shl.mi
--- a/distrib/sets/lists/tests/shl.mi Fri Jun 02 19:08:48 2023 +0000
+++ b/distrib/sets/lists/tests/shl.mi Fri Jun 02 19:09:11 2023 +0000
@@ -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
diff -r 67b2283af2d6 -r 8f2cae116fe2 tests/libexec/ld.elf_so/Makefile
--- a/tests/libexec/ld.elf_so/Makefile Fri Jun 02 19:08:48 2023 +0000
+++ b/tests/libexec/ld.elf_so/Makefile Fri Jun 02 19:09:11 2023 +0000
@@ -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 -r 67b2283af2d6 -r 8f2cae116fe2 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/Makefile Fri Jun 02 19:09:11 2023 +0000
@@ -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 -r 67b2283af2d6 -r 8f2cae116fe2 tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_onlyctor_dynamic/h_onlyctor_dynamic.c Fri Jun 02 19:09:11 2023 +0000
@@ -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 -r 67b2283af2d6 -r 8f2cae116fe2 tests/libexec/ld.elf_so/t_tls_extern.c
--- a/tests/libexec/ld.elf_so/t_tls_extern.c Fri Jun 02 19:08:48 2023 +0000
+++ b/tests/libexec/ld.elf_so/t_tls_extern.c Fri Jun 02 19:09:11 2023 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index