Support Rust's stack-protector
feature
#1135
Merged
+66
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While stack smashing is less of a problem in Rust it's still worth it to support Rust's
stack-protector
feature.The stack canary is not zero-cost but it's also not too expensive (occupies one word in every stack frame and a few CPU cycles for every instrumented function)
Additionally, this can be also used to detect a possible stack overflow for the main stack by placing
__stack_chk_guard
near the bottom of the stack.Example
Add this to
rustflags
in.cargo/config.toml
"-Z", "stack-protector=all",
Use this example (imports are for ESP32-C6)
It will result in this:
![image](https://private-user-images.githubusercontent.com/5682593/301824980-5a3c90b4-6e00-4a7c-b225-5426d795e53c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NzU1MTYsIm5iZiI6MTczOTY3NTIxNiwicGF0aCI6Ii81NjgyNTkzLzMwMTgyNDk4MC01YTNjOTBiNC02ZTAwLTRhN2MtYjIyNS01NDI2ZDc5NWU1M2MucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTZUMDMwNjU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmFiYzM1ODgzY2I0MjcwNTU1MTJmZjRiNDI5ZDZkN2I0M2IyZTg2ZDViMTg4MTkwM2M3MmFjNzk2NWFiOWY0OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Gp_DcxrWEDhw8Fj-_fTguS0rlbUHt_bEB_5tMSw4RR4)