Skip to content

Commit

Permalink
trusty: arm32: fix potential double fault when printing diagnostics
Browse files Browse the repository at this point in the history
When dumping_mode_regs() on a fault, avoid printing the stack beyond the
current page.  This prevents exceeding the stack base and hitting a
guard page in the case the stack use is < 128 bytes.

Bug: 336957655
Test: crash test, observe double fault fixed
Change-Id: If49b5fe5e1651557d19bf18c4026224cfb038101
  • Loading branch information
Mike McTernan authored and travisg committed May 24, 2024
1 parent ec4da96 commit e870c0b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arch/arm/arm/faults.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <arch/arm.h>
#include <kernel/thread.h>
#include <platform.h>
#include <stdlib.h>

struct fault_handler_table_entry {
uint32_t pc;
Expand Down Expand Up @@ -54,8 +55,12 @@ static void dump_mode_regs(uint32_t spsr, uint32_t svc_r13, uint32_t svc_r14) {
}

if (stack != 0) {
dprintf(CRITICAL, "bottom of stack at 0x%08x:\n", (unsigned int)stack);
hexdump((void *)stack, 128);
dprintf(CRITICAL, "stack pointer at 0x%08x:\n", (unsigned int)stack);

/* Avoid crossing page-boundary in case near stack base */
const size_t used_stack = PAGE_SIZE - ((unsigned int)stack % PAGE_SIZE);

hexdump((void *)stack, MIN(used_stack, 128));
}
}

Expand Down

0 comments on commit e870c0b

Please sign in to comment.