Putting Static Analysis to Work for Verification A Case Study Tal Lev-Ami Thomas Reps Mooly Sagiv Reinhard Wilhelm.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Abstract Interpretation Part II
Automated Verification with HIP and SLEEK Asankhaya Sharma.
Semantics Static semantics Dynamic semantics attribute grammars
Predicate Abstraction and Canonical Abstraction for Singly - linked Lists Roman Manevich Mooly Sagiv Tel Aviv University Eran Yahav G. Ramalingam IBM T.J.
Interprocedural Shape Analysis for Recursive Programs Noam Rinetzky Mooly Sagiv.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
1 Lecture 08(a) – Shape Analysis – continued Lecture 08(b) – Typestate Verification Lecture 08(c) – Predicate Abstraction Eran Yahav.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Local Heap Shape Analysis Noam Rinetzky Tel Aviv University Joint work with Jörg Bauer Universität des Saarlandes Thomas Reps University of Wisconsin Mooly.
Program analysis Mooly Sagiv html://
Finite Differencing of Logical Formulas for Static Analysis Thomas Reps University of Wisconsin Joint work with M. Sagiv and A. Loginov.
Program analysis Mooly Sagiv html://
Model Checking of Concurrent Software: Current Projects Thomas Reps University of Wisconsin.
1 Eran Yahav and Mooly Sagiv School of Computer Science Tel-Aviv University Verifying Safety Properties.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Abstract Interpretation Part I Mooly Sagiv Textbook: Chapter 4.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Overview of program analysis Mooly Sagiv html://
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Detecting Memory Errors using Compile Time Techniques Nurit Dor Mooly Sagiv Tel-Aviv University.
1 Shape Analysis via 3-Valued Logic Mooly Sagiv Tel Aviv University Shape analysis with applications Chapter 4.6
Describing Syntax and Semantics
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Overview of program analysis Mooly Sagiv html://
Static Program Analysis via Three-Valued Logic Thomas Reps University of Wisconsin Joint work with M. Sagiv (Tel Aviv) and R. Wilhelm (U. Saarlandes)
Dagstuhl Seminar "Applied Deductive Verification" November Symbolically Computing Most-Precise Abstract Operations for Shape.
Program Analysis and Verification Noam Rinetzky Lecture 10: Shape Analysis 1 Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav.
June 27, 2002 HornstrupCentret1 Using Compile-time Techniques to Generate and Visualize Invariants for Algorithm Explanation Thursday, 27 June :00-13:30.
1 Employing decision procedures for automatic analysis and verification of heap-manipulating programs Greta Yorsh under the supervision of Mooly Sagiv.
Shape Analysis Overview presented by Greta Yorsh.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
CS 363 Comparative Programming Languages Semantics.
Symbolically Computing Most-Precise Abstract Operations for Shape Analysis Greta Yorsh Thomas Reps Mooly Sagiv Tel Aviv University University of Wisconsin.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
1 Shape Analysis via 3-Valued Logic Mooly Sagiv Tel Aviv University Shape analysis with applications Chapter 4.6
Data Structures and Algorithms for Efficient Shape Analysis by Roman Manevich Prepared under the supervision of Dr. Shmuel (Mooly) Sagiv.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
1 Program Analysis via 3-Valued Logic Mooly Sagiv, Tal Lev-Ami, Roman Manevich Tel Aviv University Thomas Reps, University of Wisconsin, Madison Reinhard.
Quantified Data Automata on Skinny Trees: an Abstract Domain for Lists Pranav Garg 1, P. Madhusudan 1 and Gennaro Parlato 2 1 University of Illinois at.
Program Analysis via 3-Valued Logic Thomas Reps University of Wisconsin Joint work with Mooly Sagiv and Reinhard Wilhelm.
Roman Manevich Ben-Gurion University Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 16: Shape Analysis.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Interprocedural shape analysis for cutpoint-free programs Noam Rinetzky Tel Aviv University Joint work with Mooly Sagiv Tel Aviv University Eran Yahav.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Spring 2017 Program Analysis and Verification
Functional Programming
Interprocedural shape analysis for cutpoint-free programs
Compactly Representing First-Order Structures for Static Analysis
Spring 2016 Program Analysis and Verification
Program Analysis and Verification
Seminar in automatic tools for analyzing programs with dynamic memory
Formal Methods in Software Engineering 1
Symbolic Implementation of the Best Transformer
Programming Languages 2nd edition Tucker and Noonan
Parametric Shape Analysis via 3-Valued Logic
Predicate Transformers
Symbolic Characterization of Heap Abstractions
A Semantics for Procedure Local Heaps and its Abstractions
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Putting Static Analysis to Work for Verification A Case Study Tal Lev-Ami Thomas Reps Mooly Sagiv Reinhard Wilhelm

Program Verification Mathematically prove that the program is “partially” correct on all inputs Example: Hoare style verification x  n {x := x + 1} x  n + 1

Why Use Program Verification? Debugging programs is hard Testing can only show the presence of errors - not their absence Can provide counter examples...

Obstacles to Program Verification Hard to specify software Does not “scale” –Limited program size –Programmer needs to provide loop invariants –Pointers and dynamically allocated objects are not handled

Our Goals Handle pointers and dynamically allocated objects (unbounded memory and/or multi-threading) No loop invariants Input: pre {Procedure} post Output: –A safe approximation to the strongest postcondition p –Issue a warning if p  post Conservative: –Never misses an error –May yield false warnings

L insert_sort(L x) { L r, pr, rn, l, pl;r = x; pr = NULL; while (r != NULL) { l = x;rn = r ->n; pl = NULL; while (l != r) { if (l->data > r->data) { pr->n = rn; r->n = l; if (pl == NULL) x = r; else pl->n = r; r = pr; break; } pl = l; l = l->n; } pr = r; r = rn; } return x; } list(x) olist(x) typedef struct node { int data; struct node *n; *L;

int main() { L x, y, z, w; L create(), insert_sort(L); L merge(L,L), reverse(L); x = create(); x = insert_sort(x); y = create(); y = insert_sort(y); z = merge(x,y); w = reverse(z); } olist(x)list(x) olist(y) list(y) olist(z) rolist(w)

Conventional Verification Formulae over program variables express pre- and post-conditions The assignment rule is used to generate the strongest postcondition for non-destructive updates Programmer provides loop invariants Finite set of descriptors express pre- and post-conditions Predicate-update formulae specify safe set of descriptors (abstract semantics) Iteratively explore all the descriptors at every program point (abstract interpretation) The ADT designer can provide domain specific information via instrumentation Our Approach

Outline of the Rest of this Talk Concentrate on sorting Descriptors Compact representation of stores State-space exploration via abstract interpretation Prototype implementation in TVLA Three-Valued Logic Analyzer Conclusions

Logical representation of stores 19796null x data nnn p[x](v) n(v1, v2)dle(v1, v2)predicates p[x]=1 n dle p[x]=0 n dle p[x]=0 dle

Three-Valued Logic 1 - True 0 - False ½ = {1, 0} Unknown A join semi-lattice 0  1 = ½   ½ Information order

Blurred Representation of Stores 19796null x data nnn p[x]=1 n dle p[x]=0 n dle p[x]=0 dle p[x]=1 n dle p[x]=0 n dle

Parametric Abstraction (Blur) Merge all the nodes with the same unary “abstraction” predicate values into a single summary node Join predicate values Convert a structure of arbitrary size into a 3-valued structure of bounded size

Instrumentation Explicitly maintains information about distinctions among cells Leads to less blurring when used as abstraction predicates Unary predicates defined via a first order formula+transitive closure Example “local order” –inOrder[n](v) =  v 1 : n(v, v 1 )  dle(v, v 1 ) –inROrder[n](v) =  v 1 : n(v, v 1 )  dle(v 1, v)

Blurred Representation of Stores p[x]=1 inOrder[n]=1 n dle p[x]=0 inOrder[n]=1 n dle p[x]=0 inOrder[n]=1 dle inOrder[n](v1)n(v1, v2)dle(v1, v2)p[x](v) dle n n p[x]=1 inOrder[n]=1 dle p[x]=0 inOrder[n]=1 dle

Arbitrary Lists n p[x]=0 inOrder[n]=½ p[x]=1 inOrder[n]=½ dle n n p[x]=1 inOrder[n]=1 dle p[x]=0 inOrder[n]=1 dle n vs.

Abstract Interpretation Iteratively compute a set of structures at every program location Conservatively interpret statements (conditions) on blurred structures Must terminate since the number of blurred structures is finite for a given program Fully automatic Guaranteed to be sound But may be overly conservative

Abstract Interpretation of Insertion Sort p[x]=0 inOrder[n]=½ p[x]=1 inOrder[n]=½ dle n p[x]=1 inOrder[n]=1 dle p[x]=0 inOrder[n]=1 dle n n n

The Key Problem How to interpret statements (conditions) on blurred structures? Difficult to provide a conservative (and reasonably precise) interpretation –It is difficult to show that specific abstractions are conservative (Sagiv, Reps, Wilhelm, TOPLAS 98) –Long and intimidating proofs –Or no proofs (and bugs)

The best conservative interpretation Cousot&Cousot 1979 abstract representation Set of states concretization Abstract semantics statement s abstract representation abstraction Operational semantics statement s Set of states

The 3 Valued-Logic Approach Automatically derives a conservative interpretation of statements and conditions from: –structural operational semantics written using logical formulae global properties –abstraction predicates An experimental system (TVLA) Correct by construction

x->d d  v 1, v 2 :p[x] (v 1 )  p[y]( v 2 )  dle (v 1, v 2 ) true p[x]=1 p[y]=0 inOrder[n]=1 dle n p[x]=0 p[y]=1 inOrder[n]=½ n dle p[x]=0 p[y]=0 inOrder[n]=½ dle n p[x]=1 p[y]=0 inOrder[n]=½ n dle p[x]=0 p[y]=1 inOrder[n]=½ n dle p[x]=0 p[y]=0 inOrder[n]=½ dle n

From Local Outlook to Global Outlook (Safety) Every time control reaches a given point: –there are no garbage memory cells –the list is acyclic –each cell is locally ordered (History) The list is a permutation of the original list

Bugs Found Pointer manipulations –null dereferences –memory leaks Forget to sort the first element Swap equal elements in bubble sort (non-termination)

L insert_sort_b2(L x) { L r, pr, rn, l, pl; if (x == NULL) return NULL; pr = x; r = x->n; while (r != NULL) { pl = x; rn = r->n; l = x->n; while (l != r) { if (l->d > r->d) { pr->n = rn; r->n = l ; pl->n = r; r = pr; break } pl = l;l = l->n; } pr = r; r = rn;} return x; } n p[x]=1 inOrder[n]=½ dle p[x]=0 inOrder[n]=1 dle n

Running Times

Properties Not Proved (Liveness) Termination Stability

Related Work Temporal-logic model checking –Manually extracts finite-state machine –Does not handle dynamically allocated data –But proves stronger properties, e.g., liveness Bourdoncle 93 –Handles integer arithmetic –Cannot handle pointers

Further Work Recursive programs (Quicksort) Experiment with other ADTs (AVL trees) Automatically derive predicate-update formulae for instrumentation predicates Scaling to larger programs –User annotations –Class-level analysis –Modular analysis –Space optimizations –Smart front-end that precomputes “cheap” information

Conclusions It is possible to automatically verify non- trivial properties of complex C programs that manipulate dynamically allocated memory w/o providing loop invariant The implementation is automatically generated from TVLA But scaling is an issue

Other Applications of TVLA Verifying “cleanness” properties of C programs (Dor, Rodeh, Sagiv 2000) –null derefernces –memory leaks Verifying safety properties of Mobile Ambients (Nielson, Nielson, Sagiv 2000) Verifying safety programs of multithreaded Java programs (Yahav 2000) –Deadlocks –Nested monitors –Read/Write interference

Boolean Connectives [Kleene]

The Operational Semantics of x = t->n x’(v 1, v 2 ) =  v 1 : t (v 1 )  n (v 1, v 2 )

The Operational Semantics of x->n = NULL inOrder’[dle, n](v) = inOrder [dle, n](v)  x (v) n’(v 1, v 2 ) = n (v 1, v 2 )  x (v 1 ) inROrder’[dle, n](v) = inROrder [dle, n](v)  x (v)

inOrder’[dle, n](v) = (x(v)?  v 1 : t(v 1 )  dle(v, v 1 ): InOrder[dle, n](v) ) inROrder’[dle, n](v) = (x(v)?  v 1 : t(v 1 )  dle(v 1, v): inROrder[dle, n](v) ) The Operational Semantics of x->n = t n’(v 1, v 2 ) = n (v 1, v 2 )  (x (v 1 )  t(v 2 ))