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

mem: implement a stack overflow detection mechanism #293

Merged
merged 4 commits into from
Jan 27, 2021

Conversation

shintaro-iwasaki
Copy link
Collaborator

@shintaro-iwasaki shintaro-iwasaki commented Jan 27, 2021

Problems

With Argobots, stack overflow can easily happen because each stack tends to be small (e.g., #274), but this overflow is often silent because there is no stack guard page. Creating an mprotect()-ed stack is not very trivial, but at least Argobots should employ a simple mechanism to detect it.

Solution

This patch implements a stack canary that can check whether a stack overflow happens or not when a ULT is freed. This check is quite simple and lightweight. If stack overflow is detected, the runtime terminates. Please check the mechanism here: https://en.wikipedia.org/wiki/Stack_buffer_overflow#Stack_canaries

Note that this mechanism is to make sure that there is no stack overflow. This mechanism cannot pinpoint where the stack overflow happens.

This mechanism slightly degrades the performance, so it is disabled by default. It can be enabled by setting --enable-stack-overflow-check=canary (or --enable-stack-overflow-check=canary-XX where XX is a large number to use a larger canary) at configuration time.

Impact

This feature is disabled by default, so it will not affect the default behavior.

enable-stack-overflow-check is a configuration option to enable stack overflow
check.
ABTI_mem_register_stack() and ABTI_mem_unregister_stack() are functions to
register and unregister a stack.  Currently only Valgrind uses these functions,
but they will be used to insert and check a stack canary value.
A stack canary is a special value that is written at the bottom of the ULT
stack.  The Argobots runtime can detect if this value is overwritten by stack
overflow when a stack is freed.  This mechanism does not catch stack overflow
when it happens, but this is a quick method to check if there is no stack
overflow.

This option is disabled by default.  It can be enabled by setting
--enable-stack-overflow-check=canary-XX where XX is the canary size.
@shintaro-iwasaki
Copy link
Collaborator Author

test:argobots/all
test:argobots/freebsd
test:argobots/solaris

@shintaro-iwasaki
Copy link
Collaborator Author

test:argobots/all

2 similar comments
@shintaro-iwasaki
Copy link
Collaborator Author

test:argobots/all

@shintaro-iwasaki
Copy link
Collaborator Author

test:argobots/all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant