Skip to content

Commit 5e3dc2c

Browse files
author
Ariel Ben-Yehuda
committed
Deny partial -Z stack-protector by default in all editions
This enables RFC 3855 for stack-protector. With this PR, uses of stack-protector that only have it enabled for a subset of the crates within a process need to pass `-Z allow-partial-mitigations=stack-protector` as well. This was not done in #149357 to allow for a smooth transition period. cc the stack-protector tracking issue at #114903.
1 parent 5930afc commit 5e3dc2c

8 files changed

Lines changed: 162 additions & 15 deletions

compiler/rustc_session/src/options/mitigation_coverage.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ denied_partial_mitigations! {
203203
enum DeniedPartialMitigationKind {
204204
// The mitigation name should match the option name in rustc_session::options,
205205
// to allow for resetting the mitigation
206-
(StackProtector, "stack-protector", EditionFuture, self.stack_protector()),
206+
207+
// stack-protector is an unstable option, so it can be denied-partial
208+
(StackProtector, "stack-protector", Edition2015, self.stack_protector()),
207209
(ControlFlowGuard, "control-flow-guard", EditionFuture, self.opts.cg.control_flow_guard == CFGuard::Checks)
208210
}
209211
}

tests/ui/abi/stack-protector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22
//@ only-x86_64-unknown-linux-gnu
33
//@ revisions: ssp no-ssp
4-
//@ [ssp] compile-flags: -Z stack-protector=all
4+
//@ [ssp] compile-flags: -Z stack-protector=all -Z allow-partial-mitigations=stack-protector
55
//@ compile-flags: -C opt-level=2
66
//@ compile-flags: -g
77
//@ ignore-backends: gcc

tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.control-flow-2024-explicit-deny.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: your program uses the crate `std`, that is not compiled with `control-flow-guard` enabled
2-
--> $DIR/err-allow-partial-mitigations-current-edition.rs:18:1
2+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
33
|
44
LL | fn main() {}
55
| ^
@@ -8,7 +8,7 @@ LL | fn main() {}
88
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
99

1010
error: your program uses the crate `core`, that is not compiled with `control-flow-guard` enabled
11-
--> $DIR/err-allow-partial-mitigations-current-edition.rs:18:1
11+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
1212
|
1313
LL | fn main() {}
1414
| ^
@@ -17,7 +17,7 @@ LL | fn main() {}
1717
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
1818

1919
error: your program uses the crate `alloc`, that is not compiled with `control-flow-guard` enabled
20-
--> $DIR/err-allow-partial-mitigations-current-edition.rs:18:1
20+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
2121
|
2222
LL | fn main() {}
2323
| ^
@@ -26,7 +26,7 @@ LL | fn main() {}
2626
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
2727

2828
error: your program uses the crate `compiler_builtins`, that is not compiled with `control-flow-guard` enabled
29-
--> $DIR/err-allow-partial-mitigations-current-edition.rs:18:1
29+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
3030
|
3131
LL | fn main() {}
3232
| ^
@@ -35,7 +35,7 @@ LL | fn main() {}
3535
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
3636

3737
error: your program uses the crate `unwind/libc`, that is not compiled with `control-flow-guard` enabled
38-
--> $DIR/err-allow-partial-mitigations-current-edition.rs:18:1
38+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
3939
|
4040
LL | fn main() {}
4141
| ^

tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-linelength
2-
//@ revisions: control-flow-2024-explicit-deny
2+
//@ revisions: control-flow-2024-explicit-deny stack-protector-2024 stack-protector-2024-allow-deny-reset-by-mitigation stack-protector-2024-deny-reset-by-mitigation
33
//@ check-fail
44
//@ ignore-nvptx64 stack protector is not supported
55
//@ ignore-wasm32-unknown-unknown stack protector is not supported
@@ -14,6 +14,14 @@
1414

1515
//@ [control-flow-2024-explicit-deny] compile-flags: -C control-flow-guard=on -Z deny-partial-mitigations=control-flow-guard
1616

17+
// check that explicit deny of stack-protector works in edition 2024
18+
//@ [stack-protector-2024-deny-reset-by-mitigation] compile-flags: -Z deny-partial-mitigations=stack-protector -Z stack-protector=all
19+
20+
// check that this is the case even if there was an "allow" then a "deny"
21+
//@ [stack-protector-2024-allow-deny-reset-by-mitigation] compile-flags: -Z unstable-options -Z allow-partial-mitigations=stack-protector -Z deny-partial-mitigations=stack-protector -Z stack-protector=all
22+
23+
// check that stack-protector is partial-denied in edition 2024
24+
//@ [stack-protector-2024] compile-flags: -Z stack-protector=all
1725

1826
fn main() {}
1927
//~^ ERROR that is not compiled with
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled
2+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
3+
|
4+
LL | fn main() {}
5+
| ^
6+
|
7+
= note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
8+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
9+
10+
error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled
11+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
12+
|
13+
LL | fn main() {}
14+
| ^
15+
|
16+
= note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
17+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
18+
19+
error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled
20+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
21+
|
22+
LL | fn main() {}
23+
| ^
24+
|
25+
= note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
26+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
27+
28+
error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled
29+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
30+
|
31+
LL | fn main() {}
32+
| ^
33+
|
34+
= note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
35+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
36+
37+
error: your program uses the crate `unwind/libc`, that is not compiled with `stack-protector=all` enabled
38+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
39+
|
40+
LL | fn main() {}
41+
| ^
42+
|
43+
= note: recompile `unwind/libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
44+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
45+
46+
error: aborting due to 5 previous errors
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled
2+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
3+
|
4+
LL | fn main() {}
5+
| ^
6+
|
7+
= note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
8+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
9+
10+
error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled
11+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
12+
|
13+
LL | fn main() {}
14+
| ^
15+
|
16+
= note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
17+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
18+
19+
error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled
20+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
21+
|
22+
LL | fn main() {}
23+
| ^
24+
|
25+
= note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
26+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
27+
28+
error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled
29+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
30+
|
31+
LL | fn main() {}
32+
| ^
33+
|
34+
= note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
35+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
36+
37+
error: your program uses the crate `unwind/libc`, that is not compiled with `stack-protector=all` enabled
38+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
39+
|
40+
LL | fn main() {}
41+
| ^
42+
|
43+
= note: recompile `unwind/libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
44+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
45+
46+
error: aborting due to 5 previous errors
47+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled
2+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
3+
|
4+
LL | fn main() {}
5+
| ^
6+
|
7+
= note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
8+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
9+
10+
error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled
11+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
12+
|
13+
LL | fn main() {}
14+
| ^
15+
|
16+
= note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
17+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
18+
19+
error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled
20+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
21+
|
22+
LL | fn main() {}
23+
| ^
24+
|
25+
= note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
26+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
27+
28+
error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled
29+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
30+
|
31+
LL | fn main() {}
32+
| ^
33+
|
34+
= note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
35+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
36+
37+
error: your program uses the crate `unwind/libc`, that is not compiled with `stack-protector=all` enabled
38+
--> $DIR/err-allow-partial-mitigations-current-edition.rs:26:1
39+
|
40+
LL | fn main() {}
41+
| ^
42+
|
43+
= note: recompile `unwind/libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled
44+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
45+
46+
error: aborting due to 5 previous errors
47+

tests/ui/allow-partial-mitigations/ok-allow-partial-mitigations-current-edition.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-linelength
2-
//@ revisions: control-flow-guard-2024-default control-flow-guard-2024-deny-reset-by-mitigation stack-protector-2024-deny-reset-by-mitigation stack-protector-2024-allow-deny-reset-by-mitigation
2+
//@ revisions: control-flow-guard-2024-default control-flow-guard-2024-deny-reset-by-mitigation stack-protector-2024-explicit-allow
33
//@ check-pass
44
//@ ignore-nvptx64 stack protector is not supported
55
//@ ignore-wasm32-unknown-unknown stack protector is not supported
@@ -15,11 +15,7 @@
1515
// test that -C control-flow-guard=on resets -Z deny-partial-mitigations=control-flow-guard
1616
//@ [control-flow-guard-2024-deny-reset-by-mitigation] compile-flags: -Z deny-partial-mitigations=control-flow-guard -C control-flow-guard=on
1717

18-
// same but for stack-protector, to match the stack-protector-future-deny-reset-by-mitigation test in
19-
// err-allow-partial-mitigations-1-error (which has the same args but on edition=future).
20-
//@ [stack-protector-2024-deny-reset-by-mitigation] compile-flags: -Z deny-partial-mitigations=stack-protector -Z stack-protector=all
21-
22-
// check that this is the case even if there was an "allow" then a "deny"
23-
//@ [stack-protector-2024-allow-deny-reset-by-mitigation] compile-flags: -Z unstable-options -Z allow-partial-mitigations=stack-protector -Z deny-partial-mitigations=stack-protector -Z stack-protector=all
18+
// also test that stack protector is fine in edition 2024 with an explicit allow
19+
//@ [stack-protector-2024-explicit-allow] compile-flags: -Z stack-protector=all -Z allow-partial-mitigations=stack-protector
2420

2521
fn main() {}

0 commit comments

Comments
 (0)