Skip to contentSkip to conversation

Need -w for destructive actions, even if clause is not used

PATCH Superseded [email protected] 3 participants 10 messages Jul 11, 2025 – Aug 1, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Need -w for destructive actions, even if clause is not used

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

---
 libdtrace/dt_bpf.c                            | 14 ++++
 libdtrace/dt_cg.c                             |  4 +-
 libdtrace/dt_impl.h                           |  1 +
 .../options/err.no-w-or-destructive2.d        | 25 ++++++
 .../options/err.no-w-or-destructive2.r        |  3 +
 test/unittest/usdt/err.Z_no-w.r               |  4 -
 test/unittest/usdt/err.Z_no-w.sh              | 76 -------------------
 7 files changed, 46 insertions(+), 81 deletions(-)
 create mode 100644 test/unittest/options/err.no-w-or-destructive2.d
 create mode 100644 test/unittest/options/err.no-w-or-destructive2.r
 delete mode 100644 test/unittest/usdt/err.Z_no-w.r
 delete mode 100755 test/unittest/usdt/err.Z_no-w.sh
libdtrace/dt_bpf.c +14 -0
index 4e7618e05..e2c3bfebc 100644
@@ -1286,6 +1286,15 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 	 */
 	dtrace_getopt(dtp, "destructive", &dest_ok);
 
