Checking Memory Safety with BLAST Dirk Beyer, et al. FASE 2005 KAIST CS750b 2006 Fall Seonggun Kim.

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

CHECKING MEMORY SAFETY AND TEST GENERATION USING B LAST By: Pashootan Vaezipoor Computing Science Dept of Simon Fraser University.
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
Fortran Jordan Martin Steven Devine. Background Developed by IBM in the 1950s Designed for use in scientific and engineering fields Originally written.
The Interface Definition Language for Fail-Safe C Kohei Suenaga, Yutaka Oiwa, Eijiro Sumii, Akinori Yonezawa University of Tokyko.
Rational XL C/C++ Compiler Development © 2007 IBM Corporation Identifying Aliasing Violations in Source Code A Points-to Analysis Approach Ettore Tiotto,
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Malloc Recitation Section K (Kevin Su) November 5 th, 2012.
Chapter Four Data Types Pratt 2 Data Objects A run-time grouping of one or more pieces of data in a virtual machine a container for data it can be –system.
SAFECode SAFECode: Enforcing Alias Analysis for Weakly Typed Languages Dinakar Dhurjati University of Illinois at Urbana-Champaign Joint work with Sumant.
Using Statically Computed Invariants Inside the Predicate Abstraction and Refinement Loop Himanshu Jain Franjo Ivančić Aarti Gupta Ilya Shlyakhter Chao.
Introduction The Approach ’ s Overview A Language of Pointers The Type System Operational Semantics Type Safety Type Inference The Rest of C Experiments.
Strength Through Typing: A more powerful dependently-typed assembly language Matt Harren George Necula OSQ 2004.
Securing software by enforcing data-flow integrity Manuel Costa Joint work with: Miguel Castro, Tim Harris Microsoft Research Cambridge University of Cambridge.
Type-Safe Programming in C George Necula EECS Department University of California, Berkeley.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
LIFT: A Low-Overhead Practical Information Flow Tracking System for Detecting Security Attacks Feng Qin, Cheng Wang, Zhenmin Li, Ho-seop Kim, Yuanyuan.
1 Efficient Memory Safety for TinyOS 2.1 Yang Chen Nathan Cooprider Will Archer Eric Eide David Gay † John Regehr University of Utah School of Computing.
A Type System for Expressive Security Policies David Walker Cornell University.
PathExpander: Architectural Support for Increasing the Path Coverage of Dynamic Bug Detection S. Lu, P. Zhou, W. Liu, Y. Zhou, J. Torrellas University.
Load-Reuse Analysis design and evaluation Rastislav Bodík Rajiv Gupta Mary Lou Soffa.
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.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
May 22, 2002OSQ Retreat 1 CCured: Taming C Pointers George Necula Scott McPeak Wes Weimer
Formal Verification of SpecC Programs using Predicate Abstraction Himanshu Jain Daniel Kroening Edmund Clarke Carnegie Mellon University.
Michael Ernst, page 1 Static and dynamic analysis: synergy and duality Michael Ernst CSE 503, Winter 2010 Lecture 1.
Thread-modular Abstraction Refinement Thomas A. Henzinger, et al. CAV 2003 Seonggun Kim KAIST CS750b.
Safety in the C programming Language Peter Wihl May 26 th, 2005 CS 297 Security and Programming Languages.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
15-740/ Oct. 17, 2012 Stefan Muller.  Problem: Software is buggy!  More specific problem: Want to make sure software doesn’t have bad property.
Presentation of Failure- Oblivious Computing vs. Rx OS Seminar, winter 2005 by Lauge Wullf and Jacob Munk-Stander January 4 th, 2006.
1 Efficient Type and Memory Safety for Tiny Embedded Systems John Regehr Nathan Cooprider Will Archer Eric Eide University of Utah School of Computing.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Extended Static Checking for Java  ESC/Java finds common errors in Java programs: null dereferences, array index bounds errors, type cast errors, race.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
The Fail-Safe C to Java translator Yuhki Kamijima (Tohoku Univ.)
Page 1 5/2/2007  Kestrel Technology LLC A Tutorial on Abstract Interpretation as the Theoretical Foundation of CodeHawk  Arnaud Venet Kestrel Technology.
Convergence of Model Checking & Program Analysis Philippe Giabbanelli CMPT 894 – Spring 2008.
1 Splint: A Static Memory Leakage tool Presented By: Krishna Balasubramanian.
Highly Scalable Distributed Dataflow Analysis Joseph L. Greathouse Advanced Computer Architecture Laboratory University of Michigan Chelsea LeBlancTodd.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
Protecting C Programs from Attacks via Invalid Pointer Dereferences Suan Hsi Yong, Susan Horwitz University of Wisconsin – Madison.
Debugging via Run-Time Type Checking Title Page Alexey Loginov, Suan Yong, Susan Horwitz, Thomas Reps University of Wisconsin - Madison.
Efficient Detection of All Pointer and Array Access Errors Todd M.Austin Scott E.Breach Gurindar S.Sohi Computer Sciences Department University of Wisconsin-Madison.
Sampling Dynamic Dataflow Analyses Joseph L. Greathouse Advanced Computer Architecture Laboratory University of Michigan University of British Columbia.
PLC '06 Experience in Testing Compiler Optimizers Using Comparison Checking Masataka Sassa and Daijiro Sudo Dept. of Mathematical and Computing Sciences.
© 2006 Carnegie Mellon University Introduction to CBMC: Part 1 Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Arie Gurfinkel,
Combining Static and Dynamic Reasoning for Bug Detection Yannis Smaragdakis and Christoph Csallner Elnatan Reisner – April 17, 2008.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
CSE-321 Programming Languages Dependent Types POSTECH June 5, 2006 박성우.
© 2006 Carnegie Mellon University Introduction to CBMC: Part 1 Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Arie Gurfinkel,
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Memory-Related Perils and Pitfalls in C
Optimistic Hybrid Analysis
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
Context-Sensitive Analysis
Compositional Pointer and Escape Analysis for Java Programs
Seminar in automatic tools for analyzing programs with dynamic memory
High Coverage Detection of Input-Related Security Faults
Runtime Monitoring of C Programs for Security and Correctness
CETS: Compiler-Enforced Temporal Safety for C
Suan Hsi Yong University of Wisconsin – Madison
SOFTWARE ENGINEERING INSTITUTE
Presentation transcript:

