Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Aug 2014 15:36:24 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r269521 - in stable/9: cddl/contrib/opensolaris/lib/libdtrace/common cddl/lib/libdtrace sys/cddl/contrib/opensolaris/uts/common/dtrace sys/cddl/contrib/opensolaris/uts/common/sys sys/cd...
Message-ID:  <53dfa878.54f7.4b5a27a8@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Mon Aug  4 15:36:23 2014
New Revision: 269521
URL: http://svnweb.freebsd.org/changeset/base/269521

Log:
  MFC r256571:
  Add a function, memstr, which can be used to convert a buffer of
  null-separated strings to a single string. This can be used to print the
  full arguments of a process using execsnoop (from the DTrace toolkit) or
  with the following one-liner:
  
  dtrace -n 'syscall::execve:return {trace(curpsinfo->pr_psargs);}'
  
  Note that this relies on the process arguments being cached via the struct
  proc, which means that it will not work for argvs longer than
  kern.ps_arg_cache_limit. However, the following rather non-portable
  script can be used to extract any argv at exec time:
  
  fbt::kern_execve:entry
  {
      printf("%s", memstr(args[1]->begin_argv, ' ',
          args[1]->begin_envv - args[1]->begin_argv));
  }
  
  The debug.dtrace.memstr_max sysctl limits the maximum argument size to
  memstr().

Modified:
  stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
  stable/9/cddl/lib/libdtrace/psinfo.d
  stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
  stable/9/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
  stable/9/sys/cddl/dev/dtrace/dtrace_sysctl.c
Directory Properties:
  stable/9/cddl/contrib/opensolaris/   (props changed)
  stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/   (props changed)
  stable/9/cddl/lib/libdtrace/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)

Modified: stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
==============================================================================
--- stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c	Mon Aug  4 15:36:22 2014	(r269520)
+++ stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c	Mon Aug  4 15:36:23 2014	(r269521)
@@ -311,6 +311,10 @@ static const dt_ident_t _dtrace_globals[
 	&dt_idops_func, "void(@)" },
 { "memref", DT_IDENT_FUNC, 0, DIF_SUBR_MEMREF, DT_ATTR_STABCMN, DT_VERS_1_1,
 	&dt_idops_func, "uintptr_t *(void *, size_t)" },
+#if !defined(sun)
+{ "memstr", DT_IDENT_FUNC, 0, DIF_SUBR_MEMSTR, DT_ATTR_STABCMN, DT_VERS_1_0,
+	&dt_idops_func, "string(void *, char, size_t)" },
+#endif
 { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0,
 	&dt_idops_func, "void(@)" },
 { "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN,

Modified: stable/9/cddl/lib/libdtrace/psinfo.d
==============================================================================
--- stable/9/cddl/lib/libdtrace/psinfo.d	Mon Aug  4 15:36:22 2014	(r269520)
+++ stable/9/cddl/lib/libdtrace/psinfo.d	Mon Aug  4 15:36:23 2014	(r269521)
@@ -56,7 +56,8 @@ translator psinfo_t < struct proc *T > {
 	pr_gid = T->p_ucred->cr_rgid;
 	pr_egid = T->p_ucred->cr_groups[0];
 	pr_addr = 0;
-	pr_psargs = stringof(T->p_args->ar_args);
+	pr_psargs = (T->p_args->ar_args == 0) ? "" :
+	    memstr(T->p_args->ar_args, ' ', T->p_args->ar_length);
 	pr_arglen = T->p_args->ar_length;
 };
 

Modified: stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
==============================================================================
--- stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c	Mon Aug  4 15:36:22 2014	(r269520)
+++ stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c	Mon Aug  4 15:36:23 2014	(r269521)
@@ -185,6 +185,9 @@ hrtime_t	dtrace_deadman_interval = NANOS
 hrtime_t	dtrace_deadman_timeout = (hrtime_t)10 * NANOSEC;
 hrtime_t	dtrace_deadman_user = (hrtime_t)30 * NANOSEC;
 hrtime_t	dtrace_unregister_defunct_reap = (hrtime_t)60 * NANOSEC;
+#if !defined(sun)
+int		dtrace_memstr_max = 4096;
+#endif
 
 /*
  * DTrace External Variables
@@ -4921,6 +4924,45 @@ inetout:	regs[rd] = (uintptr_t)end + 1;
 		break;
 	}
 
+#if !defined(sun)
+	case DIF_SUBR_MEMSTR: {
+		char *str = (char *)mstate->dtms_scratch_ptr;
+		uintptr_t mem = tupregs[0].dttk_value;
+		char c = tupregs[1].dttk_value;
+		size_t size = tupregs[2].dttk_value;
+		uint8_t n;
+		int i;
+
+		regs[rd] = 0;
+
+		if (size == 0)
+			break;
+
+		if (!dtrace_canload(mem, size - 1, mstate, vstate))
+			break;
+
+		if (!DTRACE_INSCRATCH(mstate, size)) {
+			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+			break;
+		}
+
+		if (dtrace_memstr_max != 0 && size > dtrace_memstr_max) {
+			*flags |= CPU_DTRACE_ILLOP;
+			break;
+		}
+
+		for (i = 0; i < size - 1; i++) {
+			n = dtrace_load8(mem++);
+			str[i] = (n == 0) ? c : n;
+		}
+		str[size - 1] = 0;
+
+		regs[rd] = (uintptr_t)str;
+		mstate->dtms_scratch_ptr += size;
+		break;
+	}
+#endif
+
 	case DIF_SUBR_TYPEREF: {
 		uintptr_t size = 4 * sizeof(uintptr_t);
 		uintptr_t *typeref = (uintptr_t *) P2ROUNDUP(mstate->dtms_scratch_ptr, sizeof(uintptr_t));
@@ -9103,6 +9145,9 @@ dtrace_difo_validate_helper(dtrace_difo_
 			    subr == DIF_SUBR_NTOHL ||
 			    subr == DIF_SUBR_NTOHLL ||
 			    subr == DIF_SUBR_MEMREF ||
+#if !defined(sun)
+			    subr == DIF_SUBR_MEMSTR ||
+#endif
 			    subr == DIF_SUBR_TYPEREF)
 				break;
 

Modified: stable/9/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h
==============================================================================
--- stable/9/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h	Mon Aug  4 15:36:22 2014	(r269520)
+++ stable/9/sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h	Mon Aug  4 15:36:23 2014	(r269521)
@@ -311,8 +311,9 @@ typedef enum dtrace_probespec {
 #define	DIF_SUBR_SX_SHARED_HELD		48
 #define	DIF_SUBR_SX_EXCLUSIVE_HELD	49
 #define	DIF_SUBR_SX_ISEXCLUSIVE		50
+#define	DIF_SUBR_MEMSTR			51
 
-#define	DIF_SUBR_MAX			50	/* max subroutine value */
+#define	DIF_SUBR_MAX			51	/* max subroutine value */
 
 typedef uint32_t dif_instr_t;
 

Modified: stable/9/sys/cddl/dev/dtrace/dtrace_sysctl.c
==============================================================================
--- stable/9/sys/cddl/dev/dtrace/dtrace_sysctl.c	Mon Aug  4 15:36:22 2014	(r269520)
+++ stable/9/sys/cddl/dev/dtrace/dtrace_sysctl.c	Mon Aug  4 15:36:23 2014	(r269521)
@@ -89,3 +89,6 @@ SYSCTL_LONG(_kern_dtrace, OID_AUTO, dof_
 
 SYSCTL_LONG(_kern_dtrace, OID_AUTO, helper_actions_max, CTLFLAG_RW,
     &dtrace_helper_actions_max, 0, "maximum number of allowed helper actions");
+
+SYSCTL_INT(_kern_dtrace, OID_AUTO, memstr_max, CTLFLAG_RW, &dtrace_memstr_max,
+    0, "largest allowed argument to memstr(), 0 indicates no limit");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53dfa878.54f7.4b5a27a8>