From d83d7b513d38791751e46a05e382b1e6876abefc Mon Sep 17 00:00:00 2001 From: Dave Brolley Date: Wed, 16 Sep 2009 12:18:15 -0400 Subject: Create is_myproc helper function. --- tapset/context.stp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tapset/context.stp') diff --git a/tapset/context.stp b/tapset/context.stp index 5be9f21f..92c325ce 100644 --- a/tapset/context.stp +++ b/tapset/context.stp @@ -147,6 +147,20 @@ function euid:long () %{ /* pure */ #endif %} +/** + * sfunction is_myproc - Determines if the current probe point has occurred in + * the user's own process. + * + * Return 1 if the current probe point has occurred in the user's own process. + */ +function is_myproc:long () %{ /* pure */ /* unprivileged */ +#ifdef STAPCONF_TASK_UID + THIS->__retvalue = (current->euid == _stp_uid); +#else + THIS->__retvalue = (task_euid(current) == _stp_uid); +#endif +%} + // cpuid() is not documented function cpuid:long () %{ /* pure */ THIS->__retvalue = smp_processor_id(); -- cgit From b57367210bd84bdbf6a78785905127fb7711e567 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 16 Sep 2009 15:23:50 -0700 Subject: Spelling fixes in the tapsets --- tapset/context.stp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'tapset/context.stp') diff --git a/tapset/context.stp b/tapset/context.stp index 92c325ce..21af79b4 100644 --- a/tapset/context.stp +++ b/tapset/context.stp @@ -7,8 +7,8 @@ // Public License (GPL); either version 2, or (at your option) any // later version. // -// Context functions provide additional information about where an event occurred. These functions can -//provide information such as a backtrace to where the event occured and the current register values for the +// Context functions provide additional information about where an event occurred. These functions can +//provide information such as a backtrace to where the event occurred and the current register values for the //processor. // @@ -78,7 +78,7 @@ function pgrp:long () %{ /* pure */ /** * sfunction sid - Returns the session ID of the current process. - * + * * The session ID of a process is the process group ID of the session * leader. Session ID is stored in the signal_struct since Kernel 2.6.0. */ @@ -108,9 +108,9 @@ function pexecname:string () %{ /* pure */ */ function gid:long () %{ /* pure */ #ifdef STAPCONF_TASK_UID - THIS->__retvalue = current->gid; + THIS->__retvalue = current->gid; #else - THIS->__retvalue = current_gid(); + THIS->__retvalue = current_gid(); #endif %} @@ -119,9 +119,9 @@ function gid:long () %{ /* pure */ */ function egid:long () %{ /* pure */ #ifdef STAPCONF_TASK_UID - THIS->__retvalue = current->egid; + THIS->__retvalue = current->egid; #else - THIS->__retvalue = current_egid(); + THIS->__retvalue = current_egid(); #endif %} @@ -130,9 +130,9 @@ function egid:long () %{ /* pure */ */ function uid:long () %{ /* pure */ #ifdef STAPCONF_TASK_UID - THIS->__retvalue = current->uid; + THIS->__retvalue = current->uid; #else - THIS->__retvalue = current_uid(); + THIS->__retvalue = current_uid(); #endif %} @@ -141,15 +141,14 @@ function uid:long () %{ /* pure */ */ function euid:long () %{ /* pure */ #ifdef STAPCONF_TASK_UID - THIS->__retvalue = current->euid; + THIS->__retvalue = current->euid; #else - THIS->__retvalue = current_euid(); + THIS->__retvalue = current_euid(); #endif %} /** - * sfunction is_myproc - Determines if the current probe point has occurred in - * the user's own process. + * sfunction is_myproc - Determines if the current probe point has occurred in the user's own process. * * Return 1 if the current probe point has occurred in the user's own process. */ @@ -177,7 +176,7 @@ function cpu:long () %{ /* pure */ * sfunction pp - Return the probe point associated with the currently running probe handler, * including alias and wildcard expansion effects * Context: - * The current probe point. + * The current probe point. */ function pp:string () %{ /* pure */ strlcpy (THIS->__retvalue, CONTEXT->probe_point, MAXSTRINGLEN); @@ -221,8 +220,8 @@ function user_mode:long () %{ /* pure */ /* currently a user-mode address? */ function is_return:long () %{ /* pure */ if (CONTEXT->pi) THIS->__retvalue = 1; - else - THIS->__retvalue = 0; + else + THIS->__retvalue = 0; %} /** @@ -285,7 +284,7 @@ function stack_unused:long () %{ /* pure */ * sfunction uaddr - User space address of current running task. EXPERIMENTAL. * * Description: Returns the address in userspace that the current - * task was at when the probe occured. When the current running task + * task was at when the probe occurred. When the current running task * isn't a user space thread, or the address cannot be found, zero * is returned. Can be used to see where the current task is combined * with usymname() or symdata(). Often the task will be in the VDSO -- cgit From 6ecd877049008c5abe9c6720ea8fc64732f47eb5 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 16 Sep 2009 22:32:28 -0400 Subject: PR10650: markup some unprivileged-safe tapset functions Add /* unprivileged */ to a variety of tapset embedded-c functions, together with uid-assertion-checking code as needed. This is only an initial set, and may need to grow or shrink after further testing. Prototyped-By: Dave Brolley * runtime/runtime.h (is_myproc, assert_is_myproc): New macros. * runtime/addr-map.c (lookup_bad_addr): Reject if !is_myproc in unprivileged mode. * runtime/print.c (_stp_print_kernel_info): Add unprivileged mode info. * tapset/DEVGUIDE: Document /* pure */ and /* unprivileged */. * tapset/*.stp: Add /* unprivileged */ here and there, in questionable cases along with an assert_is_myproc(). --- tapset/context.stp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'tapset/context.stp') diff --git a/tapset/context.stp b/tapset/context.stp index 21af79b4..226e3ee5 100644 --- a/tapset/context.stp +++ b/tapset/context.stp @@ -34,28 +34,28 @@ function print_regs () %{ /** * sfunction execname - Returns the execname of a target process (or group of processes). */ -function execname:string () %{ /* pure */ +function execname:string () %{ /* pure */ /* unprivileged */ strlcpy (THIS->__retvalue, current->comm, MAXSTRINGLEN); %} /** * sfunction pid - Returns the ID of a target process. */ -function pid:long () %{ /* pure */ +function pid:long () %{ /* pure */ /* unprivileged */ THIS->__retvalue = current->tgid; %} /** * sfunction tid - Returns the thread ID of a target process. */ -function tid:long () %{ /* pure */ +function tid:long () %{ /* pure */ /* unprivileged */ THIS->__retvalue = current->pid; %} /** * sfunction ppid - Returns the process ID of a target process's parent process. */ -function ppid:long () %{ /* pure */ +function ppid:long () %{ /* pure */ /* unprivileged */ #if defined(STAPCONF_REAL_PARENT) THIS->__retvalue = current->real_parent->tgid; #else @@ -66,7 +66,7 @@ function ppid:long () %{ /* pure */ /** * sfunction pgrp - Returns the process group ID of the current process. */ -function pgrp:long () %{ /* pure */ +function pgrp:long () %{ /* pure */ /* unprivileged */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) struct signal_struct *ss = kread( &(current->signal) ); THIS->__retvalue = kread ( &(ss->pgrp) ); @@ -82,7 +82,7 @@ function pgrp:long () %{ /* pure */ * The session ID of a process is the process group ID of the session * leader. Session ID is stored in the signal_struct since Kernel 2.6.0. */ -function sid:long () %{ /* pure */ +function sid:long () %{ /* pure */ /* unprivileged */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) struct signal_struct *ss = kread( &(current->signal) ); THIS->__retvalue = kread ( &(ss->session) ); @@ -95,7 +95,7 @@ function sid:long () %{ /* pure */ /** * sfunction pexecname - Returns the execname of a target process's parent process. */ -function pexecname:string () %{ /* pure */ +function pexecname:string () %{ /* pure */ /* unprivileged */ #if defined(STAPCONF_REAL_PARENT) strlcpy (THIS->__retvalue, current->real_parent->comm, MAXSTRINGLEN); #else @@ -106,7 +106,7 @@ function pexecname:string () %{ /* pure */ /** * sfunction gid - Returns the group ID of a target process. */ -function gid:long () %{ /* pure */ +function gid:long () %{ /* pure */ /* unprivileged */ #ifdef STAPCONF_TASK_UID THIS->__retvalue = current->gid; #else @@ -117,7 +117,7 @@ function gid:long () %{ /* pure */ /** * sfunction egid - Returns the effective gid of a target process. */ -function egid:long () %{ /* pure */ +function egid:long () %{ /* pure */ /* unprivileged */ #ifdef STAPCONF_TASK_UID THIS->__retvalue = current->egid; #else @@ -128,7 +128,7 @@ function egid:long () %{ /* pure */ /** * sfunction uid - Returns the user ID of a target process. */ -function uid:long () %{ /* pure */ +function uid:long () %{ /* pure */ /* unprivileged */ #ifdef STAPCONF_TASK_UID THIS->__retvalue = current->uid; #else @@ -139,7 +139,7 @@ function uid:long () %{ /* pure */ /** * sfunction euid - Return the effective uid of a target process. */ -function euid:long () %{ /* pure */ +function euid:long () %{ /* pure */ /* unprivileged */ #ifdef STAPCONF_TASK_UID THIS->__retvalue = current->euid; #else @@ -147,19 +147,18 @@ function euid:long () %{ /* pure */ #endif %} + /** * sfunction is_myproc - Determines if the current probe point has occurred in the user's own process. * * Return 1 if the current probe point has occurred in the user's own process. */ function is_myproc:long () %{ /* pure */ /* unprivileged */ -#ifdef STAPCONF_TASK_UID - THIS->__retvalue = (current->euid == _stp_uid); -#else - THIS->__retvalue = (task_euid(current) == _stp_uid); -#endif + THIS->__retvalue = is_myproc(); %} + + // cpuid() is not documented function cpuid:long () %{ /* pure */ THIS->__retvalue = smp_processor_id(); @@ -168,7 +167,7 @@ function cpuid:long () %{ /* pure */ /** * sfunction cpu - Returns the current cpu number. */ -function cpu:long () %{ /* pure */ +function cpu:long () %{ /* pure */ /* unprivileged */ THIS->__retvalue = smp_processor_id(); %} @@ -178,7 +177,7 @@ function cpu:long () %{ /* pure */ * Context: * The current probe point. */ -function pp:string () %{ /* pure */ +function pp:string () %{ /* pure */ /* unprivileged */ strlcpy (THIS->__retvalue, CONTEXT->probe_point, MAXSTRINGLEN); %} @@ -190,7 +189,7 @@ function pp:string () %{ /* pure */ * For example, registers_valid() returns 0 * when called from a begin or end probe. */ -function registers_valid:long () %{ /* pure */ +function registers_valid:long () %{ /* pure */ /* unprivileged */ THIS->__retvalue = (CONTEXT->regs != NULL); %} @@ -199,7 +198,7 @@ function registers_valid:long () %{ /* pure */ * * Return 1 if the probe point occurred in user-mode. */ -function user_mode:long () %{ /* pure */ /* currently a user-mode address? */ +function user_mode:long () %{ /* pure */ /* unprivileged */ if (CONTEXT->regs) { #if defined(__i386__) || defined(__x86_64__) THIS->__retvalue = (uint64_t) user_mode_vm (CONTEXT->regs); @@ -227,7 +226,7 @@ function is_return:long () %{ /* pure */ /** * sfunction target - Return the process ID of the target process. */ -function target:long () %{ /* pure */ +function target:long () %{ /* pure */ /* unprivileged */ THIS->__retvalue = _stp_target; %} @@ -238,7 +237,7 @@ function target:long () %{ /* pure */ /// FIXME: need description. /// /// -function module_name:string () %{ /* pure */ +function module_name:string () %{ /* pure */ /* unprivileged */ strlcpy(THIS->__retvalue, THIS_MODULE->name, MAXSTRINGLEN); %} @@ -290,8 +289,9 @@ function stack_unused:long () %{ /* pure */ * with usymname() or symdata(). Often the task will be in the VDSO * where it entered the kernel. FIXME - need VDSO tracking support #10080. */ -function uaddr:long () %{ /* pure */ +function uaddr:long () %{ /* pure */ /* unprivileged */ int64_t addr = 0; + assert_is_myproc(); if (current->mm) { struct pt_regs *uregs; -- cgit