CQual: A Tool for Adding Type Qualifiers to C Jeff Foster et al UC Berkeley OSQ Retreat, May 21-23 2002.

Slides:



Advertisements
Similar presentations
Static Analysis for Security
Advertisements

Type-based Taint Analysis for Java Web Applications Wei Huang, Yao Dong and Ana Milanova Rensselaer Polytechnic Institute 1.
Transition from C to C++ …and a Review of Basic Problem Solving.
Type Qualifiers CS Software Quality Today Even after large, extensive testing efforts, commercial software is shipped riddled with errors ("bugs").
Preventing bugs with pluggable type checking Michael D. Ernst University of Washington Object x)
Detecting and preventing bugs with pluggable type-checking Michael D. Ernst University of Washington Joint work with Mahmood Ali, Werner Dietl, …
Lab#1 (14/3/1431h) Introduction To java programming cs425
Detecting Format String Vulnerabilities with Type Qualifier Umesh Shankar, Kunal Talwar, Jeffrey S. Foster, David Wanger University of California at Berkeley.
Checking and Inferring Local Non-Aliasing Alex AikenJeffrey S. Foster UC BerkeleyUMD College Park John KodumalTachio Terauchi UC Berkeley.
Type Qualifiers: Lightweight Specifications to Improve Software Quality Jeffrey S. Foster.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
#1 The Future of Software Security David Wagner U.C. Berkeley.
ReferencesReferences DiscussionDiscussion Vulnerability Example: SQL injection Auditing Tool for Eclipse LAPSE: a Security Auditing Tool for Eclipse IntroductionIntroductionResultsResults.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Visualizing Type Qualifier Inference with Eclipse David Greenfieldboyce Jeffrey S. Foster University of Maryland.
12/2/05CS591-F2005, UCCS Frank Gearhart 1 Why doesn’t “gets()” get it? Or more formally: An investigation into the use of the buffer overflow vulnerability.
Software Reliability Methods Sorin Lerner. Software reliability methods: issues What are the issues?
A Type-Checked Restrict Qualifier Jeff Foster OSQ Retreat May 9-10, 2001.
COMS S1007 Object-Oriented Programming and Design in Java August 7, 2007.
Guide To UNIX Using Linux Third Edition
May 9, 2001OSQ Retreat 1 Run-Time Type Checking for Pointers and Arrays in C Wes Weimer, George Necula Scott McPeak, S.P. Rahul, Raymond To.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
May 22, 2002OSQ Retreat 1 CCured: Taming C Pointers George Necula Scott McPeak Wes Weimer
Testing Static Analysis Tools using Exploitable Buffer Overflows from Open Source Code Zitser, Lippmann & Leek Presented by: José Troche.
C++ fundamentals.
Statically Detecting Likely Buffer Overflow Vulnerabilities David Larochelle David Evans University of Virginia Department of Computer Science Supported.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
CSCI 5801: Software Engineering
CSC 107 – Programming For Science. Today’s Goal  Learn how arrays normally used in real programs  Why a function returning an array causes bugs  How.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Elsa/Oink/Cqual++: Open-Source Static Analysis for C++ Scott McPeak Daniel Wilkerson work with Rob Johnson CodeCon 2006.
University of Maryland Bug Driven Bug Finding Chadd Williams.
CSE 232: C++ pointers, arrays, and references Overview of References and Pointers Often need to refer to another object –Without making a copy of the object.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Use of Coverity & Valgrind in Geant4 Gabriele Cosmo.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Preliminaries on Security. Security Summer School, June What is security? Security: prevent bad things from happening – Confidential information.
CLIP Command Line InterPreter for a subset of C++.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
1 Splint: A Static Memory Leakage tool Presented By: Krishna Balasubramanian.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Demo of Scalable Pluggable Types Michael Ernst MIT Dagstuhl Seminar “Scalable Program Analysis” April 17, 2008.
PHY 107 – Programming For Science. Today’s Goal  Learn how arrays normally used in real programs  Why a function returning an array causes bugs  How.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Language-Based Security. Outline CQUAL CQUAL CCured CCured Valgrind Valgrind Memcheck, AddrcheckMemcheck, Addrcheck HelgrindHelgrind Applying on PttBBS.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
ESSoS: February Leuven, Belgium1 Measuring the Effect of Code Complexity on Static Analysis Results James Walden, Adam Messer, Alex Kuhl Northern.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Preventing bugs with pluggable type-checking Michael Ernst MIT
Security via Type Qualifiers 2004 SIGPL 여름학교 조 장 우 부산외대 컴퓨터공학부 (based on J. Foster’s lecture at 2004 summer school on software security)
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
9/21/04 James Gallagher Server Installation and Testing: Hands-on ● Install the CGI server with the HDF and FreeForm handlers ● Link data so the server.
University of Virginia Computer Science Extensible Lightweight Static Checking David Evans On the I/O.
Content Coverity Static Analysis Use cases of Coverity Examples
Types for Programs and Proofs
AVR-GCC Programming Using C Development Tools to program your Arduino Microcontrollers. Presented by: Charles Norona November 17th, 2011 C. Norona,
Objectives Identify the built-in data types in C++
Ik-Soon Kim December 18, 2010 Embedded Software Platform Team
Secure Software Development: Theory and Practice
Accessible Formal Methods A Study of the Java Modeling Language
Object Oriented Analysis and Design
All You Ever Wanted to Know About Dynamic Taint Analysis & Forward Symbolic Execution (but might have been afraid to ask) Edward J. Schwartz, Thanassis.
POWERPOINT PRESENTATION
Introduction to Static Analyzer
Focus of the Course Object-Oriented Software Development
Annotation-Assisted Lightweight Static Checking
Semantic Type Qualifiers
Presentation transcript:

CQual: A Tool for Adding Type Qualifiers to C Jeff Foster et al UC Berkeley OSQ Retreat, May

Jeff Foster, OSQ Retreat, May Background Software is buggy! How can we improve the quality of software? –We want to build tools to analyze source code Find bugs at compile-time Help programmers write correct code But tools need to know what is ‘‘correct’’ –...they need specifications

Jeff Foster, OSQ Retreat, May Tools Need Specifications put_tty_queue_nolock(c, tty); spin_lock_irqsave(&tty->read_lock, flags); spin_unlock_irqrestore(&tty->read_lock, flags); Goal: Add specifications to programs In a way that... –Programmers will accept Lightweight –Scales to large programs –Solves many different problems

Jeff Foster, OSQ Retreat, May Type Qualifiers Extend standard type systems (C, Java, ML) –Programmers already use types –Programmers understand types –Get programmers to write down a little more... intconstANSI C taintedSecurity vulnerabilities spinlock_tunlockedLocking char *

Jeff Foster, OSQ Retreat, May CQual A tool for adding type qualifiers to C –User-specified qualifiers –Annotate some qualifiers by hand –CQual infers the rest Version 1: –Written in SML/NJ –Used C parser from alias analysis Was lots of work to fix, extend to GNU C –Constraints solved with BANE

Jeff Foster, OSQ Retreat, May Application: Const Inference Main use of const: non-modified parameters void foo(const int *x); /* foo does not write *x */ How many more consts can we add? –Left-hand side of assignment non-const –Everything that's not non-const is const Analyzed six C programs – lines –All make effort to use const

Jeff Foster, OSQ Retreat, May Const Inference Results

Jeff Foster, OSQ Retreat, May Carillon CQual for finding Y2K bugs –Mark date strings with YYYY, YY, NONYEAR,... Better user interface –(Demo later) Found known bug in CVS 1.9 –Took only a few hours of work

Jeff Foster, OSQ Retreat, May Problems with CQual Version 1 Bad error messages in parser Too slow, used too much memory Written in ML –No tools available (debugger, profiler, etc) –Hard to control memory usage, performance –|{know ML}| is small –|{know ML}  {care about C}| very small

Jeff Foster, OSQ Retreat, May CQual Version 2: Rewrite to C Use David Gay's parser –Extracted/modified from gcc –Very compatible –Very good error messages Custom constraint solver –Solves atomic subtyping constraints –Dropped polymorphic qualifier inference But allow user-specified polymorphism

Jeff Foster, OSQ Retreat, May Application: Format-String Vulnerabilities Adversary-controlled format specifier name := printf(name);/* Oops */ –Attacker sets name = “%s%s%s” to crash program –Attacker sets name = “...%n...” to write to memory Lots of these bugs in the wild –New ones weekly on bugtraq mailing list –Too restrictive to forbid variable format strings

Jeff Foster, OSQ Retreat, May Using Tainted and Untainted Add qualifier annotations int printf(untainted char *fmt,...) tainted char *getenv(const char *) tainted = may be controlled by adversary untainted = must not be controlled by adversary

Demo of cqual

Jeff Foster, OSQ Retreat, May Results: Format String Vulnerabilities Analyzed 10 popular unix daemon programs Annotations shared across applications –One annotated header file for standard libraries –Taint flows across type casts Found several known vulnerabilities –Including ones we didn’t know about –CQual's user interface critical

Jeff Foster, OSQ Retreat, May Application: Locking Lock x; lock(x);...critical section... unlock(x); x : locked Lock x : unlocked Lock

Jeff Foster, OSQ Retreat, May Flow-Sensitivity Standard type systems are flow-insensitive –Variable x has one type –And one set of qualifiers We need flow-sensitivity –Different qualifiers for x at each program point Enter CQual Version 3 –Support for flow-sensitive qualifiers

Demo of cqual

Jeff Foster, OSQ Retreat, May Results: Locking Looked for simple deadlocks in Linux –Double acquires/releases Analyzed 892 files in linux/drivers individually Analyzed 513 modules (all linked files) –14 type errors  deadlocks –~41/892 fail to typecheck but appear correct –~196/513 fail to typecheck added restrict by hand to remove type errors due to aliasing for 64/196

Jeff Foster, OSQ Retreat, May Running Time: Locking

Jeff Foster, OSQ Retreat, May Memory Usage: Locking

Jeff Foster, OSQ Retreat, May Applications Published experiments: const Inference[Foster, Fahndrich, Aiken, PLDI99] Y2K bug detection[Elsman, Foster, Aiken, 1999] Format-string vuln. [Shankar, Talwar, Foster, Wagner, Usenix Sec 01] Locking, stream operations [Foster, Terauchi, Aiken, PLDI 02] Linux Security Modules[Zhang, Edwards, Jaeger, (IBM Watson) Usenix Sec 02] Other experiments: Null pointer errorsTinyOS (Intel) User/kernel pointersFile open/close

Jeff Foster, OSQ Retreat, May What's Next for CQual? Better version of restrict Polymorphic-recursive qualifier inference –Adapt known tech. for flow-insensitive analysis –Less clear for flow-sensitive analysis Better alias analysis –Names vs. location abstraction

Jeff Foster, OSQ Retreat, May Conclusion CQual adds specifications to programs In a way that... –Programmers will accept Lightweight –Scales to large programs –Solves many different problems Flow-insensitive version available