diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2008-02-08 07:18:58 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-08 12:22:26 -0500 |
commit | 6b39c7bfbd1436836c0fb34c5b437fda1a7a3dd4 (patch) | |
tree | 60d3d9719eef3076527fcbf9c3cb362fe0f52d61 | |
parent | 01b8b07a5d77d22e609267dcae74d15e3e9c5f13 (diff) |
kill PT_ATTACHED
Since the patch
"Fix ptrace_attach()/ptrace_traceme()/de_thread() race"
commit f5b40e363ad6041a96e3da32281d8faa191597b9
we set PT_ATTACHED and change child->parent "atomically" wrt task_list lock.
This means we can remove the checks like "PT_ATTACHED && ->parent != ptracer"
which were needed to catch the "ptrace attach is in progress" case. We can
also remove the flag itself since nobody else uses it.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: Roland McGrath <roland@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/ptrace.h | 1 | ||||
-rw-r--r-- | kernel/exit.c | 13 | ||||
-rw-r--r-- | kernel/ptrace.c | 6 | ||||
-rw-r--r-- | kernel/signal.c | 5 |
4 files changed, 3 insertions, 22 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index 6ab80714a916..ebe0c17039cf 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h | |||
@@ -67,7 +67,6 @@ | |||
67 | #define PT_TRACE_EXEC 0x00000080 | 67 | #define PT_TRACE_EXEC 0x00000080 |
68 | #define PT_TRACE_VFORK_DONE 0x00000100 | 68 | #define PT_TRACE_VFORK_DONE 0x00000100 |
69 | #define PT_TRACE_EXIT 0x00000200 | 69 | #define PT_TRACE_EXIT 0x00000200 |
70 | #define PT_ATTACHED 0x00000400 /* parent != real_parent */ | ||
71 | 70 | ||
72 | #define PT_TRACE_MASK 0x000003f4 | 71 | #define PT_TRACE_MASK 0x000003f4 |
73 | 72 | ||
diff --git a/kernel/exit.c b/kernel/exit.c index eb9934a82fc1..1f2c15297f2d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -1514,18 +1514,7 @@ static int wait_task_continued(struct task_struct *p, int noreap, | |||
1514 | 1514 | ||
1515 | static inline int my_ptrace_child(struct task_struct *p) | 1515 | static inline int my_ptrace_child(struct task_struct *p) |
1516 | { | 1516 | { |
1517 | if (!(p->ptrace & PT_PTRACED)) | 1517 | return p->ptrace & PT_PTRACED; |
1518 | return 0; | ||
1519 | if (!(p->ptrace & PT_ATTACHED)) | ||
1520 | return 1; | ||
1521 | /* | ||
1522 | * This child was PTRACE_ATTACH'd. We should be seeing it only if | ||
1523 | * we are the attacher. If we are the real parent, this is a race | ||
1524 | * inside ptrace_attach. It is waiting for the tasklist_lock, | ||
1525 | * which we have to switch the parent links, but has already set | ||
1526 | * the flags in p->ptrace. | ||
1527 | */ | ||
1528 | return (p->parent != p->real_parent); | ||
1529 | } | 1518 | } |
1530 | 1519 | ||
1531 | static long do_wait(pid_t pid, int options, struct siginfo __user *infop, | 1520 | static long do_wait(pid_t pid, int options, struct siginfo __user *infop, |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 628b03ab88a5..2dc00298e678 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -100,8 +100,7 @@ int ptrace_check_attach(struct task_struct *child, int kill) | |||
100 | */ | 100 | */ |
101 | read_lock(&tasklist_lock); | 101 | read_lock(&tasklist_lock); |
102 | if ((child->ptrace & PT_PTRACED) && child->parent == current && | 102 | if ((child->ptrace & PT_PTRACED) && child->parent == current && |
103 | (!(child->ptrace & PT_ATTACHED) || child->real_parent != current) | 103 | child->signal != NULL) { |
104 | && child->signal != NULL) { | ||
105 | ret = 0; | 104 | ret = 0; |
106 | spin_lock_irq(&child->sighand->siglock); | 105 | spin_lock_irq(&child->sighand->siglock); |
107 | if (task_is_stopped(child)) | 106 | if (task_is_stopped(child)) |
@@ -200,8 +199,7 @@ repeat: | |||
200 | goto bad; | 199 | goto bad; |
201 | 200 | ||
202 | /* Go */ | 201 | /* Go */ |
203 | task->ptrace |= PT_PTRACED | ((task->real_parent != current) | 202 | task->ptrace |= PT_PTRACED; |
204 | ? PT_ATTACHED : 0); | ||
205 | if (capable(CAP_SYS_PTRACE)) | 203 | if (capable(CAP_SYS_PTRACE)) |
206 | task->ptrace |= PT_PTRACE_CAP; | 204 | task->ptrace |= PT_PTRACE_CAP; |
207 | 205 | ||
diff --git a/kernel/signal.c b/kernel/signal.c index 5d30ff561847..6d6d1ab39e7e 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -1556,11 +1556,6 @@ static inline int may_ptrace_stop(void) | |||
1556 | { | 1556 | { |
1557 | if (!likely(current->ptrace & PT_PTRACED)) | 1557 | if (!likely(current->ptrace & PT_PTRACED)) |
1558 | return 0; | 1558 | return 0; |
1559 | |||
1560 | if (unlikely(current->parent == current->real_parent && | ||
1561 | (current->ptrace & PT_ATTACHED))) | ||
1562 | return 0; | ||
1563 | |||
1564 | /* | 1559 | /* |
1565 | * Are we in the middle of do_coredump? | 1560 | * Are we in the middle of do_coredump? |
1566 | * If so and our tracer is also part of the coredump stopping | 1561 | * If so and our tracer is also part of the coredump stopping |