2.1.111 simple enhancement/fix for safe debugging

Eric Paire (e.paire@opengroup.org)
Wed, 29 Jul 1998 16:12:28 +0200


Hi Linus,

Yet another bug using GDB on i386 Linux systems (which should be the same
for other processors managing the PTRACE_SINGLESTEP ptrace request):
1) When a debugger runs a PTRACE_SINGLESTEP ptrace request, the TRAP_FLAG is
put in the flags of the traced process, and the traced process is
waken up.
2) If the following action of the traced process is to jump into a signal
handler, then the TRAP_FLAG is kept in the sigcontext structure,
restored in sys_sigreturn() when the signal handler is completed,
and removed while executing the first instruction of the signal
handler.
3) The problem is the following: If the debugger decides to detach the process
when the traced child is in the signal handler, then the debugger
should remove the TRAP_FLAG from all sigcontext in the stack, which
is impossible since signal handlers may be skipped with user code
like longjmp(), and replaced by other data without noticing the
debugger.

The following patch fixes this problem by removing the TRAP_FLAG from the
sigcontext at restore time if the current process is no longer traced,
which allows the old traced process to continue without spurious
SIGTRAP.

Best regards,
Eric
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ Eric PAIRE
Email : e.paire@gr.opengroup.org | The Open Group - Grenoble Research
Institute
Phone : +33 (0) 476 63 48 71 | 2, avenue de Vignate
Fax : +33 (0) 476 51 05 32 | F-38610 Gieres FRANCE
------ Cut Here ------ Cut Here ------ Cut Here ------ Cut Here ------
--- arch/i386/kernel/signal.c.OLD Fri Jul 17 07:48:53 1998
+++ arch/i386/kernel/signal.c Wed Jul 29 13:56:36 1998
@@ -219,6 +219,8 @@
COPY_SEG_STRICT(ss);

err |= __get_user(tmp, &sc->eflags);
+ if ((tmp & TF_MASK) != 0 && (current->flags & PF_PTRACED) == 0)
+ tmp &= ~TF_MASK;
regs->eflags = (regs->eflags & ~0x40DD5) | (tmp & 0x40DD5);
regs->orig_eax = -1; /* disable syscall checks */

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html