@@ -42,8 +42,7 @@ understood within a given context.
42
42
43
43
This section documents the exploit mitigations applicable to the Rust compiler
44
44
when building programs for the Linux operating system on the AMD64 architecture
45
- and equivalent.<sup id =" fnref:1 " role =" doc-noteref " ><a href="#fn:1"
46
- class="footnote">1</a ></sup > All examples in this section were built using
45
+ and equivalent.[ ^ all-targets ] All examples in this section were built using
47
46
nightly builds of the Rust compiler on Debian testing.
48
47
49
48
The Rust Programming Language currently has no specification. The Rust compiler
@@ -67,11 +66,8 @@ equivalent.
67
66
| Forward-edge control flow protection | Yes | Nightly |
68
67
| Backward-edge control flow protection (e.g., shadow and safe stack) | Yes | Nightly |
69
68
70
- <small id =" fn:1 " >1\. See
71
- < https://github.com/rust-lang/rust/tree/master/compiler/rustc_target/src/spec >
72
- for a list of targets and their default options. <a href="#fnref:1"
73
- class="reversefootnote" role="doc-backlink">↩</a ></small >
74
-
69
+ [ ^ all-targets ] : See < https://github.com/rust-lang/rust/tree/master/compiler/rustc_target/src/spec >
70
+ for a list of targets and their default options.
75
71
76
72
### Position-independent executable
77
73
@@ -141,18 +137,15 @@ Integer overflow checks are enabled when debug assertions are enabled (see Fig.
141
137
3), and disabled when debug assertions are disabled (see Fig. 4). To enable
142
138
integer overflow checks independently, use the option to control integer
143
139
overflow checks, scoped attributes, or explicit checking methods such as
144
- ` checked_add ` <sup id =" fnref:2 " role =" doc-noteref " ><a href="#fn:2"
145
- class="footnote">2</a ></sup >.
140
+ ` checked_add ` [ ^ checked-methods ] .
146
141
147
142
It is recommended that explicit wrapping methods such as ` wrapping_add ` be used
148
143
when wrapping semantics are intended, and that explicit checking and wrapping
149
144
methods always be used when using Unsafe Rust.
150
145
151
- <small id =" fn:2 " >2\. See [ the ` u32 ` docs] ( ../std/primitive.u32.html ) for more
152
- information on the checked, overflowing, saturating, and wrapping methods
153
- (using u32 as an example). <a href="#fnref:2" class="reversefootnote"
154
- role="doc-backlink">↩</a ></small >
155
-
146
+ [ ^ checked-methods ] : See [ the ` u32 ` docs] ( ../std/primitive.u32.html ) for more
147
+ information on the checked, overflowing, saturating, and wrapping methods
148
+ (using u32 as an example).
156
149
157
150
### Non-executable memory regions
158
151
@@ -180,17 +173,14 @@ binary.
180
173
181
174
The presence of an element of type ` PT_GNU_STACK ` in the program header table
182
175
with the ` PF_X ` (i.e., executable) flag unset indicates non-executable memory
183
- regions<sup id =" fnref:3 " role =" doc-noteref " ><a href="#fn:3"
184
- class="footnote">3</a ></sup > are enabled for a given binary (see Fig. 5).
176
+ regions[ ^ other-regions ] are enabled for a given binary (see Fig. 5).
185
177
Conversely, the presence of an element of type ` PT_GNU_STACK ` in the program
186
178
header table with the ` PF_X ` flag set or the absence of an element of type
187
179
` PT_GNU_STACK ` in the program header table indicates non-executable memory
188
180
regions are not enabled for a given binary.
189
181
190
- <small id =" fn:3 " >3\. See the Appendix section for more information on why it
191
- affects other memory regions besides the stack. <a href="#fnref:3"
192
- class="reversefootnote" role="doc-backlink">↩</a ></small >
193
-
182
+ [ ^ other-regions ] : See the [ Appendix section] ( #appendix ) for more information
183
+ on why it affects other memory regions besides the stack.
194
184
195
185
### Stack clashing protection
196
186
@@ -270,8 +260,7 @@ $ readelf -d target/release/hello-rust | grep BIND_NOW
270
260
Fig. 10. Checking if immediate binding is enabled for a given binary.
271
261
272
262
The presence of an element with the ` DT_BIND_NOW ` tag and the ` DF_BIND_NOW `
273
- flag<sup id =" fnref:4 " role =" doc-noteref " ><a href="#fn:4"
274
- class="footnote">4</a ></sup > in the dynamic section indicates immediate binding
263
+ flag[ ^ bind-now ] in the dynamic section indicates immediate binding
275
264
is enabled for a given binary (see Fig. 10). Conversely, the absence of an
276
265
element with the ` DT_BIND_NOW ` tag and the ` DF_BIND_NOW ` flag in the dynamic
277
266
section indicates immediate binding is not enabled for a given binary.
@@ -281,9 +270,7 @@ table and of an element with the `DT_BIND_NOW` tag and the `DF_BIND_NOW` flag
281
270
in the dynamic section indicates full RELRO is enabled for a given binary (see
282
271
Figs. 9–10).
283
272
284
- <small id =" fn:4 " >4\. And the ` DF_1_NOW ` flag for some link editors. <a
285
- href="#fnref:4" class="reversefootnote" role="doc-backlink">↩</a ></small >
286
-
273
+ [ ^ bind-now ] : And the ` DF_1_NOW ` flag for some link editors.
287
274
288
275
### Heap corruption protection
289
276
@@ -303,8 +290,7 @@ Rust’s default allocator has historically been
303
290
[ jemalloc] ( http://jemalloc.net/ ) , and it has long been the cause of issues and
304
291
the subject of much discussion[ 32] –[ 38] . Consequently, it has been removed as
305
292
the default allocator in favor of the operating system’s standard C library
306
- default allocator<sup id =" fnref:5 " role =" doc-noteref " ><a href="#fn:5"
307
- class="footnote">5</a ></sup > since version 1.32.0 (2019-01-17)[ 39] .
293
+ default allocator[ ^ linx-allocator ] since version 1.32.0 (2019-01-17)[ 39] .
308
294
309
295
``` rust,no_run
310
296
fn main() {
@@ -343,11 +329,9 @@ Fig. 13. Build and execution of hello-rust-heap with debug assertions disabled
343
329
Heap corruption checks are performed when using the default allocator (i.e.,
344
330
the GNU Allocator) (see Figs. 12–13).
345
331
346
- <small id =" fn:5 " >5\. Linux's standard C library default allocator is the GNU
347
- Allocator, which is derived from ptmalloc (pthreads malloc) by Wolfram Gloger,
348
- which in turn is derived from dlmalloc (Doug Lea malloc) by Doug Lea. <a
349
- href="#fnref:5" class="reversefootnote" role="doc-backlink">↩</a ></small >
350
-
332
+ [ ^ linx-allocator ] : Linux's standard C library default allocator is the GNU
333
+ Allocator, which is derived from ptmalloc (pthreads malloc) by Wolfram Gloger,
334
+ which in turn is derived from dlmalloc (Doug Lea malloc) by Doug Lea.
351
335
352
336
### Stack smashing protection
353
337
@@ -385,8 +369,7 @@ commercially available [grsecurity/PaX Reuse Attack Protector
385
369
(RAP)] ( https://grsecurity.net/rap_faq ) .
386
370
387
371
The Rust compiler supports forward-edge control flow protection on nightly
388
- builds[ 41] -[ 42] <sup id =" fnref:6 " role =" doc-noteref " ><a href="#fn:6"
389
- class="footnote">6</a ></sup >.
372
+ builds[ 41] -[ 42] [ ^ win-cfg ] .
390
373
391
374
``` text
392
375
$ readelf -s -W target/release/hello-rust | grep "\.cfi"
@@ -401,10 +384,8 @@ of symbols suffixed with ".cfi" or the `__cfi_init` symbol (and references to
401
384
` __cfi_check ` ) indicates that LLVM CFI is not enabled for a given binary (see
402
385
Fig. 15).
403
386
404
- <small id =" fn:6 " >6\. It also supports Control Flow Guard (CFG) on Windows (see
405
- < https://github.com/rust-lang/rust/issues/68793 > ). <a href="#fnref:6"
406
- class="reversefootnote" role="doc-backlink">↩</a ></small >
407
-
387
+ [ ^ win-cfg ] : It also supports Control Flow Guard (CFG) on Windows (see
388
+ < https://github.com/rust-lang/rust/issues/68793 > ).
408
389
409
390
### Backward-edge control flow protection
410
391
@@ -431,8 +412,7 @@ Newer processors provide hardware assistance for backward-edge control flow
431
412
protection, such as ARM Pointer Authentication, and Intel Shadow Stack as part
432
413
of Intel CET.
433
414
434
- The Rust compiler supports shadow stack for the AArch64 architecture<sup
435
- id="fnref:7" role="doc-noteref"><a href =" #fn:7 " class =" footnote " >7</a ></sup >on
415
+ The Rust compiler supports shadow stack for the AArch64 architecture[ ^ amd64-shadow ] on
436
416
nightly builds[ 43] -[ 44] , and also supports safe stack on nightly
437
417
builds[ 45] -[ 46] .
438
418
@@ -447,9 +427,8 @@ enabled for a given binary. Conversely, the absence of the `__safestack_init`
447
427
symbol indicates that LLVM SafeStack is not enabled for a given binary (see
448
428
Fig. 16).
449
429
450
- <small id =" fn:7 " >7\. The shadow stack implementation for the AMD64 architecture
451
- and equivalent in LLVM was removed due to performance and security issues. <a
452
- href="#fnref:7" class="reversefootnote" role="doc-backlink">↩</a ></small >
430
+ [ ^ amd64-shadow ] : The shadow stack implementation for the AMD64 architecture
431
+ and equivalent in LLVM was removed due to performance and security issues.
453
432
454
433
455
434
## Appendix
0 commit comments