]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
tracehook: exec
authorRoland McGrath <roland@redhat.com>
Sat, 26 Jul 2008 02:45:44 +0000 (19:45 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 26 Jul 2008 19:00:08 +0000 (12:00 -0700)
This moves all the ptrace hooks related to exec into tracehook.h inlines.

This also lifts the calls for tracing out of the binfmt load_binary hooks
into search_binary_handler() after it calls into the binfmt module.  This
change has no effect, since all the binfmt modules' load_binary functions
did the call at the end on success, and now search_binary_handler() does
it immediately after return if successful.  We consolidate the repeated
code, and binfmt modules no longer need to import ptrace_notify().

Signed-off-by: Roland McGrath <roland@redhat.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/ia32/ia32_aout.c
fs/binfmt_aout.c
fs/binfmt_elf.c
fs/binfmt_elf_fdpic.c
fs/binfmt_flat.c
fs/binfmt_som.c
fs/exec.c
include/linux/tracehook.h

index 58cccb6483b0580d28d935b4692f62b2675f7d02..a0e1dbe67dc145cd437661ea2f472c9865e08578 100644 (file)
@@ -441,12 +441,6 @@ beyond_if:
        regs->r8 = regs->r9 = regs->r10 = regs->r11 =
        regs->r12 = regs->r13 = regs->r14 = regs->r15 = 0;
        set_fs(USER_DS);
-       if (unlikely(current->ptrace & PT_PTRACED)) {
-               if (current->ptrace & PT_TRACE_EXEC)
-                       ptrace_notify((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
-               else
-                       send_sig(SIGTRAP, current, 0);
-       }
        return 0;
 }
 
index ba4cddb92f1ddf02330760e7b7614d7b261a5a64..204cfd1d76762e22cf2e62bd447fb6c7fd7da0d9 100644 (file)
@@ -444,12 +444,6 @@ beyond_if:
        regs->gp = ex.a_gpvalue;
 #endif
        start_thread(regs, ex.a_entry, current->mm->start_stack);
-       if (unlikely(current->ptrace & PT_PTRACED)) {
-               if (current->ptrace & PT_TRACE_EXEC)
-                       ptrace_notify ((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
-               else
-                       send_sig(SIGTRAP, current, 0);
-       }
        return 0;
 }
 
index 3b6ff854d98379b9af3dca3ea6889e79879575e7..655ed8d30a86ef7e963414a9cb56d6ed7dc5d3c4 100644 (file)
@@ -1003,12 +1003,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
 #endif
 
        start_thread(regs, elf_entry, bprm->p);
-       if (unlikely(current->ptrace & PT_PTRACED)) {
-               if (current->ptrace & PT_TRACE_EXEC)
-                       ptrace_notify ((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
-               else
-                       send_sig(SIGTRAP, current, 0);
-       }
        retval = 0;
 out:
        kfree(loc);
index 1b59b1edf26de890b8d4ebfd54912f670c0ba2c2..fdeadab2f18bb030288f00e98755bfb2b4cba1e3 100644 (file)
@@ -433,13 +433,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm,
        entryaddr = interp_params.entry_addr ?: exec_params.entry_addr;
        start_thread(regs, entryaddr, current->mm->start_stack);
 
-       if (unlikely(current->ptrace & PT_PTRACED)) {
-               if (current->ptrace & PT_TRACE_EXEC)
-                       ptrace_notify((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
-               else
-                       send_sig(SIGTRAP, current, 0);
-       }
-
        retval = 0;
 
 error:
index 2cb1acda3a82f70a9f809e880d499999e39edd9d..56372ecf16909d8dd7c2e37062c044d2aa147c23 100644 (file)
@@ -920,9 +920,6 @@ static int load_flat_binary(struct linux_binprm * bprm, struct pt_regs * regs)
        
        start_thread(regs, start_addr, current->mm->start_stack);
 
-       if (current->ptrace & PT_PTRACED)
-               send_sig(SIGTRAP, current, 0);
-
        return 0;
 }
 
index fdc36bfd6a7beb8d1b63b91520ece0a7d2a347b7..68be580ba289fc3135a0dcd93595ce5b66062206 100644 (file)
@@ -274,8 +274,6 @@ load_som_binary(struct linux_binprm * bprm, struct pt_regs * regs)
        map_hpux_gateway_page(current,current->mm);
 
        start_thread_som(regs, som_entry, bprm->p);
-       if (current->ptrace & PT_PTRACED)
-               send_sig(SIGTRAP, current, 0);
        return 0;
 
        /* error cleanup */
index 5e559013e303fbcb6f9666828cca450ab57de7f9..b8792a13153377f83bc465a320eb35d6d0bd2c33 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
 #include <linux/module.h>
 #include <linux/namei.h>
 #include <linux/proc_fs.h>
-#include <linux/ptrace.h>
 #include <linux/mount.h>
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/tsacct_kern.h>
 #include <linux/cn_proc.h>
 #include <linux/audit.h>
+#include <linux/tracehook.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -1071,13 +1071,8 @@ EXPORT_SYMBOL(prepare_binprm);
 
 static int unsafe_exec(struct task_struct *p)
 {
-       int unsafe = 0;
-       if (p->ptrace & PT_PTRACED) {
-               if (p->ptrace & PT_PTRACE_CAP)
-                       unsafe |= LSM_UNSAFE_PTRACE_CAP;
-               else
-                       unsafe |= LSM_UNSAFE_PTRACE;
-       }
+       int unsafe = tracehook_unsafe_exec(p);
+
        if (atomic_read(&p->fs->count) > 1 ||
            atomic_read(&p->files->count) > 1 ||
            atomic_read(&p->sighand->count) > 1)
@@ -1214,6 +1209,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
                        read_unlock(&binfmt_lock);
                        retval = fn(bprm, regs);
                        if (retval >= 0) {
+                               tracehook_report_exec(fmt, bprm, regs);
                                put_binfmt(fmt);
                                allow_write_access(bprm->file);
                                if (bprm->file)
index bea0f3eeff541094131efafee705342bf91356af..6276353709c1fcfaf5d7a5698a3f529c89c0c72b 100644 (file)
 
 #include <linux/sched.h>
 #include <linux/ptrace.h>
+#include <linux/security.h>
+struct linux_binprm;
+
+/**
+ * tracehook_unsafe_exec - check for exec declared unsafe due to tracing
+ * @task:              current task doing exec
+ *
+ * Return %LSM_UNSAFE_* bits applied to an exec because of tracing.
+ *
+ * Called with task_lock() held on @task.
+ */
+static inline int tracehook_unsafe_exec(struct task_struct *task)
+{
+       int unsafe = 0;
+       int ptrace = task_ptrace(task);
+       if (ptrace & PT_PTRACED) {
+               if (ptrace & PT_PTRACE_CAP)
+                       unsafe |= LSM_UNSAFE_PTRACE_CAP;
+               else
+                       unsafe |= LSM_UNSAFE_PTRACE;
+       }
+       return unsafe;
+}
+
+/**
+ * tracehook_report_exec - a successful exec was completed
+ * @fmt:               &struct linux_binfmt that performed the exec
+ * @bprm:              &struct linux_binprm containing exec details
+ * @regs:              user-mode register state
+ *
+ * An exec just completed, we are shortly going to return to user mode.
+ * The freshly initialized register state can be seen and changed in @regs.
+ * The name, file and other pointers in @bprm are still on hand to be
+ * inspected, but will be freed as soon as this returns.
+ *
+ * Called with no locks, but with some kernel resources held live
+ * and a reference on @fmt->module.
+ */
+static inline void tracehook_report_exec(struct linux_binfmt *fmt,
+                                        struct linux_binprm *bprm,
+                                        struct pt_regs *regs)
+{
+       if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) &&
+           unlikely(task_ptrace(current) & PT_PTRACED))
+               send_sig(SIGTRAP, current, 0);
+}
 
 #endif /* <linux/tracehook.h> */