rust/src
bors 7c4be43b27 Auto merge of #84197 - bbjornse:stack-protector, r=nikic
add codegen option for using LLVM stack smash protection

LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This PR adds a codegen
option `-C stack-protector={basic,strong,all}` which controls the use of these
attributes. This gives rustc the same stack smash protection support as clang
offers through options `-fstack-protector`, `-fstack-protector-strong`, and
`-fstack-protector-all`. The protection this can offer is demonstrated in
test/ui/abi/stack-protector.rs. This fills a gap in the current list of rustc
exploit mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.

Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.

Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This PR follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.

Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.

LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.

The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
2021-11-23 06:08:37 +00:00
..
bootstrap Rollup merge of #90800 - aplanas:fix_cargo_config, r=Mark-Simulacrum 2021-11-19 13:06:35 +09:00
build_helper Migrate to 2021 2021-09-20 22:21:42 -04:00
ci Rollup merge of #90733 - wesleywiser:musl_debuginfo, r=Mark-Simulacrum 2021-11-16 23:58:21 +01:00
doc Update books 2021-11-22 13:39:44 -08:00
etc Encode json files with UTF-8 2021-09-30 00:11:14 +09:00
librustdoc Auto merge of #91094 - inquisitivecrystal:rustdoc-top-mod, r=jyn514 2021-11-23 03:13:26 +00:00
llvm-project@f9b03d0e2d Update llvm submodule 2021-11-16 16:49:16 +00:00
rustdoc-json-types Moved format-version constant to rustdoc-json-types 2021-10-15 12:27:42 +03:00
test Auto merge of #84197 - bbjornse:stack-protector, r=nikic 2021-11-23 06:08:37 +00:00
tools Rollup merge of #91144 - ehuss:update-cargo, r=ehuss 2021-11-22 23:30:32 +01:00
README.md
stage0.json bump boostrap compiler 2021-10-23 21:55:57 -04:00
version bump version to rust 1.58.0 2021-10-17 16:04:44 +02:00

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.