aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/ptrace.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-03-23 18:02:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 19:58:40 -0400
commit8c5cf9e5c50dc902713897e10201aa71f3546aa1 (patch)
tree9d5590690c0bf2b596697768972b8d42de2e8a28 /kernel/ptrace.c
parentb1845ff53f1a9eadba005ae53dfe60ab00dfe83b (diff)
ptrace: don't modify flags on PTRACE_SETOPTIONS failure
On ptrace(PTRACE_SETOPTIONS, pid, 0, <opts>), we used to set those option bits which are known, and then fail with -EINVAL if there are some unknown bits in <opts>. This is inconsistent with typical error handling, which does not change any state if input is invalid. This patch changes PTRACE_SETOPTIONS behavior so that in this case, we return -EINVAL and don't change any bits in task->ptrace. It's very unlikely that there is userspace code in the wild which will be affected by this change: it should have the form ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_BOGUSOPT) where PTRACE_O_BOGUSOPT is a constant unknown to the kernel. But kernel headers, naturally, don't contain any PTRACE_O_BOGUSOPTs, thus the only way userspace can use one if it defines one itself. I can't see why anyone would do such a thing deliberately. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Acked-by: Tejun Heo <tj@kernel.org> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Cc: Pedro Alves <palves@redhat.com> Cc: Jan Kratochvil <jan.kratochvil@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/ptrace.c')
-rw-r--r--kernel/ptrace.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 00ab2ca5ed11..273f56ea39d2 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -528,6 +528,9 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
528 528
529static int ptrace_setoptions(struct task_struct *child, unsigned long data) 529static int ptrace_setoptions(struct task_struct *child, unsigned long data)
530{ 530{
531 if (data & ~(unsigned long)PTRACE_O_MASK)
532 return -EINVAL;
533
531 child->ptrace &= ~PT_TRACE_MASK; 534 child->ptrace &= ~PT_TRACE_MASK;
532 535
533 if (data & PTRACE_O_TRACESYSGOOD) 536 if (data & PTRACE_O_TRACESYSGOOD)
@@ -551,7 +554,7 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data)
551 if (data & PTRACE_O_TRACEEXIT) 554 if (data & PTRACE_O_TRACEEXIT)
552 child->ptrace |= PT_TRACE_EXIT; 555 child->ptrace |= PT_TRACE_EXIT;
553 556
554 return (data & ~PTRACE_O_MASK) ? -EINVAL : 0; 557 return 0;
555} 558}
556 559
557static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info) 560static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info)