Skip to content

Commit

Permalink
Furi: Detect use-after-free
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Nov 9, 2024
1 parent 68fba5b commit 996e62e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion furi/core/memmgr_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void vPortFree(void* pv) {
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;
traceFREE(pv, pxLink->xBlockSize);
memset(pv, 0, pxLink->xBlockSize - xHeapStructSize);
memset(pv, 0xDD, pxLink->xBlockSize - xHeapStructSize);
prvInsertBlockIntoFreeList((BlockLink_t*)pxLink);
}
(void)xTaskResumeAll();
Expand Down
6 changes: 5 additions & 1 deletion targets/f7/furi_hal/furi_hal_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ void MemManage_Handler(void) {
}

void BusFault_Handler(void) {
const char* crash_msg = "BusFault";

furi_log_puts("\r\n" _FURI_LOG_CLR_E "Bus fault:\r\n");
if(FURI_BIT(SCB->CFSR, SCB_CFSR_LSPERR_Pos)) {
furi_log_puts(" - lazy stacking for exception entry\r\n");
Expand Down Expand Up @@ -351,11 +353,13 @@ void BusFault_Handler(void) {

if(busfault_address == (uint32_t)NULL) {
furi_log_puts(" -- NULL pointer dereference\r\n");
} else if(busfault_address >= 0xDDDDDDDD && busfault_address <= 0xDDDEDDDD) {
crash_msg = "Possible use-after-free";
}
}
furi_log_puts(_FURI_LOG_CLR_RESET);

furi_crash("BusFault");
furi_crash(crash_msg);
}

void UsageFault_Handler(void) {
Expand Down

0 comments on commit 996e62e

Please sign in to comment.