Annotation-Assisted Lightweight Static Checking

Slides:



Advertisements
Similar presentations
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Advertisements

Modular and Verified Automatic Program Repair Francesco Logozzo, Thomas Ball RiSE - Microsoft Research Redmond.
C Language.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
C++ Programming Languages
SPLINT STATIC CHECKING TOOL Sripriya Subramanian 10/29/2002.
Joel Winstead CS201j: Engineering Software University of Virginia Computer Science Lecture 16: Pointers and Memory Management.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Road Map Introduction to object oriented programming. Classes
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Statically Detecting Likely Buffer Overflow Vulnerabilities David Larochelle David Evans University of Virginia Department of Computer Science Supported.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Natalia Yastrebova What is Coverity? Each developer should answer to some very simple, yet difficult to answer questions: How do I find new.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
David Evans These slides: Introduction to Static Analysis.
DTS ( Defect Testing System ) Yang Zhao Hong, Gong Yun Zhan,Xiao Qing, Wang Ya Wen Beijing University of Posts and Telecommunications
David Evans CS551/651: Dependable Computing University of Virginia Computer Science Static Analysis.
David Evans The Bugs and the Bees Research in Swarm Programming and Security University of Virginia.
David Evans The Bugs and the Bees Research in Programming Languages and Security University of.
Systems for Safety and Dependability David Evans University of Virginia Department of Computer Science.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
1 Splint: A Static Memory Leakage tool Presented By: Krishna Balasubramanian.
(A Somewhat Self-Indulgent) Splint Retrospective David Evans University of Virginia 25 October 2010.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
POINTERS. // Chapter 3 - Program 1 - POINTERS.CPP #include int main() { int *pt_int; float *pt_float; int pig = 7, dog = 27; float x = , y = 32.14;
David Evans The Bugs and the Bees Research in Programming Languages and Security University of.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
CS 5150 Software Engineering Lecture 21 Reliability 2.
University of Virginia Computer Science Extensible Lightweight Static Checking David Evans On the I/O.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
Jeremy Nimmer, page 1 Automatic Generation of Program Specifications Jeremy Nimmer MIT Lab for Computer Science Joint work with.
Memory Management.
Secure Coding Rules for C++ Copyright © 2016 Curt Hill
Principles of programming languages 10: Object oriented languages
Chapter 10 : Implementing Subprograms
Computer Organization and Design Pointers, Arrays and Strings in C
User-Written Functions
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 8 – Software Testing
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
Pointers Revisited What is variable address, name, value?
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Pointers and References
Advanced Programming Behnam Hatami Fall 2017.
CSCI 3370: Principles of Programming Languages Chapter 9 Subprograms
The Future of Software Engineering: Tools
Dynamic Memory Allocation
High Coverage Detection of Input-Related Security Faults
Improving software quality using Visual Studio 11 C++ Code Analysis
Improving Security Using Extensible Lightweight Static Analysis
Pointers, Dynamic Data, and Reference Types
Built-In (a.k.a. Native) Types in C++
Reference Parameters.
Effective and Efficient memory Protection Using Dynamic Tainting
Lecture 22: Shameless Self-Promotion From (Bob Nelson)
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
Java Programming Language
Programming in C Pointer Basics.
Pointers, Dynamic Data, and Reference Types
Standard Version of Starting Out with C++, 4th Edition
Classes and Objects Object Creation
SPL – PS3 C++ Classes.
CMSC 202 Constructors Version 9/10.
Presentation transcript:

Annotation-Assisted Lightweight Static Checking Thanks Thesis work on policy-directed code safety. Goal: Prevent programs from doing bad things but allow good programs to do useful work. David Evans evans@cs.virginia.edu http://lclint.cs.virginia.edu Collaborators: John Knight, David Larochelle LCLint University of Virginia Department of Computer Science

A Gross Oversimplification all Formal Verifiers Bugs Detected State of the world before LCLint (gross simplification) Static checking as part of compilers or standard lint Formal verification tools – range from fiendishly expensive to unfathomable not used much except in academic research projects and when taxpayers are paying Just to prove I have some powerpoint animation skills, even if they aren’t as impressive as Nick McKeown’s Compilers none Low Unfathomable Effort Required 4 June 2000 David Evans

State of the world before LCLint (gross simplification) Static checking as part of compilers or standard lint Formal verification tools – range from fiendishly expensive to unfathomable not used much except in academic research projects and when taxpayers are paying Just to prove I have some powerpoint animation skills, even if they aren’t as impressive as Nick McKeown’s LCLint 4 June 2000 David Evans

Requirements No interaction required – as easy to use as a compiler Fast checking – as fast as a compiler Gradual Learning/Effort Curve Little needed to start Clear payoff relative to user effort 4 June 2000 David Evans

