rust
play

Rust In It for the Long Haul Carol (Nichols || Goulding) - PowerPoint PPT Presentation

Rust In It for the Long Haul Carol (Nichols || Goulding) @carols10cents is.gd/rustLH Online Print Manning liveVideo Integer 32 Rust Core Team (yep, Im biased) Plan Railroad industry C Rust What the software


  1. Rust In It for the Long Haul Carol (Nichols || Goulding) @carols10cents

  2. is.gd/rustLH

  3. • Online • Print

  4. Manning liveVideo

  5. Integer 32

  6. Rust Core Team

  7. (yep, I’m biased)

  8. Plan • Railroad industry • C • Rust • What the software industry can learn from the railroad industry

  9. Plan ➡ Railroad industry • C • Rust • What the software industry can learn from the railroad industry

  10. 1830

  11. Miles of Rail in the US 140,000 105,000 70,000 35,000 0 1840 1850 1860 1870 1880 1890 Wikipedia

  12. Brakeman Engraving by Peckwell Published 1890 in The Railroad Conductor Public Domain in the US, Wikipedia

  13. George Westinghouse Photo: public domain in the US, Wikipedia

  14. Air Brakes • Compressed air • Controls in the locomotive • Air lines connecting all cars • Apply brakes all at once • Brakes on when there’s no pressure

  15. “Do you pretend to tell me that you could stop trains with air?” – Cornelius Vanderbilt, owner of the New York Central Railroad

  16. Ad in 1936 Railway Age Public Domain in the US, Wikipedia

  17. “The swift operation of these nightly carriers is safeguarded by Westinghouse Air Brakes” Ad in 1936 Railway Age Public Domain in the US, Wikipedia

  18. “They thought it was a necessity somehow, that it occurred as a matter of course, that some men had to be killed.” –L.S. Co ffi n, Iowa Railroad Commissioner, Senate Hearing, 1890

  19. “If you are going to subject the railroad companies to this class of supervision, then you might as well go into the character of bridges, which is as serious a question as we have to deal with, and say that the bridges must conform to such and such standards.” –Mr. Roberts, President of the Pennsylvania Railroad Company, Senate Hearing, 1890

  20. 1893 US Railroad Safety Appliance Act

  21. 1900 Act fully enforced

  22. Not perfect; Vast improvement

  23. Plan • Railroad industry ➡ C • Rust • What the software industry can learn from the railroad industry

  24. why C?

  25. performance 👎

  26. portability 👎

  27. simplicity 👎

  28. legacy code 👎

  29. stability 👎

  30. memory unsafety 👏👏👏👏👏👏👏

  31. Memory Safety Problems • Use after free • Double free • Memory leaks • Bu ff er overreads/overwrites • Null pointers • Data races

  32. Memory Safety Problems • Use after free 😲 • Double free • Memory leaks • Bu ff er overreads/overwrites • Null pointers • Data races

  33. “The best way to prevent these kinds of attacks is either to use a higher level language, which manages memory for you (albeit with less performance), or to be very, very, very, very careful when coding. More careful than the entirety of the Android security team, for sure.” -Pulser_G2, A Demonstration of Stagefright-like Mistakes

  34. “Around 70 percent of all the vulnerabilities in Microsoft products addressed through a security update each year are memory safety issues” –Catalin Cimpanu reporting on a presentation by Matt Miller, MS security engineer. ZDNet, 2019-02-11

  35. Efforts to make C safer

  36. valgrind

  37. ASAN

  38. UBSAN

  39. IKOS

  40. MISRA

  41. Write code THEN make it safe

  42. Safe-C, Checked C

  43. C++

  44. Plan • Railroad industry • C ➡ Rust • What the software industry can learn from the railroad industry

  45. Rust

  46. #1: Fixes common memory safety problems

  47. Ownership Borrowing

  48. fn main() { let x = String::from("hi"); println!("{}", x); }

  49. Allocates memory fn main() { let x = String::from("hi"); println!("{}", x); }

  50. Allocates memory fn main() { Owner let x = String::from("hi"); println!("{}", x); }

  51. Allocates memory fn main() { Owner let x = String::from("hi"); println!("{}", x); } Owner goes out of scope, memory is cleaned up

  52. fn main() { let x = String::from("hi"); let y = x; println!("{}", x); }

  53. fn main() { let x = String::from("hi"); let y = x; Moves ownership println!("{}", x); }

  54. error[E0382]: borrow of moved value: `x` fn main() { let x = String::from("hi"); let y = x; - value moved here println!("{}", x); ^ value borrowed } here after move

  55. fn main() { let x = String::from("hi"); let y = &x; println!("{}", x); }

  56. fn main() { let x = String::from("hi"); let y = &x; Immutable borrow println!("{}", x); }

  57. fn main() { let x = String::from("hi"); let y = &x; println!("{}", x); println!("{}", y); }

  58. fn main() { let y = { let x = String::from("hi"); &x }; println!("{}", y); }

  59. fn main() { let y = { let x = String::from("hi"); Returning a reference &x }; println!("{}", y); }

  60. fn main() { let y = { let x = String::from("hi"); Returning a reference &x x is cleaned up }; println!("{}", y); }

  61. error[E0597]: `x` does not live long enough --> src/main.rs:4:9 | 2 | let y = { | - borrow later stored here 3 | let x = String::from("hi"); 4 | &x | ^^ borrowed value does not live long enough 5 | }; | - `x` dropped here while still borrowed

  62. Rust Safety • Either one mutable reference OR many immutable references • No null, only Option • Out-of-bounds access = at runtime, program stops • Ownership rules apply across multiple threads

  63. Computers are good at tedium. ⚠ Beep, boop. You forgot a semicolon in 23,982 places

  64. #2: Systems programming is for superhumans everyone

  65. unsafe

  66. Unsafe code can… • Dereference a raw pointer • Call an unsafe function • Implement unsafe traits • Mutate global variables • Access fields of unions

  67. 👌 Look here for the cause of memory problems! 👌

  68. Opt OUT

  69. Further unsafe Info • Building on an Unsafe Foundation - Jason Orendor ff , RBR 2018 • The Rustonomicon

  70. Logic bugs

  71. Tests

  72. Fuzzers

  73. memory safety 👎 👎

  74. performance 👎

  75. portability 👎👏

  76. simplicity 👏

  77. legacy code 👎

  78. legacy code My "Rust out your C" Talk

  79. stability 👎

  80. * stability 👎 *We reserve the right to fix compiler bugs, patch safety holes, and change type inference in ways that may occasionally require new type annotations. We do not expect any of these changes to cause headaches when upgrading Rust. (more detailed documentation)

  81. Has upgrading broken your code? Yes - 7.4% No - 92.6%

  82. #3: stability without stagnation

  83. Editions

  84. Source code

  85. Source HIR code

  86. Source HIR MIR code

  87. Source LLVM HIR MIR code IR

  88. Source LLVM Machine HIR MIR code IR code

  89. Source LLVM Machine HIR MIR code IR code Borrow checking, Optimizations, Code generation

  90. 2015 Edition Source HIR Code LLVM Machine MIR IR Code HIR 2018 Edition Borrow Checking, Source Optimizations, Code Code Generation

  91. No ecosystem split!!! Rust 2015 Rust 2018 Project Library Rust 2018 Rust 2015 Project Library

  92. You pick when to switch editions (never is totally fine!)

  93. rustfix

  94. X Rust 2.0

  95. // TODO • ISO/ECMA Standard • Compiler certification • LTS Release • Better cargo/build system integration • Private crate hosting • Improved ecosystem

  96. #4: Large Enterprises are using Rust

  97. Mozilla

  98. CSS Component Implications of Rewriting a Browser Component in Rust By Diane Hosfelt, 2019-02-28

  99. CSS Component • Security bugs since Firefox started: 69 Implications of Rewriting a Browser Component in Rust By Diane Hosfelt, 2019-02-28

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend