Skip to contentSkip to conversation

ptrace bugs and related problems

DISCUSSION Chuck Ebbert 2 participants 2 messages Jul 31, 2006 – Aug 1, 2006

lore
Share & tools
lore
#0 lore raw

In-Reply-To: <[email protected]>

Quoted 2 lines · Albert Cahalan

Both i386 and x86-64 PTRACE_SINGLESTEP only check for popf, not iret. Yes, really, iret can be used by normal apps.

Well there's a FIXME in the x86_64 code for that, anyway. (lahf/sahf can't cause problems, so iret is the only remaining problem.)

Quoted 3 lines

There is also no check
for failure, as when the popf or iret takes an alignment exception or hits an unmapped page.

Can that happen? Singlestep traps happen after the instruction has already executed. Or are you talking about starting to singlestep after hitting a code breakpoint fault?

Quoted 2 lines

There is the pushf problem. Single-stepping this simple code
does not work: pushf ; popf

The debugger needs to mask TF in the pushed flags. Read the comment in is_at_popf().

Quoted 3 lines

The is_at_popf function on x86-64 fails to account for instruction set differences. Many prefixes are only valid in 32-bit mode, and many others are only valid in 64-bit mode.

I only see one bug here: the REX prefixes are 'inc' instructions in compatibility mode. Otherwise, prefixes that are only valid in 32-bit mode are ignored in 64-bit mode.

Quoted 3 lines

The debugger has no way to reliably stop a process without causing confusion. The SIGSTOP signal is not queued. The app under debug might use SIGSTOP and rely on SIGSTOP to work. The debugger can't steal this.

I sort of got this working some time ago but I forget what the problems were. The idea was to decide whether or not a SIGSTOP was meant for the debugger or not, and forward the unwanted ones to the app. But yeah, the interface really sucks and that probably can't be made to work.

What Linux needs is a fresh new design for a debugging interface to sit on top if utrace, one that solves the current inherent problems. Just making a list of these problems is probably the place to start.

Signature · 1 line
Chuck
#1 lore raw
Quoted 9 lines · Chuck Ebbert
Quoted 3 lines · Albert Cahalan

There is also no check
for failure, as when the popf or iret takes an alignment exception or hits an unmapped page.

Can that happen? Singlestep traps happen after the instruction has already executed. Or are you talking about starting to singlestep after hitting a code breakpoint fault?

You're at a popf that can not complete.
You single-step.
The kernel sets TF.
The kernel notes the popf.
The kernel assumes that TF will be determined by the popf. The kernel tries to run the popf.
The popf faults, leaving TF unmodified.
The kernel fails to clear TF.

Quoted 5 lines
Quoted 2 lines

There is the pushf problem. Single-stepping this simple code
does not work: pushf ; popf

The debugger needs to mask TF in the pushed flags. Read the comment in is_at_popf().

I saw the comment. I don't consider that documentation. Why even have single-step support if the debugger has to mess with eflags manually anyway? I might as well just exclusively use PTRACE_SYSCALL.

I think the term is "known bug".

Quoted 7 lines
Quoted 3 lines

The is_at_popf function on x86-64 fails to account for instruction set differences. Many prefixes are only valid in 32-bit mode, and many others are only valid in 64-bit mode.

I only see one bug here: the REX prefixes are 'inc' instructions in compatibility mode. Otherwise, prefixes that are only valid in 32-bit mode are ignored in 64-bit mode.

Oh, OK, I thought they faulted. (AMD botched this)

There is a problem with instruction length though. The buffer is 16 bytes long, but should be only 15.

The 0xf0 (lock) prefix is not valid for popf or iret.