Introducing BLAST Software Verification

17
Introducing BLAST Introducing BLAST Software Software Verification Verification John Gallagher John Gallagher CS4117 CS4117

description

Introducing BLAST Software Verification. John Gallagher CS4117. What is BLAST?. The Berkeley Lazy Abstraction Software-verification Tool is a model checker that checks the safety properties of C programs. “Automated, precise and scalable” (so, usable). What BLAST Isn’t. - PowerPoint PPT Presentation

Transcript of Introducing BLAST Software Verification

Page 1: Introducing BLAST Software Verification

Introducing BLAST Introducing BLAST Software VerificationSoftware Verification

John GallagherJohn Gallagher

CS4117CS4117

Page 2: Introducing BLAST Software Verification

What is BLAST?What is BLAST?

The Berkeley Lazy Abstraction Software-The Berkeley Lazy Abstraction Software-verification Tool is a model checker that verification Tool is a model checker that checks the safety properties of C checks the safety properties of C programs.programs.

““Automated, precise and scalable” (so, Automated, precise and scalable” (so, usable).usable).

Page 3: Introducing BLAST Software Verification

What BLAST Isn’tWhat BLAST Isn’t

A magical solution to the halting problem, A magical solution to the halting problem, so BLAST may run forever on some input. so BLAST may run forever on some input. And it may not be able to assert that a And it may not be able to assert that a given execution path will not occur.given execution path will not occur.

A C compiler, though it parses and A C compiler, though it parses and validates preprocessed C.validates preprocessed C.

Page 4: Introducing BLAST Software Verification

Quick ExampleQuick Example

InputInput OutputOutput#include "assert.h"#include "assert.h"

/*Blast's assert.h*//*Blast's assert.h*/

int foo(int x, int y) {int foo(int x, int y) {

if (x > y) {if (x > y) {

x = x - y;x = x - y;

assert(x > 0);assert(x > 0);

}}

return 0;return 0;

}}

addPred: 0: (gui) adding predicate 1<=x@foo-addPred: 0: (gui) adding predicate 1<=x@foo-y@foo to the systemy@foo to the system

addPred: 0: (gui) adding predicate 1<=x@foo-addPred: 0: (gui) adding predicate 1<=x@foo-y@foo to the systemy@foo to the system

addPred: 1: (gui) adding predicate 1<=x@foo to addPred: 1: (gui) adding predicate 1<=x@foo to the systemthe system

addPred: 1: (gui) adding predicate 1<=x@foo to addPred: 1: (gui) adding predicate 1<=x@foo to the systemthe system

Adding all preds now...Adding all preds now...

[BAT] Done refiner[BAT] Done refiner

Non-trivial functions 0Non-trivial functions 0

Depth of tree: 7Depth of tree: 7

No error found. The system is safe :-)No error found. The system is safe :-)

Page 5: Introducing BLAST Software Verification

What Just Happened?What Just Happened?

First, BLAST builds a Control Flow Automata (basically, a First, BLAST builds a Control Flow Automata (basically, a flow graph) from the preprocessed C, which in simplified flow graph) from the preprocessed C, which in simplified form looks like:form looks like:

void __blast_assert(){void __blast_assert(){ ERROR: goto ERROR;ERROR: goto ERROR;}}void __assert_fail(){__blast_assert();}void __assert_fail(){__blast_assert();}int foo(int x, int y) {int foo(int x, int y) {

if (x > y) {if (x > y) { x = x - y;x = x - y; ((void) (((void) ((x > 0)(x > 0) ? 0 : (__assert_fail())))) ? 0 : (__assert_fail()))))

}}return 0;return 0;

}}

Page 6: Introducing BLAST Software Verification

Is Label ERROR Reachable?Is Label ERROR Reachable?

The assert safety check has been The assert safety check has been converted into a reachability problem.converted into a reachability problem.

BLAST represents the code as a Control BLAST represents the code as a Control Flow Automata, then constructs an Flow Automata, then constructs an Abstract Reachability Tree to try and Abstract Reachability Tree to try and answer this question without exploding the answer this question without exploding the state space or looping forever.state space or looping forever.

Page 7: Introducing BLAST Software Verification

The CFAThe CFA

1:foo

3:Pred(x<=y) 2:Pred(x>y)

5:x=x-y

7:x>0 6:x<=0

8:__assert_fail()

10:__blast_assert()

12:ERROR

9:return 0

Page 8: Introducing BLAST Software Verification

Properties of the ARTProperties of the ART

