This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Tapset difficulties w/ pointers


joshua.i.stone wrote:

> For the process.exec probe, I would like to make the pointer to the new
> task_struct available.  This is fine, and then I can make
> access-functions for the user to extract data from this, like so:
> 
>  function task_pid:long (task:long) %{ /* pure */
>  [...]
>    struct task_struct *t = [...] (THIS->task)-> [...]
>
> The obvious problem here is safety.  I can check that the parameter is
> not zero, but what do I do if the user calls task_pid(0xDEADBEEF)?
> Oops...  Or what happens if the user stashes the pointer away in a
> global, and tries to read it later?  Oops...

We don't have to return correct answers to trick questions, just avoid
hurting the system.  Dereference operations in exposed embedded-C code
can be channeled through the same deref() macro used by $target
variable expansions, which aims to catch ordinary faults.  The new
kprobes fault-handling code being discussed may do this automatically
for some probes.  Further, we can mark mapped-but-unsafe memory
regions (bug #1288) in a similar way as dtrace does, to filter
addresses further.

Some of this would require some discipline from the author of an
embedded-C function.


> One solution is to "hide" task_pid(), perhaps by renaming it to
> __task_pid(), and then have the tapset provide variables for pid,
> tid, etc. and rely on the compiler to elide those that are unused.
> [...]

This style should work well with recent optimizer tweaks.

> This is still not really safe though, because that __task_pid() is
> only discouraged, not protected.  [...]

Another possibility is to impose a naming convention for "internal"
functions (and probes? variables?), so that only guru-mode code can
resolve references to them.  (i.e., external references to "__FOO"
symbols would only resolve in guru mode).


> A more general solution would be if we had some sort of "handle"
> type.  [...]  It can have metadata to identify the type, and perhaps
> also to limit the valid lifetime of the pointer. [...]

Unless the machinery involved in something like this is fairly small
and simple, I'd prefer to first explore the limits of the simpler ones
above.


- FChE


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]