ptrace: ptrace_signal: fix the usage of ->parent
RFC PATCH v3 1/12 ptrace: ptrace_signal: fix the usage of ->parent
This patch complicates the code to fix the pure theoretical problems. But since we are going to change this code, it is better to fix them anyway.
- If we are not traced any longer after ptrace_stop(), si_pid/si_uid are not necessary right.
- It is not safe to dereference current->parent without tasklist or RCU lock. The tracer can detach and exit. ->siglock can't prevent this, and (in theory) local_irq_disable() doesn't imply RCU lock.
Hopefully this "signr != info->si_signo" code will go away eventually.
Signed-off-by Oleg Nesterov <[email protected]>
---
kernel/signal.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
kernel/signal.c renamed from kernel/signal.c~01_PTRACE_SIGNAL +13 -2
@@ -1770,11 +1770,22 @@ static int ptrace_signal(int signr, sigispecific in the siginfo structure then it should have updated *info via PTRACE_SETSIGINFO. */ if (signr != info->si_signo) { +struct task_struct *tracer; + info->si_signo = signr; info->si_errno =0 ; info->si_code =SI_USER ; - info->si_pid =task_pid_vnr (current->parent); - info->si_uid =task_uid (current->parent); + +rcu_read_lock (); + tracer = current->parent; +if (task_ptrace (current)) { + info->si_pid =task_pid_vnr (tracer); + info->si_uid =task_uid (tracer); + }else { + info->si_pid =0 ; + info->si_uid =0 ; + } +rcu_read_unlock (); }/* If the (new) signal is now blocked, requeue it. */