This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
Adding stack canary support for safe large stack usages. #5
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.
Change Description
Currently with CDT, the only way to use a large stack is to use the option
-fno-stack-first
. This is problematic as it forces the smart contract developer to choose a non-safe option. To circumvent this, this PR adds support for a new command line option-stack-canary
which will protect against stack overflow issues from possibly allowing corrupted action runs to succeed.The current way linear memory is laid out with
-fno-stack-first
is:[ data section | stack section | heap section ]
By placing a canary value at the border of the stack section and data section and placing the same canary into a WASM global at the beginning of execution we can test these values at the end of execution and assert if they are no longer equal (i.e. the stack overflowed and overwrote part of the data section).
This new assert code is 8000000000000000002 to signify that a canary failure has occurred.
API Changes
One new command line option to both cdt-cpp, cdt-cc, and cdt-ld has been added (
-stack-canary
).One new assert code has been added to compiler owned and generated errors (8000000000000000002).
Documentation Additions