Commit 8c5cf9e5 authored by Denys Vlasenko's avatar Denys Vlasenko Committed by Linus Torvalds

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: default avatarDenys Vlasenko <vda.linux@googlemail.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Pedro Alves <palves@redhat.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b1845ff5
...@@ -528,6 +528,9 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds ...@@ -528,6 +528,9 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
static int ptrace_setoptions(struct task_struct *child, unsigned long data) static int ptrace_setoptions(struct task_struct *child, unsigned long data)
{ {
if (data & ~(unsigned long)PTRACE_O_MASK)
return -EINVAL;
child->ptrace &= ~PT_TRACE_MASK; child->ptrace &= ~PT_TRACE_MASK;
if (data & PTRACE_O_TRACESYSGOOD) if (data & PTRACE_O_TRACESYSGOOD)
...@@ -551,7 +554,7 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data) ...@@ -551,7 +554,7 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data)
if (data & PTRACE_O_TRACEEXIT) if (data & PTRACE_O_TRACEEXIT)
child->ptrace |= PT_TRACE_EXIT; child->ptrace |= PT_TRACE_EXIT;
return (data & ~PTRACE_O_MASK) ? -EINVAL : 0; return 0;
} }
static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info) static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment