Commit 4f8782e
fix(interrupts): use proper kernel stack when returning to idle loop (#82)
When returning to idle_loop from exception handlers (page fault, etc.),
we were using `current_rsp + 256` as the stack pointer. This is wrong
when running on IST stacks (page fault uses IST[1]).
IST stacks are small (~4KB) and meant only for exception handling.
When idle_loop runs on the IST stack and timer interrupts fire,
the interrupt frames and nested calls can overflow the small IST stack,
causing memory corruption and crashes.
This bug manifested as kernel page faults at 0xffffc97ffffffff0 (top of
PML4[402] region) - a corrupted RSP value. It only appeared on QEMU 8.x
(GitHub CI) but not QEMU 10.x (local) due to timing differences.
Fix: Use per_cpu::kernel_stack_top() which returns the idle thread's
actual kernel stack, which is large enough for normal execution.
Changed in two places:
- kernel/src/interrupts.rs: page fault handler recovery path
- kernel/src/interrupts/context_switch.rs: setup_idle_return()
Co-authored-by: Ryan Breen <ryanbreen@gmail.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 9e165dc commit 4f8782e
2 files changed
+13
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1217 | 1217 | | |
1218 | 1218 | | |
1219 | 1219 | | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
1223 | | - | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1224 | 1226 | | |
1225 | 1227 | | |
1226 | 1228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
668 | 668 | | |
669 | 669 | | |
670 | 670 | | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
| |||
0 commit comments