Detecting and preventing bugs with pluggable type-checking Michael D. Ernst University of Washington Joint work with Mahmood Ali, Werner Dietl, …

Slides:



Advertisements
Similar presentations
Static Analysis for Security
Advertisements

Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
Introduction to Maven 2.0 An open source build tool for Enterprise Java projects Mahen Goonewardene.
De necessariis pre condiciones consequentia sine machina P. Consobrinus, R. Consobrinus M. Aquilifer, F. Oratio.
Identity and Equality Based on material by Michael Ernst, University of Washington.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Type-based Taint Analysis for Java Web Applications Wei Huang, Yao Dong and Ana Milanova Rensselaer Polytechnic Institute 1.
Object and Reference Immutability using Java Generics Yoav Zibin, Alex Potanin(*), Mahmood Ali, Shay Artzi, Adam Kiezun, and Michael D. Ernst MIT Computer.
Preventing bugs with pluggable type checking Michael D. Ernst University of Washington Object x)
GUI Threading Explained and Verified Michael Ernst U. of Washington, Seattle, USA IMDEA Software Institute, Madrid, Spain joint work with Colin Gordon,
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
Static code check – Klocwork
Detecting Format String Vulnerabilities with Type Qualifier Umesh Shankar, Kunal Talwar, Jeffrey S. Foster, David Wanger University of California at Berkeley.
Visualizing Type Qualifier Inference with Eclipse David Greenfieldboyce Jeffrey S. Foster University of Maryland.
CQual: A Tool for Adding Type Qualifiers to C Jeff Foster et al UC Berkeley OSQ Retreat, May
Javari: Adding Reference Immutability to Java Matthew Tschantz and Michael Ernst MIT CSAIL.
Usable code verification: balancing costs and benefits Two nuggets: User-defined verifiers Crowd-sourced verification Michael D. Ernst University of Washington.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Object x) { List lst; … } Detecting and preventing null pointer errors with pluggable type-checking CSE 331 University of Washington.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
Introduction to the Visual Studio.NET IDE (LAB 1 )
A Bipartite Graph Model of Information Flow IFIP WG 2.3, May 2014 Gary T. Leavens (with John L. Singleton) University of Central Florida Orlando Florida.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Preventing bugs with pluggable type checking Michael Ernst and Mahmood Ali University of Washington and MIT OOPSLA 2009 tutorial Object.
Modern Software Development Using C#.NET Chapter 5: More Advanced Class Construction.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Axel Naumann. Outline  Static Code Analysis  Coverity  Reporting Tools, Report Quality  "Demo": Examples Axel Naumann Application Area Meeting2.
User-defined type checkers for error detection and prevention in Java Michael D. Ernst MIT Computer Science & AI Lab
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
1 XINS features 101 new features of XINS This presentation has 102 pages.
Advanced C# Types Tom Roeder CS fa. From last time out parameters difference is that the callee is required to assign it before returning not the.
Finding Errors in.NET with Feedback-Directed Random Testing Carlos Pacheco (MIT) Shuvendu Lahiri (Microsoft) Thomas Ball (Microsoft) July 22, 2008.
Demo of Scalable Pluggable Types Michael Ernst MIT Dagstuhl Seminar “Scalable Program Analysis” April 17, 2008.
Michael Dalton, Christos Kozyrakis, and Nickolai Zeldovich MIT, Stanford University USENIX 09’ Nemesis: Preventing Authentication & Access Control Vulnerabilities.
How analysis can hinder source code manipulaton And what to do about it Michael Ernst University of Washington.
JSR 308: Type Annotations Making Java annotations more general and more useful Spec leads: Michael Ernst & Alex Buckley Implementation lead: Werner Dietl.
Java Annotations. Annotations  Annotations are metadata or data about data. An annotation indicates that the declared element should be processed in.
1 CSE 331 Hash codes; annotations slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Java Annotations for Types and Expressions Mathias Ricken October 24, 2008 COMP 617 Seminar.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
Detecting and preventing bugs with pluggable type-checking Michael D. Ernst University of Washington Joint work with Werner Dietl, and many others
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
ReIm & ReImInfer: Checking and Inference of Reference Immutability and Method Purity Wei Huang 1, Ana Milanova 1, Werner Dietl 2, Michael D. Ernst 2 1.
Secure Programming with Static Analysis Brian Chess, Ph.D.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Preventing bugs with pluggable type checking Michael Ernst University of Washington Joint work with Mahmood Ali and Matthew Papi Object.
Preventing bugs with pluggable type-checking Michael Ernst MIT
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 16 Checker Framework.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Findbugs Tin Bui-Huy September, Content What is bug? What is bug? What is Findbugs? What is Findbugs? How to use Findbugs? How to use Findbugs?
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
for regular expressions
Jeremy Nimmer, page 1 Automatic Generation of Program Specifications Jeremy Nimmer MIT Lab for Computer Science Joint work with.
CSE 331 Software Design and Implementation
Content Coverity Static Analysis Use cases of Coverity Examples
Javarifier: inference of reference immutability
Logger, Assert and Invariants
Lightweight Verification of Array Indexing
CodePeer Update Arnaud Charlet CodePeer Update Arnaud Charlet
CodePeer Update Arnaud Charlet CodePeer Update Arnaud Charlet
Introduction to Static Analyzer
CSE 331 Annotations slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Semantic Type Qualifiers
Java Annotations for Invariant Specification
Presentation transcript:

Detecting and preventing bugs with pluggable type-checking Michael D. Ernst University of Washington Joint work with Mahmood Ali, Werner Dietl, … Object x) { List lst; … }

Motivation java.lang.NullPointerException

Java’s type checking is too weak Type checking prevents many bugs int i = “hello”; // type error Type checking doesn’t prevent enough bugs System.console().readLine();  NullPointerException Collections.emptyList().add(“One”);  UnsupportedOperationException 3

Some errors are silent Date date = new Date(0); myMap.put(date, “Java epoch”); date.setYear(70); myMap.put(date, “Linux epoch”);  Corrupted map dbStatement.executeQuery(userInput);  SQL injection attack Initialization, data formatting, equality tests, … 4

Problem: Your code has bugs Who discovers the problems? – If you are very lucky, testing discovers (some of) them – If you are unlucky, your customer discovers them – If you are very unlucky, hackers discover them – If you are smart, the compiler discovers them It’s better to be smart than lucky 5

Solution: Pluggable type systems Design a type system to solve a specific problem Write type qualifiers in code (or, use type Date date = new Date(0); date.setTime(70); // compile-time error Type checker warns about violations (bugs) 6 % javac -processor NullnessChecker MyFile.java MyFile.java:149: dereference of possibly-null reference bb2 allVars = bb2.vars; ^

Outline Type qualifiers Pluggable type checkers Writing your own checker Conclusion 7

Type qualifiers JSR 308 (in Java 8): annotations on String query; List strings; myGraph = Graph) tmpGraph; class UnmodifiableList List {} Backward-compatible (not in Java 8): compile with any Java compiler List strings; 8

Benefits of type qualifiers Find bugs in programs Guarantee the absence of errors Improve documentation Improve code structure & maintainability Aid compilers, optimizers, and analysis tools Reduce number of assertions and run-time checks Possible negatives: – Must write the types (or use type inference) – False positives are possible (can be suppressed) 9

Outline Type qualifiers Pluggable type checkers Writing your own checker Conclusion 10

