Linux DTrace development list
 help / color / mirror / Atom feed
From: Kris Van Hees <kris.van.hees@oracle.com>
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH 14/20] test: detect strlen corruption of strtab rodata and zeros
Date: Fri, 30 Oct 2026 19:36:53 +0000	[thread overview]
Message-ID: <9a6be1ae2acce8402d1cf79e4a2e7b42@oracle.com> (raw)

---
 test/unittest/funcs/strlen/tst.rodata.d | 41 +++++++++++++++++++++++++
 test/unittest/funcs/strlen/tst.rodata.r |  4 +++
 test/unittest/funcs/strlen/tst.zeros.d  | 38 +++++++++++++++++++++++
 test/unittest/funcs/strlen/tst.zeros.r  |  3 ++
 4 files changed, 86 insertions(+)
 create mode 100644 test/unittest/funcs/strlen/tst.rodata.d
 create mode 100644 test/unittest/funcs/strlen/tst.rodata.r
 create mode 100644 test/unittest/funcs/strlen/tst.zeros.d
 create mode 100644 test/unittest/funcs/strlen/tst.zeros.r

diff --git a/test/unittest/funcs/strlen/tst.rodata.d b/test/unittest/funcs/strlen/tst.rodata.d
new file mode 100644
index 00000000..765a7717
--- /dev/null
+++ b/test/unittest/funcs/strlen/tst.rodata.d
@@ -0,0 +1,41 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: strlen() must not overwrite the IPv6 lookup table in the
+ *            rodata block of the strtab map.
+ *
+ * SECTION: Actions and Subroutines/strlen()
+ */
+/* @@nosort */
+
+#pragma D option quiet
+#pragma D option strsize=128
+
+BEGIN
+{
+	this->addr = (struct in6_addr *)alloca(sizeof(struct in6_addr));
+	this->addr->in6_u.u6_addr32[0] = 0;
+	this->addr->in6_u.u6_addr32[1] = 0;
+	this->addr->in6_u.u6_addr32[2] = 0;
+	this->addr->in6_u.u6_addr32[3] = 0;
+	printf("before: %s\n", inet_ntoa6(this->addr));
+
+	/*
+	 * Reach past any alignment padding and the reserved rodata byte into
+	 * the first lookup table entries, without reaching the zeros block.
+	 */
+	printf("length: %d\n", strlen(
+	    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
+	printf("after: %s\n", inet_ntoa6(this->addr));
+	exit(0);
+}
+
+ERROR
+{
+	exit(1);
+}
diff --git a/test/unittest/funcs/strlen/tst.rodata.r b/test/unittest/funcs/strlen/tst.rodata.r
new file mode 100644
index 00000000..0ad81e36
--- /dev/null
+++ b/test/unittest/funcs/strlen/tst.rodata.r
@@ -0,0 +1,4 @@
+before: ::
+length: 64
+after: ::
+
diff --git a/test/unittest/funcs/strlen/tst.zeros.d b/test/unittest/funcs/strlen/tst.zeros.d
new file mode 100644
index 00000000..c8928a1d
--- /dev/null
+++ b/test/unittest/funcs/strlen/tst.zeros.d
@@ -0,0 +1,38 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: strlen() must not overwrite the zeros block used to initialize
+ *            aggregations in the strtab map.
+ *
+ * SECTION: Actions and Subroutines/strlen()
+ */
+/* @@nosort */
+
+#pragma D option quiet
+#pragma D option strsize=128
+
+BEGIN
+{
+	/*
+	 * With no IPv6 lookup table, rodata contains only its reserved byte.
+	 * This string reaches past it and all padding into the zeros block.
+	 */
+	printf("length: %d\n", strlen(
+	    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
+
+	/* A new aggregation copies its initial value from the zeros block. */
+	@total = sum(1);
+	printa("total: %@d\n", @total);
+	clear(@total);
+	exit(0);
+}
+
+ERROR
+{
+	exit(1);
+}
diff --git a/test/unittest/funcs/strlen/tst.zeros.r b/test/unittest/funcs/strlen/tst.zeros.r
new file mode 100644
index 00000000..d8929b1a
--- /dev/null
+++ b/test/unittest/funcs/strlen/tst.zeros.r
@@ -0,0 +1,3 @@
+length: 64
+total: 1
+
-- 
2.52.0


                 reply	other threads:[~2026-10-30 19:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a6be1ae2acce8402d1cf79e4a2e7b42@oracle.com \
    --to=kris.van.hees@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox