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

Follow up on stack protector research #3201

Open
cbeck88 opened this issue Mar 6, 2023 · 0 comments
Open

Follow up on stack protector research #3201

cbeck88 opened this issue Mar 6, 2023 · 0 comments

Comments

@cbeck88
Copy link
Contributor

cbeck88 commented Mar 6, 2023

Found this old post from a long time ago: https://github.com/mobilecoinofficial/scratchpad/pull/16/files

I don't think we ever figured out what to do about this

I found this link just now, maybe this is resolved? https://doc.rust-lang.org/beta/rustc/exploit-mitigations.html#stack-clashing-protection


Intel wrote an enclave writer's guide, in section 10, page 30, they mention:

Enclave writers should set the compiler options such that by default
enclaves are built with standard defense in-depth mechanisms available on a given platform.
Regarding stack buffer overflow protection, developers must be aware that the commonly used
compiler options only provide protection when the buffer meets certain criteria.

...

The enclave writer must evaluate whether this security check
should be enabled in enclave functions that would remain unprotected otherwise (enclave
interface functions, for instance) and apply more strict checking options

...

Similary, the Intel® Compiler for Linux* supports –fstack-protector and –fstack-protector-all but does not support –fstack-protector-strong or –fstackprotector-explicit. GNU compiler supports options –fstack-protector-strong and –fstack-protector-explicit in version 4.9.2
I'm trying to understand if there is a way to get stack protectors like this in rust.

There is an old github issue that mentions this: rust-lang/rust#15179

There was a more recent stackoverflow question along these lines: https://stackoverflow.com/questions/48547475/how-to-add-stack-canaries-to-rust-executables?rq=1


I understand that there has been a lot of work creating "userspace" stackguard, and based on looking at historical issues and PRs, a lot of this work was done by @cuviper ?

rust-lang/rust#47912
rust-lang/rust#43052
rust-lang/rust#47863

There's also an internals discussion that seems relevant: https://internals.rust-lang.org/t/getting-rid-of-stack-guard-handling-an-alternative-way-to-detect-stack-overflow/9040


One issue particularly relevant to me is that, we chose to build our enclaves in a no_std environment -- the rationale for that is explained here: https://github.com/mobilecoinofficial/mobilecoin/tree/master/sgx

So we likely cannot directly use the libstd stack guard, but we might be able to port it or something, if it is indeed a thing we should be using.

There are some other core intrinsics that seem possibly relevant(?): https://docs.rs/compiler_builtins/0.1.27/compiler_builtins/probestack/index.html


My questions:

  1. What if anything are, in Intel's words, the "compiler options such that ... are built with standard defense in-depth mechanisms available on a given platform"? Is there now anything like –fstack-protector in rustc? In nightly rustc?

(In rustc 1.41-C --help I can see no-stack-check is deprecated and now does nothing)
(I looked for a while in current docu, sorry if I missed it)

Or is that simply "not available on our platform", particularly, in a no_std build?

  1. Are there any other relevant techniques or best practices in rust around stack guards manually inserted in code, or stack canaries / stack protection inserted by the compiler?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant