Top Banner
Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson, Kaiyuan Zhang, Dylan Johnson, James Bornholt, Emina Torlak, and Xi Wang
57

Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Mar 20, 2019

Download

Documents

hoangdien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Hyperkernel: Push-Button Verification of an OS Kernel

Luke Nelson, Helgi Sigurbjarnarson, Kaiyuan Zhang, Dylan Johnson,

James Bornholt, Emina Torlak, and Xi Wang

Page 2: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The OS Kernel is a critical component

• Essential for application correctness and security

• Kernel bugs can compromise the entire system

Kernel

App App App

Page 3: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,
Page 4: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,
Page 5: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Formal verification: high correctness assurance

• Write a spec of expected behavior

• Prove that implementation matches the spec

• Goal: How much can we minimize the proof burden

IronClad

Page 6: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Formal verification: high correctness assurance

• Write a spec of expected behavior

• Prove that implementation matches the spec

• Goal: How much can we minimize the proof burden

IronCladProof effort: 11 person years

Page 7: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Our result: Hyperkernel

• Unix-like OS kernel: based on xv6

• Fully automated verification using the Z3 solver• Functional correctness of system calls

• Crosscutting properties (e.g., process isolation)

• Limitations: • Uniprocessor

• Initialization & glue code unverified

Page 8: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Designing Hyperkernel for proof automation

Xv6

• Syscall semantics are loop-y and require writing loop invariants

• Kernel pointers difficult to reason about

• C is difficult to model

Hyperkernel

• Finite interface

• Separate user and kernel spaces & identity mapping for the kernel

• Verify LLVM intermediate representation (IR)

Page 9: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Designing Hyperkernel for proof automation

Xv6

• Syscall semantics are loop-y and require writing loop invariants

• Kernel pointers difficult to reason about

• C is difficult to model

Hyperkernel

• Finite interface

• Separate user and kernel spaces & identity mapping for the kernel

• Verify LLVM intermediate representation (IR)

Page 10: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Designing Hyperkernel for proof automation

Xv6

• Syscall semantics are loop-y and require writing loop invariants

• Kernel pointers difficult to reason about

• C is difficult to model

Hyperkernel

• Finite interface

• Separate user/kernel spaces and use identity mapping for kernel

• Verify LLVM intermediate representation (IR)

Page 11: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Designing Hyperkernel for proof automation

Xv6

• Syscall semantics are loop-y and require writing loop invariants

• Kernel pointers difficult to reason about

• C is difficult to model

Hyperkernel

• Finite interface

• Separate user/kernel spaces and use identity mapping for kernel

• Verify LLVM intermediate representation (IR)

Page 12: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Designing Hyperkernel for proof automation

Xv6

• Syscall semantics are loop-y and require writing loop invariants

• Kernel pointers difficult to reason about

• C is difficult to model

Hyperkernel

• Finite interface

• Separate user/kernel spaces and use identity mapping for kernel

• Verify LLVM intermediate representation (IR)

Page 13: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Outline

• Verification workflow

• Finite interface design

• Demo

• Evaluation & lessons learned

Page 14: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Outline

• Verification workflow

• Finite interface design

• Demo

• Evaluation & lessons learned

Page 15: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

Page 16: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

pre

newold

Page 17: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

pre

newold

Page 18: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

pre

newold

Page 19: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

pre

newold

Page 20: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

pre

newold

Page 21: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

Verifier

LLVM

pre

newold

Page 22: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of verification workflow

Syscall Implementation

State Machine Specification

Verifier

Bug

Counterexample

old

LLVM

pre

newold

Page 23: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

Verifier

Bug

Counterexample

old

Declarative Specification

P

LLVM

State Machine Specification

pre

newold

Page 24: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

State Machine Specification

Verifier

Bug

Counterexample

old

Declarative Specification

P

LLVM

pre

newold

Page 25: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

Verifier

Counterexample

old

LLVM

State Machine Specification

pre

newold

Bug

Declarative Specification

P

Cross-cutting properties:• Correctness of reference counters• Scheduler safety property• Process Isolation

Page 26: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

Verifier

Counterexample

old

LLVM

State Machine Specification

pre

newold

Bug

Cross-cutting properties:• Correctness of reference counters• Scheduler safety property• Process Isolation

For any virtual address in a process p, if the virtual address maps to a page

the page must be exclusively owned by p.

Declarative Specification

P

Page 27: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

Verifier

Counterexample

old

LLVM

State Machine Specification

pre

newold

Bug

Cross-cutting properties:• Correctness of reference counters• Scheduler safety property• Process Isolation

For any virtual address in a process p, if the virtual address maps to a page

the page must be exclusively owned by p.

Declarative Specification

P

Page 28: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

State Machine Specification

Verifier

Bug

Counterexample

old

Declarative Specification

P

LLVM

pre

newold

Page 29: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Syscall Implementation

State Machine Specification

Verifier

LLVM

Bug

Counterexample

old

Declarative Specification

P

OK

Kernel Image

pre

newold

Page 30: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Outline

