Blame SOURCES/rhbz1643997.0016-tapset-bpf-context.stp-add-execname-triage-other-fun.patch

cab4ad
From deb88d0b1fef10177ab197b066f434c720253f8d Mon Sep 17 00:00:00 2001
cab4ad
From: Serhei Makarov <smakarov@redhat.com>
cab4ad
Date: Tue, 30 Oct 2018 17:29:46 -0400
cab4ad
Subject: [PATCH 16/32] tapset/bpf/context.stp :: add execname(), triage other
cab4ad
 functions
cab4ad
cab4ad
* tapset/bpf/context.stp: Notes on other functions that could be added.
cab4ad
(execname): New tapset function.
cab4ad
cab4ad
* tapset/linux/context.stp: Move pexecname() to a more logical location.
cab4ad
---
cab4ad
 tapset/bpf/context.stp   | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
cab4ad
 tapset/linux/context.stp | 30 +++++++++++-----------
cab4ad
 2 files changed, 81 insertions(+), 15 deletions(-)
cab4ad
cab4ad
diff --git a/tapset/bpf/context.stp b/tapset/bpf/context.stp
cab4ad
index 45dcd4d71..55e0f871b 100644
cab4ad
--- a/tapset/bpf/context.stp
cab4ad
+++ b/tapset/bpf/context.stp
cab4ad
@@ -6,6 +6,34 @@
cab4ad
 // Public License (GPL); either version 2, or (at your option) any
cab4ad
 // later version.
cab4ad
 
cab4ad
+/**
cab4ad
+ * sfunction execname - Returns the execname of a target process (or group of processes)
cab4ad
+ *
cab4ad
+ * Description: Returns the execname of a target process (or group of processes).
cab4ad
+ */
cab4ad
+function execname:string ()
cab4ad
+%{ /* bpf */ /* pure */ /* unprivileged */ /* stable */
cab4ad
+  /* buf = bpf_stk_alloc(BPF_MAXSTRINGLEN);
cab4ad
+     buf[0] = 0x0; // guarantee NUL byte
cab4ad
+     rc = get_current_comm(buf, BPF_MAXSTRINGLEN); */
cab4ad
+  alloc, $buf, BPF_MAXSTRINGLEN;
cab4ad
+  0x62, $buf, -, -, 0x0; /* stw [$buf+0], 0x0 -- guarantee NUL byte */
cab4ad
+  call, $rc, get_current_comm, $buf, BPF_MAXSTRINGLEN;
cab4ad
+
cab4ad
+  /* if (rc < 0) return err_msg;
cab4ad
+     return buf; */
cab4ad
+  0xa5, $rc, 0, _err, -; /* jlt $rc, 0, _err */
cab4ad
+  0xbf, $$, $buf, -, -; /* mov $$, $buf */
cab4ad
+  0x05, -, -, _done, -; /* ja _done */
cab4ad
+
cab4ad
+  label, _err;
cab4ad
+  0xbf, $$, "<unknown>", -, -; /* mov $$, <unknown> */
cab4ad
+
cab4ad
+  label, _done;
cab4ad
+%}
cab4ad
+
cab4ad
+// TODO: pexecname ()
cab4ad
+
cab4ad
 /**
cab4ad
  * sfunction pid - Returns the ID of a thread group
cab4ad
  * 
cab4ad
@@ -20,6 +48,8 @@ function pid:long ()
cab4ad
    0x77, $$, 0, 0, 32   /* rshk $$, 32 */
cab4ad
 %}
cab4ad
 
cab4ad
+// TODO: ns_pid:long ()
cab4ad
+
cab4ad
 /**
cab4ad
  * sfunction tid - Returns the thread ID of a target process
cab4ad
  * 
cab4ad
@@ -33,6 +63,14 @@ function tid:long ()
cab4ad
    0xbc, $$, 0, 0, 0    /* movwx $$, r0 */
cab4ad
 %}
cab4ad
 
cab4ad
+// TODO: ns_tid:long ()
cab4ad
+// TODO: ppid:long ()
cab4ad
+// TODO: ns_ppid:long ()
cab4ad
+// TODO: pgrp:long ()
cab4ad
+// TODO: ns_pgrp:long ()
cab4ad
+// TODO: sid:long ()
cab4ad
+// TODO: ns_sid:long ()
cab4ad
+
cab4ad
 /**
cab4ad
  * sfunction gid - Returns the group ID of a target process
cab4ad
  * 
cab4ad
@@ -46,6 +84,10 @@ function gid:long ()
cab4ad
    0x77, $$, 0, 0, 32	/* rshk $$, 32 */
cab4ad
 %}
cab4ad
 
cab4ad
+// TODO: ns_gid:long ()
cab4ad
+// TODO: egid:long ()
cab4ad
+// TODO: ns_egid:long ()
cab4ad
+
cab4ad
 /**
cab4ad
  * sfunction uid - Returns the user ID of a target process
cab4ad
  *
cab4ad
@@ -58,6 +100,12 @@ function uid:long ()
cab4ad
    0xbc, $$, 0, 0, 0	/* movwx $$, r0 */
cab4ad
 %}
cab4ad
 
cab4ad
+// TODO: ns_uid:long ()
cab4ad
+// TODO: euid:long ()
cab4ad
+// TODO: ns_euid:long ()
cab4ad
+// XXX: is_myproc () is only relevant for unprivileged use of eBPF (still theoretical).
cab4ad
+
cab4ad
+// TODO: Old systemtap-compat scripts should not be running on eBPF backend in the first place?
cab4ad
 /**
cab4ad
  * sfunction cpuid - Returns the current cpu number
cab4ad
  * 
cab4ad
@@ -82,3 +130,21 @@ function cpu:long ()
cab4ad
    0x85, 0, 0, 0, 8;	/* call BPF_FUNC_get_smp_processor_id */
cab4ad
    0xbf, $$, 0, 0, 0	/* movx $$, r0 */
cab4ad
 %}
cab4ad
+
cab4ad
+// TODO: registers_valid:long ()
cab4ad
+// TODO: user_mode:long ()
cab4ad
+// TODO: is_return:long ()
cab4ad
+// TODO: target:long ()
cab4ad
+// TODO: module_name:string ()
cab4ad
+// XXX: module_size:string () -- not clear if this should refer to the entire .bo or to just the current eBPF routine.
cab4ad
+// TODO: stp_pid:long ()
cab4ad
+// XXX: remote_id:long (), remote_uri:string() -- pending an evaluation of remote eBPF execution.
cab4ad
+// XXX: stack_size() -- not clear if this should be the eBPF stack size or the kernel stack size.
cab4ad
+// XXX: stack_used(),stack_unused() probably a fairly ill-defined idea with the eBPF stack.
cab4ad
+// TODO: Other context functions for info about things like eBPF maps.
cab4ad
+
cab4ad
+// TODO: addr:long ()
cab4ad
+// TODO: uaddr:long ()
cab4ad
+// XXX: cmdline_args:string(n:long, m:long, delim:string) -- requires string concatenation & loops.
cab4ad
+// TODO: cmdline_arg:string(n:long)
cab4ad
+// XXX: cmdline_string:string() -- requires string concatenation & loops.
cab4ad
diff --git a/tapset/linux/context.stp b/tapset/linux/context.stp
cab4ad
index 2bd405186..46b1f6b32 100644
cab4ad
--- a/tapset/linux/context.stp
cab4ad
+++ b/tapset/linux/context.stp
cab4ad
@@ -19,6 +19,21 @@ function execname:string ()
cab4ad
 	strlcpy (STAP_RETVALUE, current->comm, MAXSTRINGLEN);
cab4ad
 %}
cab4ad
 
cab4ad
+/**
cab4ad
+ * sfunction pexecname - Returns the execname of a target process's parent process
cab4ad
+ *
cab4ad
+ * Description: This function returns the execname of a target
cab4ad
+ * process's parent procces.
cab4ad
+ */
cab4ad
+function pexecname:string ()
cab4ad
+%{ /* pure */ /* unprivileged */ /* stable */
cab4ad
+#if defined(STAPCONF_REAL_PARENT)
cab4ad
+	strlcpy (STAP_RETVALUE, current->real_parent->comm, MAXSTRINGLEN);
cab4ad
+#else
cab4ad
+	strlcpy (STAP_RETVALUE, current->parent->comm, MAXSTRINGLEN);
cab4ad
+#endif
cab4ad
+%}
cab4ad
+
cab4ad
 /**
cab4ad
  * sfunction pid - Returns the ID of a target process
cab4ad
  *
cab4ad
@@ -153,21 +168,6 @@ function ns_sid:long ()
cab4ad
   else STAP_RETURN (rc);
cab4ad
 %}
cab4ad
 
cab4ad
-/**
cab4ad
- * sfunction pexecname - Returns the execname of a target process's parent process
cab4ad
- *
cab4ad
- * Description: This function returns the execname of a target
cab4ad
- * process's parent procces.
cab4ad
- */
cab4ad
-function pexecname:string ()
cab4ad
-%{ /* pure */ /* unprivileged */ /* stable */
cab4ad
-#if defined(STAPCONF_REAL_PARENT)
cab4ad
-	strlcpy (STAP_RETVALUE, current->real_parent->comm, MAXSTRINGLEN);
cab4ad
-#else
cab4ad
-	strlcpy (STAP_RETVALUE, current->parent->comm, MAXSTRINGLEN);
cab4ad
-#endif
cab4ad
-%}
cab4ad
-
cab4ad
 /**
cab4ad
  * sfunction gid - Returns the group ID of a target process
cab4ad
  *
cab4ad
-- 
cab4ad
2.14.5
cab4ad