Skip to content

Commit 7d5bc08

Browse files
author
Ariel Ben-Yehuda
committed
remove stack-protector=basic
stack-protector=basic is a heuristic designed for C putting this in its own commit to allow for easy reversion if someone wants it
1 parent cd39dbe commit 7d5bc08

File tree

13 files changed

+30
-94
lines changed

13 files changed

+30
-94
lines changed

bootstrap.example.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,7 @@
715715
# Indicates whether stack protectors should be used
716716
# via `-Cstack-protector`.
717717
#
718-
# Valid options are : `none`(default),`basic`,`strong`, or `all`.
719-
# `strong` and `basic` options may be buggy and are not recommended, see rust-lang/rust#114903.
718+
# Valid options are : `none`(default), `strong`, or `all`.
720719
#rust.stack-protector = "none"
721720

722721
# Prints each test name as it is executed, to help debug issues in the test harness itself.

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ fn stackprotector_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
269269
StackProtector::None => return None,
270270
StackProtector::All => AttributeKind::StackProtectReq,
271271
StackProtector::Strong => AttributeKind::StackProtectStrong,
272-
StackProtector::Basic => AttributeKind::StackProtect,
273272
};
274273

275274
Some(sspattr.create_attr(cx.llcx))

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,6 @@ impl CodegenBackend for LlvmCodegenBackend {
294294
*post-optimization*, contain either arrays (of any size
295295
or type) or address-taken locals.
296296
297-
basic
298-
Generate stack canaries in functions that are heuristically
299-
suspected to contain buffer overflows.
300-
301-
The heuristic is subject to change, but currently it
302-
includes functions with local variables of `[T; N]`
303-
type, where `T` is byte-sized and `N` >= 8.
304-
305-
This heuristic originated from C, where it detects
306-
functions that allocate a `char buf[N];` buffer on the
307-
stack, and are therefore likely to have a stack buffer overflow
308-
in the case of a length-calculation error. It is *not* a good
309-
heuristic for Rust code.
310-
311297
none
312298
Do not generate stack canaries.
313299
"#

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ fn test_codegen_options_tracking_hash() {
641641
tracked!(relro_level, Some(RelroLevel::Full));
642642
tracked!(soft_float, true);
643643
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
644-
tracked!(stack_protector, StackProtector::All);
644+
tracked!(stack_protector, Some(StackProtector::All));
645645
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
646646
tracked!(target_cpu, Some(String::from("abc")));
647647
tracked!(target_feature, String::from("all the features, all of them"));
@@ -872,6 +872,7 @@ fn test_unstable_options_tracking_hash() {
872872
tracked!(small_data_threshold, Some(16));
873873
tracked!(split_lto_unit, Some(true));
874874
tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1));
875+
tracked!(stack_protector, Some(StackProtector::All));
875876
tracked!(teach, true);
876877
tracked!(thinlto, Some(true));
877878
tracked!(tiny_const_eval_limit, true);

compiler/rustc_target/src/spec/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,12 +1757,6 @@ pub enum StackProtector {
17571757
/// Disable stack canary generation.
17581758
None,
17591759

1760-
/// On LLVM, mark all generated LLVM functions with the `ssp` attribute (see
1761-
/// llvm/docs/LangRef.rst). This triggers stack canary generation in
1762-
/// functions which contain an array of a byte-sized type with more than
1763-
/// eight elements.
1764-
Basic,
1765-
17661760
/// On LLVM, mark all generated LLVM functions with the `sspstrong`
17671761
/// attribute (see llvm/docs/LangRef.rst). This triggers stack canary
17681762
/// generation in functions which either contain an array, or which take
@@ -1777,7 +1771,6 @@ impl StackProtector {
17771771
fn as_str(&self) -> &'static str {
17781772
match self {
17791773
StackProtector::None => "none",
1780-
StackProtector::Basic => "basic",
17811774
StackProtector::Strong => "strong",
17821775
StackProtector::All => "all",
17831776
}
@@ -1790,7 +1783,6 @@ impl FromStr for StackProtector {
17901783
fn from_str(s: &str) -> Result<StackProtector, ()> {
17911784
Ok(match s {
17921785
"none" => StackProtector::None,
1793-
"basic" => StackProtector::Basic,
17941786
"strong" => StackProtector::Strong,
17951787
"all" => StackProtector::All,
17961788
_ => return Err(()),

src/doc/rustc/src/codegen-options/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,6 @@ This flag controls stack smashing protection strategy.
682682

683683
Supported values for this option are:
684684
- `none` (default): Disable stack canary generation
685-
- `basic`: Generate stack canaries in functions that are suspected
686-
to have a high chance of containing stack buffer overflows (deprecated).
687685
- `strong`: Generate stack canaries in all functions, unless the compiler
688686
can prove these functions can't be the source of a stack
689687
buffer overflow (even in the presence of undefined behavior).

tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
//@ revisions: all strong basic none missing
1+
//@ revisions: all strong none missing
22
//@ assembly-output: emit-asm
33
//@ only-windows
44
//@ only-msvc
55
//@ ignore-64bit 64-bit table based SEH has slightly different behaviors than classic SEH
66
//@ [all] compile-flags: -C stack-protector=all
77
//@ [strong] compile-flags: -C stack-protector=strong
8-
//@ [basic] compile-flags: -C stack-protector=basic
98
//@ [none] compile-flags: -C stack-protector=none
109
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled
1110

@@ -18,7 +17,6 @@
1817
pub fn emptyfn() {
1918
// all: __security_check_cookie
2019
// strong-NOT: __security_check_cookie
21-
// basic-NOT: __security_check_cookie
2220
// none-NOT: __security_check_cookie
2321
// missing-NOT: __security_check_cookie
2422
}
@@ -36,7 +34,6 @@ pub fn array_char(f: fn(*const char)) {
3634

3735
// all: __security_check_cookie
3836
// strong: __security_check_cookie
39-
// basic: __security_check_cookie
4037
// none-NOT: __security_check_cookie
4138
// missing-NOT: __security_check_cookie
4239
}
@@ -52,7 +49,6 @@ pub fn array_u8_1(f: fn(*const u8)) {
5249

5350
// all: __security_check_cookie
5451
// strong: __security_check_cookie
55-
// basic-NOT: __security_check_cookie
5652
// none-NOT: __security_check_cookie
5753
// missing-NOT: __security_check_cookie
5854
}
@@ -66,10 +62,10 @@ pub fn array_u8_small(f: fn(*const u8)) {
6662
f(&b as *const _);
6763

6864
// Small arrays do not lead to stack protection by the 'basic' heuristic.
65+
// (basic is not currently supported, leaving the test anyway).
6966

7067
// all: __security_check_cookie
7168
// strong: __security_check_cookie
72-
// basic-NOT: __security_check_cookie
7369
// none-NOT: __security_check_cookie
7470
// missing-NOT: __security_check_cookie
7571
}
@@ -82,10 +78,10 @@ pub fn array_u8_large(f: fn(*const u8)) {
8278

8379
// Since `a` is a byte array with size greater than 8, the basic heuristic
8480
// will also protect this function.
81+
// (basic is not currently supported, leaving the test anyway).
8582

8683
// all: __security_check_cookie
8784
// strong: __security_check_cookie
88-
// basic: __security_check_cookie
8985
// none-NOT: __security_check_cookie
9086
// missing-NOT: __security_check_cookie
9187
}
@@ -101,10 +97,10 @@ pub fn array_bytesizednewtype_9(f: fn(*const ByteSizedNewtype)) {
10197

10298
// Since `a` is a byte array in the LLVM output, the basic heuristic will
10399
// also protect this function.
100+
// (basic is not currently supported, leaving the test anyway).
104101

105102
// all: __security_check_cookie
106103
// strong: __security_check_cookie
107-
// basic: __security_check_cookie
108104
// none-NOT: __security_check_cookie
109105
// missing-NOT: __security_check_cookie
110106
}
@@ -128,10 +124,10 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) {
128124
// }
129125
// EOF
130126
// ```
127+
// (basic is not currently supported, leaving the test anyway).
131128

132129
// all: __security_check_cookie
133130
// strong: __security_check_cookie
134-
// basic-NOT: __security_check_cookie
135131
// none-NOT: __security_check_cookie
136132
// missing-NOT: __security_check_cookie
137133
}
@@ -159,10 +155,10 @@ pub fn local_string_addr_taken(f: fn(&String)) {
159155
// EOF
160156
// ```
161157
//
158+
// (basic is not currently supported, leaving the test anyway).
162159

163160
// all: __security_check_cookie
164161
// strong-NOT: __security_check_cookie
165-
// basic-NOT: __security_check_cookie
166162
// none-NOT: __security_check_cookie
167163
// missing-NOT: __security_check_cookie
168164
}
@@ -191,7 +187,6 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
191187

192188
// all: __security_check_cookie
193189
// strong-NOT: __security_check_cookie
194-
// basic-NOT: __security_check_cookie
195190
// none-NOT: __security_check_cookie
196191
// missing-NOT: __security_check_cookie
197192
}
@@ -228,7 +223,6 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
228223

229224
// all: __security_check_cookie
230225
// strong: __security_check_cookie
231-
// basic: __security_check_cookie
232226
// none-NOT: __security_check_cookie
233227
// missing-NOT: __security_check_cookie
234228
}
@@ -257,7 +251,6 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
257251

258252
// all: __security_check_cookie
259253
// strong: __security_check_cookie
260-
// basic: __security_check_cookie
261254
// none-NOT: __security_check_cookie
262255
// missing-NOT: __security_check_cookie
263256
}
@@ -297,7 +290,6 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
297290

298291
// all: __security_check_cookie
299292
// strong-NOT: __security_check_cookie
300-
// basic-NOT: __security_check_cookie
301293
// none-NOT: __security_check_cookie
302294
// missing-NOT: __security_check_cookie
303295
}
@@ -309,7 +301,6 @@ pub fn alloca_large_compile_time_constant_arg(f: fn(*mut ())) {
309301

310302
// all: __security_check_cookie
311303
// strong-NOT: __security_check_cookie
312-
// basic-NOT: __security_check_cookie
313304
// none-NOT: __security_check_cookie
314305
// missing-NOT: __security_check_cookie
315306
}
@@ -321,7 +312,6 @@ pub fn alloca_dynamic_arg(f: fn(*mut ()), n: usize) {
321312

322313
// all: __security_check_cookie
323314
// strong-NOT: __security_check_cookie
324-
// basic-NOT: __security_check_cookie
325315
// none-NOT: __security_check_cookie
326316
// missing-NOT: __security_check_cookie
327317
}
@@ -353,7 +343,6 @@ pub fn unsized_fn_param(s: [u8], l: bool, f: fn([u8])) {
353343
// all-NOT: __security_check_cookie
354344
// strong-NOT: __security_check_cookie
355345

356-
// basic-NOT: __security_check_cookie
357346
// none-NOT: __security_check_cookie
358347
// missing-NOT: __security_check_cookie
359348
}

tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
//@ revisions: all strong basic none missing
1+
//@ revisions: all strong none missing
22
//@ assembly-output: emit-asm
33
//@ only-windows
44
//@ only-msvc
55
//@ ignore-32bit 64-bit table based SEH has slightly different behaviors than classic SEH
66
//@ [all] compile-flags: -C stack-protector=all
77
//@ [strong] compile-flags: -C stack-protector=strong
8-
//@ [basic] compile-flags: -C stack-protector=basic
98
//@ [none] compile-flags: -C stack-protector=none
109
//@ compile-flags: -C opt-level=2 -Z merge-functions=disabled
1110

@@ -17,7 +16,6 @@
1716
pub fn emptyfn() {
1817
// all: __security_check_cookie
1918
// strong-NOT: __security_check_cookie
20-
// basic-NOT: __security_check_cookie
2119
// none-NOT: __security_check_cookie
2220
// missing-NOT: __security_check_cookie
2321
}
@@ -35,7 +33,6 @@ pub fn array_char(f: fn(*const char)) {
3533

3634
// all: __security_check_cookie
3735
// strong: __security_check_cookie
38-
// basic: __security_check_cookie
3936
// none-NOT: __security_check_cookie
4037
// missing-NOT: __security_check_cookie
4138
}
@@ -51,7 +48,6 @@ pub fn array_u8_1(f: fn(*const u8)) {
5148

5249
// all: __security_check_cookie
5350
// strong: __security_check_cookie
54-
// basic-NOT: __security_check_cookie
5551
// none-NOT: __security_check_cookie
5652
// missing-NOT: __security_check_cookie
5753
}
@@ -65,10 +61,10 @@ pub fn array_u8_small(f: fn(*const u8)) {
6561
f(&b as *const _);
6662

6763
// Small arrays do not lead to stack protection by the 'basic' heuristic.
64+
// (basic is not currently supported, leaving the test anyway).
6865

6966
// all: __security_check_cookie
7067
// strong: __security_check_cookie
71-
// basic-NOT: __security_check_cookie
7268
// none-NOT: __security_check_cookie
7369
// missing-NOT: __security_check_cookie
7470
}
@@ -81,10 +77,10 @@ pub fn array_u8_large(f: fn(*const u8)) {
8177

8278
// Since `a` is a byte array with size greater than 8, the basic heuristic
8379
// will also protect this function.
80+
// (basic is not currently supported, leaving the test anyway).
8481

8582
// all: __security_check_cookie
8683
// strong: __security_check_cookie
87-
// basic: __security_check_cookie
8884
// none-NOT: __security_check_cookie
8985
// missing-NOT: __security_check_cookie
9086
}
@@ -100,10 +96,10 @@ pub fn array_bytesizednewtype_9(f: fn(*const ByteSizedNewtype)) {
10096

10197
// Since `a` is a byte array in the LLVM output, the basic heuristic will
10298
// also protect this function.
99+
// (basic is not currently supported, leaving the test anyway).
103100

104101
// all: __security_check_cookie
105102
// strong: __security_check_cookie
106-
// basic: __security_check_cookie
107103
// none-NOT: __security_check_cookie
108104
// missing-NOT: __security_check_cookie
109105
}
@@ -130,7 +126,6 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) {
130126

131127
// all: __security_check_cookie
132128
// strong: __security_check_cookie
133-
// basic-NOT: __security_check_cookie
134129
// none-NOT: __security_check_cookie
135130
// missing-NOT: __security_check_cookie
136131
}
@@ -158,7 +153,6 @@ pub fn local_string_addr_taken(f: fn(&String)) {
158153
// }
159154
// EOF
160155
// ```
161-
//
162156

163157
// We should have a __security_check_cookie call in `all` and `strong` modes but
164158
// LLVM does not support generating stack protectors in functions with funclet
@@ -167,7 +161,6 @@ pub fn local_string_addr_taken(f: fn(&String)) {
167161
// all-NOT: __security_check_cookie
168162
// strong-NOT: __security_check_cookie
169163

170-
// basic-NOT: __security_check_cookie
171164
// none-NOT: __security_check_cookie
172165
// missing-NOT: __security_check_cookie
173166

@@ -198,7 +191,6 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
198191

199192
// all: __security_check_cookie
200193
// strong-NOT: __security_check_cookie
201-
// basic-NOT: __security_check_cookie
202194
// none-NOT: __security_check_cookie
203195
// missing-NOT: __security_check_cookie
204196
}
@@ -235,7 +227,6 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
235227

236228
// all: __security_check_cookie
237229
// strong: __security_check_cookie
238-
// basic: __security_check_cookie
239230
// none-NOT: __security_check_cookie
240231
// missing-NOT: __security_check_cookie
241232
}
@@ -264,7 +255,6 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
264255

265256
// all: __security_check_cookie
266257
// strong: __security_check_cookie
267-
// basic: __security_check_cookie
268258
// none-NOT: __security_check_cookie
269259
// missing-NOT: __security_check_cookie
270260
}
@@ -304,7 +294,6 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
304294

