[PATCH 2/2] ptrace: add ability to attach a file descriptor to another task

From: Andrew Vagin
Date: Fri Dec 16 2011 - 05:47:54 EST



Signed-off-by: Andrew Vagin <avagin@xxxxxxxxxx>
---
include/linux/ptrace.h | 1 +
kernel/ptrace.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 800f113..8439ce9 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -50,6 +50,7 @@
#define PTRACE_SEIZE 0x4206
#define PTRACE_INTERRUPT 0x4207
#define PTRACE_LISTEN 0x4208
+#define PTRACE_DUPFD 0x4209

/* flags in @data for PTRACE_SEIZE */
#define PTRACE_SEIZE_DEVEL 0x80000000 /* temp flag for development */
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 24d0447..a646d01 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -24,6 +24,7 @@
#include <linux/regset.h>
#include <linux/hw_breakpoint.h>
#include <linux/cn_proc.h>
+#include <linux/file.h>


static int ptrace_trapping_sleep_fn(void *flags)
@@ -826,6 +827,32 @@ int ptrace_request(struct task_struct *child, long request,
break;
}
#endif
+ case PTRACE_DUPFD:
+ {
+ struct file *file = fget_raw(data);
+ ret = -EBADF;
+
+ if (!file)
+ break;
+
+ task_lock(child);
+ if (!child->files)
+ goto out_getfd;
+
+ ret = alloc_task_fd(child, 0, 0);
+ if (ret < 0) {
+ fput(file);
+ goto out_getfd;
+ }
+
+ fd_task_install(child, ret, file);
+
+out_getfd:
+ task_unlock(child);
+
+ break;
+ }
+
default:
break;
}
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/