Skip to content

Commit

Permalink
dtrace: Add a sysctl to block loading of dtrace.ko in CHERI kernels
Browse files Browse the repository at this point in the history
The DTrace port is experimental and not suitable for use in production
environments.  Add some friction to make sure that users understand this.
  • Loading branch information
markjdb committed Jan 29, 2025
1 parent d895b94 commit 83be3dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sys/cddl/dev/dtrace/dtrace_modevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ dtrace_modevent(module_t mod __unused, int type, void *data __unused)

switch (type) {
case MOD_LOAD:
if (!dtrace_enabled) {
printf(
"DTrace is experimental on this platform and is disabled by default.\n");
printf(
"Set the debug.dtrace_enabled sysctl to 1 to allow dtrace.ko to load.\n");
printf(
"Be prepared for bugs and kernel panics if you use DTrace.\n");
printf(
"Please report bugs at https://github.com/CTSRD-CHERI/cheribsd");
return (ENOTSUP);
}

break;

case MOD_UNLOAD:
Expand Down
8 changes: 8 additions & 0 deletions sys/kern/kern_dtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ FEATURE(kdtrace_hooks,

static MALLOC_DEFINE(M_KDTRACE, "kdtrace", "DTrace hooks");

#if __has_feature(capabilities)
int dtrace_enabled = 0;
#else
int dtrace_enabled = 1;
#endif
SYSCTL_INT(_debug, OID_AUTO, dtrace_enabled, CTLFLAG_RWTUN, &dtrace_enabled, 0,
"DTrace enabled");

/* Hooks used in the machine-dependent trap handlers. */
dtrace_trap_func_t dtrace_trap_func;
dtrace_doubletrap_func_t dtrace_doubletrap_func;
Expand Down
2 changes: 2 additions & 0 deletions sys/sys/dtrace_bsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@ void kdtrace_thread_dtor(struct thread *td);
uint64_t dtrace_gethrtime(void);
uint64_t dtrace_gethrestime(void);

extern int dtrace_enabled;

#endif /* _SYS_DTRACE_BSD_H */

0 comments on commit 83be3dc

Please sign in to comment.