1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research [email protected]...

88
1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research [email protected] Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg, Con McGarvey, Bohus Ondrusek, Sriram Rajamani & Abdullah Ustuner

Transcript of 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research [email protected]...

Page 1: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

1

Thorough Static Analysis of Device Drivers

Byron Cook – Microsoft Research

[email protected]

Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg, Con McGarvey, Bohus Ondrusek, Sriram Rajamani & Abdullah Ustuner

Page 2: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

2

Kernel

DD

HW

DDDD

DD

DD

DD

DD

DD DD

DD

DD

DDDD

DD

DDDD

DD

DD

DD

HW

HW

HW

HW

HW

HW

HW

Static Driver Verifier

Page 3: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

3

Static Driver Verifier (a.k.a. SDV):

A compile-time correctness checking tool based on deep semantic analysis via symbolic model checking

Now available on the latest Windows DDK beta

Static Driver Verifier

Page 4: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

4

Static Driver Verifier

Static Driver Verifier (SDV) is a tool for finding bugs in Windows device drivers:

SDV operates on the driver’s source code

SDV is completely automatic

SDV checks that drivers do not violate a set of “kernel API usage rules”

Attempts to prove the correctness of the driver with the SLAM software model checker

Page 5: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

5

Static Driver Verifier

other.h

driver.h

driver.c

Driver sources

SDV XX

XX

Page 6: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

6

Static Driver Verifier

Page 7: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

7

Static Driver Verifier

Page 8: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

8

Page 9: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

9

Page 10: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

10

Page 11: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

11

Page 12: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

12

Page 13: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

13

Page 14: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

14

Page 15: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

15

Page 16: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

16

Page 17: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

17

Page 18: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

18

Page 19: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

19

Page 20: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

20

Page 21: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

21

Page 22: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

22

Page 23: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

23

Page 24: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

24

Page 25: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

25

Page 26: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

26

Page 27: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

27

Page 28: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

28

Page 29: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

29

Outline

Introduction to Static Driver Verifier

Static Driver Verifier internals

Conclusion & Discussion

Page 30: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

30

Outline

Introduction to Static Driver Verifier

Static Driver Verifier internals

Conclusion & Discussion

Page 31: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

31

Static Driver Verifier

other.h

driver.h

driver.c

Driver sources

SDV XX

XX

Page 32: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

32

Static Driver Verifier

SDVRules

SLAM

OS model

other.h

driver.h

driver.c XX

XX

Driver sources

Page 33: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

33

Static Driver Verifier: Rules

Expressed in an event-based language

Possible events: Function entry Function exit

The code associated with events call the function error() to indicate a violation:

IoCallDriver.entry { if ($2->Tail.Overlay.CurrentStackLocation->MajorFunction ==IRP_MJ_POWER) { error(); } }

Page 34: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

34

Static Driver Verifier: Rules

Page 35: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

35

Static Driver Verifier

SDVRules

SLAM

OS model

other.h

driver.h

driver.c XX

XX

Page 36: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

36

Static Driver Verifier: OS model

Provides the main function

Abstract implementations of kernel APIs (like IoCallDriver)

Models some aspects of the OS state, like the “interrupt request level” (IRQL)

Uses non-deterministic choice

Page 37: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

37

Static Driver Verifier: OS model

Page 38: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

38

Static Driver Verifier

SDVRules

SLAM

OS model

other.h

driver.h

driver.c XX

XX

Page 39: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

39

Static Driver Verifier: SLAM

Symbolic model checker for C

Strategy: throw away as much irrelevant detail from the driver as possible through abstraction search

Algorithm = Predicate Abstraction + Counter-example based refinement + Symbolic reachability for Boolean programs

Simplifying (unsound) assumptions: C unions are ignored Memory layout is not known: pointer arithmetic is largely ignored Coincidental pointer aliasing is ignored, purposeful aliasing is not Functions cannot be called both by name and pointer The OS model does not exercise all paths possible in practice

Page 40: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

40

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

Assume that f1, f2, f3 and g do not call AcquireLock or ReleaseLock

Page 41: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

41

Static Driver Verifier: SLAM

int locked = 0;

AcquireLock.entry { if (locked==1) { error(); } else { locked=1; }}

ReleaseLock.entry { if (locked==0) { error(); } else { locked=0; }}

Page 42: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

42

SLAM

Static Driver Verifier: SLAM

Page 43: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

43

Static Driver Verifier: SLAM

SLAM RefineStep

AbstractStep

CheckStep

Driver passes rule

Rule violation foundOS model

Driver sources

Rule

Instrument

Step

Page 44: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

44

Static Driver Verifier: SLAM

int locked = 0;

if (locked==1) { error(); } else { locked=1; }

if (locked==0) { error(); } else { locked=0; }

int locked = 0;

AcquireLock.entry { if (locked==1) { error(); } else { locked=1; }}

ReleaseLock.entry { if (locked==0) { error(); } else { locked=0; }}

void AcquireLock(){ ……………}

void ReleaseLock(){ ……………}

void main(){ ……………

void AcquireLock() {

………………}

void ReleaseLock() {

………………}

void main(){ ……………

Are these reachable?

Page 45: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

45

Static Driver Verifier: SLAM

SLAM RefineStep

CheckStep

Instrument

Step

Driver passes rule

Rule violation foundOS model

Driver sources

Rule

AbstractStep

Page 46: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

46

rst=0;

!rst a = b = c = a<b && b<c rst=1;

void main(){

for(;;) { AcquireLock(); while( ) { f1(); f2(); f3(); if ( ) { ReleaseLock(); } } g(); }}

int a,b,c,rst,cnt; cnt = 0;

Static Driver Verifier: SLAM

* *

State space = 2^(#bits(pc)) + stack

Page 47: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

47

Static Driver Verifier: SLAM

SLAM Refine

Step

AbstractStep

Instrument

Step

Driver passes rule

Rule violation foundOS model

Driver sources

Rule

CheckStep

Page 48: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

48

Static Driver Verifier: SLAM

Reachable state-

space for steps <1

Page 49: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

49

Static Driver Verifier: SLAM

Reachable state-

space for steps <1

Reachable state-space for steps <2 Reachable

state-space for steps <3

Page 50: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

50

Static Driver Verifier: SLAM

Reachable state-

space for steps <1

Reachable state-space for steps <2 Reachable

state-space for steps <3

Reachable state-space for

steps <4Reachable

state-space for steps <5

Reachable state-

space for steps <6

Page 51: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

51

Static Driver Verifier: SLAM

Reachable state-

space for steps <1

Reachable state-space for steps <2 Reachable

state-space for steps <3

Reachable state-space for

steps <4Reachable

state-space for steps <5

Reachable state-

space for steps <6

Reachable state-space for steps <7

Reachable state-space for steps

<8

Page 52: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

52

Static Driver Verifier: SLAM

Reachable state-

space for steps <1

Reachable state-space for steps <2 Reachable

state-space for steps <3

Reachable state-space for

steps <4Reachable

state-space for steps <5

Reachable state-

space for steps <6

Reachable state-space for steps <7

Reachable state-space for steps

<8Reachable state-space for steps

<9State where PC is at a call to error()

Page 53: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

53

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 54: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

54

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 55: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

55

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 56: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

56

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 57: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

57

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 58: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

58

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 59: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

59

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 60: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

60

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 61: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

61

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 62: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

62

Static Driver Verifier: SLAM

void main(){

for(;;) { AcquireLock(); while( * ) { f1(); f2(); f3(); if ( * ) { ReleaseLock(); } } g(); }}

Page 63: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

63

Static Driver Verifier: SLAM

SLAMAbstract

Step

CheckStep

Instrument

Step

Driver passes rule

Rule violation foundOS model

Driver sources

Rule

RefineStep

Page 64: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

64

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

Page 65: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

65

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

Page 66: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

66

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

Page 67: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

67

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

Page 68: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

68

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

Page 69: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

69

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

Page 70: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

70

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

Page 71: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

71

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

rst==0

Page 72: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

72

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

rst==0

Page 73: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

73

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

rst==0

Page 74: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

74

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

rst==0

!(rst==0)

Page 75: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

75

Static Driver Verifier: SLAM

void main(){ int a,b,c,rst,cnt; cnt = 0; for(;;) { AcquireLock(); rst=0;

while(!rst) { a = f1(); b = f2(); c = f3(); if (a<b && b<c) { rst=1; ReleaseLock(); } } g(); }}

cnt==0

rst==0

!(rst==0)

New predicate to track: main { rst==0 }

Page 76: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

76

Static Driver Verifier: SLAM

SLAM Refine

Step

CheckStep

Instrument

Step

Driver passes rule

Rule violation foundOS model

Driver sources

Rule

AbstractStep

Page 77: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

77

int a,b,c,rst,cnt; cnt = 0;

void main(){

for(;;) { AcquireLock(); while( ) { f1(); f2(); f3(); if ( ) { ReleaseLock(); } } g(); }}

Static Driver Verifier: SLAM

v0=1;

v0 * v0=0;

State space = 2^(1 + #bits(pc)) + stack

bool v0; // represents rst==0

rst=0;

!rst a = b = c = a<b && b<c rst=1;

Page 78: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

78

Static Driver Verifier: SLAM

SLAM Refine

Step

AbstractStep

Instrument

Step

Driver passes rule

Rule violation foundOS model

Driver sources

Rule

CheckStep

Page 79: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

79

Static Driver Verifier: SLAM

Reachable state-

space for steps <n

Page 80: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

80

Static Driver Verifier: SLAM

Reachable state-

space for steps <n

Reachable state-space

for steps <n+1

Reachable state-space

for steps <n+2

Page 81: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

81

Static Driver Verifier: SLAM

Reachable state-

space for steps <n

Reachable state-space

for steps <n+1

Reachable state-space

for steps <n+2

Reachable state-space for

steps <n+3Reachable

state-space for steps <n+4

Reachable state-space for steps <n+5 and

<n+4

Page 82: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

82

Static Driver Verifier: SLAM

Reachable state-

space for steps <n

Reachable state-space

for steps <n+1

Reachable state-space

for steps <n+2

Reachable state-space for

steps <n+3Reachable

state-space for steps <n+4

Reachable state-space for steps <n+5 and

<n+4

Page 83: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

83

Static Driver Verifier: SLAM

The abstraction contains only the PC and these three state bits locked>0 locked==0 rst==0

Abstracted away Much of f1(), f2(), f3(), g(), cnt, a, b, c Potential values from rst

From this abstraction we can reasons that the original C program is also correct

Page 84: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

84

Outline

Introduction to Static Driver Verifier

Static Driver Verifier internals

Conclusion & Discussion

Page 85: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

85

Outline

Introduction to Static Driver Verifier

Static Driver Verifier internals

Conclusion & Discussion

Page 86: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

86

Conclusion

SDV

A compile-time tool that finds bugs in device drivers

Kernel API usage rules + the SLAM model checker

Released on the latest DDK beta

Subsequent releases will support additional driver models

Page 87: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

87

Conclusion

In the paper

More information on how SDV works

More information on what SDV checks, what it doesn’t check, and why.

Data from experiments with SDV on ~100 device drivers

Information about new work to support new driver models

Page 88: 1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research bycook@microsoft.com Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,

88

Conclusion

What’s next for SDV/SLAM-like tools within Microsoft?

Proving deeper properties about programs that manipulate the heap

SLAM-like tools with better support for concurrency

Liveness properties & termination

Contracts/specifications for additional APIs