APEx: Automated Inference of Error Specifications for C APIs

Slides:



Advertisements
Similar presentations
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Advertisements

Finding bugs: Analysis Techniques & Tools Symbolic Execution & Constraint Solving CS161 Computer Security Cho, Chia Yuan.
Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Finding bugs: Analysis Techniques & Tools Comparison of Program Analysis Techniques CS161 Computer Security Cho, Chia Yuan.
1/20 Generalized Symbolic Execution for Model Checking and Testing Charngki PSWLAB Generalized Symbolic Execution for Model Checking and Testing.
David Brumley, Pongsin Poosankam, Dawn Song and Jiang Zheng Presented by Nimrod Partush.
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
RUGRAT: Runtime Test Case Generation using Dynamic Compilers Ben Breech NASA Goddard Space Flight Center Lori Pollock John Cavazos University of Delaware.
The Future of Correct Software George Necula. 2 Software Correctness is Important ► Where there is software, there are bugs ► It is estimated that software.
SE 450 Software Processes & Product Metrics Reliability: An Introduction.
DART Directed Automated Random Testing Patrice Godefroid, Nils Klarlund, and Koushik Sen Syed Nabeel.
Swami NatarajanJuly 14, 2015 RIT Software Engineering Reliability: Introduction.
State coverage: an empirical analysis based on a user study Dries Vanoverberghe, Emma Eyckmans, and Frank Piessens.
1 Joe Meehean. 2 Testing is the process of executing a program with the intent of finding errors. -Glenford Myers.
Statically Detecting Likely Buffer Overflow Vulnerabilities David Larochelle David Evans University of Virginia Department of Computer Science Supported.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Language Evaluation Criteria
Reverse Engineering State Machines by Interactive Grammar Inference Neil Walkinshaw, Kirill Bogdanov, Mike Holcombe, Sarah Salahuddin.
Software Testing CS 121 “Ordering Chaos” “Mike” Michael A. Erlinger
CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
CSCE 548 Secure Software Development Test 1 Review.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
University of Maryland Bug Driven Bug Finding Chadd Williams.
Neil Ghani Software testing. 2 Introduction In a perfect world all programs fully verified testing thus redundant Back in the real.
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
On-Demand Dynamic Software Analysis Joseph L. Greathouse Ph.D. Candidate Advanced Computer Architecture Laboratory University of Michigan December 12,
Using Dynamic Compilers for Software Testing Ben Breech Lori Pollock John Cavazos.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Sampling Dynamic Dataflow Analyses Joseph L. Greathouse Advanced Computer Architecture Laboratory University of Michigan University of British Columbia.
On-Demand Dynamic Software Analysis Joseph L. Greathouse Ph.D. Candidate Advanced Computer Architecture Laboratory University of Michigan November 29,
CUTE: A Concolic Unit Testing Engine for C Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
SSH/SSL Attacks not on tests, just for fun. SSH/SSL Should Be Secure Cryptographic operations are secure SSL uses certificates to authenticate servers.
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
MOPS: an Infrastructure for Examining Security Properties of Software Authors Hao Chen and David Wagner Appears in ACM Conference on Computer and Communications.
Automatic Diagnosis and Response to Memory Corruption Vulnerabilities Authors: Jun Xu, Peng Ning, Chongkyung Kil, Yan Zhai, Chris Bookholt Cyber Defense.
Constraint Framework, page 1 Collaborative learning for security and repair in application communities MIT site visit April 10, 2007 Constraints approach.
Automatically Detecting Error Handling Bugs using Error Specifications Suman Jana 1, Yuan Kang 1, Samuel Roth 2, Baishakhi Ray 3 1 Columbia University.
Jeremy Nimmer, page 1 Automatic Generation of Program Specifications Jeremy Nimmer MIT Lab for Computer Science Joint work with.
Code improvement: Coverity static analysis Valgrind dynamic analysis GABRIELE COSMO CERN, EP/SFT.
Dynamic Allocation in C
Content Coverity Static Analysis Use cases of Coverity Examples
Secure Programming Dr. X
Mitigation against Buffer Overflow Attacks
More Security and Programming Language Work on SmartPhones
On-Demand Dynamic Software Analysis
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Secure Programming Dr. X
Chapter 8 – Software Testing
Seminar in automatic tools for analyzing programs with dynamic memory
A Security Review Process for Existing Software Applications
Secure Software Development: Theory and Practice
Chapter 18 Software Testing Strategies
RDE: Replay DEbugging for Diagnosing Production Site Failures
Secure Code Scanners Cameron Davidson.
High Coverage Detection of Input-Related Security Faults
AdaCore Technologies for Cyber Security
Fault Tolerance Distributed Web-based Systems
CSC 143 Error Handling Kinds of errors: invalid input vs programming bugs How to handle: Bugs: use assert to trap during testing Bad data: should never.
Software Security Lesson Introduction
All You Ever Wanted to Know About Dynamic Taint Analysis & Forward Symbolic Execution (but might have been afraid to ask) Edward J. Schwartz, Thanassis.
Kernel Structure and Infrastructure
Automatic Test Generation SymCrete
Language-based Security
Introduction to Static Analyzer
CUTE: A Concolic Unit Testing Engine for C
Automatically Diagnosing and Repairing Error Handling Bugs in C
Sampling Dynamic Dataflow Analyses
Presentation transcript:

