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

Rollup of 5 pull requests #88890

Closed
wants to merge 20 commits into from

Conversation

Manishearth
Copy link
Member

Successful merges:

Failed merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

WaffleLapkin and others added 20 commits September 7, 2021 16:41
This reverts commit 059b68d.

Note that this was manually adjusted to retain some of the refactoring
introduced by commit 059b68d, so that it could
likewise retain the correction introduced in commit
5b4bc05
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-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 rust-lang#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 patch 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 rust-lang#26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (rust-lang#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.

Reviewed-by: Nikita Popov <nikic@php.net>

Extra commits during review:

- [address-review] make the stack-protector option unstable

- [address-review] reduce detail level of stack-protector option help text

- [address-review] correct grammar in comment

- [address-review] use compiler flag to avoid merging functions in test

- [address-review] specify min LLVM version in fortanix stack-protector test

  Only for Fortanix test, since this target specifically requests the
  `--x86-experimental-lvi-inline-asm-hardening` flag.

- [address-review] specify required LLVM components in stack-protector tests

- move stack protector option enum closer to other similar option enums

- rustc_interface/tests: sort debug option list in tracking hash test

- add an explicit `none` stack-protector option

Revert "set LLVM requirements for all stack protector support test revisions"

This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
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 rust-lang#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 rust-lang#26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (rust-lang#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.
…flip1995

Update Clippy dependencies without patch versions

Trial run for rust-lang/rust-clippy#7606
…mut, r=dtolnay

Make `UnsafeCell::get_mut` const
Update cargo

6 commits in 18751dd3f238d94d384a7fe967abfac06cbfe0b9..e515c3277bf0681bfc79a9e763861bfe26bb05db
2021-09-01 14:26:00 +0000 to 2021-09-08 14:32:15 +0000
- Remove log output that may leak tokens (rust-lang/cargo#9873)
- rev = "refs/pull/𑑛/head" (rust-lang/cargo#9859)
- Update suggestion message on bad project name error (rust-lang/cargo#9877)
- clarify what goes into "*-sys" crates (rust-lang/cargo#9871)
- Improve error message when unable to initialize git index repo (rust-lang/cargo#9869)
- Use serde_json to generate cargo_vcs_info.json (rust-lang/cargo#9865)
… r=davidtwco

Revert anon union parsing

Revert PR rust-lang#84571 and rust-lang#85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code.

Fix rust-lang#88583.
@rustbot rustbot added the rollup A PR which is a rollup label Sep 12, 2021
@Manishearth
Copy link
Member Author

@bors r+ p=2

@bors
Copy link
Contributor

bors commented Sep 12, 2021

📌 Commit c09e12b has been approved by Manishearth

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 12, 2021
@workingjubilee
Copy link
Member

whoops, closing #88889

@bors
Copy link
Contributor

bors commented Sep 12, 2021

⌛ Testing commit c09e12b with merge 7c8294974d8fdacef42807362ee158a8f64c69c3...

@rust-log-analyzer
Copy link
Collaborator

The job test-various failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [ui] ui/abi/numbers-arithmetic/i128-ffi.rs ... ignored
test [ui] ui/abi/segfault-no-out-of-stack.rs ... ignored
test [ui] ui/abi/stack-probes-lto.rs ... ignored
test [ui] ui/abi/stack-probes.rs ... ignored
test [ui] ui/abi/stack-protector.rs#no-ssp ... ignored
test [ui] ui/abi/stack-protector.rs#ssp ... ignored
test [ui] ui/abi/struct-enums/struct-return.rs ... ignored
test [ui] ui/abi/union/union-c-interop.rs ... ignored
test [ui] ui/abi/variadic-ffi.rs ... ignored
test [ui] ui/abi/unsupported.rs#i686 ... ok
---
test [assembly] assembly/asm/powerpc-types.rs#powerpc64 ... ok
test [assembly] assembly/asm/mips-types.rs#mips64 ... ok
test [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#basic ... FAILED
test [assembly] assembly/asm/mips-types.rs#mips32 ... ok
test [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#strong ... FAILED
test [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#all ... FAILED
test [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#none ... FAILED
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r1 ... ok
test [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#missing ... FAILED
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r10 ... ok
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r11 ... ok
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r12 ... ok
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r13 ... ok
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r16 ... ok
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r14 ... ok
test [assembly] assembly/stack-protector/stack-protector-target-support.rs#r15 ... ok
---
test [assembly] assembly/target-feature-multiple.rs#TWOFLAGS ... ok
test [assembly] assembly/static-relocation-model.rs#x64 ... ok
test [assembly] assembly/target-feature-multiple.rs#SINGLEFLAG ... ok
test [assembly] assembly/asm/x86-types.rs#i686 ... ok
Some tests failed in compiletest suite=assembly mode=assembly host=x86_64-unknown-linux-gnu target=nvptx64-nvidia-cuda

failures:


---- [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#basic stdout ----

error in revision `basic`: compilation failed!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/assembly/stack-protector/stack-protector-heuristics-effect.rs" "-Zthreads=1" "--target=nvptx64-nvidia-cuda" "--cfg" "basic" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.basic/stack-protector-heuristics-effect.s" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/nvptx64-nvidia-cuda/native/rust-test-helpers" "-Z" "stack-protector=basic" "-C" "opt-level=2" "-Z" "merge-functions=disabled" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.basic/auxiliary" "--emit=asm"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
warning: `-Z stack-protector=basic` is not supported for target nvptx64-nvidia-cuda and will be ignored
error[E0463]: can't find crate for `std`
  |
  |
  = note: the `nvptx64-nvidia-cuda` target may not support the standard library
  = note: `std` is required by `<unknown>` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0463`.


------------------------------------------


---- [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#strong stdout ----

error in revision `strong`: compilation failed!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/assembly/stack-protector/stack-protector-heuristics-effect.rs" "-Zthreads=1" "--target=nvptx64-nvidia-cuda" "--cfg" "strong" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.strong/stack-protector-heuristics-effect.s" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/nvptx64-nvidia-cuda/native/rust-test-helpers" "-Z" "stack-protector=strong" "-C" "opt-level=2" "-Z" "merge-functions=disabled" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.strong/auxiliary" "--emit=asm"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
warning: `-Z stack-protector=strong` is not supported for target nvptx64-nvidia-cuda and will be ignored
error[E0463]: can't find crate for `std`
  |
  |
  = note: the `nvptx64-nvidia-cuda` target may not support the standard library
  = note: `std` is required by `<unknown>` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0463`.


------------------------------------------


---- [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#all stdout ----

error in revision `all`: compilation failed!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/assembly/stack-protector/stack-protector-heuristics-effect.rs" "-Zthreads=1" "--target=nvptx64-nvidia-cuda" "--cfg" "all" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.all/stack-protector-heuristics-effect.s" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/nvptx64-nvidia-cuda/native/rust-test-helpers" "-Z" "stack-protector=all" "-C" "opt-level=2" "-Z" "merge-functions=disabled" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.all/auxiliary" "--emit=asm"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
warning: `-Z stack-protector=all` is not supported for target nvptx64-nvidia-cuda and will be ignored
error[E0463]: can't find crate for `std`
  |
  |
  = note: the `nvptx64-nvidia-cuda` target may not support the standard library
  = note: `std` is required by `<unknown>` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0463`.


------------------------------------------


---- [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#none stdout ----

error in revision `none`: compilation failed!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/assembly/stack-protector/stack-protector-heuristics-effect.rs" "-Zthreads=1" "--target=nvptx64-nvidia-cuda" "--cfg" "none" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.none/stack-protector-heuristics-effect.s" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/nvptx64-nvidia-cuda/native/rust-test-helpers" "-Z" "stack-protector=none" "-C" "opt-level=2" "-Z" "merge-functions=disabled" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.none/auxiliary" "--emit=asm"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0463]: can't find crate for `std`
  |
  = note: the `nvptx64-nvidia-cuda` target may not support the standard library
  = note: `std` is required by `<unknown>` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.


------------------------------------------


---- [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#missing stdout ----

error in revision `missing`: compilation failed!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/assembly/stack-protector/stack-protector-heuristics-effect.rs" "-Zthreads=1" "--target=nvptx64-nvidia-cuda" "--cfg" "missing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.missing/stack-protector-heuristics-effect.s" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/nvptx64-nvidia-cuda/native/rust-test-helpers" "-C" "opt-level=2" "-Z" "merge-functions=disabled" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly/stack-protector/stack-protector-heuristics-effect.missing/auxiliary" "--emit=asm"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0463]: can't find crate for `std`
  |
  = note: the `nvptx64-nvidia-cuda` target may not support the standard library
  = note: `std` is required by `<unknown>` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.


------------------------------------------



failures:
    [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#all
    [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#basic
    [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#missing
    [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#none
    [assembly] assembly/stack-protector/stack-protector-heuristics-effect.rs#strong
test result: FAILED. 108 passed; 5 failed; 15 ignored; 0 measured; 0 filtered out; finished in 0.48s




command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/nvptx64-nvidia-cuda/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/assembly" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/assembly" "--stage-id" "stage2-nvptx64-nvidia-cuda" "--suite" "assembly" "--mode" "assembly" "--target" "nvptx64-nvidia-cuda" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--nodejs" "/node-v15.14.0-linux-x64/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/nvptx64-nvidia-cuda/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--llvm-version" "13.0.0-rust-1.57.0-nightly" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker dwp engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit orcshared orctargetprocess passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info xray" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--channel" "nightly" "--color" "always"


Build completed unsuccessfully in 0:00:33

@bors
Copy link
Contributor

bors commented Sep 12, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 12, 2021
@workingjubilee
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 14, 2021
@bors
Copy link
Contributor

bors commented Sep 16, 2021

☔ The latest upstream changes (presumably #88992) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rollup A PR which is a rollup S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants