[PATCH 09] introduce the empty struct ptrace_context

Oleg Nesterov oleg at redhat.com
Mon Aug 17 15:23:02 UTC 2009


Introduce the empty struct ptrace_context, change ptrace_attach_task()
to setup engine->data.

It should be used for ptrace_set_action() and ptrace_set_stop_event(),
the current usage of ->ptrace is racy.

Also, ->exit_code and ->last_siginfo should live in engine->data too.

Eventually, all ptrace-related members should be moved from task_struct.

Note! with this patch every attach means the memory leak, we never
free engine->data. I am not sure how we should free, let's discuss
"[RFC, PATCH] teach utrace to destroy engine->data" first.

---

 kernel/ptrace.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

--- PU/kernel/ptrace.c~09_CONTEXT	2009-08-17 16:05:21.000000000 +0200
+++ PU/kernel/ptrace.c	2009-08-17 16:25:12.000000000 +0200
@@ -24,6 +24,8 @@
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
 
+struct ptrace_context {
+};
 
 /*
  * ptrace a task: make the debugger its new parent and
@@ -469,17 +471,23 @@ static const struct utrace_engine_ops pt
  */
 static int ptrace_attach_task(struct task_struct *tracee)
 {
+	struct ptrace_context *context;
 	struct utrace_engine *engine;
 	unsigned long events;
 
+	context = kzalloc(sizeof(*context), GFP_KERNEL);
+	if (unlikely(!context))
+		return -ENOMEM;
+
 	engine = utrace_attach_task(tracee, UTRACE_ATTACH_CREATE |
 						UTRACE_ATTACH_EXCLUSIVE |
 						UTRACE_ATTACH_MATCH_OPS,
-						&ptrace_utrace_ops, NULL);
+						&ptrace_utrace_ops, context);
 	if (unlikely(IS_ERR(engine))) {
 		int err = PTR_ERR(engine);
 		if (err != -ESRCH && err != -ERESTARTNOINTR)
-			err = -EPERM ;
+			err = -EPERM;
+		kfree(context);
 		return err;
 	}
 	/*




More information about the utrace-devel mailing list