

- #Stack guard stack smashing detected generator#
- #Stack guard stack smashing detected manual#
- #Stack guard stack smashing detected code#
Note that this function and its intended behavior are not important since I’ve chosen it primarily for demonstration purposes. More specifically the first and last part of the address_check_prefix() function. What you’re looking at here is a color-coded interpretation of the assembler instructions in ARM Thumb format that make up the firmware program, elf debugger symbol version of the KeepKey firmware. This led me to discovering the issue that is at the heart of this article.Ĭonsider the following disassembler view of the ARM firmware code, generated with Ghidra on the. I didn’t find anything usable at first, but then stumbled over some error behavior that surprised me since it did not fit my expectations of what should happen. So I dug deeper into the firmware code, looking for incorrect initialization, problematic linker settings or other implementation problems.
#Stack guard stack smashing detected code#
This should be a strong defense against code execution via the described out of bounds writes.ĭuring the disclosure process for CVE-2021-31616, I found myself in a position where I had exhausted other attack variants,īut wasn’t yet willing to give up on showing a more severe impact than a device crash.

Unless there is a way for the attacker to read the current _stack_chk_guard canary value from the device through an information leak before the attack and dynamically adjust the exploit data that is written into memory,
#Stack guard stack smashing detected manual#
It has a custom error handler that triggers an endless loop once stack smashing is detected, giving the attacker only one chance to guess the value before manual intervention by the user is required.
#Stack guard stack smashing detected generator#
The build configuration sets the strongest stack canary flag -fstack-protector-all and correctly seeds the 32bit uint32_t _stack_chk_guard variable from the internal random number generator at every device boot. The KeepKey uses arm-none-eabi-gcc with the CPU architecture -mcpu=cortex-m3 -mthumb since it is based on the Cortex-M3 STM32F205 chip. Which makes the compiler add the described security checks to some or all functions. Notably, stack canaries are not enabled by default in C compilers such as GCC, in part due to their performance impact and very conservative compiler default settings.īuild systems have to explicitly enable canaries with one of the -fstack-protector* flags levels Since every other value leads to a hard exit. This mechanism makes it very difficult to overwrite the stack canary with the right value so that the problematic write stays undetected in step no. If the original contents of the stack canary are not known to the attacker, Like a canary in a coal mine, the problematic state of the stack canary triggers emergency procedures, which explains the name.

Stack canaries are one of the few low-level countermeasures that are available If you are looking for assistance to secure your projects or organization, get in touch. I’m a freelance Security Consultant and currently available for new projects.
