Skip to contentSkip to conversation

desc v0.61 found a 2.5 kernel bug

DISCUSSION Chuck Ebbert 2 participants 2 messages Apr 30, 2003 – May 9, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines · Gabriel Paubert
Quoted 3 lines

I want to write a TSS-based debug exception handler that just does
an iret when it gets invoked. For now it looks easier to just keep CR3 up-to-date on every switch.

It seems cr3 is in the same cache line as esp0 for a 32 byte cache line, so it's not that big a deal, but I'd still try to avoid this.

There's no easy way of fixing this up in the handler, so that's the plan
for now. It also puts more info in the TSS dump right away.

.> Currently %fs and %gs are lazily cleaned up when switching processes .> using the standard fixup mechanism, %ds and %es are cleaned up if .> necessary when popping them off the stack in the return to user .> mode path (the one which ends up in iret). There is no way to recover .> from bad user %cs/%ss, the process simply exits in the iret fixup.

Looks like the only clean way is to follow the TSS back link and manually
validate the segment registers before returning:

invalid FS,GS -> 0

     "    DS,ES -> __USER_DS
          CS,SS -> panic?

Bad things can happen if a debug fault happens in certain places... for now
the solution is to only support int3 breakpoints and avoid those places.

Given the above, I hope to be able to put int3 instructions in either
kernel or user code and get snapshots of CPU state in the kernel TSS.
------
Chuck

#1 lore raw

On Wed, Apr 30, 2003 at 04:08:05PM -0400, Chuck Ebbert wrote:
[Sorry for the delay I've been extremely busy on other things]

Quoted 7 lines

Looks like the only clean way is to follow the TSS back link and manually
validate the segment registers before returning:

invalid FS,GS -> 0

     "    DS,ES -> __USER_DS
          CS,SS -> panic?

It's still racy on SMP if a thread with the same MM is modifying the LDT between the time you check whether the selectors are valid and the iret instruction restoring the previous stack.

Quoted 3 lines

Bad things can happen if a debug fault happens in certain places... for now
the solution is to only support int3 breakpoints and avoid those places.

Can you elaborate a bit, in which places?

Quoted 3 lines

Given the above, I hope to be able to put int3 instructions in either
kernel or user code and get snapshots of CPU state in the kernel TSS.

And what about the little bit called TS in CR0 which is always set by a task switch. That's one bit of state which will be always set when the debug interrupt returns, and the current code for FPU will be confused by this AFAICT. Things become even more interesting if you want to allow debug traps between in the kernel routines using the FPU, between kernel_fpu_begin() and kernel_fpu_end().

Gabriel