Checking Memory Safety with BLAST Dirk Beyer, et al. FASE 2005 KAIST CS750b 2006 Fall Seonggun Kim

2 Outline Memory Safety Two-step Approach –CCured: a type-based memory safety analyzer –BLAST: a temporal safety property checker CCured Conclusion –An improvement in the memory safety analysis

3 Memory Safety Essential for security systems –Invalid memory access can… Cause a process to crash Produce incorrect results –Buffer overflows are the basis of many attacks Memory bugs –Dereferencing null-pointer –Dereferencing outside of object bounds –Freeing non-pointers –Using freed memory

4 C and Memory Safety C is designed and used for efficiency –Allows many ‘unsafe’ operations E.g., casting to arbitrary types –Sacrifices safety for efficiency A solution: Run-time checking int array[10]; … if ( (array+i >= array+10) || (array+i < array)) { exit(EXIT_FAILURE); } val = array[i]; Inserted code

5 Run-time Overhead Run-time checking causes slow-down –Time spent executing inserted code –E.g., IBM Rational® Purify: 10x slow-down But, in many C programs, –Most pointers are used safely –Only small portions are responsible for unsafe behavior Static analysis can eliminate many run-time checking

6 Checking Memory Safety with BLAST BLAST can guarantee a pointer is safely used –by checking if the location labeled __BLAST_ERROR is reachable –If __BLAST_ERROR is not reachable, we can eliminate the corresponding checking code OBJ *p = malloc(sizeof(OBJ)); … if (p == NULL) { __BLAST_ERROR: ; } val = p->value;

7 Disadvantage of BLAST Expensive (takes long time) –Path sensitive –Generates an execution trace Overkill for some checks Not good for large programs Solution –Combine BLAST with more efficient tool: CCured

8 Combining BLAST and CCured CCured –Efficient –More runtime checks BLAST –Expensive –More powerful –Feedback Together –Efficient –Fewer runtime checks –Feedback CCured BLAST program codechecking code

9 CCured The CCured System CCured Translator Compile & Execute C Program Instrumented C Program Halt: Memory Safety Violation Success

10 A Little More about CCured A type-based memory safety analyzer for C Classifies the pointers according to usage –Type-inference –SAFE, SEQ, WILD –Transform normal pointers to “fat-pointers” Annotates with run-time checks –SAFE: Null-check –SEQ: check array bound –WILD: check non-pointer and bounds and non-null

11 A Little More about CCured Classifies the pointers according to usage casting arith. on pointer –SAFE:NONO –SEQ:NOYES –WILD:YESYES (roughly) Annotates with run-time checks –SAFE: null-check –SEQ: array bound check (implicit null-check) –WILD: null-check + bound check + non-pointer check Remove redundant checks by naïve optimizer

12 SAFE Pointer Invariants and Representation T * SAFE –Prototypical example: FILE *fp = fopen(filename, “r”); –Can be 0 or a pointer to storage containing a T –All aliases agree on the type of the referenced storage –Must do null-check before dereference –Inexpensive to store and to use (just null-check) p statically typed home area T x: assert(x.p != null);

13 SEQ Pointer Invariants and Representation T * SEQ –Can be 0 –Can be involved in pointer arithmetic: val = array++; –Null check and bounds check before use –Carries the bounds of a home area consisting of a sequence of T ’ s –All SAFE or SEQ aliases agree on the type of the referenced area basepend statically typed home area TT … T … assert(x.b <= x.p); assert(x.p <= x.e – sizeof(T)); x:

14 WILD Pointer Invariants and Representation T * WILD –Can be a non-pointer (any primitive) –Carries the bounds of a dynamic home area –Has only WILD pointer aliases –Must do a non-pointer and a bounds check –Must maintain the tags when writing (1 bit per word) dynamically typed home areaendtag bits basep indicates which words contain base assert(x.b != null); assert(x.b <= x.p); assert(x.p <= len(x.b) – sizeof(T’)); if (typeof(*(x.p)) is *WILD) assert(tag(x.b, x.p+1) == 1);

15 Example 1: OBJ* f (int **a) { 2: int **x; 3: int **y = a + 10; 4: for (x = a; x < y; x++) 5: *x = *y; 6: return (OBJ*) *y; 7: } 1: OBJ *WILD f (int *WILD *SEQ a) { 2: int *WILD *SEQ x; 3: int *WILD *SAFE y = a + 10; 4: for (x = a; x < y; x++) 5: *x = *y; 6: return (OBJ *WILD) *y; 7: }

16 Example (cont) 1: OBJ *WILD f (int *WILD *SEQ a) { 2: int *WILD *SEQ x; 3: int *WILD *SAFE y = a + 10; 4: for (x = a; x < y; x++) 5: *x = *y; 6: return (OBJ *WILD) *y; 7: } 1 : OBJ *WILD f (int *WILD *SEQ a) { 2 : int *WILD *SEQ x; 3 : int *WILD *SAFE y = a + 10; 4 : for (x = a; x < y; x++) 5’: __CHECK_SEQ(x); 5”; __CHECK_SAFE(y); 5 : *x = *y; 6 : return (OBJ *WILD) *y; 7 : }

17 Experimental Results of CCured LOC%Safe%Seq%WildCCured RatioPurify Ratio compress go ijpeg li bh bisort em3d ks health

18 CCured + BLAST Null-pointer dereferencing 1.Annotate a program using CCured __CHECK_NULL(p); 2.Replace the call to __CHECK_NULL to __BLAST_CHECK_NULL void __BLAST_CHECK_NULL(void *p) { if (!p) { __BLAST_ERROR: ; } } 3.Check if __BLAST_ERROR : is reachable

19 Experimental Results Timeout: 200s

20 Conclusion and Discussion An improvement in the memory safety analysis –Scalability and precision Pros –A kind of coarse-grained refinement –C.E. can be used for debugging Cons –Only handles null-pointer check Pointers can be regarded as Boolean variables State explosion for array bound checking?

21 References s/se-sem/ss2005/slides/geissbuehler.ppthttp:// s/se-sem/ss2005/slides/geissbuehler.ppt Adamek-Blast.pdfhttp://nenya.ms.mff.cuni.cz/teaching/seminars/ Adamek-Blast.pdf CCured.ppthttp://osq.cs.berkeley.edu/retreat02/Weimer- CCured.ppt /02/neculaResOverview.ppthttp://chess.eecs.berkeley.edu/publications/talks /02/neculaResOverview.ppt