Skip to content
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

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

larryk85
Copy link

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

  • 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

  • Documentation Additions

@larryk85 larryk85 requested a review from arhag May 20, 2022 17:46
@tedcahalleos tedcahalleos requested a review from heifner May 31, 2022 17:28
Copy link
Member

@heifner heifner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the submodules.

@larryk85 larryk85 merged commit 5a6e44b into master Jun 6, 2022
@larryk85 larryk85 deleted the larryk85/stack-canary branch June 6, 2022 00:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants