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

unix: Set a guard page at the end of signal stacks #69969

Merged
merged 3 commits into from
Mar 19, 2020

Conversation

iximeow
Copy link
Contributor

@iximeow iximeow commented Mar 13, 2020

This mitigates possible issues when signal stacks overflow, which could
manifest as segfaults or in unlucky circumstances possible clobbering of
other memory values as stack overflows tend to enable.

I went ahead and made a PR for this because it's a pretty small change, though if I should open an issue/RFC for this and discuss there first I'll happily do so. I've also added some example programs that demonstrate the uncomfortably clobber-happy behavior we currently have, and the segfaults that could/should result instead, here.

This mitigates possible issues when signal stacks overflow, which could
manifest as segfaults or in unlucky circumstances possible clobbering of
other memory values as stack overflows tend to enable.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 13, 2020
@cuviper
Copy link
Member

cuviper commented Mar 13, 2020

This should close #69533.

src/libstd/sys/unix/stack_overflow.rs Outdated Show resolved Hide resolved
…ther

also unmap the whole thing when cleaning up, rather than leaving a spare
page floating around.
Copy link
Member

@cuviper cuviper left a comment

Choose a reason for hiding this comment

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

LGTM, but someone from @rust-lang/libs should probably give final say.

src/libstd/sys/unix/stack_overflow.rs Outdated Show resolved Hide resolved
@cuviper
Copy link
Member

cuviper commented Mar 13, 2020

I've also added some example programs that demonstrate the uncomfortably clobber-happy behavior we currently have, and the segfaults that could/should result instead, here.

How reliably are these tests able to get a nearby mapping to clobber? It would be nice to have a regression test, something like src/test/ui/out-of-stack.rs that watches for SIGABRT. (I guess it should get a raw SIGSEGV death in this case, when the signal handler itself dies.)

@iximeow
Copy link
Contributor Author

iximeow commented Mar 13, 2020

How reliably are these tests able to get a nearby mapping to clobber?

This is entirely a question of the OS doing the mmaping. On linuxes I know of, I'm pretty sure mapping just a single page in main should be sufficient, since it'll get the next unreserved page. I've seen mmap larger than one page get satisfied with pages later on in memory that don't end up adjacent to the signal stack, which is why the examples have a sequence of single-page mappings.

@cuviper
Copy link
Member

cuviper commented Mar 18, 2020

I raised this to the team on zulip and got no objections, so let's go with it.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 18, 2020

📌 Commit 28eeea6 has been approved by cuviper

@bors
Copy link
Contributor

bors commented Mar 18, 2020

🌲 The tree is currently closed for pull requests below priority 5, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 19, 2020
unix: Set a guard page at the end of signal stacks

This mitigates possible issues when signal stacks overflow, which could
manifest as segfaults or in unlucky circumstances possible clobbering of
other memory values as stack overflows tend to enable.

I went ahead and made a PR for this because it's a pretty small change, though if I should open an issue/RFC for this and discuss there first I'll happily do so. I've also added some example programs that demonstrate the uncomfortably clobber-happy behavior we currently have, and the segfaults that could/should result instead, [here](https://github.com/iximeow/jubilant-train).
bors added a commit that referenced this pull request Mar 19, 2020
Rollup of 9 pull requests

Successful merges:

 - #69036 (rustc: don't resolve Instances which would produce malformed shims.)
 - #69443 (tidy: Better license checks.)
 - #69814 (Smaller and more correct generator codegen)
 - #69929 (Regenerate tables for Unicode 13.0.0)
 - #69959 (std: Don't abort process when printing panics in tests)
 - #69969 (unix: Set a guard page at the end of signal stacks)
 - #70005 ([rustdoc] Improve visibility for code blocks warnings)
 - #70088 (Use copy bound in atomic operations to generate simpler MIR)
 - #70095 (Implement -Zlink-native-libraries)

Failed merges:

r? @ghost
bors added a commit that referenced this pull request Mar 19, 2020
Rollup of 9 pull requests

Successful merges:

 - #68941 (Properly handle Spans that reference imported SourceFiles)
 - #69036 (rustc: don't resolve Instances which would produce malformed shims.)
 - #69443 (tidy: Better license checks.)
 - #69814 (Smaller and more correct generator codegen)
 - #69929 (Regenerate tables for Unicode 13.0.0)
 - #69959 (std: Don't abort process when printing panics in tests)
 - #69969 (unix: Set a guard page at the end of signal stacks)
 - #70005 ([rustdoc] Improve visibility for code blocks warnings)
 - #70088 (Use copy bound in atomic operations to generate simpler MIR)

Failed merges:

r? @ghost
@bors bors merged commit 4c3a5a5 into rust-lang:master Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust's signal stack should be guarded against overflow
5 participants