Skip to content

Commit 6a2d90b

Browse files
committed
ptrace: Reimplement PTRACE_KILL by always sending SIGKILL
The current implementation of PTRACE_KILL is buggy and has been for many years as it assumes it's target has stopped in ptrace_stop. At a quick skim it looks like this assumption has existed since ptrace support was added in linux v1.0. While PTRACE_KILL has been deprecated we can not remove it as a quick search with google code search reveals many existing programs calling it. When the ptracee is not stopped at ptrace_stop some fields would be set that are ignored except in ptrace_stop. Making the userspace visible behavior of PTRACE_KILL a noop in those case. As the usual rules are not obeyed it is not clear what the consequences are of calling PTRACE_KILL on a running process. Presumably userspace does not do this as it achieves nothing. Replace the implementation of PTRACE_KILL with a simple send_sig_info(SIGKILL) followed by a return 0. This changes the observable user space behavior only in that PTRACE_KILL on a process not stopped in ptrace_stop will also kill it. As that has always been the intent of the code this seems like a reasonable change. Cc: [email protected] Reported-by: Al Viro <[email protected]> Suggested-by: Al Viro <[email protected]> Tested-by: Kees Cook <[email protected]> Reviewed-by: Oleg Nesterov <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent cb3c19c commit 6a2d90b

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

arch/x86/kernel/step.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ void set_task_blockstep(struct task_struct *task, bool on)
180180
*
181181
* NOTE: this means that set/clear TIF_BLOCKSTEP is only safe if
182182
* task is current or it can't be running, otherwise we can race
183-
* with __switch_to_xtra(). We rely on ptrace_freeze_traced() but
184-
* PTRACE_KILL is not safe.
183+
* with __switch_to_xtra(). We rely on ptrace_freeze_traced().
185184
*/
186185
local_irq_disable();
187186
debugctl = get_debugctlmsr();

kernel/ptrace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,8 @@ int ptrace_request(struct task_struct *child, long request,
12361236
return ptrace_resume(child, request, data);
12371237

12381238
case PTRACE_KILL:
1239-
if (child->exit_state) /* already dead */
1240-
return 0;
1241-
return ptrace_resume(child, request, SIGKILL);
1239+
send_sig_info(SIGKILL, SEND_SIG_NOINFO, child);
1240+
return 0;
12421241

12431242
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
12441243
case PTRACE_GETREGSET:

0 commit comments

Comments
 (0)