Need -w for destructive actions, even if clause is not used
PATCH v2 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.
Signed-off-by Eugene Loh <[email protected]>
Reviewed-by Nick Alcock <[email protected]>
--- libdtrace/dt_bpf.c | 15 ++-- libdtrace/dt_cg.c | 1 + libdtrace/dt_impl.h | 1 + .../options/err.no-w-or-destructive2.d | 26 +++++++ .../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, 40 insertions(+), 86 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 +9 -6
@@ -1343,6 +1343,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_destructive && dest_ok ==DTRACEOPT_UNSET ) +return dt_set_errno (dtp,EDT_DESTRUCTIVE ); + dp =NULL ;for (prp =dt_list_next (&dtp->dt_enablings); prp !=NULL ; prp =dt_list_next (prp)) {
@@ -1362,12 +1371,6 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)DT_DISASM_PROG_LINKED (dtp, cflags, dp, stderr,NULL , prp->desc); -if (dp->dtdo_flags &DIFOFLG_DESTRUCTIVE && - dest_ok ==DTRACEOPT_UNSET ) { -dt_set_errno (dtp,EDT_DESTRUCTIVE ); - goto fail; - } - fd =dt_bpf_load_prog (dtp, prp, dp, cflags);if (fd ==-1 ) goto fail;
libdtrace/dt_cg.c +1 -0
@@ -1876,6 +1876,7 @@ dt_cg_clsflags(dt_pcb_t *pcb, dtrace_actkind_t kind, const dt_node_t *dnp)if (DTRACEACT_ISDESTRUCTIVE (kind)) { *cfp |=DT_CLSFLAG_DESTRUCT ; + pcb->pcb_hdl->dt_destructive |=1 ;if (kind ==DTRACEACT_RETURN ) *cfp |=DT_CLSFLAG_RETURN ;
libdtrace/dt_impl.h +1 -0
@@ -367,6 +367,7 @@ struct dtrace_hdl {char *dt_sysslice;/* the systemd system slice: set via -xsysslice */ uint_t dt_lazyload;/* boolean: set via -xlazyload */ uint_t dt_droptags;/* boolean: set via -xdroptags */ +uint_t dt_destructive;/* have any destructive actions */ uint_t dt_active;/* boolean: set once tracing is active */ uint_t dt_stopped;/* boolean: set once tracing is stopped */ processorid_t dt_beganon;/* CPU that executed BEGIN probe (if any) */
test/unittest/options/err.no-w-or-destructive2.d new file +26 -0
@@ -0,0 +1,26 @@ +/* + * 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 the associated probe + * does not exist at the point of initial program construction + * and loading). + * + * 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
@@ -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
@@ -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