Approach Programmers add annotations (formal specifications) Simple and precise Describe programmers intent: Types, memory management, data hiding, aliasing, modification, null-ity, etc. LCLint detects inconsistencies between annotations and code Simple (fast!) dataflow analyses 4 June 2000 David Evans

Sample Annotation: only extern only char *gptr; extern only out null void *malloc (int); Reference (return value) owns storage No other persistent (non-local) references to it Implies obligation to transfer ownership Transfer ownership by: Assigning it to an external only reference Return it as an only result Pass it as an only parameter: e.g., extern void free (only void *); 4 June 2000 David Evans

Example extern only null void *malloc (int); in library 1 int dummy (void) { 2 int *ip= (int *) malloc (sizeof (int)); 3 *ip = 3; 4 return *ip; 5 } Note: user didn’t have to write any annotations to discover these bugs! LCLint output: dummy.c:3:4: Dereference of possibly null pointer ip: *ip dummy.c:2:13: Storage ip may become null dummy.c:4:14: Fresh storage ip not released before return dummy.c:2:43: Fresh storage ip allocated 4 June 2000 David Evans

Checking Examples Encapsulation – abstract types (rep exposure), global variables, documented modifications Memory management – leaks, dead references De-referencing null pointers, dangerous aliasing, undefined behavior (order of modifications, etc.) 4 June 2000 David Evans

Unsoundness & Incompleteness are Good! Okay to miss errors Report as many as possible Okay to issue false warnings But don’t annoy the user to too many Make it easy to configure checking and override warnings Design tradeoff – do more ambitious checking the best you can 4 June 2000 David Evans

LCLint Status Public distribution since 1993 Effective checking >100K line programs (checks about 1K lines per second) Detects lots of real bugs in real programs (including itself, of course) Over 1000 users More information: lclint.cs.virginia.edu PLDI ’96, FSE’94 4 June 2000 David Evans

Where do we go from here? Extensible Checking Allow users to define new annotations and associated checking Integrate run-time checking Combine static and run-time checking to enable additional checking and completeness guarantees Generalize framework Support static checking for multiple source languages in a principled way 4 June 2000 David Evans

Extensible Checking LCLint engine provides analysis core Events associated with code points Control flow analysis, alias analysis User (library) defines checking rules Introduces state associated with types of objects (e.g., references, numeric values) Defines annotations for initializing and constraining that state Defines checking rules associated with code events 4 June 2000 David Evans

Example: Nullity state nullity { applies to reference oneof { notnull, maybenull, isnull } default maybenull merge { notnull + (maybenull | isnull) = maybenull maybenull + * = maybenull isnull + (maybenull | notnull) = maybenull } guard { != NULL => notnull == NULL => isnull 4 June 2000 David Evans

Nullity Checks checks (reference x) nullity { transfer (notnull, { notnull, maybenull }) transfer (maybenull, maybenull) transfer (isnull, { isnull, maybenull }); *x requires notnull } annotation null : reference declaration requires state nullity nullity = maybenull; annotation notnull : reference declaration nullity = notnull; 4 June 2000 David Evans

Example: Sharing state sharing { applies to reference oneof { only, temp, shared, dead } default { result, global, field } only parameter temp } annotation only : reference x { x.sharing = only; } annotation temp : reference x { x.sharing = temp; } 4 June 2000 David Evans

Sharing Checks checks (reference x) { must transfer transfer (only, only) becomes dead transfer (temp, only) use x requires not dead } 4 June 2000 David Evans

Open Questions What are the primitives? What are the limits on checking? Without sacrificing static and efficient requirements Can decent messages be generated automatically from checking definitions? Is this framework sufficiently powerful to describe a useful class of checks? Is this framework sufficiently accessible to allow programmers to define application-specific checks? 4 June 2000 David Evans

Test Cases Built-in LCLint annotations and checks Buffer Overflows [David Larochelle] Adapted from [Wagner00] Depends on numerical range analysis Can this be defined or must it be a primitive? Information flow Based on JFlow [Myers99] Need to provide parameterized annotations Support for polymorphism Can this be defined or must to be added to engine? 4 June 2000 David Evans

Summary A little redundancy goes a long way Don’t need a full specification to do useful checking Gradually add more redundancy to get better checking Lots of opportunity for user-defined checking But many open questions to answer 4 June 2000 David Evans

Credits LCLint Funding David Larochelle LCL: Yang Meng Tan, John Guttag, Jim Horning Funding DARPA, NSF, ONR, NASA 4 June 2000 David Evans

State, Annotations and Checking A large class of useful checking involves: Associating state with references at execution points Providing type-judgment rules for the new state Providing state transition rules Can we define this class? Can we describe new annotations and checks in a way the is accessible to normal programmers? Don’t want rules for every grammar production 4 June 2000 David Evans

Concrete Example: Buffer Overflow Errors [credits] State: reference { bool nullterminated; int allocated; int 4 June 2000 David Evans