[PATCH 06/33] restore the EXEC/EXIT/CLONE utrace hooks

Oleg Nesterov oleg at redhat.com
Mon Nov 21 20:01:45 UTC 2011


Restore the "trivial" EXEC/EXIT/CLONE utrace hooks. Add the
simple helper, UTRACE_HOOK(), to minimize the changes.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 fs/exec.c              |    5 ++++-
 include/linux/utrace.h |    6 ++++++
 kernel/exit.c          |    1 +
 kernel/fork.c          |    4 ++++
 4 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 3625464..7d8f8bd 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1397,9 +1397,12 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 			 */
 			bprm->recursion_depth = depth;
 			if (retval >= 0) {
-				if (depth == 0)
+				if (depth == 0) {
+					UTRACE_HOOK(current, EXEC,
+						report_exec(fmt, bprm, regs));
 					ptrace_event(PTRACE_EVENT_EXEC,
 							old_pid);
+				}
 				put_binfmt(fmt);
 				allow_write_access(bprm->file);
 				if (bprm->file)
diff --git a/include/linux/utrace.h b/include/linux/utrace.h
index 1b8da1c..9ac0b1b 100644
--- a/include/linux/utrace.h
+++ b/include/linux/utrace.h
@@ -109,6 +109,12 @@ void utrace_signal_handler(struct task_struct *, int);
 
 #define UTRACE_FLAG(task, ev)	(task_utrace_flags(task) & UTRACE_EVENT(ev))
 
+#define UTRACE_HOOK(task, ev, callback)			\
+	do {						\
+		if (UTRACE_FLAG(task, ev))		\
+			utrace_ ## callback;		\
+	} while (0)
+
 #ifndef CONFIG_UTRACE
 
 /*
diff --git a/kernel/exit.c b/kernel/exit.c
index d0b7d98..f5eba3b 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -911,6 +911,7 @@ NORET_TYPE void do_exit(long code)
 	 */
 	set_fs(USER_DS);
 
+	UTRACE_HOOK(current, EXIT, report_exit(&code));
 	ptrace_event(PTRACE_EVENT_EXIT, code);
 
 	validate_creds_for_do_exit(tsk);
diff --git a/kernel/fork.c b/kernel/fork.c
index b8719c2..09d5049 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1535,6 +1535,8 @@ long do_fork(unsigned long clone_flags,
 
 		audit_finish_fork(p);
 
+		UTRACE_HOOK(current, CLONE, report_clone(clone_flags, p));
+
 		/*
 		 * We set PF_STARTING at creation in case tracing wants to
 		 * use this to distinguish a fully live task from one that
@@ -1546,6 +1548,8 @@ long do_fork(unsigned long clone_flags,
 		wake_up_new_task(p);
 
 		/* forking complete and child started to run, tell ptracer */
+		if (clone_flags & CLONE_VFORK)
+			UTRACE_HOOK(current, CLONE, finish_vfork(current));
 		if (unlikely(trace))
 			ptrace_event(trace, nr);
 
-- 
1.5.5.1



More information about the kernel mailing list