APEx: Automated Inference of Error Specifications for C APIs Yuan Kang1, Suman Jana1, Baishakhi Ray2 1Columbia University 2University of Virginia ASE 2016, September 6, 2016

Incorrect error handling: a serious source of bugs One of OWASP’s top 10 sources of security vulnerabilities CVE-2015-0208 CVE-2015-8617 CVE-2015-0288 CVE-2015-7941 CVE-2014-9826 CVE-2015-8340 CVE-2015-0285 CVE-2014-0092 CVE-2015-0292 ...

Error handling is especially problematic in C int ret = func1(...); if (ret == 0) { /* pass the error upstream or exit */ } char *ptr = func2(...); if (!ptr) { No built-in exception reporting mechanism Developers design custom error protocols (e.g., 0 means error)

We need error specs What are the errors? Where are the errors? Dynamic analysis: Fault injection [Marinescu et al.] Static analysis: EPEx [Jana et al.]

Automated, accurate & relevant Manually from documentation and code Apply general intuition Not Automated Not Accurate Is the error critical?

APEx: automated error path exploration

Non-error paths if (inflateInit2(...) != 0) return; buf = malloc(...); if (buf != NULL) { while(1) { status = inflate(...); if (status == 0) {...} else break; } inflateEnd(...);

Error paths if (inflateInit2(...) != 0) return; buf = malloc(...); if (buf != NULL) { while(1) { status = inflate(...); if (status == 0) {...} else break; } inflateEnd(...);

Error vs. non-error paths Error paths are less complex Less statements Less function calls Less branches Error constraints: Less paths if (inflateInit2(...) != 0) return; buf = malloc(...); if (buf != NULL) { while(1) { ... } inflateEnd(...);

What matters?

Identifying error constraints Gather path features Statement count Combine path features of constraints Path count Median statement count if (inflateInit2(...) != 0) return; buf = malloc(...); if (buf != NULL) { while(1) { ... } inflateEnd(...); != 0 is the inferred error constraint

What about mistakes? No error spec

Gathering path features APEx architecture Error spec Application source codes Gathering path features Voting APEx

Implementing APEx in Clang Used Clang static analyzer for under-constrained symbolic execution Implemented as a custom checker 1180 lines of C++ code and 7063 lines of Python code

Evaluation subjects 6 libraries 28 applications 67 combinations GnuTLS GTK libc libgcrypt 6 libraries 28 applications 67 combinations

Precision APEx Baseline 77% 64%

Running time Application LOC Time ClamAV 575104 1h 3m 39s Pidgin 343416 1h 37m 50s Grep 285705 6m 59s GnuTLS 179322 59m 18s

A simple application Is fallible function checked? If not, it’s a bug Ignore if majority does not check Probably not a critical error

Bug finding accuracy Unfiltered bugs Filtered bugs Real bugs Precision 3256 175 118 67%

Exhibit 1: OpenSSL & Mutt static int ssl_socket_open (CONNECTION *conn) { ... data->ctx = SSL_CTX_new (SSLv23_client_method ()); if (!option(OPTTLSV1)) { SSL_CTX_set_options(data->ctx, SSL_OP_NO_TLSv1); } Crash

Exhibit 2: GnuTLS & Pidgin static PurpleCertificate * x509_import_from_datum(const gnutls_datum_t dt, gnutls_x509_crt_fmt_tmode) { ... gnutls_x509_crt_init(&(certdat->crt)); } Invalid certificate

Exhibit 2: GnuTLS & Pidgin

Exhibit 3: libgcrypt & misc Missing thread safety gcry_control (GCRYCTL_SET_THREAD_CBS, ...); gcry_control (GCRYCTL_INIT_SECMEM, ..., ...); Insecure memory and user privileges

Limitations Cleanup functions are always followed by simple code Can the caller safely avoid an error in some cases? Cleanup function { ... inflateEnd(...); }

Conclusions Error specs are needed for correct error handling and finding bugs APEx can automatically identify error paths and error specs Error paths have less statements Error return values lead to less paths APEx can successfully find error handling bugs Check us out on: https://github.com/yujokang/APEx