]> sourceware.org Git - systemtap.git/commitdiff
Allow process begin/end probes for unprivileged users.
authorDave Brolley <brolley@redhat.com>
Thu, 3 Sep 2009 20:13:30 +0000 (16:13 -0400)
committerDave Brolley <brolley@redhat.com>
Thu, 3 Sep 2009 20:13:30 +0000 (16:13 -0400)
2009-09-03  Dave Brolley  <brolley@redhat.com>

        * tapsets.cxx (visit_cast_op): Don't disallow unprivileged users.
        Annotate synthesized function with /* unprivileged */.
        * tapset-utrace.cxx (register_tapset_utrace): Call allow_unprivileged
        for process begin and end probes.
        * translate.cxx (translate_pass): Generate '#define STP_PRIVILEGED 1'
        unless --unprivileged was specified.
        * runtime/transport/transport.c: Don't define _stp_unprivileged_user.
        * runtime/task_finder.c (__stp_utrace_attach_match_filename): Check
        that _stp_uid equals the task euid when STP_PRIVILEGED is not defined.
        (stap_start_task_finder): Likewise.
        * runtime/staprun/staprun.c (insert_stap_module): Don't generate
        module option _stp_unprivileged_user.

runtime/staprun/staprun.c
runtime/task_finder.c
runtime/transport/transport.c
tapset-utrace.cxx
tapsets.cxx
translate.cxx

index 7eb7f28fecc8005153b85ea536c6fbcca8ca8fe8..da3e304b0650273df6168045cf62c19ffb181751 100644 (file)
@@ -145,19 +145,11 @@ static int enable_uprobes(void)
 static int insert_stap_module(void)
 {
        char special_options[128];
-       char *bufptr = special_options;
 
        /* Add the _stp_bufsize option.  */
-       if (snprintf_chk(bufptr, sizeof (special_options), "_stp_bufsize=%d", buffer_size))
+       if (snprintf_chk(special_options, sizeof (special_options), "_stp_bufsize=%d", buffer_size))
                return -1;
 
-       /* Add the _stp_unprivileged_user option.  */
-       bufptr += strlen (bufptr);
-       if (snprintf_chk(bufptr,
-                        sizeof (special_options) - (bufptr - special_options),
-                        " _stp_unprivileged_user=%d", unprivileged_user))
-         return -1;
-
        return insert_module(modpath, special_options, modoptions);
 }
 
index ca807020a7b8d47cb36c575a7dff85e1d0eb66ad..fb6dc20dc7fba52f4fca1877b25d73be6286acee 100644 (file)
@@ -753,6 +753,18 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
                /* Notice that "pid == 0" (which means to probe all
                 * threads) falls through. */
 
+#ifndef STP_PRIVILEGED
+               /* Make sure unprivileged users only probe their own threads. */
+               if (_stp_uid != tsk->euid) {
+                       if (tgt->pid != 0) {
+                               _stp_warn("Process %d does not belong to unprivileged user %d",
+                                         tsk->pid, _stp_uid);
+                       }
+                       continue;
+               }
+#endif
+
+
                // Set up events we need for attached tasks. When
                // register_p is set, we won't actually call the
                // callbacks here - we'll call it when the thread gets
@@ -1414,6 +1426,17 @@ stap_start_task_finder(void)
                        /* Notice that "pid == 0" (which means to
                         * probe all threads) falls through. */
 
+#ifndef STP_PRIVILEGED
+                       /* Make sure unprivileged users only probe their own threads.  */
+                       if (_stp_uid != tsk->euid) {
+                               if (tgt->pid != 0) {
+                                       _stp_warn("Process %d does not belong to unprivileged user %d",
+                                                 tsk->pid, _stp_uid);
+                               }
+                               continue;
+                       }
+#endif
+
                        // Set up events we need for attached tasks.
                        rc = __stp_utrace_attach(tsk, &tgt->ops, tgt,
                                                 __STP_ATTACHED_TASK_EVENTS,
index ec73f05fe3a1555208136b8e2c0130911deec411..1d029e53745476f164d0df81fdd368337a89bbb0 100644 (file)
@@ -59,10 +59,6 @@ static int _stp_bufsize;
 module_param(_stp_bufsize, int, 0);
 MODULE_PARM_DESC(_stp_bufsize, "buffer size");
 
-static int _stp_unprivileged_user;
-module_param(_stp_unprivileged_user, int, 1);
-MODULE_PARM_DESC(_stp_unprivileged_user, "user is unprivileged");
-
 /* forward declarations */
 static void probe_exit(void);
 static int probe_start(void);
index 6872c87c011f4d208513ea59c9366de8cbdd2dd5..d9d95f823b19df7a1450df4b8a0768e14584a1ab 100644 (file)
@@ -1033,12 +1033,20 @@ register_tapset_utrace(systemtap_session& s)
 
   for (unsigned i = 0; i < roots.size(); ++i)
     {
-      roots[i]->bind(TOK_BEGIN)->bind(builder);
-      roots[i]->bind(TOK_END)->bind(builder);
-      roots[i]->bind(TOK_THREAD)->bind(TOK_BEGIN)->bind(builder);
-      roots[i]->bind(TOK_THREAD)->bind(TOK_END)->bind(builder);
-      roots[i]->bind(TOK_SYSCALL)->bind(builder);
-      roots[i]->bind(TOK_SYSCALL)->bind(TOK_RETURN)->bind(builder);
+      roots[i]->bind(TOK_BEGIN)
+       ->allow_unprivileged()
+       ->bind(builder);
+      roots[i]->bind(TOK_END)
+       ->allow_unprivileged()
+       ->bind(builder);
+      roots[i]->bind(TOK_THREAD)->bind(TOK_BEGIN)
+       ->bind(builder);
+      roots[i]->bind(TOK_THREAD)->bind(TOK_END)
+       ->bind(builder);
+      roots[i]->bind(TOK_SYSCALL)
+       ->bind(builder);
+      roots[i]->bind(TOK_SYSCALL)->bind(TOK_RETURN)
+       ->bind(builder);
     }
 }
 
index fccb73c889f2f7a22e7240c0ed3858151755822d..6a52050c152347ce72ad85fb75108a1e2a331af2 100644 (file)
@@ -2510,9 +2510,6 @@ void dwarf_cast_expanding_visitor::filter_special_modules(string& module)
 
 void dwarf_cast_expanding_visitor::visit_cast_op (cast_op* e)
 {
-  if (s.unprivileged)
-    throw semantic_error("typecasting may not be used when --unprivileged is specified", e->tok);
-
   bool lvalue = is_active_lvalue(e);
   if (lvalue && !s.guru_mode)
     throw semantic_error("write to typecast value not permitted", e->tok);
@@ -2618,6 +2615,8 @@ void dwarf_cast_expanding_visitor::visit_cast_op (cast_op* e)
   else
     ec->code += "/* pure */";
 
+  ec->code += "/* unprivileged */";
+
   s.functions[fdecl->name] = fdecl;
 
   // Synthesize a functioncall.
index 65acd2cab8c7511d87d88958284788a71ebaf796..c0f7b48bb91cb785803c1d372e30d71b565a5603 100644 (file)
@@ -5210,6 +5210,8 @@ translate_pass (systemtap_session& s)
       if (ri.recursive) nesting += 10;
 
       // This is at the very top of the file.
+      if (! s.unprivileged)
+       s.op->newline() << "#define STP_PRIVILEGED 1";
       s.op->newline() << "#ifndef MAXNESTING";
       s.op->newline() << "#define MAXNESTING " << nesting;
       s.op->newline() << "#endif";
This page took 0.055936 seconds and 5 git commands to generate.