• Verification workflow

• Finite interface design

• Demo

• Evaluation & lessons learned

Page 31: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Verification through symbolic execution

• Goal: Minimize proof burden• No manual proofs or code annotations

• Symbolic execution• Fully automated technique, used in bug-finding

• Full functional verification if program is free of loops and state is finite

• Feasible when units of work sufficiently small for solving

• Hyperkernel approach: Finite interface design

Page 32: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of techniques

• Safely push loops into user space

• Explicit resource management

• Decompose complex syscalls

• Validate linked data structures

• Smart SMT encodings

Page 33: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Overview of techniques

• Safely push loops into user space

• Explicit resource management

• Decompose complex syscalls

• Validate linked data structures

• Smart SMT encodings

Page 34: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call

User space virtual address space

brk

void *sbrk(intptr_t increment)

Page 35: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call

increments the programs data space by increment bytes

User space virtual address space

brk

void *sbrk(intptr_t increment)

increment

Page 36: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call

User space virtual address space

brk

void *sbrk(intptr_t increment)

increments the programs data space by increment bytes

Page 37: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call

Goal: Redesign sbrk(); ensuring process isolation.

User space virtual address space

brk

void *sbrk(intptr_t increment)

increments the programs data space by increment bytes

Page 38: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Dealing with loops

void *sbrk(intptr_t increment)

Page 39: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Dealing with loops

void *sbrk(intptr_t increment)

Page 40: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Dealing with loops

void *sbrk(intptr_t increment)

page table root

entry4K page

Page 41: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Dealing with loops

void *sbrk(intptr_t increment)

void *sbrk_one_page()

page table root

entry4K page

Page 42: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Decomposition

page table root

entry4K page

void *sbrk_one_page()

Page 43: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Decomposition

PML4 table

entry4K page

page directory page table

entry

page directory

entry

page table

entry

void *sbrk_one_page()

Page 44: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Decomposition

PML4 table

entry4K page

page directory page table

entry

page directory

entry

page table

entry

alloc_pdpt(…) alloc_pd(…) alloc_pt(…) alloc_frame(…)

void *sbrk_one_page()

Page 45: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Decomposition

PML4 table

entry4K page

page directory page table

entry

page directory

entry

page table

entry

alloc_pdpt(…) alloc_pd(…) alloc_pt(…) alloc_frame(…)

void *sbrk_one_page()

Page 46: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Decomposition

int alloc_pdpt(int pml4, size_t index)

int alloc_pd(int pdpt, size_t index)

int alloc_pt(int pd, size_t index)

int alloc_frame(int pt, size_t index)

Page 47: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Explicit allocation

App Kernel

Search for free page

alloc

page#

1

2

3

Page 48: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Explicit allocation

App Kernelalloc, page#

success/fail

• Kernel keeps track of per-page metadata: owner/type

• User space searches for free page; kernel validates

Page 49: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

The sbrk() system call: Finite Interface

• Any composition of these system calls maintains isolation

int alloc_pdpt(int pml4, size_t index, int free_pn)

int alloc_pd(int pdpt, size_t index, int free_pn)

int alloc_pt(int pd, size_t index, int free_pn)

int alloc_frame(int pt, size_t index, int free_pn)

For any virtual address in a process p, if the virtual address maps to a page

the page must be exclusively owned by p.

Page 50: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Implementation

Component Lines Languages

Kernel implementation 7,616 C, assembly

State-machine specification 804 Python

Declarative specification 263 Python

Verifier 2,878 C++, Python

User-space implementation 10,025 C, assembly

Page 51: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Outline

• Verification workflow

• Finite interface design

• Demo

• Evaluation & lessons learned

Page 52: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Demo

• Hyperkernel in action

• Catching a low-level bugproducing a stack trace

• Catching a process isolation bugproducing a visualized counterexample

Page 53: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Outline

• Verification workflow

• Finite interface design

• Demo

• Evaluation & lessons learned

Page 54: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

What was the development effort?

• Write a state machine specification

• Relate LLVM data structures toabstract specification state

• Write checks for the representationinvariants if needed.

Page 55: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

What was the development effort?

• Adding and verifying a system call usually takes < 1 hour

• Write a state machine specification

• Relate LLVM data structures toabstract specification state

• Write checks for the representationinvariants if needed.

Page 56: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Is the design effective for scalable verification?

• 45 minutes on a single core machine

• 15 minutes on an 8-core Intel i7

• Not sensitive to system parameters (e.g., number of pages)

• Design is effective for scalable verification

Page 57: Hyperkernel: Push-Button Verification of an OS Kernelbornholt/papers/hyperkernel-sosp... · Hyperkernel: Push-Button Verification of an OS Kernel Luke Nelson, Helgi Sigurbjarnarson,

Conclusion

• Feasible to verify simple Unix-like OS kernel

• Automatic verification through symbolic execution• Make interface finite

• Decompose complex system calls to scale verification

• Verifiability as a first-class system design concern

• http://locore.cs.washington.edu/hyperkernel