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

rust
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Rust

In It for the Long Haul

Carol (Nichols || Goulding) @carols10cents
slide-2
SLIDE 2

is.gd/rustLH

slide-3
SLIDE 3
  • Online
  • Print
slide-4
SLIDE 4

Manning liveVideo

slide-5
SLIDE 5

Integer 32

slide-6
SLIDE 6

Rust Core Team

slide-7
SLIDE 7

(yep, I’m biased)

slide-8
SLIDE 8
slide-9
SLIDE 9

Plan

  • Railroad industry
  • C
  • Rust
  • What the software industry can
learn from the railroad industry
slide-10
SLIDE 10

Plan

➡ Railroad industry

  • C
  • Rust
  • What the software industry can
learn from the railroad industry
slide-11
SLIDE 11

1830

slide-12
SLIDE 12

Miles of Rail in the US

35,000 70,000 105,000 140,000 1840 1850 1860 1870 1880 1890 Wikipedia
slide-13
SLIDE 13

Brakeman

Engraving by Peckwell Published 1890 in The Railroad Conductor Public Domain in the US, Wikipedia
slide-14
SLIDE 14

George Westinghouse

Photo: public domain in the US, Wikipedia
slide-15
SLIDE 15

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
slide-16
SLIDE 16 – Cornelius Vanderbilt, owner of the New York Central Railroad

“Do you pretend to tell me that you could stop trains with air?”

slide-17
SLIDE 17 Ad in 1936 Railway Age Public Domain in the US, Wikipedia
slide-18
SLIDE 18 Ad in 1936 Railway Age Public Domain in the US, Wikipedia “The swift operation of these nightly carriers is safeguarded by Westinghouse Air Brakes”
slide-19
SLIDE 19 –L.S. Coffin, Iowa Railroad Commissioner, Senate Hearing, 1890 “They thought it was a necessity somehow, that it occurred as a matter of course, that some men had to be killed.”
slide-20
SLIDE 20 –Mr. Roberts, President of the Pennsylvania Railroad Company, Senate Hearing, 1890 “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.”
slide-21
SLIDE 21

US Railroad Safety Appliance Act

1893

slide-22
SLIDE 22

Act fully enforced

1900

slide-23
SLIDE 23

Not perfect; Vast improvement

slide-24
SLIDE 24

Plan

  • Railroad industry

➡ C

  • Rust
  • What the software industry can
learn from the railroad industry
slide-25
SLIDE 25

why C?

slide-26
SLIDE 26

performance

👎

slide-27
SLIDE 27

portability

👎

slide-28
SLIDE 28

simplicity

👎

slide-29
SLIDE 29

legacy code

👎

slide-30
SLIDE 30

stability

👎

slide-31
SLIDE 31

memory unsafety

👏👏👏👏👏👏👏

slide-32
SLIDE 32

Memory Safety Problems

  • Use after free
  • Double free
  • Memory leaks
  • Buffer overreads/overwrites
  • Null pointers
  • Data races
slide-33
SLIDE 33

Memory Safety Problems

  • Use after free
  • Double free
  • Memory leaks
  • Buffer overreads/overwrites
  • Null pointers
  • Data races

😲

slide-34
SLIDE 34
  • Pulser_G2, A Demonstration of Stagefright-like Mistakes
“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.”
slide-35
SLIDE 35 –Catalin Cimpanu reporting on a presentation by Matt Miller, MS security
  • engineer. ZDNet, 2019-02-11
“Around 70 percent of all the vulnerabilities in Microsoft products addressed through a security update each year are memory safety issues”
slide-36
SLIDE 36

Efforts to make C safer

slide-37
SLIDE 37

valgrind

slide-38
SLIDE 38

ASAN

slide-39
SLIDE 39

UBSAN

slide-40
SLIDE 40

IKOS

slide-41
SLIDE 41

MISRA

slide-42
SLIDE 42

Write code THEN make it safe

slide-43
SLIDE 43

Safe-C, Checked C

slide-44
SLIDE 44

C++

slide-45
SLIDE 45

Plan

  • Railroad industry
  • C

➡ Rust

  • What the software industry can
learn from the railroad industry
slide-46
SLIDE 46

Rust

slide-47
SLIDE 47

#1: Fixes common memory safety problems

slide-48
SLIDE 48

Ownership Borrowing

slide-49
SLIDE 49 fn main() { let x = String::from("hi"); println!("{}", x); }
slide-50
SLIDE 50 fn main() { let x = String::from("hi"); println!("{}", x); } Allocates memory
slide-51
SLIDE 51 fn main() { let x = String::from("hi"); println!("{}", x); } Allocates memory Owner
slide-52
SLIDE 52 fn main() { let x = String::from("hi"); println!("{}", x); } Allocates memory Owner Owner goes out of scope, memory is cleaned up
slide-53
SLIDE 53 fn main() { let x = String::from("hi"); let y = x; println!("{}", x); }
slide-54
SLIDE 54 fn main() { let x = String::from("hi"); let y = x; println!("{}", x); } Moves ownership
slide-55
SLIDE 55 fn main() { let x = String::from("hi"); let y = x; println!("{}", x); } error[E0382]: borrow of moved value: `x`
  • value moved here
^ value borrowed here after move
slide-56
SLIDE 56 fn main() { let x = String::from("hi"); let y = &x; println!("{}", x); }
slide-57
SLIDE 57 fn main() { let x = String::from("hi"); let y = &x; println!("{}", x); } Immutable borrow
slide-58
SLIDE 58 fn main() { let x = String::from("hi"); let y = &x; println!("{}", x); println!("{}", y); }
slide-59
SLIDE 59 fn main() { let y = { let x = String::from("hi"); &x }; println!("{}", y); }
slide-60
SLIDE 60 fn main() { let y = { let x = String::from("hi"); &x }; println!("{}", y); } Returning a reference
slide-61
SLIDE 61 fn main() { let y = { let x = String::from("hi"); &x }; println!("{}", y); } Returning a reference x is cleaned up
slide-62
SLIDE 62 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
slide-63
SLIDE 63

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
slide-64
SLIDE 64

Computers are good at tedium.

⚠ Beep, boop. You forgot a semicolon in 23,982 places
slide-65
SLIDE 65

#2: Systems programming is for superhumans everyone

slide-66
SLIDE 66

unsafe

slide-67
SLIDE 67

Unsafe code can…

  • Dereference a raw pointer
  • Call an unsafe function
  • Implement unsafe traits
  • Mutate global variables
  • Access fields of unions
slide-68
SLIDE 68

👌 Look here for the cause of memory problems! 👌

slide-69
SLIDE 69

Opt OUT

slide-70
SLIDE 70

Further unsafe Info

  • Building on an Unsafe Foundation -
Jason Orendorff, RBR 2018
  • The Rustonomicon
slide-71
SLIDE 71

Logic bugs

slide-72
SLIDE 72

Tests

slide-73
SLIDE 73

Fuzzers

slide-74
SLIDE 74

memory safety

👎 👎

slide-75
SLIDE 75

performance

👎

slide-76
SLIDE 76

portability

👎👏

slide-77
SLIDE 77

simplicity

👏

slide-78
SLIDE 78

legacy code

👎

slide-79
SLIDE 79

legacy code

My "Rust out your C" Talk

slide-80
SLIDE 80

stability

👎

slide-81
SLIDE 81

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)
slide-82
SLIDE 82

Has upgrading broken your code?

Yes - 7.4% No - 92.6%
slide-83
SLIDE 83

#3: stability without stagnation

slide-84
SLIDE 84

Editions

slide-85
SLIDE 85 Source code
slide-86
SLIDE 86 Source code HIR
slide-87
SLIDE 87 Source code HIR MIR
slide-88
SLIDE 88 Source code HIR MIR LLVM IR
slide-89
SLIDE 89 Source code HIR MIR LLVM IR Machine code
slide-90
SLIDE 90 Source code HIR MIR Borrow checking, Optimizations, Code generation LLVM IR Machine code
slide-91
SLIDE 91 2015 Edition Source Code HIR MIR Borrow Checking, Optimizations, Code Generation LLVM IR Machine Code 2018 Edition Source Code HIR
slide-92
SLIDE 92

No ecosystem split!!!

Rust 2015 Library Rust 2018 Library Rust 2018 Project Rust 2015 Project
slide-93
SLIDE 93

You pick when to switch editions

(never is totally fine!)
slide-94
SLIDE 94

rustfix

slide-95
SLIDE 95

Rust 2.0

X

slide-96
SLIDE 96

// TODO

  • ISO/ECMA Standard
  • Compiler certification
  • LTS Release
  • Better cargo/build system integration
  • Private crate hosting
  • Improved ecosystem
