Verifying the seL4 Microkernel Formal Proof in Mathematics and - - PowerPoint PPT Presentation

verifying the sel4 microkernel
SMART_READER_LITE
LIVE PREVIEW

Verifying the seL4 Microkernel Formal Proof in Mathematics and - - PowerPoint PPT Presentation

Verifying the seL4 Microkernel Formal Proof in Mathematics and Computer Science Lukas Stevens 21st June 2018 Outline 2. Design process of seL4 3. Formal methods of the correctness proof 4. Layers of the correctness proof 5. Conclusion 1 1.


slide-1
SLIDE 1

Verifying the seL4 Microkernel

Formal Proof in Mathematics and Computer Science

Lukas Stevens 21st June 2018

slide-2
SLIDE 2

Outline

  • 1. What is a µ-kernel?
  • 2. Design process of seL4
  • 3. Formal methods of the correctness proof
  • 4. Layers of the correctness proof
  • 5. Conclusion

1

slide-3
SLIDE 3

What is a µ-kernel?

slide-4
SLIDE 4

What is a kernel anyway?

  • Necessary abstractions for applications
  • Interaction via system calls
  • Loaded into protected memory region

Bugs are potentially fatal

2

slide-5
SLIDE 5

What is a kernel anyway?

  • Necessary abstractions for applications
  • Interaction via system calls
  • Loaded into protected memory region

Bugs are potentially fatal

2

slide-6
SLIDE 6

What is a kernel anyway?

  • Necessary abstractions for applications
  • Interaction via system calls
  • Loaded into protected memory region

Bugs are potentially fatal

2

slide-7
SLIDE 7

What is a kernel anyway?

  • Necessary abstractions for applications
  • Interaction via system calls
  • Loaded into protected memory region

Bugs are potentially fatal

2

slide-8
SLIDE 8

What is a kernel anyway?

  • Necessary abstractions for applications
  • Interaction via system calls
  • Loaded into protected memory region

⇒ Bugs are potentially fatal

2

slide-9
SLIDE 9

Defjnition: Microkernel

A concept is tolerated inside the µ-kernel only if mov- ing it outside the kernel, i.e. permitting competing implementations, would prevent the implementation

  • f the system’s required functionality.

— Jochen Liedtke

3

slide-10
SLIDE 10

Monolithic kernels and µ-kernels

Device Drivers File System IPC, Virtual Memory, Scheduling etc. Basic IPC, Virtual Memory, Scheduling UNIX- Server Device Drivers File System Application IPC Applications Hardware Hardware

OS based on Monolithic Kernel OS based on Microkernel

Applications User Mode Kernel mode

4

slide-11
SLIDE 11

The seL4 µ-kernel

  • Member of the L4
  • kernel family
  • Correctness verifjed with Isabelle
  • High performance

5

slide-12
SLIDE 12

The seL4 µ-kernel

  • Member of the L4 µ-kernel family
  • Correctness verifjed with Isabelle
  • High performance

5

slide-13
SLIDE 13

The seL4 µ-kernel

  • Member of the L4 µ-kernel family
  • Correctness verifjed with Isabelle
  • High performance

5

slide-14
SLIDE 14

The seL4 µ-kernel

  • Member of the L4 µ-kernel family
  • Correctness verifjed with Isabelle
  • High performance

5

slide-15
SLIDE 15

Design process of seL4

slide-16
SLIDE 16

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-17
SLIDE 17

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-18
SLIDE 18

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-19
SLIDE 19

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-20
SLIDE 20

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-21
SLIDE 21

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-22
SLIDE 22

Design process for verifjcation

Requirements Haskell Prototype Executable Specifjcation Abstract Specifjcation C imple- mentation Proof Proof Implementation Implementation Design Improvement Automatic Translation Stage 1 Stage 2 6

slide-23
SLIDE 23

Formal methods of the correctness proof

slide-24
SLIDE 24

Hoare logic

P {x = 1} C

  • x := x + 1

Q {x = 2}

7

slide-25
SLIDE 25

More Hoare logic

{x = 0 ∧ x = 1} y := 2 ∗ x { x and y are even }

8

slide-26
SLIDE 26

More Hoare logic

{x is even} y := 2 ∗ x { x and y are even }

8

slide-27
SLIDE 27

More Hoare logic

{x is even} y := 2 ∗ x {x and y are even}

8