What bugs can you detect & prevent? Null Mutation and Concurrency: Security: Equality Strings: regular expression signature Typestate (e.g., open/closed Users can write their own checkers! The annotation you write: 11 The property you care about:

Using a checker Run in IDE or on command line Works as a compiler plug-in (annotation processor) Uses familiar error messages % javac –processor NullnessChecker MyFile.java MyFile.java:9: incompatible types. nonNullVar = nullableValue; ^ found String String 12

Nullness and mutation demo Detect errors Guarantee the absence of errors Verify the correctness of optimizations 13

Checkers are effective Over 3,000,000 LOC checked Each checker found errors in each code base it ran on – Verified by a human and fixed 14

Recent case study results Compiler messages: 8 wrong keys in Checker Framework Fake enumerations: minor problems in Swing, JabRef Signature strings: 28 errors in OpenJDK, ASM, AFU Interning: >200 minor problems in Xerces, Lucene Nullness: >200 errors in Google Collections, Daikon First-year CS majors used the Checker Framework – Stated they preferred using it to not

Comparison: other Nullness tools Null pointer errorsFalse warnings Annotations written FoundMissed Checker Framework FindBugs081 0 Jlint088 0 PMD080 0 Checking the Lookup program for file system searching (4KLOC) Distributed with Daikon (>100KLOC verified by our checker) False warnings are suppressed via an annotation or assertion Also, errors in Google Collections (>20,000 tests, FindBugs) 16

Checkers are featureful Full type systems: inheritance, overriding, etc. Generics (type polymorphism) – Also qualifier polymorphism Flow-sensitive type qualifier inference – Infers types for local variables Qualifier defaults Warning suppression 17

Checkers are usable Integrated with toolchain – javac, Eclipse, Ant, Maven Few false positives Annotations are not too verbose : 1 per 75 lines with program-wide defaults, 1 per 2000 lines : 124 annotations in 220KLOC revealed 11 bugs – Possible to annotate part of program – Fewer annotations in new code Inference tools: nullness, mutability – Adds annotations throughout your program 18

What a checker guarantees The program satisfies the type property. There are: – no bugs (of particular varieties) – no wrong annotations Caveat 1: only for code that is checked – Native methods – Reflection – Code compiled without the pluggable type checker – Suppressed warnings Indicates what code a human should analyze – Checking part of a program is still useful Caveat 2: The checker itself might contain an error 19

Annotating libraries Each checker comes with JDK annotations – For signatures, not bodies – Finds errors in clients, but not in the library itself Inference tools for annotating new libraries 20

Outline Type qualifiers Pluggable type checkers Writing your own checker Conclusion 21

SQL injection attack Server code bug: SQL query constructed using unfiltered user input query = “SELECT * FROM users ” + “WHERE name=‘” + userInput + “’;”; User inputs: a’ or ‘1’=‘1 Result: query  SELECT * FROM users WHERE name=‘a’ or ‘1’=‘1’; Query returns information about all users 22

Taint checker To use it: in your program List String category) {…} 2.Compile your program javac -processor BasicChecker @ImplicitFor(trees = {STRING_LITERAL}) Untainted { } 23

Taint checker demo Detect SQL injection vulnerability Guarantee absence of such vulnerabilities 24

Defining a type NonNull { } 25

Defining a type system 1.Qualifier hierarchy – rules for assignment 2.Type introduction– types for expressions 3.Type rules– checker-specific NonNull { } 26

Defining a type system 1.Qualifier hierarchy 2.Type introduction Nullable.class ) NonNull { } 27 What assignments are legal:

Defining a type system 1.Qualifier hierarchy 2.Type introduction Nullable.class NEW_CLASS, PLUS, BOOLEAN_LITERAL,... } ) NonNull { } 28 new Date() “hello ” + getName() Boolean.TRUE Gives the type of expressions:

Defining a type system 1.Qualifier hierarchy 2.Type introduction 3.Type rules void visitSynchronized(SynchronizedTree node) { ExpressionTree expr = node.getExpression(); AnnotatedTypeMirror type = getAnnotatedType(expr); if (! type.hasAnnotation(NONNULL)) checker.report(Result.failure(...), expr); } 29 synchronized(expr) { … } Warn if expr may be null Errors for unsafe code:

Outline Type qualifiers Pluggable type checkers Writing your own checker Conclusion 30

Pluggable type-checking Java 8 syntax for type annotations Checker Framework for creating type checkers – Featureful, effective, easy to use, scalable Prevent bugs at compile time Create custom type-checkers Learn more, or download the Checker Framework: (or, web search for “Checker Framework” or “JSR 308”) 31