aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/signal.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-05-11 05:07:19 -0400
committerDavid S. Miller <davem@davemloft.net>2008-05-11 05:07:19 -0400
commit28e6103665301ce60634e8a77f0b657c6cc099de (patch)
tree1ba78c7db8d139529b8f0db5f0de60a6fbf701cb /arch/sparc/kernel/signal.c
parent986bef854fab44012df678a5b51817d5274d3ca1 (diff)
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation which tries to handle all of the nasties that can occur when the debugger looks at a process about to take a signal. It's meant to address all of these issues inside of the kernel so that the debugger need not be mindful of such things. Problem is, this doesn't work. The idea was that we should do the syscall restart business first, so that the debugger captures that state. Otherwise, if the debugger for example saves the child's state, makes the child execute something else, then restores the saved state, we won't handle the syscall restart properly because we lose the "we're in a syscall" state. The code here worked for most cases, but if the debugger actually passes the signal through to the child unaltered, it's possible that we would do a syscall restart when we shouldn't have. In particular this breaks the case of debugging a process under a gdb which is being debugged by yet another gdb. gdb uses sigsuspend to wait for SIGCHLD of the inferior, but if gdb itself is being debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the signal. But ptrace_signal_deliver() assumed the debugger would cancel out the signal and therefore did a syscall restart, because the return error was ERESTARTNOHAND. Fix this by simply making ptrace_signal_deliver() a nop, and providing a way for the debugger to control system call restarting properly: 1) Report a "in syscall" software bit in regs->{tstate,psr}. It is set early on in trap entry to a system call and is fully visible to the debugger via ptrace() and regsets. 2) Test this bit right before doing a syscall restart. We have to do a final recheck right after get_signal_to_deliver() in case the debugger cleared the bit during ptrace_stop(). 3) Clear the bit in trap return so we don't accidently try to set that bit in the real register. As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just like sparc64 has. M68K has this same exact bug, and is now the only other user of the ptrace_signal_deliver hook. It needs to be fixed in the same exact way as sparc. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/kernel/signal.c')
-rw-r--r--arch/sparc/kernel/signal.c64
1 files changed, 28 insertions, 36 deletions
diff --git a/arch/sparc/kernel/signal.c b/arch/sparc/kernel/signal.c
index 368157926d24..3fd1df9f9ba7 100644
--- a/arch/sparc/kernel/signal.c
+++ b/arch/sparc/kernel/signal.c
@@ -145,6 +145,9 @@ asmlinkage void do_sigreturn(struct pt_regs *regs)
145 regs->psr = (up_psr & ~(PSR_ICC | PSR_EF)) 145 regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
146 | (regs->psr & (PSR_ICC | PSR_EF)); 146 | (regs->psr & (PSR_ICC | PSR_EF));
147 147
148 /* Prevent syscall restart. */
149 pt_regs_clear_syscall(regs);
150
148 err |= __get_user(fpu_save, &sf->fpu_save); 151 err |= __get_user(fpu_save, &sf->fpu_save);
149 152
150 if (fpu_save) 153 if (fpu_save)
@@ -199,6 +202,9 @@ asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
199 202
200 regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC); 203 regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);
201 204
205 /* Prevent syscall restart. */
206 pt_regs_clear_syscall(regs);
207
202 err |= __get_user(fpu_save, &sf->fpu_save); 208 err |= __get_user(fpu_save, &sf->fpu_save);
203 209
204 if (fpu_save) 210 if (fpu_save)
@@ -507,26 +513,36 @@ static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
507 * want to handle. Thus you cannot kill init even with a SIGKILL even by 513 * want to handle. Thus you cannot kill init even with a SIGKILL even by
508 * mistake. 514 * mistake.
509 */ 515 */
510asmlinkage void do_signal(struct pt_regs * regs, unsigned long orig_i0, int restart_syscall) 516asmlinkage void do_signal(struct pt_regs * regs, unsigned long orig_i0)
511{ 517{
512 siginfo_t info;
513 struct sparc_deliver_cookie cookie;
514 struct k_sigaction ka; 518 struct k_sigaction ka;
515 int signr; 519 int restart_syscall;
516 sigset_t *oldset; 520 sigset_t *oldset;
521 siginfo_t info;
522 int signr;
517 523
518 cookie.restart_syscall = restart_syscall; 524 if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
519 cookie.orig_i0 = orig_i0; 525 restart_syscall = 1;
526 else
527 restart_syscall = 0;
520 528
521 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 529 if (test_thread_flag(TIF_RESTORE_SIGMASK))
522 oldset = &current->saved_sigmask; 530 oldset = &current->saved_sigmask;
523 else 531 else
524 oldset = &current->blocked; 532 oldset = &current->blocked;
525 533
526 signr = get_signal_to_deliver(&info, &ka, regs, &cookie); 534 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
535
536 /* If the debugger messes with the program counter, it clears
537 * the software "in syscall" bit, directing us to not perform
538 * a syscall restart.
539 */
540 if (restart_syscall && !pt_regs_is_syscall(regs))
541 restart_syscall = 0;
542
527 if (signr > 0) { 543 if (signr > 0) {
528 if (cookie.restart_syscall) 544 if (restart_syscall)
529 syscall_restart(cookie.orig_i0, regs, &ka.sa); 545 syscall_restart(orig_i0, regs, &ka.sa);
530 handle_signal(signr, &ka, &info, oldset, regs); 546 handle_signal(signr, &ka, &info, oldset, regs);
531 547
532 /* a signal was successfully delivered; the saved 548 /* a signal was successfully delivered; the saved
@@ -538,16 +554,16 @@ asmlinkage void do_signal(struct pt_regs * regs, unsigned long orig_i0, int rest
538 clear_thread_flag(TIF_RESTORE_SIGMASK); 554 clear_thread_flag(TIF_RESTORE_SIGMASK);
539 return; 555 return;
540 } 556 }
541 if (cookie.restart_syscall && 557 if (restart_syscall &&
542 (regs->u_regs[UREG_I0] == ERESTARTNOHAND || 558 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
543 regs->u_regs[UREG_I0] == ERESTARTSYS || 559 regs->u_regs[UREG_I0] == ERESTARTSYS ||
544 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { 560 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
545 /* replay the system call when we are done */ 561 /* replay the system call when we are done */
546 regs->u_regs[UREG_I0] = cookie.orig_i0; 562 regs->u_regs[UREG_I0] = orig_i0;
547 regs->pc -= 4; 563 regs->pc -= 4;
548 regs->npc -= 4; 564 regs->npc -= 4;
549 } 565 }
550 if (cookie.restart_syscall && 566 if (restart_syscall &&
551 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) { 567 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
552 regs->u_regs[UREG_G1] = __NR_restart_syscall; 568 regs->u_regs[UREG_G1] = __NR_restart_syscall;
553 regs->pc -= 4; 569 regs->pc -= 4;
@@ -599,27 +615,3 @@ do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
599out: 615out:
600 return ret; 616 return ret;
601} 617}
602
603void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
604{
605 struct sparc_deliver_cookie *cp = cookie;
606
607 if (cp->restart_syscall &&
608 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
609 regs->u_regs[UREG_I0] == ERESTARTSYS ||
610 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
611 /* replay the system call when we are done */
612 regs->u_regs[UREG_I0] = cp->orig_i0;
613 regs->pc -= 4;
614 regs->npc -= 4;
615 cp->restart_syscall = 0;
616 }
617
618 if (cp->restart_syscall &&
619 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
620 regs->u_regs[UREG_G1] = __NR_restart_syscall;
621 regs->pc -= 4;
622 regs->npc -= 4;
623 cp->restart_syscall = 0;
624 }
625}