-
Notifications
You must be signed in to change notification settings - Fork 168
Enable stack overflow protection by default #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jonas-schievink I do not agree with the "unsound" part of your intro but it would certainly be nice to have it. |
This may not work well on Cortex-M0 microcontrollers when you have to relocate vector table to the start of the RAM. For example, when you have a bootloader at the beginning of the FLASH with its own interrupt vector table and you want to have your own one. |
@therealprof "unsound" just means that it's possible to cause undefined behavior in safe code, which is the case here (just grow the stack enough). While there are exceptions to this that aren't really modeled by Rust's type system (such as writing to @Disasm Ah, you mean when using a vendor-specific feature to map SRAM to address 0. I'm hoping that we'll add features for controlling the memory layout more precisely before 1.0, and it doesn't seem like this situation would be worse than what we have now (you'd just smash the vector table instead of application data, which is hopefully more noticeable). |
This sounds like a code execution vulnerability out of the box. Quite easy to exploit. |
That's true, but the same is the case today from what I can tell (only you'd also have to overwrite |
Anyway, I think it's a good idea to have this stack protection feature, but I'd also like to have a possibility for opt-out. |
For reference / posteriority: the trick I have tried is "end address" aligning
The expression after the section name ( A complete, working example can be found here: https://github.com/japaric/xenon/blob/02e36e97777a8ebc53ccf202bb3cf278e1662de9/firmware/xenon/link.x#L25 For whatever reason, that example breaks down (you get weird linker errors) once |
Not providing this is unsound, so we should make sure this is on by default before 1.0. This was already implemented in the past, but was removed with the switch to LLD (if I'm not mistaken).
@japaric has been working on flip-lld, a small wrapper that invokes LLD twice to place the stack below the static data sections. An older description of this approach is described in this blog article.
(unfortunately, experiments with doing it with one linker invocation have so far not worked out, but according to rust-embedded/cortex-m-rt#34 (comment) there's another way to do it with a single linker invocation, might be worth checking out)
The text was updated successfully, but these errors were encountered: