extent-2016: industry practices of advanced program analysis

52
Institute for System Programming of the Russian Academy of Sciences Industry practices of advanced program analysis Alexey Khoroshilov [email protected] ExTENT-2016 London, 22 June 2016

Upload: iosif-itkin

Post on 16-Jan-2017

1.336 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: EXTENT-2016: Industry Practices of Advanced Program Analysis

Institute for System Programming of the Russian Academy of Sciences

Industry practices of advanced program analysis

Alexey [email protected]

ExTENT-2016London, 22 June 2016

Page 2: EXTENT-2016: Industry Practices of Advanced Program Analysis

The Goal of Verification

to make sure there is no any bugs in any possible execution of the target software

● with minimal cost

Verification

Fresh Software Verified Software

Page 3: EXTENT-2016: Industry Practices of Advanced Program Analysis

The Goal of Verification

to achieve maximal assurance that there is no any bugs in any possible execution of the target software

● within reasonable cost

Verification

Fresh Software Verified Software

Page 4: EXTENT-2016: Industry Practices of Advanced Program Analysis

Testing

Test

Test Suite

1 kindof bugs

all kindsof bugs

in all executionsin 1 execution

Page 5: EXTENT-2016: Industry Practices of Advanced Program Analysis

Inductive Reasoning● Conclusions are supported by its premises● If premises are true, it would be unlikely

impossible for the conclusions to be false● Example:

● Every time I’ve walked by that dog,he hasn’t tried to bite me.

● So, the next time I walk by that dog he won’t try to bite me.

Page 6: EXTENT-2016: Industry Practices of Advanced Program Analysis

Inductive Reasoning● Conclusions are supported by its premises● If premises are true, it would be unlikely

impossible for the conclusions to be false● Example:

● The component behaves correctly on all test data.

● So, the component always behaves correctly.

Page 7: EXTENT-2016: Industry Practices of Advanced Program Analysis

Inductive Reasoning on Program Correctness

● The component behaves correctly on all test data

● Tests are quite representative

=>● The component always behaves correctly

Page 8: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Reasoning● Conclusions certainly follow

from its premises● If premises are true, it is impossible for the

conclusions to be false● Example:

● All men are mortal.● Socrates is a man.● Therefore, Socrates is mortal.

Page 9: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Reasoning on Program Correctness

TargetComponent

Requirements

Review

Page 10: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Reasoning on Program Correctness

TargetComponent

Requirements

Page 11: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Reasoning on Program Correctness● If assumptions are held

● regarding compiler&linker● regarding environment behaviour● regarding input data

● The component always behaves correctly

Page 12: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Reasoning on Program Correctness● If assumptions are held

● regarding compiler&linker● regarding environment behaviour● regarding input data

● The component always behaves correctly

(i.e. terminates and its output satisfies to postcondition)

Page 13: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive VerificationHistorical Perspective

1947

1970

● Lecture of Alan Turing to London Mathematical Society

● Methods of Floyd/Hoare

Page 14: EXTENT-2016: Industry Practices of Advanced Program Analysis

START:( y

1, y

2 ) ( 0, x

1 )

y2 x

2

FT

( y1, y

2 ) ( y

1+1, y

2- x

2 ) HALT:

( z1, z

2 ) ( y

1, y

2 )

A: Precondition(x

1 0) (x

2 0)

С: Postcondition (x

1 = z

1x

2 + z

2) (0 z

2 < x

2)

B: Invariant (x

1 = y

1x

2 + y

2) ∧ (y

2 0)

Deductive Verification

Prove program correctness by induction:

Let precondition to be held in A we pass A->B => Invariant is held in BLet invariant to be held in B we pass B-T->B => Invariant is held in BLet invariant to be held in B we pass B-F->C => Postcondition is held in С

Let precondition to be held in A we pass A->C => Postcondition is held in С

=>

Page 15: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive VerificationHistorical Perspective

1947

1970

2000

● Lecture of Alan Turing to London Mathematical Society

● Methods of Floyd/Hoare

● Deductive verifcation tools for Ada, C, Java, С#● SunRise, ESC/Java, Frama-C, LOOP, Boogie/VCC

Page 16: EXTENT-2016: Industry Practices of Advanced Program Analysis
Page 17: EXTENT-2016: Industry Practices of Advanced Program Analysis
Page 18: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive VerificationHistorical Perspective

1947

1970

2000

2010

● Lecture of Alan Turing to London Mathematical Society

● Methods of Floyd/Hoare

● Deductive verifcation tools for Ada, C, Java, С#● SunRise, ESC/Java, Frama-C, LOOP, Boogie/VCC

● Application in real-life projects for small-size components● Nuclear power (UK, France)● Avionics (Airbus, NASA, UK Air Traffic Control)● Components of operating systems

(seL4, Verisoft, Verisoft-XT)

Page 19: EXTENT-2016: Industry Practices of Advanced Program Analysis

Industry Applications● UK Air Traffic Management System

● 250 KLOC of logical lines of code (in Ada)● proof type safety, few functional correctness

code● 153K VCs, of which 98.76% are proven

automatically

(*) Angela Wallenburg “Safe and Secure Programming Using Spark”

Page 20: EXTENT-2016: Industry Practices of Advanced Program Analysis

Years Tools Target code Scope Size

Verisoft 2004-2008 Isabelledesigned for verification

hw/kernel/ compiler/

libraries/apps10 kLOC(kernel)

L4.verifiedseL4

2004-2009 Isabelle

designed for verification,

performance oriented

microkernelsecurity model

(no MMU)

7.5 kLOC(without asm and

boot)

Verisoft-XT small-hv

2007-2013 VCCdesigned for verification

separation property only

2.5 kLOC

Verisoft-XT Hyper-V

2007-2013 VCC industrialseparation

property only100 kLOC

Verisoft-XT PikeOS

2007-2013 VCCindustrial,

simplicity for performance

some system calls

10 KLOC

OS Deductive Verification

Page 21: EXTENT-2016: Industry Practices of Advanced Program Analysis

Linux Verification Center

founded in 2005● OLVER Program● Linux Standard Base Infrastructure Program● Linux Driver Verification Program● Linux File System Verification Program● Linux Deductive Verification Program

Page 22: EXTENT-2016: Industry Practices of Advanced Program Analysis

Toolset for Event-B models verification

Model of securityrequirements

Formalized securitymodel

Formalizedlow-level security

model

Manual

Automatedverification

Securityrequirements

Security model

AstraVer Toolchain (*)for deductive verification of C programs(based on Frama-C – Jessie – Why3)

Pre-/post-conditionsof LSM operations

Securityarcitecture

LSMsource code

Model of securityrequirements

Mathematicalnotation

LSMImplementation

implements

Specificatiion oflibrary functions

Linuxkernel

AstraVer Project

AstraLinux(*) The research on deductive verification tools development was carried out with funding from the Ministry of Education and Science of Russia (the project unique identifier is RFMEFI60414X0051

Page 23: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Verification Status

● Reasonable Tool Support● Ada, C, C#, Java● Functional specification as comments,

even natively supported in Ada-2012● Dedicated languages: Boogie, Why3

● Manual efforts still significant● up to 10x of development efforts● highly skilled team required

Page 24: EXTENT-2016: Industry Practices of Advanced Program Analysis

Testing and Deductive Verification

1 kindbugs

all kindsof bugs

in all executions

Deductive

1. Proof of complete correctnessunder some assumptions 2. Very labour intensive and time consuming

in 1 execution

Test

Test Suite

Page 25: EXTENT-2016: Industry Practices of Advanced Program Analysis

TestingDeductive

Verification

Kind of bugs almost all almost all

Executionsunder analysis small almost all

Development cost

linear huge

Executioncost

hw small(target hw)

hw small

Result analysiscost small big

Maintenancecost

small to big huge

Testing and Deductive Verification

Page 26: EXTENT-2016: Industry Practices of Advanced Program Analysis

Deductive Verification Status (2)

● reasonable to apply only for really important code

Page 27: EXTENT-2016: Industry Practices of Advanced Program Analysis

Static Analysis

● is a commodity● mature market of static analysis tools

Page 28: EXTENT-2016: Industry Practices of Advanced Program Analysis

SVACE by ISPRAS

● Static analysis of C/C++/Java code, Linux/Windows

● 150+ kinds of defects● Buffer overflows, NULL-pointer dereferences● Memory management, tainted input● Concurrency issues● Lightweight analysis of semantic patterns

● Eclipse plugin or WebUI

Page 29: EXTENT-2016: Industry Practices of Advanced Program Analysis

TestingStatic

AnalysisDeductive

Verification

Kind of bugs almost allsafetyonly almost all

Executionsunder analysis small almost all almost all

Development cost

linear 0 to small huge

Executioncost

hw small(target hw)

hw small hw small

Result analysiscost

smallmedium

(false alarms)big

Maintenancecost

small to big small huge

Testing and Program Analysis

Page 30: EXTENT-2016: Industry Practices of Advanced Program Analysis

TestingStatic

AnalysisDeductive

Verification

Kind of bugs almost allsafetyonly almost all

Executionsunder analysis small

bigalmost all almost all

Development cost

linear 0 to small huge

Executioncost

hw small(target hw)

hw small hw small

Result analysiscost

smallmedium

(false alarms)big

Maintenancecost

small to big small huge

Testing and Program Analysis

Page 31: EXTENT-2016: Industry Practices of Advanced Program Analysis

Testing and Program Analysis

1 kindbugs

all kindsof bugs

in all executions

Deductive

in 1 execution

Test

Test Suite

SVACE

1. Static analysis2. Quickly finds potential bugs3. No any guarantee

Page 32: EXTENT-2016: Industry Practices of Advanced Program Analysis

R...

Model Checking

R2

R1

R0

[Clarke/Emerson, Sifakis 1981]

● Iterative fixpoint post computation

Page 33: EXTENT-2016: Industry Practices of Advanced Program Analysis

Software Model Checking

entry point

error location

● Reachability problem

Page 34: EXTENT-2016: Industry Practices of Advanced Program Analysis

Error Location?int f(int y){struct urb *x;

x = usb_alloc_urb(0,GFP_KERNEL); ... usb_free_urb(x);

return y;}

Page 35: EXTENT-2016: Industry Practices of Advanced Program Analysis

Error Location?int f(int y){struct urb *x;

x = usb_alloc_urb(0,GFP_KERNEL); // allocate new URB ... usb_free_urb(x); // deallocate URB: assert(x is NULL or previously allocated URB)

return y;}

… // after module exit: assert( all allocated URBs are deallocated)

Page 36: EXTENT-2016: Industry Practices of Advanced Program Analysis

Instrumentation

int f(int y){struct urb *x;

x = usb_alloc_urb(0,GFP_KERNEL);

...

usb_free_urb(x);

return y;}

set URBS = empty;

int f(int y){struct urb *x;

x = usb_alloc_urb(); add(URBS, urb); ... assert(contains(URBS, x)); usb_free_urb(x); remove(URBS, urb);

return y;} … // after module exit assert(is_empty(URBS));

Page 37: EXTENT-2016: Industry Practices of Advanced Program Analysis

Software Model Checking

entry point

error location

● Reachability problem

Page 38: EXTENT-2016: Industry Practices of Advanced Program Analysis

Bounded Model Checking

● finite unfolding of transition relation

b1

a2 a2

b2 b2 b2 b2

b1

a2 a2

b2 b2 b2 b2

r

Page 39: EXTENT-2016: Industry Practices of Advanced Program Analysis

Counter-Example Guided Abstraction Refinement● Detailed model of a program is huge● Detailed model of a program is not needed to

check a particular property● Detailed model of a concrete path in a program

is suitable for analysis

=>● Build a model that is just enough to check the

particular property

Page 40: EXTENT-2016: Industry Practices of Advanced Program Analysis

SV-COMP-2013 Competition Results

DriversDrivers

Bit Bit operationsoperations

PointersPointers

CEGARCEGAR BMCBMC

Sh

ape-

Sh

ape-

an

alys

isa

nal

ysis

Page 41: EXTENT-2016: Industry Practices of Advanced Program Analysis

SVCOMP'14 Results

Page 42: EXTENT-2016: Industry Practices of Advanced Program Analysis

SVCOMP'15 Results

BLASTCPAchecker

15 tools in 201422 tools in 201535 tools in 2016

Page 43: EXTENT-2016: Industry Practices of Advanced Program Analysis

Industry Applications

Page 44: EXTENT-2016: Industry Practices of Advanced Program Analysis

Linux Verification Center

founded in 2005● OLVER Program● Linux Standard Base Infrastructure Program● Linux Driver Verification Program● Linux File System Verification Program● Linux Deductive Verification Program

Page 45: EXTENT-2016: Industry Practices of Advanced Program Analysis

Linux Driver Verification

http://linuxtesting.org/ldv

Page 46: EXTENT-2016: Industry Practices of Advanced Program Analysis

Bugs Foundhttp://linuxtesting.org/results/ldv

>230 patches already applied

Page 47: EXTENT-2016: Industry Practices of Advanced Program Analysis

SVACE vs. LDVSVACE LDV-CPAchecker

Time of analysis 2 hrs 111 hrs (4.5 days)

Warnings 35 328

True bugs 8 103

True positive rate 23% 31%

● Target code:● Linux kernel 3.17-rc1, allmodconfig, x86-64● 3 223 modules, 33 373 source files

● Target bugs:● double free, memory leaks

There is no a single common bugs!

Page 48: EXTENT-2016: Industry Practices of Advanced Program Analysis

Testing and Program Analysis

1 kindbugs

all kindsof bugs

in all executions

Deductive

in 1 execution

Test

Test Suite

SVACE LDV

1. Investigates all possible paths2. Is able to prove absence of bugs of particular kind3. Domain-specific (framework) adaptation (environment model, library model)4. Applicability limited to medium-sized components (up to 50 KLoC)5. Requires nonzero hardware resources - time: 15 minutes per rule per module - memory: 15 Gb

Page 49: EXTENT-2016: Industry Practices of Advanced Program Analysis

TestingStatic

AnalysisSoftware Model

CheckingDeductive

Verification

Kind of bugs almost allsafetyonly

safetyonly almost all

Executionsunder analysis small big almost all almost all

Development cost

linear 0 to small medium huge

Executioncost

hw small(target hw)

hw small hw big hw small

Result analysiscost small

medium(false alarms)

medium(false alarms) big

Maintenancecost

small to big small small huge

Testing and Program Analysis

Page 50: EXTENT-2016: Industry Practices of Advanced Program Analysis

Conclusions● There is no silver bullet● The key is in a competent combination of

available techniques

Page 51: EXTENT-2016: Industry Practices of Advanced Program Analysis

Conclusions (2)● Two advanced program analysis techniques:

● Deductive verification● + proof of complete correctness under some

assumptions ● – significant manual efforts● – highly skilled team required● => only for really important code

● Software model checking● + investigates almost all possible paths● + complimentary to static analysis● – per framework/domian adaptation required● – limited to medium-sized components (up to 50 KLoC)

Page 52: EXTENT-2016: Industry Practices of Advanced Program Analysis

Institute for System Programming of the Russian Academy of Sciences

Thank you!

Alexey [email protected]://linuxtesting.org/

Morris Kline. “Mathematics: The Loss of Certainty” Oxford Press, 1980