A node in the ART has a triple of (Label # A node in the ART has a triple of (Label # CFA, Call Stack, Reachable Region)CFA, Call Stack, Reachable Region)

Reachable Region is a boolean formula Reachable Region is a boolean formula representing the set of data statesrepresenting the set of data states

An ART is safe if for every node whose An ART is safe if for every node whose CFA Label is an error location, the CFA Label is an error location, the Reachable Region expression ^ with the Reachable Region expression ^ with the predicate is unsatisfiable. predicate is unsatisfiable.

Page 9: Introducing BLAST Software Verification

Properties of the ARTProperties of the ART

For us, that means the node whose CFA For us, that means the node whose CFA Label is 6 must have a non satisfiable set Label is 6 must have a non satisfiable set of data states when ^ with (x <= 0).of data states when ^ with (x <= 0).

Page 10: Introducing BLAST Software Verification

The ART (Call Stack Omitted)The ART (Call Stack Omitted)

1 TRUE

5 x>y ^ x=x-y

7x>y ^ x>0 6 x>y ^ x=x-y ^x<=0

12

3 x<=y

9

2 x>y

Pred (x>y)Pred (x<=y)

x=x-y

Pred (x<=0)Pred (x>0)

return 0

return 0

ERROR

Page 11: Introducing BLAST Software Verification

Safe?Safe?

If the program is safe, the node labeled 6 If the program is safe, the node labeled 6 (there is one such node in this program) (there is one such node in this program) must have an unsatisfiable data state.must have an unsatisfiable data state.

x>y ^ x=x-y ^ x<=0 is unsatisfiable. >y can x>y ^ x=x-y ^ x<=0 is unsatisfiable. >y can be substituted for x in the subtraction. set be substituted for x in the subtraction. set x (>y)-y, set x >0. If x>0 is pred p1, x<=0 x (>y)-y, set x >0. If x>0 is pred p1, x<=0 is !p1. p1 ^ !p1 is always false, so the is !p1. p1 ^ !p1 is always false, so the program is safe.program is safe.

Page 12: Introducing BLAST Software Verification

Predicate DiscoveryPredicate Discovery

Build ART by setting all of the data states to true, Build ART by setting all of the data states to true, and exercising the CFA to find all reachable error and exercising the CFA to find all reachable error states, including the data state.states, including the data state.There now exists a path between the root (initial) There now exists a path between the root (initial) state and the error state, but predicate discovery state and the error state, but predicate discovery is used to determine whether the path is feasible. is used to determine whether the path is feasible. (Lazy Predicate Abstraction)(Lazy Predicate Abstraction)By examining the program at certain cut points, By examining the program at certain cut points, predicates are added to show the feasibility or predicates are added to show the feasibility or infeasibility of a path (using Craig Interpolants, infeasibility of a path (using Craig Interpolants, probably the subject of another presentation).probably the subject of another presentation).

Page 13: Introducing BLAST Software Verification

An Unsafe ModificationAn Unsafe Modification

InputInput OutputOutput#include "assert.h"#include "assert.h"

/*Blast's assert.h*//*Blast's assert.h*/

int foo(int x, int y) {int foo(int x, int y) {

if (x > y) {if (x > y) {

x = 2 + y - x;x = 2 + y - x;

assert(x > 0);assert(x > 0);

}}

return 0;return 0;

}}

Error found! The system is unsafe :-(Error found! The system is unsafe :-(

Error trace:Error trace:

src="tut1unsafe.i"; line=0src="tut1unsafe.i"; line=0

FunctionCall(__BLAST_initialize_tut1unsafe.i())FunctionCall(__BLAST_initialize_tut1unsafe.i())

Pred(x@foo > y@foo) Pred(x@foo > y@foo)

Block(x@foo = 2 + y@foo - x@foo;)Block(x@foo = 2 + y@foo - x@foo;)

Pred(x@foo <= 0) FunctionCall(__assert_fail))Pred(x@foo <= 0) FunctionCall(__assert_fail))

FunctionCall(__blast_assert())FunctionCall(__blast_assert())

Page 14: Introducing BLAST Software Verification

The ART (Call Stack Omitted)The ART (Call Stack Omitted)

1 TRUE

5 x>y ^ x=2+y-x

7x>y ^ x>0 6x>y ^ x=2+y-x

^x<=0

12

3 x<=y

9

2 x>y

Pred (x>y)Pred (x<=y)

x=x-y

Pred (x<=0)Pred (x>0)

return 0

return 0

ERROR

Page 15: Introducing BLAST Software Verification

Beyond AssertBeyond Assert

BLAST is designed to be useful for legacy BLAST is designed to be useful for legacy code, so it has a language for writing code, so it has a language for writing specifications to determine whether a specifications to determine whether a safety property is violated: The BLAST safety property is violated: The BLAST Query Language.Query Language.

Specifications are kept separate from the Specifications are kept separate from the code in their own file. Pattern matching is code in their own file. Pattern matching is used to associate a specification item with used to associate a specification item with its relevant location in code.its relevant location in code.

Page 16: Introducing BLAST Software Verification

BLAST Query LanguageBLAST Query Languageglobal int lockStatus = 0;

event { pattern { FSMInit(); } action { lockStatus = 0; }}

event { pattern { FSMLock(); } guard { lockStatus == 0 } action { lockStatus = 1; }}

event { pattern { FSMUnLock(); } guard { lockStatus == 1 } action { lockStatus = 0; }}

Page 17: Introducing BLAST Software Verification

ReferencesReferences

http://mtc.epfl.ch/software-tools/blast/The BLAST query language for software verificationDirk Beyer, Adam J. Chlipala, Thomas A. Henzinger, Ranjit Dirk Beyer, Adam J. Chlipala, Thomas A. Henzinger, Ranjit Jhala, and Rupak Majumdar. Jhala, and Rupak Majumdar. Proceedings of the 11th Proceedings of the 11th International Static Analysis SymposiumInternational Static Analysis Symposium (SAS 2004), LNCS (SAS 2004), LNCS 3148, pages 2-18, Springer-Verlag, 2004.3148, pages 2-18, Springer-Verlag, 2004.The software model checker BLAST Thomas A. Henzinger, Ranjit Jhala, Rupak Majumdar, and Thomas A. Henzinger, Ranjit Jhala, Rupak Majumdar, and Gregoire Sutre. Software verification with Blast. In Tenth Gregoire Sutre. Software verification with Blast. In Tenth International Workshop on Model Checking of Software International Workshop on Model Checking of Software (SPIN), volume 2648 of Lecture Notes in Computer Science, (SPIN), volume 2648 of Lecture Notes in Computer Science, pages 235--239. Springer-Verlag, 2003.pages 235--239. Springer-Verlag, 2003.