305295
// all: __security_check_cookie
306296
// strong-NOT: __security_check_cookie
307-
// basic-NOT: __security_check_cookie
308297
// none-NOT: __security_check_cookie
309298
// missing-NOT: __security_check_cookie
310299
}
@@ -316,7 +305,6 @@ pub fn alloca_large_compile_time_constant_arg(f: fn(*mut ())) {
316305

317306
// all: __security_check_cookie
318307
// strong-NOT: __security_check_cookie
319-
// basic-NOT: __security_check_cookie
320308
// none-NOT: __security_check_cookie
321309
// missing-NOT: __security_check_cookie
322310
}
@@ -328,7 +316,6 @@ pub fn alloca_dynamic_arg(f: fn(*mut ()), n: usize) {
328316

329317
// all: __security_check_cookie
330318
// strong-NOT: __security_check_cookie
331-
// basic-NOT: __security_check_cookie
332319
// none-NOT: __security_check_cookie
333320
// missing-NOT: __security_check_cookie
334321
}
@@ -360,7 +347,6 @@ pub fn unsized_fn_param(s: [u8], l: bool, f: fn([u8])) {
360347
// all-NOT: __security_check_cookie
361348
// strong-NOT: __security_check_cookie
362349

363-
// basic-NOT: __security_check_cookie
364350
// none-NOT: __security_check_cookie
365351
// missing-NOT: __security_check_cookie
366352
}

0 commit comments

Comments
 (0)