cleanup ptrace stops and remove notify_parent
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · Roland McGrath
This patch is against Linus's current tree.
This adds a new state
TASK_TRACEDthat is used in place ofTASK_STOPPEDwhen a thread stops because it is ptraced. Now ptrace operations are only permitted when the target is inTASK_TRACEDstate, not inTASK_STOPPED. This means that if a process is stopped normally by a job control signal and then youPTRACE_ATTACHto it, you will have to send it a SIGCONT before you can do any ptrace operations on it. (The SIGCONT will be reported to ptrace and then you can discard it instead of passing it through when you callPTRACE_CONTet al.)
Are you sure such a user visible semantic change is a good idea?
I at least have written (not very important, but existing) user space code in the past that assumed it can stop and single step without SIGCONT. I wouldn't be surprised if other debuggers ran into the same issue.
And the Linux debugging world is not gdb only anymore, there are a lot of other users of ptrace around these days ...
I don't think it is very good to change such behaviour in 2.6. Please don't do it.
-Andi
Quoted 1 line
Are you sure such a user visible semantic change is a good idea?
Not if it's not too hard to avoid. I think I can make it not come up by converting TASK_STOPPED into TASK_TRACED when you use ptrace. It will just take some synchronization for that case.
Quoted 4 lines
I at least have written (not very important, but existing) user space code in the past that assumed it can stop and single step without SIGCONT. I wouldn't be surprised if other debuggers ran into the same issue.
I assume you mean stop with SIGSTOP, then attach with PTRACE_ATTACH, then step with PTRACE_SINGLESTEP. If you are already attached, then any stop will report to you first in TASK_TRACED and never end up TASK_STOPPED unless you explicitly pass a stop signal through with ptrace.
Thanks,
Roland
I don't have a program like yours to test that it was broken with my patch (now in 2.6.9-rc1-mm2). But the following additional patch relative to 2.6.9-rc1-mm2 should do it. I've tested that it doesn't create any new problems. I don't have something right handy that tests the case in question, but you've said that you do.
This makes any ptrace operation that finds the target in TASK_STOPPED state morph it into TASK_TRACED state before doing anything. This necessitates reverting the last_siginfo accesses to check instead of assume last_siginfo is set, since it's no longer impossible to be in TASK_TRACED without being stopped in ptrace_stop (though there are no associated races to worry about).
Thanks,
Roland
kernel/ptrace.c renamed from kernel/ptrace.c.~1~ +14 -5
@@ -81,13 +81,20 @@ int ptrace_check_attach(struct task_stru* be changed by us so it's not changing right after this. */ read_lock (&tasklist_lock); -if ((child->ptrace &PT_PTRACED ) && child->parent == current) +if ((child->ptrace &PT_PTRACED ) && child->parent == current && + child->signal !=NULL ) { ret =0 ; +spin_lock_irq (&child->sighand->siglock); +if (child->state ==TASK_STOPPED ) { + child->state =TASK_TRACED ; + }else if (child->state !=TASK_TRACED && !kill) { + ret = -ESRCH ; + } +spin_unlock_irq (&child->sighand->siglock); + }read_unlock (&tasklist_lock);if (!ret && !kill) { -if (child->state !=TASK_TRACED ) -return -ESRCH ;wait_task_inactive (child); }
@@ -298,13 +305,15 @@ static int ptrace_setoptions(struct taskstatic int ptrace_getsiginfo (struct task_struct *child,siginfo_t __user * data) { -BUG_ON (child->last_siginfo ==NULL ); +if (child->last_siginfo ==NULL ) +return -EINVAL ;return copy_siginfo_to_user (data, child->last_siginfo); }static int ptrace_setsiginfo (struct task_struct *child,siginfo_t __user * data) { -BUG_ON (child->last_siginfo ==NULL ); +if (child->last_siginfo ==NULL ) +return -EINVAL ;if (copy_from_user (child->last_siginfo, data,sizeof (siginfo_t)) !=0 )return -EFAULT ;return 0 ;
Quoted 5 lines · Roland McGrath
I don't have a program like yours to test that it was broken with my patch (now in 2.6.9-rc1-mm2). But the following additional patch relative to 2.6.9-rc1-mm2 should do it. I've tested that it doesn't create any new problems. I don't have something right handy that tests the case in question, but you've said that you do.
I am travelling and can't reach the code right now, but I will test later.
Quoted 7 lines
This makes any ptrace operation that finds the target in
TASK_STOPPEDstate morph it intoTASK_TRACEDstate before doing anything. This necessitates reverting thelast_siginfoaccesses to check instead of assumelast_siginfois set, since it's no longer impossible to be inTASK_TRACEDwithout being stopped inptrace_stop(though there are no associated races to worry about).
Looks good, thanks.
-Andi