Differential program verification: Verifying properties of differences (instead of programs) Shuvendu Lahiri Research in Software Engineering (RiSE), Microsoft.

Slides:



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

Modular and Verified Automatic Program Repair Francesco Logozzo, Thomas Ball RiSE - Microsoft Research Redmond.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
Semantics Static semantics Dynamic semantics attribute grammars
Masahiro Fujita Yoshihisa Kojima University of Tokyo May 2, 2008
A Program Transformation For Faster Goal-Directed Search Akash Lal, Shaz Qadeer Microsoft Research.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
1 Regression-Verification Benny Godlin Ofer Strichman Technion.
1 1 Regression Verification for Multi-Threaded Programs Sagar Chaki, SEI-Pittsburgh Arie Gurfinkel, SEI-Pittsburgh Ofer Strichman, Technion-Haifa Originally.
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Koushik Sen CS 265.
SymDiff: Leveraging Program Verification for Comparing Programs Shuvendu Lahiri Research in Software Engineering (RiSE), Microsoft Research, Redmond Contributors:
Background for “KISS: Keep It Simple and Sequential” cs264 Ras Bodik spring 2005.
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
ISBN Chapter 3 Describing Syntax and Semantics.
Establishing Local Temporal Heap Safety Properties with Applications to Compile-Time Memory Management Ran Shaham Eran Yahav Elliot Kolodner Mooly Sagiv.
Houdini: An Annotation Assistant for ESC/Java Cormac Flanagan and K. Rustan M. Leino Compaq Systems Research Center.
Software Reliability Methods Sorin Lerner. Software reliability methods: issues What are the issues?
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Michael Ernst, page 1 Improving Test Suites via Operational Abstraction Michael Ernst MIT Lab for Computer Science Joint.
From last time S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l t S1 p L2 l t S1 p S2 l t.
Overview of program analysis Mooly Sagiv html://
Describing Syntax and Semantics
CS527: (Advanced) Topics in Software Engineering Overview of Software Quality Assurance Tao Xie ©D. Marinov, T. Xie.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Towards Scalable Modular Checking of User-defined Properties Thomas Ball, MSR Brian Hackett, Mozilla Shuvendu Lahiri, MSR Shaz Qadeer, MSR Julien Vanegue,
1 Testing, Abstraction, Theorem Proving: Better Together! Greta Yorsh joint work with Thomas Ball and Mooly Sagiv.
Program Analysis with Dynamic Change of Precision Dirk Beyer Tom Henzinger Grégory Théoduloz Presented by: Pashootan Vaezipoor Directed Reading ASE 2008.
Software testing Main issues: There are a great many testing techniques Often, only the final code is tested.
Differential and cross-version program verification Shuvendu Lahiri Research in Software Engineering (RiSE), Microsoft Research, Redmond, WA USA Halmstad.
Aditya V. Nori, Sriram K. Rajamani Microsoft Research India.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
1 Program Slicing Amir Saeidi PhD Student UTRECHT UNIVERSITY.
University of Toronto Department of Computer Science Lifting Transformations to Product Lines Rick Salay, Michalis Famelis, Julia Rubin, Alessio Di Sandro,
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Formal Verification. Background Information Formal verification methods based on theorem proving techniques and model­checking –To prove the absence of.
1 Proving program termination Lecture 5 · February 4 th, 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A.
Student: Shaobo He, Advisor: Zvonimir Rakamarić TOWARDS AUTOMATED DIFFERENTIAL PROGRAM VERIFICATION FOR APPROXIMATE COMPUTING.
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 4 Static Analysis. Summary (1) Building a model of the program:  Lexical analysis  Parsing  Abstract syntax  Semantic Analysis  Tracking.
CS 5150 Software Engineering Lecture 21 Reliability 2.
Jeremy Nimmer, page 1 Automatic Generation of Program Specifications Jeremy Nimmer MIT Lab for Computer Science Joint work with.
Presentation Title 2/4/2018 Software Verification using Predicate Abstraction and Iterative Refinement: Part Bug Catching: Automated Program Verification.
Path-Based Fault Correlations
Weakest Precondition of Unstructured Programs
SymDiff: A differential program verifier
Program Analysis via Satisfiability Modulo Path Programs
Input Space Partition Testing CS 4501 / 6501 Software Testing
runtime verification Brief Overview Grigore Rosu
Symbolic Implementation of the Best Transformer
Relatively Complete Refinement Type System for Verification of Higher-Order Non-deterministic Programs Hiroshi Unno (University of Tsukuba) Yuki Satake.
Aspect Validation: Connecting Aspects and Formal Methods
Programming Languages 2nd edition Tucker and Noonan
Over-Approximating Boolean Programs with Unbounded Thread Creation
The Zoo of Software Security Techniques
Predicate Abstraction
Model Checking and Its Applications
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Continuously Reasoning about Programs
SOFTWARE ENGINEERING INSTITUTE
Presentation transcript:

Differential program verification: Verifying properties of differences (instead of programs) Shuvendu Lahiri Research in Software Engineering (RiSE), Microsoft Research, Redmond Reps at 60 September 11, 2016

Sources of program differences f() { Print(foo); g(); } g() {... Print(foo); } f() { Print(foo); g(); } g() {... Print(foo); } g() {... Print(foo); Print(bar); } g() {... Print(foo); Print(bar); } New features Refactoring Approximate compilers Library API changes Bug fixes Most differences may not be equivalence preserving Version control

Two-fold motivation for diff verification High domain-specific upfront investment for static assertion verification (not for masses yet) – Need for assertions and ghost state – Model environment – Infer program-specific invariants – Scalability Natural way to specify regression-freedom – Equivalence – Preserves Memory safety Termination Performance Call chains … Verification failures  semantic diff Correctness of production code is not feasible worthwhile, but perhaps preserving “quality” of code with newly written code may be feasible worthwhile

Research questions What differential specifications distinguish intended from unintended semantic differences Equivalence, Assertion safety, Termination safety, … Can some software engineering tasks leverage differential verification? Change impact analysis, conflict-freedom, debugging regressions, … How to leverage/extend program specification and verification advances for differential verification? SMT, abstract interpretation, predicate abstraction, CEGAR, interpolants, …

Progress Applications – Differential assertion checking (DAC) [FSE’13] – Verification modulo versions (VMV) [PLDI’14] – Safety of approximate transformations [NFM’16] – Cross-version compiler validation for CLR [FSE’13, CAV’15] – Partition changesets for more efficient reviewing [ICSE’15] – Conflict-freedom of 3-way merge – Semantic change impact analysis – Semantic diff of concurrent programs SymDiff – Framework for differential program verification and invariant inference [CAV’12] – Differential specifications and proof system [CADE’13] mutual summaries and (relative) termination conditions Ongoing work

Overview Assertion specific – Differential assertion checking Generic properties of differences – Conflict-freedom of 3-way merge – Semantic change impact analysis Roots in Reps’ Wisconsin Program Integration project [late ‘80s] Starting point for me

Differential assertion checking

Verifying a bug fix void StringCopy2 (char* dst, char*src, int size) { int i=0; for(;i<size-1 && *src; i++) *dst++ = *src++; *dst = 0; } void StringCopy1 (char* dst, char*src, int size) { int i=0; for(;*src && i<size-1; i++) *dst++ = *src++; *dst = 0; } Does the difference introduce any invalid pointer access?

Option: verify the fixed program directly Check all dereferences are in bound Need precondition relating dst,src, size, null- terminated Need a program- specific  loop invariant void StringCopy2 (char* dst, char*src, int size) { int i=0; for(;i<size-1 && *src; i++) *dst++ = *src++; *dst = 0; } Add ghost variables to define buffer bounds and their quantified updates at malloc and postconditions

False alarms from no preconditions assert(Valid(x)) before every *x size ==2, !Valid(src)size ==2, !Valid(dst)size ==1, !Valid(dst) void StringCopy2 (char* dst, char*src, int size) { int i=0; for(;i<size-1 && *src; i++) *dst++ = *src++; *dst = 0; }

Differential assertion checking (DAC) – [Joshi, Lahiri, Lal POPL’12] [Lahiri et al. FSE’13] Correctness  Relative correctness – An input that can* satisfy P, cannot fail P’. – Note: asymmetric check How? – Replace assert A with ok := ok && A ; – Express it as a mutual summary specification: (i 1 ==i 2 && ok 1 ’) ==> ok 2 ’)

Weaker check: verify absence of regressions void StringCopy2 (char* dst, char*src, int size) { int i=0; for(;i<size-1 && *src; i++) *dst++ = *src++; *dst = 0; } void StringCopy1 (char* dst, char*src, int size) { int i=0; for(;*src && i<size-1; i++) *dst++ = *src++; *dst = 0; } Does the difference introduce any invalid pointer access? == Is there any input that passes StringCopy1 but fails StringCopy2?

Diff verification  Relative correctness void StringCopy2 (char* dst, char*src, int size) { int i=0; for(;i<size-1 && *src; i++) *dst++ = *src++; *dst = 0; } void StringCopy1 (char* dst, char*src, int size) { int i=0; for(;*src && i<size-1; i++) *dst++ = *src++; *dst = 0; } No need for any preconditions Mutual loop invariants: src.1=src.2, dst.1=dst.2, size.1=size.2, i.1=i.2, Mem_char.1 == Mem_char.2, ok1  ok2

Verifying real-world bug fixes and regressions Does a fix inadvertently introduce new bugs (wrt given assertions)? Verisec suite “snippets of open source programs which contain buffer overflow vulnerabilities, and corresponding patched versions.” – Relative memory safety (e.g. buffer overflow) checking – Snippets from apache, madwifi, sendmail etc. – Verified several bug fixes automatically using SymDiff [FSE’13] Verification modulo versions (VMV) [Logozzo, Lahiri, Blackshear, Fahndrich PLDI’14] – Another approach using abstract interpretation in Clousot – 10k+ LOC of C# projects, verified fixes, verified regressions 14

Similar problem in approximations Strcpy() { i := 0; while(src[i] != 0) { dst[i] := src[i]; i := i + 1; } dst[i] := 0; } StrcpyApprox() { i := 0; j := 0; while(src[i] != 0) { dst[j] := src[i]; i := i + 1; j := j + 1; if (src[i] == 0) {break;} i := i + 1; } dst[j] := 0; } [He, Lahiri, Rakamaric NFM’16] Show that StrcpyApprox preserves memory safety and termination Termination preservation does not even need a ranking function

Takeaway from DAC Relative correctness proofs have a better chance of automation – Weaker guarantees – Tolerates environment imprecision – Often a small space of proof works across domains

Conflict-freedom in 3-way merge

Conflict-freedom for 3-way merge (Informally) A merge is conflict-free if – changes from both branches A and B are preserved in merge – unchanged behaviors in both branches over Base are preserved in merge Popular merge are based on textual (semantics-unaware) diffs (e.g. diff3) – False positives: Spurious merge-conflicts due to overlapping textual diffs – False negatives: Silently admit merges that do not preserve conflict-freedom Base A B M

False alarms  dev frustration

False negatives  regressions Inconsistency can be introduced silently by (text- based) git merge – Blamed for Apple SSL/TLS Goto Bug 2014 (led to widely publicized security exploits)Apple SSL/TLS Goto Bug 2014 Questions – Can we have a semantic formulation of conflict- freedom? – Can we check such a property automatically?

Wisconsin Program Integration project Seminal work of Horwitz, Reps et al. – [POPL’88, ESOP’88, TAPSOFT’89, SCM’89, TOPLAS’89, SDE’90, ESOP’90, TAPSOFT’91,AMAST’91, SCP’91, TOSEM’92] Formalism – If value of a variable x differs in A (respectively B) from Base, then M should concur with A (respectively B). Otherwise x should have identical values in all 4 programs Synthesizing merges – Use of program dependence graphs (PDGs) and program slicing to merge programs [SCP’91] – Merge: Union of slices of changed behavior of A, B and the preserved behavior: – Test for interference: (a) change slices are preserved, (b) graph is a feasible PDG

Conflict-freedom as program verification – [Dillig, Sousa, Lahiri, Cheung, Vytiniotis] (ongoing) Proof-of-concept tool to verify conflict-freedom for (Base, A, B, M) – Uses advances in program verification (SMT, product programs, Horn-clause based invariant generation, …) – Requires manually specifying the “edits” Current work – End-to-end automated tool for Java/C – Synthesize conflict-free merges using program synthesis (verifier as an oracle)

Conflict-freedom verification sketch – Verify Conflict-freedom(Base, A, B, M) Come up with sound edit scripts eA, eB, eM – Maps a node in Base to an edit – s.t. Apply(Base,eA) == A etc. Create a 4-way product program – Uses a 4-way mini-product for each edited node n in Base – Add conflict-freedom assertion as postcondition Verification – Infer invariant (simulation relations) on the product program using Horn-clause solver (Duality)

Semantic change impact

Which statements are impacted by a change (soundly)? – Useful in code review – Hard to localize change (even for refactoring parts) Foo(x, z) { y = x + x 2x ; Bar(y); Complex(z); } Bar(y) { Baz(y+1); …. } Baz(z) { … Foo(.., z); …. } Spurious impacts in unchanged procedures makes code review ineffective Problem with existing approaches – CIA is not change-semantics aware

Semantic change impact Which statements are impacted by a change (soundly)? – Useful in code review – Hard to localize change (even for refactoring parts) Solution – Incorporate change semantics by inferring equivalences when they hold (SymDiff) – More subtle than checking two procedures are equal – Novel combination of data-flow and differential invariant inference Foo(x, z) { y = x + x 2x ; Bar(y); Complex(z); } Bar(y) { Baz(y+1); …. } Baz(z) { … Foo(.., z); …. } Bar’s arguments are identical in two versions

Refining change impact analysis with equivalences

Formalizing semantic impact and PreEquiv Formulation – Impacted statement: A (mapped) statement is impacted if there exists an initial state (from main) that results in difference sequence of read values in the two versions. – PreEquiv(x, f, f’): parameter x has the same sequence of values in both f and f’ for executions starting at an identical state The idea of comparing “sequence of vaues” appears in [Wang,Horwitz,Reps TOSEM’92], Intraprocedural setting

Semantic CIA Prototype – Use SymDiff to infer equivalence relations SummaryEquiv and PreEquiv – An algorithm to incrementally apply expensive eq uiv-inference over (1 program) data-flow analysis to refine the precision Evaluation – Applied to 164 real changes on 5 Github projects – Reduces impacted statements by 35% on average

Research questions What differential specifications distinguish intended from unintended semantic differences Equivalence, Assertion safety, Termination safety, Can some software engineering tasks leverage differential verification? Change impact analysis, conflict-freedom, debugging regressions, … How to leverage/extend program specification and verification advances for differential verification? SMT, abstract interpretation, predicate abstraction, CEGAR, interpolants, …

Progress Applications – Differential assertion checking (DAC) [FSE’13] – Verification modulo versions (VMV) [PLDI’14] – Safety of approximate transformations [NFM’16] – Cross-version compiler validation for CLR [FSE’13, CAV’15] – Partition changesets for more efficient reviewing [ICSE’15] – Conflict-freedom of 3-way merge – Semantic change impact analysis – Semantic diff of concurrent programs SymDiff – Tool for differential program verification and invariant inference [CAV’12] – Differential specifications and proof system [CADE’13] mutual summaries and (relative) termination conditions Chicken and Egg problem for difference verification – Industry needs well- studied problems to build production quality tools – Academia needs a well- defined problem to study the problem Reps’ Program Integration problem is a great example – Are there others?

Backup

Apple SSL bug