Checking and Inferring Local Non-Aliasing Alex AikenJeffrey S. Foster UC BerkeleyUMD College Park John KodumalTachio Terauchi UC Berkeley.

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Static Analysis for Security
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
“FENDER” AUTOMATIC MEMORY FENCE INFERENCE Presented by Michael Kuperstein, Technion Joint work with Martin Vechev and Eran Yahav, IBM Research 1.
1 1 Regression Verification for Multi-Threaded Programs Sagar Chaki, SEI-Pittsburgh Arie Gurfinkel, SEI-Pittsburgh Ofer Strichman, Technion-Haifa Originally.
Demand-driven Alias Analysis Implementation Based on Open64 Xiaomi An
Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
Type Qualifiers CS Software Quality Today Even after large, extensive testing efforts, commercial software is shipped riddled with errors ("bugs").
Background for “KISS: Keep It Simple and Sequential” cs264 Ras Bodik spring 2005.
1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
6/14/991 Symbolic verification of systems with state machines David L. Dill Jeffrey Su Jens Skakkebaek Computer System Laboratory Stanford University.
Using Programmer-Written Compiler Extensions to Catch Security Holes Authors: Ken Ashcraft and Dawson Engler Presented by : Hong Chen CS590F 2/7/2007.
Optimistic Bug Finding David Gupta and Junfeng Yang.
C. FlanaganSAS’04: Type Inference Against Races1 Type Inference Against Races Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College.
Scalable Error Detection using Boolean Satisfiability 1 Yichen Xie and Alex Aiken Stanford University.
Vertically Integrated Analysis and Transformation for Embedded Software John Regehr University of Utah.
Type-Safe Programming in C George Necula EECS Department University of California, Berkeley.
Type Qualifiers: Lightweight Specifications to Improve Software Quality Jeffrey S. Foster.
Aliases in a bug finding tool Benjamin Chelf Seth Hallem June 5 th, 2002.
Thread-modular Abstraction Refinement Tom Henzinger Ranjit Jhala Rupak Majumdar [UC Berkeley] Shaz Qadeer [Microsoft Research]
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
Program analysis Mooly Sagiv html://
Interprocedural analyses and optimizations. Costs of procedure calls Up until now, we treated calls conservatively: –make the flow function for call nodes.
Synergy: A New Algorithm for Property Checking
CS 536 Spring Global Optimizations Lecture 23.
1 Predicate Abstraction of ANSI-C Programs using SAT Edmund Clarke Daniel Kroening Natalia Sharygina Karen Yorav (modified by Zaher Andraus for presentation.
Speeding Up Dataflow Analysis Using Flow- Insensitive Pointer Analysis Stephen Adams, Tom Ball, Manuvir Das Sorin Lerner, Mark Seigle Westley Weimer Microsoft.
Visualizing Type Qualifier Inference with Eclipse David Greenfieldboyce Jeffrey S. Foster University of Maryland.
Refining Abstract Locations Tachio Terauchi Jeff Foster Alex Aiken.
A Type-Checked Restrict Qualifier Jeff Foster OSQ Retreat May 9-10, 2001.
Intraprocedural Points-to Analysis Flow functions:
Michael Ernst, page 1 Improving Test Suites via Operational Abstraction Michael Ernst MIT Lab for Computer Science Joint.
Prof. Fateman CS 164 Lecture 221 Global Optimization Lecture 22.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
From last time: Inlining pros and cons Pros –eliminate overhead of call/return sequence –eliminate overhead of passing args & returning results –can optimize.
Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization.
1 Loop-Extended Symbolic Execution on Binary Programs Pongsin Poosankam ‡* Prateek Saxena * Stephen McCamant * Dawn Song * ‡ Carnegie Mellon University.
CQual: A Tool for Adding Type Qualifiers to C Jeff Foster et al UC Berkeley OSQ Retreat, May
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
Region-Based Model Abstraction Jeremy Condit Jim Larus Sriram Rajamani Jakob Rehof OSQ Lunch 7 September 2003.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Automated Whitebox Fuzz Testing (NDSS 2008) Presented by: Edmund Warner University of Central Florida April 7, 2011 David Molnar UC Berkeley
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Aditya V. Nori, Sriram K. Rajamani Microsoft Research India.
Race Checking by Context Inference Tom Henzinger Ranjit Jhala Rupak Majumdar UC Berkeley.
Use of Coverity & Valgrind in Geant4 Gabriele Cosmo.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
1 Predicate Abstraction and Refinement for Verifying Hardware Designs Himanshu Jain Joint work with Daniel Kroening, Natasha Sharygina, Edmund M. Clarke.
Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Quality Assurance in the Presence of Variability Kim Lauenroth, Andreas Metzger, Klaus Pohl Institute for Computer Science and Business Information Systems.
/ PSWLAB Thread Modular Model Checking by Cormac Flanagan and Shaz Qadeer (published in Spin’03) Hong,Shin Thread Modular Model.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
1PLDI 2000 Off-line Variable Substitution for Scaling Points-to Analysis Atanas (Nasko) Rountev PROLANGS Group Rutgers University Satish Chandra Bell Labs.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
A User-Guided Approach to Program Analysis Ravi Mangal, Xin Zhang, Mayur Naik Georgia Tech Aditya Nori Microsoft Research.
The PLA Model: On the Combination of Product-Line Analyses 강태준.
Language-Based Security: Overview of Types Deepak Garg Foundations of Security and Privacy October 27, 2009.
Generating Automated Tests from Behavior Models
Threads Cannot Be Implemented As a Library
Locking discipline inference and checking Michael D
Over-Approximating Boolean Programs with Unbounded Thread Creation
CSE 153 Design of Operating Systems Winter 19
Automatic Abstraction of Microprocessors for Verification
Presentation transcript:

Checking and Inferring Local Non-Aliasing Alex AikenJeffrey S. Foster UC BerkeleyUMD College Park John KodumalTachio Terauchi UC Berkeley

Jeff Foster, PLDI'03, June 9, Introduction Aliasing: A long-standing problem –Pointers are hard to analyze...*p = 3... what is updated? –We need to know for compilers (optimization) software analysis tools (CQual, Cyclone, Vault, SLAM, ESP,...)

Jeff Foster, PLDI'03, June 9, Alias Analysis What expressions may refer to same location? –To what memory locations do expressions point? Alias analysis abstracts memory with bounded set of locations –Choices affect subsequent analysis Programmer has little input to alias analysis

Jeff Foster, PLDI'03, June 9, Example from CQual: Modeling Arrays lock *locks[n]; // define array of n locks actual memory locks abstraction CQual: All elements of locks[] may alias –Represented with a single abstract location  

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *l) { spin_lock(l); work(); spin_unlock(l); }  unlocked ?

Jeff Foster, PLDI'03, June 9, Example from CQual: Weak Update After acquiring lock,  is locked or unlocked –This is a weak update actual memory locks abstraction  UUUL L/U

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *l) { spin_lock(l); work(); spin_unlock(l); }  unlocked  locked or unlocked

Jeff Foster, PLDI'03, June 9, Why This Design? Simple, efficient, scalable alias analysis More abstract locations = –Greater precision –Less efficiency Need to model facts about more names at each state Observation: A little extra local information would make a big difference

Jeff Foster, PLDI'03, June 9, Restrict void do_with_lock(lock *restrict l) {... } –Let l point to lock a –Within l’s scope, all accesses to a are through l (Approximately)  In do_with_lock, no other aliases of a used Can use strong updates on state of l

Jeff Foster, PLDI'03, June 9, Contributions of This Work Type and effect system for checking that uses of restrict are safe –Provably sound –Contrast to ANSI C: restrict annotation trusted unchecked, with informal semantics New construct confine –Short-hand for common uses of restrict –Easier to use

Jeff Foster, PLDI'03, June 9, Contributions of This Work (cont’d) Automatic inference of restrict and confine Experiment using confine inference in checking locking in Linux kernel –Recovered strong updates in 95% of cases –Enabled new deadlocks to come to light

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked  U

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked copy  to   U  U

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked copy  to   U  U

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked copy  to   locked strong update  U  L  represents only one location –Safe to perform strong update (replacement)

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked  unlocked copy  to   locked  U  U  represents only one location –Safe to perform strong update (replacement)

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked  unlocked copy  to  copy  to   locked  U  U  represents only one location –Safe to perform strong update (replacement)

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked  unlocked copy  to  copy  to   locked  U  U  represents only one location –Safe to perform strong update (replacement)

Jeff Foster, PLDI'03, June 9, Example from CQual void foo(int i) { do_with_lock(locks[i]); } void do_with_lock(lock *restrict l) { spin_lock(l); work(); spin_unlock(l); }  unlocked  unlocked copy  to  copy  to   locked  U  U  unlocked  represents only one location –Safe to perform strong update (replacement)

Jeff Foster, PLDI'03, June 9, Check Restrict with Type and Effect System Types extended with abstract locations –Flow-insensitive, unification-based may-alias analysis  ::=  | ref  (  )pointer to abstract loc  Effects are sets of locations L ::= Ø | {  }  | L1  L2 | L1  L2

Jeff Foster, PLDI'03, June 9, Type Rules A | e :  ; L –In environment A, expression e has type  –evaluating e has effect L A | e : ref  (  ); L A | *e :  ; L  {  }

Jeff Foster, PLDI'03, June 9, Restrict restrict x = e1 in e2 –x is a pointer initialized to e1 –x is in scope only within e2 –within e2, only x and copies derived from x can be used to access *x –outside of e2, values derived from x cannot be used

Jeff Foster, PLDI'03, June 9, Restrict Rule A | e1 : ref  (  1); L1 A | restrict x = e1 in e2 : A[ref  (  1)\x] | e2 :  2; L2   L2  locs(A  1  2)  2; L1  L2  {  }

Jeff Foster, PLDI'03, June 9, Soundness Type system for checking restrict is sound –Well-typed program doesn’t go wrong according to a formal semantics  uses of restrict are safe Provable using standard subject-reduction techniques

Jeff Foster, PLDI'03, June 9, Improving Restrict Must bind a variable name in restrict spin_lock(locks[i]); work(); spin_unlock(locks[i]);

Jeff Foster, PLDI'03, June 9, Improving Restrict Must bind a variable name in restrict restrict mylock = locks[i] in { spin_lock(mylock) work(); spin_unlock(mylock); } –Time consuming, need to manually check transformation is safe

Jeff Foster, PLDI'03, June 9, Confine Short-hand for previous transformation confine (locks[i]) in { spin_lock(locks[i]) work(); spin_unlock(locks[i]); } –Only need to pick expression, introduce scope

Jeff Foster, PLDI'03, June 9, Confine Inference Assume we know expression to confine –In experiment, given spin_lock(e) try confining e Algorithm –Introduce confine everywhere –Eliminate incorrect confines –Greedily combine adjacent confines (confine e in e1 ; confine e in e2) = confine e in e1;e2 Use heuristics in practice to speed up

Jeff Foster, PLDI'03, June 9, PLDI’02 Results Found a number of locking bugs in Linux kernel –Many weak updates with multi-file analysis In CQual, weak updates to locks yield type errors –Makes it hard to find true locking bugs Can we eliminate weak updates with restrict? –Yes, but painful to put in by hand

Jeff Foster, PLDI'03, June 9, New Experiment: Eliminating Weak Updates How many more strong updates with confine inference? Metric: # lock updates involved in error –Lower bound: Assume all updates are strong But unsound!

Jeff Foster, PLDI'03, June 9, Type Errors No type errors because of weak updates Potential improvement 352/ 60% 85/ 14% 152/ 26% 589 total modules

Jeff Foster, PLDI'03, June 9, Actual Improvement in Strong Updates 138/152: Same as assuming updates strong –Optimal result 14/152: Confine misses some strong updates –See paper for numbers

Jeff Foster, PLDI'03, June 9, Experimental Summary Overall, confine inference gets 95% of cases –Could eliminate 3277 type errors –Does eliminate 3116 type errors –(Includes duplicates from duplicated modules) Remaining type errors –Deadlocks (found 4 new ones) –Aliasing conservatism and lack of path sensitivity

Jeff Foster, PLDI'03, June 9, Conclusion restrict and confine successfully recover local strong updates –Can be used as programmer annotations to document aliasing properties Automatic confine inference works 95% of the time –Large improvement in quality of type errors