+	/*
+	 * If we have any destructive actions at all and -w is not set,
+	 * error out.  Solaris would reject this as a runtime error.  So,
+	 * although we could have detected this problem at compilation,
+	 * we mimic Solaris and wait until now to report.
+	 */
+	if (dtp->dt_havedest && dest_ok == DTRACEOPT_UNSET)
+		return dt_set_errno(dtp, EDT_DESTRUCTIVE);
+
 	for (prp = dt_list_next(&dtp->dt_enablings); prp != NULL;
 	     prp = dt_list_next(prp)) {
 		int		fd;
@@ -1304,6 +1313,11 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 
 		DT_DISASM_PROG_LINKED(dtp, cflags, dp, stderr, NULL, prp->desc);
 
+		/*
+		 * This check should never fail since, if any action is
+		 * destructive and -w is not set, we should already have
+		 * failed.
+		 */
 		if (dp->dtdo_flags & DIFOFLG_DESTRUCTIVE &&
 		    dest_ok == DTRACEOPT_UNSET)
 			return dt_set_errno(dtp, EDT_DESTRUCTIVE);
libdtrace/dt_cg.c +3 -1
index e1bb59289..0e0648969 100644
@@ -1833,8 +1833,10 @@ dt_cg_clsflags(dt_pcb_t *pcb, dtrace_actkind_t kind, const dt_node_t *dnp)
 {
 	int		*cfp = &pcb->pcb_stmt->dtsd_clauseflags;
 
-	if (DTRACEACT_ISDESTRUCTIVE(kind))
+	if (DTRACEACT_ISDESTRUCTIVE(kind)) {
 		*cfp |= DT_CLSFLAG_DESTRUCT;
+		pcb->pcb_hdl->dt_havedest |= 1;
+	}
 
 	if (kind == DTRACEACT_COMMIT) {
 		if (*cfp & (DT_CLSFLAG_DATAREC | DT_CLSFLAG_AGGREGATION))
libdtrace/dt_impl.h +1 -0
index 1e105b6e9..cdb222b3f 100644
@@ -431,6 +431,7 @@ struct dtrace_hdl {
 	dt_list_t dt_lib_dep_sorted;	/* dependency sorted library list */
 	dt_global_pcap_t dt_pcap; /* global tshark/pcap state */
 	char *dt_freopen_filename; /* filename for freopen() action */
+	int dt_havedest;	/* have any destructive actions */
 };
 
 /*
test/unittest/options/err.no-w-or-destructive2.d new file +25 -0
new file mode 100644
index 000000000..eb9365fea
@@ -0,0 +1,25 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, 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: Without -w or -xdestructive, destructive operations are not ok,
+ *            even if a clause will be ignored since it does not exist and
+ *            -Z was specified.
+ *
+ * SECTION: Options and Tunables/Consumer Options
+ */
+/* @@runtest-opts: -Z */
+
+BEGIN
+{
+	exit(0);
+}
+
+bogus:bogus:bogus:bogus
+{
+	system("echo ok");
+}
test/unittest/options/err.no-w-or-destructive2.r new file +3 -0
new file mode 100644
index 000000000..1a6959475
@@ -0,0 +1,3 @@
+-- @@stderr --
+dtrace: script 'test/unittest/options/err.no-w-or-destructive2.d' matched 1 probe
+dtrace: could not enable tracing: Destructive actions not allowed
test/unittest/usdt/err.Z_no-w.r deleted +0 -4
deleted file mode 100644
index b81622481..000000000
@@ -1,4 +0,0 @@
-dtrace is running so start the trigger
-dtrace died as expected after trigger started
--- @@stderr --
-dtrace: processing aborted: Destructive actions not allowed
test/unittest/usdt/err.Z_no-w.sh deleted +0 -76

76 lines not on this page · raw message

Signature · 1 line
2.43.5
Reviewed-by on v1 1/1
#1 lore raw

On 11 Jul 2025, eugene loh uttered the following:

Quoted 10 lines

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

modulo one microscopic annoyance (I am not a real unix programmer, I don't like creat() and think we shouldn't add more).

Quoted 21 lines
libdtrace/dt_bpf.c +9 -0
index 4e7618e05..e2c3bfebc 100644
@@ -1286,6 +1286,15 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 	 */
 	dtrace_getopt(dtp, "destructive", &dest_ok);
 
+	/*
+	 * If we have any destructive actions at all and -w is not set,
+	 * error out.  Solaris would reject this as a runtime error.  So,
+	 * although we could have detected this problem at compilation,
+	 * we mimic Solaris and wait until now to report.
+	 */
+	if (dtp->dt_havedest && dest_ok == DTRACEOPT_UNSET)
+		return dt_set_errno(dtp, EDT_DESTRUCTIVE);
+
 	for (prp = dt_list_next(&dtp->dt_enablings); prp != NULL;
 	     prp = dt_list_next(prp)) {
 		int		fd;

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1317

Quoted 5 lines
libdtrace/dt_bpf.c +2 -0
@@ -1304,6 +1313,11 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 
 		DT_DISASM_PROG_LINKED(dtp, cflags, dp, stderr, NULL, prp->desc);
 
+		/*
+		 * This check should never fail since, if any action is

Grammar:

This check should never fail, since if any action is

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1320

Quoted 3 lines
libdtrace/dt_bpf.c +3 -0
+		 * destructive and -w is not set, we should already have
+		 * failed.
+		 */

(but worth keeping anyway, I agree.)

libdtrace/dt_bpf.c struct dtrace_hdl { · line 435

Quoted 6 lines
libdtrace/dt_bpf.c +1 -0
@@ -431,6 +431,7 @@ struct dtrace_hdl {
 	dt_list_t dt_lib_dep_sorted;	/* dependency sorted library list */
 	dt_global_pcap_t dt_pcap; /* global tshark/pcap state */
 	char *dt_freopen_filename; /* filename for freopen() action */
+	int dt_havedest;	/* have any destructive actions */
 };

A piteous plea: could we call this dt_have_destructive or something? We call destructive stuff "destructive", unabbreviated, everywhere else, this flag is only checked in *one place* and thus hardly need concision, and to me 'dest' always means 'destination' and thus causes a double-take every time I see it used for something else.

Quoted 9 lines
libdtrace/dt_bpf.c +0 -0
 /*
test/unittest/options/err.no-w-or-destructive2.d new file +1 -0
new file mode 100644
index 000000000..eb9365fea
@@ -0,0 +1,25 @@
+/*

test/unittest/options/err.no-w-or-destructive2.d line 11

Quoted 10 lines
test/unittest/options/err.no-w-or-destructive2.d new file +10 -0
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, 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: Without -w or -xdestructive, destructive operations are not ok,
+ *            even if a clause will be ignored since it does not exist and
+ *            -Z was specified.

Pedantry: ... it does not *yet* exist :)

Signature · 1 line
NULL && (void)
author
#2 lore raw
Quoted 7 lines · Nick Alcock

On 11 Jul 2025, eugene loh uttered the following:

Quoted 6 lines

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

Quoted 8 lines
Quoted 4 lines

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

modulo one microscopic annoyance (I am not a real unix programmer, I don't like creat() and think we shouldn't add more).

Sorry, I don't know what you're asking for here.

Quoted 10 lines

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1317

Quoted 7 lines
libdtrace/dt_bpf.c +2 -0
@@ -1304,6 +1313,11 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 
  		DT_DISASM_PROG_LINKED(dtp, cflags, dp, stderr, NULL, prp->desc);
 
+		/*
+		 * This check should never fail since, if any action is

Grammar:

This check should never fail, since if any action is

I think I see what you're saying:  separate the two phrases with a comma.  But there is a big appositional phrase in there ("if any action is destructive and -w is not set") and I wanted to set it off with the commas.  Maybe I'm wrong.  Dunno.

Quoted 4 lines

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1320

Quoted 3 lines
libdtrace/dt_bpf.c +3 -0
+		 * destructive and -w is not set, we should already have
+		 * failed.
+		 */

(but worth keeping anyway, I agree.)

#3 lore raw

On 17 Jul 2025, Eugene Loh outgrape:

Quoted 12 lines · Nick Alcock
Quoted 11 lines

On 11 Jul 2025, eugene loh uttered the following:

Quoted 9 lines

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

modulo one microscopic annoyance (I am not a real unix programmer, I don't like creat() and think we shouldn't add more).

Sorry, I don't know what you're asking for here.

"Name too short" :) referring to:

Quoted 8 lines

libdtrace/dt_impl.h struct dtrace_hdl { · line 435

Quoted 2 lines
libdtrace/dt_impl.h +1 -0
+	int dt_havedest;	/* have any destructive actions */
 };

A piteous plea: could we call this dt_have_destructive or something? We call destructive stuff "destructive", unabbreviated, everywhere else, this flag is only checked in *one place* and thus hardly need concision, and to me 'dest' always means 'destination' and thus causes a double-take every time I see it used for something else.

Anyway...

Quoted 9 lines
Quoted 4 lines

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1317

Quoted 1 line
libdtrace/dt_bpf.c +1 -0
+		 * This check should never fail since, if any action is

Grammar:

This check should never fail, since if any action is

I think I see what you're saying:  separate the two phrases with a comma.  But there is a big appositional phrase in there ("if any action is destructive and -w is not set") and I wanted to set it off with the commas.  Maybe I'm wrong.  Dunno.

I tried that -- it feels clumsier, since you definitely cannot set it off with a comma but *not* set off the clause surrounding it (as you did above).

Quoted 4 lines
Quoted 4 lines

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1320

Quoted 3 lines
libdtrace/dt_bpf.c +3 -0
+		 * destructive and -w is not set, we should already have
+		 * failed.
+		 */

(but worth keeping anyway, I agree.)

Signature · 1 line
NULL && (void)
#4 lore raw
In reply to [email protected]

In addition to Nick's comments...

Quoted 30 lines · On Fri, Jul 11, 2025 at 12:40:24AM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

---
 libdtrace/dt_bpf.c                            | 14 ++++
 libdtrace/dt_cg.c                             |  4 +-
 libdtrace/dt_impl.h                           |  1 +
 .../options/err.no-w-or-destructive2.d        | 25 ++++++
 .../options/err.no-w-or-destructive2.r        |  3 +
 test/unittest/usdt/err.Z_no-w.r               |  4 -
 test/unittest/usdt/err.Z_no-w.sh              | 76 -------------------
 7 files changed, 46 insertions(+), 81 deletions(-)
 create mode 100644 test/unittest/options/err.no-w-or-destructive2.d
 create mode 100644 test/unittest/options/err.no-w-or-destructive2.r
 delete mode 100644 test/unittest/usdt/err.Z_no-w.r
 delete mode 100755 test/unittest/usdt/err.Z_no-w.sh
libdtrace/dt_bpf.c +0 -0
index 4e7618e05..e2c3bfebc 100644
@@ -1286,6 +1286,15 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 	 */

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1296

Quoted 10 lines
libdtrace/dt_bpf.c +8 -0
 	dtrace_getopt(dtp, "destructive", &dest_ok);
 
+	/*
+	 * If we have any destructive actions at all and -w is not set,
+	 * error out.  Solaris would reject this as a runtime error.  So,
+	 * although we could have detected this problem at compilation,
+	 * we mimic Solaris and wait until now to report.
+	 */
+	if (dtp->dt_havedest && dest_ok == DTRACEOPT_UNSET)
+		return dt_set_errno(dtp, EDT_DESTRUCTIVE);

How about using dt_destructive as name?

Quoted 6 lines
libdtrace/dt_bpf.c +1 -0
+
 	for (prp = dt_list_next(&dtp->dt_enablings); prp != NULL;
 	     prp = dt_list_next(prp)) {
 		int		fd;
@@ -1304,6 +1313,11 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1323

Quoted 10 lines
libdtrace/dt_bpf.c +5 -0
 		DT_DISASM_PROG_LINKED(dtp, cflags, dp, stderr, NULL, prp->desc);
 
+		/*
+		 * This check should never fail since, if any action is
+		 * destructive and -w is not set, we should already have
+		 * failed.
+		 */
 		if (dp->dtdo_flags & DIFOFLG_DESTRUCTIVE &&
 		    dest_ok == DTRACEOPT_UNSET)
 			return dt_set_errno(dtp, EDT_DESTRUCTIVE);

If this check should never fail, then it should be removed -or- turned into an assert as a safeguard. But rmoving it ought to be OK.

libdtrace/dt_cg.c dt_cg_clsflags(dt_pcb_t *pcb, dtrace_actkind_t kind, const dt_node_t *dnp) · line 1838

Quoted 12 lines
libdtrace/dt_cg.c +2 -1
index e1bb59289..0e0648969 100644
@@ -1833,8 +1833,10 @@ dt_cg_clsflags(dt_pcb_t *pcb, dtrace_actkind_t kind, const dt_node_t *dnp)
 {
 	int		*cfp = &pcb->pcb_stmt->dtsd_clauseflags;
 
-	if (DTRACEACT_ISDESTRUCTIVE(kind))
+	if (DTRACEACT_ISDESTRUCTIVE(kind)) {
 		*cfp |= DT_CLSFLAG_DESTRUCT;
+		pcb->pcb_hdl->dt_havedest |= 1;

dt_destructive

libdtrace/dt_impl.h struct dtrace_hdl { · line 434

Quoted 13 lines
libdtrace/dt_cg.c +1 -0
+	}
 
 	if (kind == DTRACEACT_COMMIT) {
 		if (*cfp & (DT_CLSFLAG_DATAREC | DT_CLSFLAG_AGGREGATION))
libdtrace/dt_impl.h +1 -0
index 1e105b6e9..cdb222b3f 100644
@@ -431,6 +431,7 @@ struct dtrace_hdl {
 	dt_list_t dt_lib_dep_sorted;	/* dependency sorted library list */
 	dt_global_pcap_t dt_pcap; /* global tshark/pcap state */
 	char *dt_freopen_filename; /* filename for freopen() action */
+	int dt_havedest;	/* have any destructive actions */

dt_destructive, and add it after dt_droptags to keep the booleans together. In a later patch, we should combine those uint_t booleans into a single uint_t dt_flags member.

Quoted 10 lines
libdtrace/dt_impl.h +0 -0
 };
 
 /*
test/unittest/options/err.no-w-or-destructive2.d new file +1 -0
new file mode 100644
index 000000000..eb9365fea
@@ -0,0 +1,25 @@
+/*

test/unittest/options/err.no-w-or-destructive2.d line 11

Quoted 10 lines
test/unittest/options/err.no-w-or-destructive2.d new file +10 -0
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, 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: Without -w or -xdestructive, destructive operations are not ok,
+ *            even if a clause will be ignored since it does not exist and
+ *            -Z was specified.

This could do with some rewriting. The issue is that DTrace used to always load all tracing programs, and the kernel would activate them as needed. We now only load programs for enabled probes (and with -Z active, we may load some programs later).

What we need to be testing here is that if any clauses of a tracing script contain destructive actions, and we are using the script for probing, then an error should be reported unless we are allowing destructive actions (-w or -xdestructive).

Quoted 118 lines
test/unittest/options/err.no-w-or-destructive2.d new file +14 -0
+ *
+ * SECTION: Options and Tunables/Consumer Options
+ */
+/* @@runtest-opts: -Z */
+
+BEGIN
+{
+	exit(0);
+}
+
+bogus:bogus:bogus:bogus
+{
+	system("echo ok");
+}
test/unittest/options/err.no-w-or-destructive2.r new file +3 -0
new file mode 100644
index 000000000..1a6959475
@@ -0,0 +1,3 @@
+-- @@stderr --
+dtrace: script 'test/unittest/options/err.no-w-or-destructive2.d' matched 1 probe
+dtrace: could not enable tracing: Destructive actions not allowed
test/unittest/usdt/err.Z_no-w.r deleted +0 -4
deleted file mode 100644
index b81622481..000000000
@@ -1,4 +0,0 @@
-dtrace is running so start the trigger
-dtrace died as expected after trigger started
--- @@stderr --
-dtrace: processing aborted: Destructive actions not allowed
test/unittest/usdt/err.Z_no-w.sh deleted +0 -76
deleted file mode 100755
index 4f129341d..000000000
@@ -1,76 +0,0 @@
-#!/bin/bash
-#
-# Oracle Linux DTrace.
-# Copyright (c) 2024, 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.
-#
-# This test verifies that dtrace will not run a destructive script
-# for USDT probes if -w is not specified.
-#
-# Specifically, the script is launched with -Z and no USDT processes are
-# initially present.  Only once a USDT process is detected does dtrace
-# fail due to the destructive action.
-
-dtrace=$1
-trigger=`pwd`/test/triggers/usdt-tst-defer
-
-# Set up test directory.
-
-DIRNAME=$tmpdir/Z_no-w.$$.$RANDOM
-mkdir -p $DIRNAME
-cd $DIRNAME
-
-# Make a private copy of the trigger executable so that we get our
-# own DOF stash.
-
-cp $trigger main
-
-# Run dtrace.
-
-$dtrace $dt_flags -Zq -o dtrace.out -n '
-testprov*:::foo
-{
-	raise(SIGUSR1);
-}' &
-dtpid=$!
-
-# Wait up to half of the timeout period for dtrace to start up.
-
-iter=$((timeout / 2))
-while [ $iter -gt 0 ]; do
-	sleep 1
-	if [ -e dtrace.out ]; then
-		break
-	fi
-	iter=$((iter - 1))
-done
-if [[ $iter -eq 0 ]]; then
-	echo ERROR starting DTrace job
-	cat dtrace.out
-	exit 1
-fi
-
-# Start a trigger process.
-
-echo dtrace is running so start the trigger
-./main > main.out &
-pid=$!
-
-# Check again if dtrace is still running.
-
-sleep 2
-if [[ ! -d /proc/$dtpid ]]; then
-	echo dtrace died as expected after trigger started
-else
-	echo dtrace is unexpectedly still running
-	kill -9 $dtpid
-	wait    $dtpid
-fi
-
-# Tell the trigger to proceed to completion.
-
-kill -USR1 $pid
-wait       $pid
-
-exit 1
Signature · 1 line
2.43.5
#5 lore raw

Another question...

Quoted 26 lines · Kris Van Hees

In addition to Nick's comments...

Quoted 23 lines · On Fri, Jul 11, 2025 at 12:40:24AM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

---
 libdtrace/dt_bpf.c                            | 14 ++++
 libdtrace/dt_cg.c                             |  4 +-
 libdtrace/dt_impl.h                           |  1 +
 .../options/err.no-w-or-destructive2.d        | 25 ++++++
 .../options/err.no-w-or-destructive2.r        |  3 +
 test/unittest/usdt/err.Z_no-w.r               |  4 -
 test/unittest/usdt/err.Z_no-w.sh              | 76 -------------------
 7 files changed, 46 insertions(+), 81 deletions(-)
 create mode 100644 test/unittest/options/err.no-w-or-destructive2.d
 create mode 100644 test/unittest/options/err.no-w-or-destructive2.r
 delete mode 100644 test/unittest/usdt/err.Z_no-w.r
 delete mode 100755 test/unittest/usdt/err.Z_no-w.sh

Why did you delete this test? Isn't it still a valid test anyway, and since it tests this in a more practical sense, it seems to have value.

Quoted 222 lines
Quoted 7 lines
libdtrace/dt_bpf.c +0 -0
index 4e7618e05..e2c3bfebc 100644
@@ -1286,6 +1286,15 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 	 */

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1296

Quoted 10 lines
libdtrace/dt_bpf.c +8 -0
 	dtrace_getopt(dtp, "destructive", &dest_ok);
 
+	/*
+	 * If we have any destructive actions at all and -w is not set,
+	 * error out.  Solaris would reject this as a runtime error.  So,
+	 * although we could have detected this problem at compilation,
+	 * we mimic Solaris and wait until now to report.
+	 */
+	if (dtp->dt_havedest && dest_ok == DTRACEOPT_UNSET)
+		return dt_set_errno(dtp, EDT_DESTRUCTIVE);

How about using dt_destructive as name?

Quoted 6 lines
libdtrace/dt_bpf.c +1 -0
+
 	for (prp = dt_list_next(&dtp->dt_enablings); prp != NULL;
 	     prp = dt_list_next(prp)) {
 		int		fd;
@@ -1304,6 +1313,11 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
 

libdtrace/dt_bpf.c dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags) · line 1323

Quoted 10 lines
libdtrace/dt_bpf.c +5 -0
 		DT_DISASM_PROG_LINKED(dtp, cflags, dp, stderr, NULL, prp->desc);
 
+		/*
+		 * This check should never fail since, if any action is
+		 * destructive and -w is not set, we should already have
+		 * failed.
+		 */
 		if (dp->dtdo_flags & DIFOFLG_DESTRUCTIVE &&
 		    dest_ok == DTRACEOPT_UNSET)
 			return dt_set_errno(dtp, EDT_DESTRUCTIVE);

If this check should never fail, then it should be removed -or- turned into an assert as a safeguard. But rmoving it ought to be OK.

libdtrace/dt_cg.c dt_cg_clsflags(dt_pcb_t *pcb, dtrace_actkind_t kind, const dt_node_t *dnp) · line 1838

Quoted 12 lines
libdtrace/dt_cg.c +2 -1
index e1bb59289..0e0648969 100644
@@ -1833,8 +1833,10 @@ dt_cg_clsflags(dt_pcb_t *pcb, dtrace_actkind_t kind, const dt_node_t *dnp)
 {
 	int		*cfp = &pcb->pcb_stmt->dtsd_clauseflags;
 
-	if (DTRACEACT_ISDESTRUCTIVE(kind))
+	if (DTRACEACT_ISDESTRUCTIVE(kind)) {
 		*cfp |= DT_CLSFLAG_DESTRUCT;
+		pcb->pcb_hdl->dt_havedest |= 1;

dt_destructive

libdtrace/dt_impl.h struct dtrace_hdl { · line 434

Quoted 13 lines
libdtrace/dt_cg.c +1 -0
+	}
 
 	if (kind == DTRACEACT_COMMIT) {
 		if (*cfp & (DT_CLSFLAG_DATAREC | DT_CLSFLAG_AGGREGATION))
libdtrace/dt_impl.h +1 -0
index 1e105b6e9..cdb222b3f 100644
@@ -431,6 +431,7 @@ struct dtrace_hdl {
 	dt_list_t dt_lib_dep_sorted;	/* dependency sorted library list */
 	dt_global_pcap_t dt_pcap; /* global tshark/pcap state */
 	char *dt_freopen_filename; /* filename for freopen() action */
+	int dt_havedest;	/* have any destructive actions */

dt_destructive, and add it after dt_droptags to keep the booleans together. In a later patch, we should combine those uint_t booleans into a single uint_t dt_flags member.

Quoted 10 lines
libdtrace/dt_impl.h +0 -0
 };
 
 /*
test/unittest/options/err.no-w-or-destructive2.d new file +1 -0
new file mode 100644
index 000000000..eb9365fea
@@ -0,0 +1,25 @@
+/*

test/unittest/options/err.no-w-or-destructive2.d line 11

Quoted 10 lines
test/unittest/options/err.no-w-or-destructive2.d new file +10 -0
+ * Oracle Linux DTrace.
+ * Copyright (c) 2025, 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: Without -w or -xdestructive, destructive operations are not ok,
+ *            even if a clause will be ignored since it does not exist and
+ *            -Z was specified.

This could do with some rewriting. The issue is that DTrace used to always load all tracing programs, and the kernel would activate them as needed. We now only load programs for enabled probes (and with -Z active, we may load some programs later).

What we need to be testing here is that if any clauses of a tracing script contain destructive actions, and we are using the script for probing, then an error should be reported unless we are allowing destructive actions (-w or -xdestructive).

Quoted 118 lines
test/unittest/options/err.no-w-or-destructive2.d new file +14 -0
+ *
+ * SECTION: Options and Tunables/Consumer Options
+ */
+/* @@runtest-opts: -Z */
+
+BEGIN
+{
+	exit(0);
+}
+
+bogus:bogus:bogus:bogus
+{
+	system("echo ok");
+}
test/unittest/options/err.no-w-or-destructive2.r new file +3 -0
new file mode 100644
index 000000000..1a6959475
@@ -0,0 +1,3 @@
+-- @@stderr --
+dtrace: script 'test/unittest/options/err.no-w-or-destructive2.d' matched 1 probe
+dtrace: could not enable tracing: Destructive actions not allowed
test/unittest/usdt/err.Z_no-w.r deleted +0 -4
deleted file mode 100644
index b81622481..000000000
@@ -1,4 +0,0 @@
-dtrace is running so start the trigger
-dtrace died as expected after trigger started
--- @@stderr --
-dtrace: processing aborted: Destructive actions not allowed
test/unittest/usdt/err.Z_no-w.sh deleted +0 -76
deleted file mode 100755
index 4f129341d..000000000
@@ -1,76 +0,0 @@
-#!/bin/bash
-#
-# Oracle Linux DTrace.
-# Copyright (c) 2024, 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.
-#
-# This test verifies that dtrace will not run a destructive script
-# for USDT probes if -w is not specified.
-#
-# Specifically, the script is launched with -Z and no USDT processes are
-# initially present.  Only once a USDT process is detected does dtrace
-# fail due to the destructive action.
-
-dtrace=$1
-trigger=`pwd`/test/triggers/usdt-tst-defer
-
-# Set up test directory.
-
-DIRNAME=$tmpdir/Z_no-w.$$.$RANDOM
-mkdir -p $DIRNAME
-cd $DIRNAME
-
-# Make a private copy of the trigger executable so that we get our
-# own DOF stash.
-
-cp $trigger main
-
-# Run dtrace.
-
-$dtrace $dt_flags -Zq -o dtrace.out -n '
-testprov*:::foo
-{
-	raise(SIGUSR1);
-}' &
-dtpid=$!
-
-# Wait up to half of the timeout period for dtrace to start up.
-
-iter=$((timeout / 2))
-while [ $iter -gt 0 ]; do
-	sleep 1
-	if [ -e dtrace.out ]; then
-		break
-	fi
-	iter=$((iter - 1))
-done
-if [[ $iter -eq 0 ]]; then
-	echo ERROR starting DTrace job
-	cat dtrace.out
-	exit 1
-fi
-
-# Start a trigger process.
-
-echo dtrace is running so start the trigger
-./main > main.out &
-pid=$!
-
-# Check again if dtrace is still running.
-
-sleep 2
-if [[ ! -d /proc/$dtpid ]]; then
-	echo dtrace died as expected after trigger started
-else
-	echo dtrace is unexpectedly still running
-	kill -9 $dtpid
-	wait    $dtpid
-fi
-
-# Tell the trigger to proceed to completion.
-
-kill -USR1 $pid
-wait       $pid
-
-exit 1
Signature · 1 line
2.43.5
author
#6 lore raw
Quoted 8 lines · Kris Van Hees
Quoted 7 lines · Kris Van Hees
Quoted 6 lines · On Fri, Jul 11, 2025 at 12:40:24AM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

delete mode 100644 test/unittest/usdt/err.Z_no-w.r delete mode 100755 test/unittest/usdt/err.Z_no-w.sh

Why did you delete this test? Isn't it still a valid test anyway, and since it tests this in a more practical sense, it seems to have value.

The test was failing consistently on every platform;  it was based on assumptions that were eventually discarded.  So, no, not a valid test.  It assumed behavior different from what this commit message asserts.

author
#8 lore raw
In reply to Kris Van Hees
Quoted 7 lines · Kris Van Hees
Quoted 6 lines · On Fri, Jul 11, 2025 at 12:40:24AM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

Quoted 8 lines

test/unittest/options/err.no-w-or-destructive2.d line 4

Quoted 7 lines
test/unittest/options/err.no-w-or-destructive2.d new file +4 -0
new file mode 100644
@@ -0,0 +1,25 @@
+/*
+ * ASSERTION: Without -w or -xdestructive, destructive operations are not ok,
+ *            even if a clause will be ignored since it does not exist and
+ *            -Z was specified.

This could do with some rewriting.

Sorry, what does "this" refer to?  The comment, the test, or the patch?

Quoted 9 lines

The issue is that DTrace used to always
load all tracing programs, and the kernel would activate them as needed. We now only load programs for enabled probes (and with -Z active, we may load some programs later).

What we need to be testing here is that if any clauses of a tracing script contain destructive actions, and we are using the script for probing, then an error should be reported unless we are allowing destructive actions (-w or -xdestructive).

I think we have such a test?

The case being tested here is where a destructive action is specified, no -w is specified, but the clause will not be exercised since the probe does not exist and -Z allows us to ignore it.  In this case, should the script be accepted or rejected?  The patch says the script should be rejected, which was the legacy behavior. (People familiar with the legacy implementation may understand why the legacy behavior was what it was, but the question now is whether that behavior should be changed.)

Quoted 6 lines
Quoted 6 lines
test/unittest/options/err.no-w-or-destructive2.d new file +6 -0
+/* @@runtest-opts: -Z */
+
+bogus:bogus:bogus:bogus
+{
+	system("echo ok");
+}
#7 lore raw
In reply to Eugene Loh
Quoted 13 lines · Eugene Loh
Quoted 11 lines · Kris Van Hees
Quoted 10 lines · Kris Van Hees
Quoted 9 lines · On Fri, Jul 11, 2025 at 12:40:24AM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

The test err.Z_no-w.sh was misguided and is replaced by a more direct test.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

delete mode 100644 test/unittest/usdt/err.Z_no-w.r delete mode 100755 test/unittest/usdt/err.Z_no-w.sh

Why did you delete this test? Isn't it still a valid test anyway, and since it tests this in a more practical sense, it seems to have value.

The test was failing consistently on every platform;  it was based on assumptions that were eventually discarded.  So, no, not a valid test.  It assumed behavior different from what this commit message asserts.

Ah, overlooked that it was testing for the non-compatible behaviour. OK.

#9 lore raw
In reply to Eugene Loh
Quoted 18 lines · Eugene Loh
Quoted 7 lines · Kris Van Hees
Quoted 6 lines · On Fri, Jul 11, 2025 at 12:40:24AM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

If a clause includes a destructive action but -w is not used, dtrace should not start up, even if the clause is ignored (due to -Z). Solaris treated this as a runtime error. We should do the same.

Quoted 8 lines

test/unittest/options/err.no-w-or-destructive2.d line 4

Quoted 7 lines
test/unittest/options/err.no-w-or-destructive2.d new file +4 -0
new file mode 100644
@@ -0,0 +1,25 @@
+/*
+ * ASSERTION: Without -w or -xdestructive, destructive operations are not ok,
+ *            even if a clause will be ignored since it does not exist and
+ *            -Z was specified.

This could do with some rewriting.

Quoted 1 line

Sorry, what does "this" refer to?  The comment, the test, or the patch?

The text of the assertion.

Quoted 11 lines
Quoted 9 lines

The issue is that DTrace used to always
load all tracing programs, and the kernel would activate them as needed. We now only load programs for enabled probes (and with -Z active, we may load some programs later).

What we need to be testing here is that if any clauses of a tracing script contain destructive actions, and we are using the script for probing, then an error should be reported unless we are allowing destructive actions (-w or -xdestructive).

I think we have such a test?

Yes, I just don't think that the way the assertion is phrased well. E.g. talking about a clause being ignored since it does not exist. The clause very certainly exists (since it is in the script). It is the probe that does not exist at the point of initial program construction and loading).

Quoted 7 lines

The case being tested here is where a destructive action is specified, no -w is specified, but the clause will not be exercised since the probe does not exist and -Z allows us to ignore it.  In this case, should the script be accepted or rejected?  The patch says the script should be rejected, which was the legacy behavior. (People familiar with the legacy implementation may understand why the legacy behavior was what it was, but the question now is whether that behavior should be changed.)

Yes, again, it is the way the assertion is phrased that needs fixing I think.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
test/unittest/options/err.no-w-or-destructive2.d new file +6 -0
+/* @@runtest-opts: -Z */
+
+bogus:bogus:bogus:bogus
+{
+	system("echo ok");
+}