slide-28
SLIDE 28

Partial correctness of Hoare logic

{ } WHILE true DO c { }

9

slide-29
SLIDE 29

Data refjnement

A concrete system C refjnes an abstract specifjcation A if the behaviour of C is contained in that of A.

10

slide-30
SLIDE 30

Data refjnement

A concrete system C refjnes an abstract specifjcation A if the behaviour of C is contained in that of A.

10

slide-31
SLIDE 31

Data refjnement: Examples

  • The scheduler selects runnable threads
  • System calls return non-zero values on error

11

slide-32
SLIDE 32

Layers of the correctness proof

slide-33
SLIDE 33

Proof structure

Executable Specifjcation Abstract Specifjcation C implementation (Semantics) Haskell prototype C implementation Isabelle/HOL Proof Automatic translation

12

slide-34
SLIDE 34

Abstract specifjcation

The abstract specifjcation is the most high-level layer still fully encapturing the behaviour of the kernel.

13

slide-35
SLIDE 35

Scheduler on the abstract level

schedule ≡ do threads ← all_active_tcbs; thread ← select threads; switch_to_thread thread

  • d OR switch_to_idle_thread

14

slide-36
SLIDE 36

Executable specifjcation

Fill in the details left open by the abstract specifjcation.

15

slide-37
SLIDE 37

Haskell implementation of the scheduler

schedule = do action <- getSchedulerAction case action of ChooseNewThread -> do chooseThread setSchedulerAction ResumeCurrentThread ... chooseThread = do r <- findM chooseThread' (reverse [minBound .. maxBound]) when (r == Nothing) $ switchToIdleThread chooseThread' prio = do q <- getQueue prio liftM isJust $ findM chooseThread'' q chooseThread'' thread = do runnable <- isRunnable thread if not runnable then do tcbSchedDequeue thread return False else do switchToThread thread return True

Get runnable thread with highest priority using chooseThread' or schedule idle thread. Call chooseThread to select next thread. Try to fjnd runnable thread in Queue. Check if thread is runnable and act accordingly.

16

slide-38
SLIDE 38

Haskell implementation of the scheduler

schedule = do action <- getSchedulerAction case action of ChooseNewThread -> do chooseThread setSchedulerAction ResumeCurrentThread ... chooseThread = do r <- findM chooseThread' (reverse [minBound .. maxBound]) when (r == Nothing) $ switchToIdleThread chooseThread' prio = do q <- getQueue prio liftM isJust $ findM chooseThread'' q chooseThread'' thread = do runnable <- isRunnable thread if not runnable then do tcbSchedDequeue thread return False else do switchToThread thread return True

Get runnable thread with highest priority using chooseThread' or schedule idle thread. Call chooseThread to select next thread. Try to fjnd runnable thread in Queue. Check if thread is runnable and act accordingly.

16

slide-39
SLIDE 39

Haskell implementation of the scheduler

schedule = do action <- getSchedulerAction case action of ChooseNewThread -> do chooseThread setSchedulerAction ResumeCurrentThread ... chooseThread = do r <- findM chooseThread' (reverse [minBound .. maxBound]) when (r == Nothing) $ switchToIdleThread chooseThread' prio = do q <- getQueue prio liftM isJust $ findM chooseThread'' q chooseThread'' thread = do runnable <- isRunnable thread if not runnable then do tcbSchedDequeue thread return False else do switchToThread thread return True

Get runnable thread with highest priority using chooseThread' or schedule idle thread. Call chooseThread to select next thread. Try to fjnd runnable thread in Queue. Check if thread is runnable and act accordingly.

16

slide-40
SLIDE 40

Haskell implementation of the scheduler

schedule = do action <- getSchedulerAction case action of ChooseNewThread -> do chooseThread setSchedulerAction ResumeCurrentThread ... chooseThread = do r <- findM chooseThread' (reverse [minBound .. maxBound]) when (r == Nothing) $ switchToIdleThread chooseThread' prio = do q <- getQueue prio liftM isJust $ findM chooseThread'' q chooseThread'' thread = do runnable <- isRunnable thread if not runnable then do tcbSchedDequeue thread return False else do switchToThread thread return True

Get runnable thread with highest priority using chooseThread' or schedule idle thread. Call chooseThread to select next thread. Try to fjnd runnable thread in Queue. Check if thread is runnable and act accordingly.

16

slide-41
SLIDE 41

Haskell implementation of the scheduler

schedule = do action <- getSchedulerAction case action of ChooseNewThread -> do chooseThread setSchedulerAction ResumeCurrentThread ... chooseThread = do r <- findM chooseThread' (reverse [minBound .. maxBound]) when (r == Nothing) $ switchToIdleThread chooseThread' prio = do q <- getQueue prio liftM isJust $ findM chooseThread'' q chooseThread'' thread = do runnable <- isRunnable thread if not runnable then do tcbSchedDequeue thread return False else do switchToThread thread return True

Get runnable thread with highest priority using chooseThread' or schedule idle thread. Call chooseThread to select next thread. Try to fjnd runnable thread in Queue. Check if thread is runnable and act accordingly.

16

slide-42
SLIDE 42

C implementation

Translate the Haskell implementation to C.

17

slide-43
SLIDE 43

Machine Model

invalidateTLB :: unit machine_m => unit machine_m invalidateCacheRange :: unit machine_m => word => word => unit machine_m

18

slide-44
SLIDE 44

Data refjnement for state machines

σ1 σ2 σn s1 s2 sn · · · Abstract operations in M1 State relation State relation · · · Concrete operations in M2

19

slide-45
SLIDE 45

Data refjnement for state machines

σ1 σ2 σn s1 s2 sn · · · Abstract operations in M1 State relation State relation · · · Concrete operations in M2

19

slide-46
SLIDE 46

Data refjnement for state machines

σ1 σ2 σn s1 s2 sn · · · Abstract operations in M1 State relation State relation · · · Concrete operations in M2

19

slide-47
SLIDE 47

Data refjnement for state machines

σ1 σ2 σn s1 s2 sn · · · Abstract operations in M1 State relation State relation · · · Concrete operations in M2

19

slide-48
SLIDE 48

Refjnement by forward simulation

σ σ′ s s′

State Relation State Relation Abstract Operation in M1 Concrete Operation in M2

20

slide-49
SLIDE 49

Example for forward simulation

On the Board

21

slide-50
SLIDE 50

Types of state transitions

Kernel Mode User Mode Idle Mode

22

slide-51
SLIDE 51

Main result

MA ME MC refjnes refjnes refjnes

23

slide-52
SLIDE 52

Main result

MA ME MC refjnes refjnes refjnes

23

slide-53
SLIDE 53

Main result

MA ME MC refjnes refjnes refjnes

23

slide-54
SLIDE 54

Conclusion

slide-55
SLIDE 55

Expenditure of time

Artefact Efgort (py) Total (py) Haskell impl. 2.0 2.2 C impl. 0.2 Generic framework 9.0 20.5 Abstract spec. 0.3 Executable spec. 0.2 Refjnement MA ↔ ME 8.0 Refjnement ME ↔ MC 3.0

24

slide-56
SLIDE 56

How does the efgort compare?

  • EAL7: 1000$/LOC

seL4: 370$/LOC

  • L4 Pistachio kernel: 6 py

seL4 kernel: 2.2 py

25

slide-57
SLIDE 57

How does the efgort compare?

  • EAL7: 1000$/LOC ↔ seL4: 370$/LOC
  • L4 Pistachio kernel: 6 py

seL4 kernel: 2.2 py

25

slide-58
SLIDE 58

How does the efgort compare?

  • EAL7: 1000$/LOC ↔ seL4: 370$/LOC
  • L4 Pistachio kernel: 6 py ↔ seL4 kernel: 2.2 py

25

slide-59
SLIDE 59

Changes due to verifjcation

100 200 300 400 500 600 C Spec 16 54 34 144 44 250 250 Bugs VC Bugs VC Bugs Refjnement 1 Refjnement 2 Testing

26

slide-60
SLIDE 60

What was achieved?

  • Correctness proof down to binary level
  • Trust in hardware
  • What about Spectre and Meltdown?

27

slide-61
SLIDE 61

What was achieved?

  • Correctness proof down to binary level
  • Trust in hardware
  • What about Spectre and Meltdown?

27

slide-62
SLIDE 62

The future of seL4

  • More architectures
  • Multicore support
  • Exclude timing-channel attacks

28

slide-63
SLIDE 63

The future of seL4

  • More architectures
  • Multicore support
  • Exclude timing-channel attacks

28

slide-64
SLIDE 64

Questions?

28