slide-97
SLIDE 97

#4: Large Enterprises are using Rust

slide-98
SLIDE 98

Mozilla

slide-99
SLIDE 99

CSS Component

Implications of Rewriting a Browser Component in Rust By Diane Hosfelt, 2019-02-28
slide-100
SLIDE 100

CSS Component

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

CSS Component

  • Security bugs since Firefox started: 69
  • Rust would have prevented: 51
Implications of Rewriting a Browser Component in Rust By Diane Hosfelt, 2019-02-28
slide-102
SLIDE 102

CSS Component

  • Security bugs since Firefox started: 69
  • Rust would have prevented: 51

73.9%

Implications of Rewriting a Browser Component in Rust By Diane Hosfelt, 2019-02-28
slide-103
SLIDE 103

AppAmaGooBookSoft

  • Apple
  • Amazon - Firecracker
  • Google - Fuchsia
  • Facebook - Mononoke
  • Microsoft - IoT Edge
slide-104
SLIDE 104

#5: Rust Governance

slide-105
SLIDE 105

No BDFL

slide-106
SLIDE 106

Teams and Working Groups

  • Programming language theorists and designers
  • Enterprise users
  • Hobby users
  • People from low-level languages
  • People from high-level languages
  • People from functional languages
slide-107
SLIDE 107

Decisions made via public RFCs

slide-108
SLIDE 108

Code of Conduct

slide-109
SLIDE 109

Rust’s staying power

  • Significant improvement in memory safety over the
status quo
  • More programmers can write and maintain it
  • Editions enable stability without stagnation
  • Large companies are depending on it
  • Governance set up to endure
slide-110
SLIDE 110

Plan

  • Railroad industry
  • C
  • Rust

➡ What the software industry can

learn from the railroad industry
slide-111
SLIDE 111

Silicon Valley arrogance

slide-112
SLIDE 112

Juicero shows what’s wrong with Silicon Valley thinking

–Christine Emba, Washington Post, 2017-04-24
slide-113
SLIDE 113

The Lyft Shuttle is pretty much a glorified city bus — with fewer poor people

–Keith Spencer, Salon, 2017-06-19
slide-114
SLIDE 114 –Nick Allen, The Telegraph, 2018-07-14

Elon Musk ‘can stick his submarine where it hurts’ says British diver who helped Thai cave rescue

slide-115
SLIDE 115

Trains not stopping = people dying

slide-116
SLIDE 116

Memory unsafety?? = ???

slide-117
SLIDE 117

Actual Consequences

slide-118
SLIDE 118

Actual Consequences

WannaCry Ransomware May 2017

slide-119
SLIDE 119

Actual Consequences

slide-120
SLIDE 120

Actual Consequences

+ =

X

slide-121
SLIDE 121

Actual Consequences

+ =

X

slide-122
SLIDE 122

Actual Consequences

+ =

X X

slide-123
SLIDE 123

Actual Consequences

+ =

Images from Shastry, Eucalyp, and Maxim Kulikov via the Noun Project

X X

people dying

slide-124
SLIDE 124 July 17, 2019 House Financial Services Committee Hearing on Facebook’s Libra Cryptocurrency
slide-125
SLIDE 125 July 17, 2019 House Financial Services Committee Hearing on Facebook’s Libra Cryptocurrency Congressman Riggleman
  • f Virginia
slide-126
SLIDE 126 July 17, 2019 House Financial Services Committee Hearing on Facebook’s Libra Cryptocurrency Congressman Riggleman
  • f Virginia
David Marcus Head of Calibra at Facebook
slide-127
SLIDE 127
slide-128
SLIDE 128

Not the norm!!!

slide-129
SLIDE 129

We are our own informed consumers

slide-130
SLIDE 130

1830 -> 1869 -> 1900

39 years 31 years
slide-131
SLIDE 131

1973 -> 2015 -> ????

42 years ?? years
slide-132
SLIDE 132

Are we better?

slide-133
SLIDE 133

Rust

In It for the Long Haul

slide-134
SLIDE 134

Rust

In It for the Long Haul???

slide-135
SLIDE 135

I could be wrong!

slide-136
SLIDE 136
slide-137
SLIDE 137
slide-138
SLIDE 138

Why not all of them? 🤸

slide-139
SLIDE 139

new mistakes!

slide-140
SLIDE 140

50% off Rust in Motion course at manning.com: tsrust

is.gd/rustLH @carols10cents