Memory Safety Through Runtime Analysis Justin Samuel for CSE 504, Spring ‘10 Instructor: Ben Livshits.

Slides:



Advertisements
Similar presentations
Architectural Support for Software-Based Protection Mihai Budiu Úlfar Erlingsson Martín Abadi ASID Workshop, Oct 21, 2006 Silicon Valley.
Advertisements

Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
CS457 – Introduction to Information Systems Security Software 4 Elias Athanasopoulos
The Interface Definition Language for Fail-Safe C Kohei Suenaga, Yutaka Oiwa, Eijiro Sumii, Akinori Yonezawa University of Tokyko.
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
Computer Security: Principles and Practice First Edition by William Stallings and Lawrie Brown Lecture slides by Lawrie Brown Chapter 11 – Buffer Overflow.
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
Bouncer securing software by blocking bad input Miguel Castro Manuel Costa, Lidong Zhou, Lintao Zhang, and Marcus Peinado Microsoft Research.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 2007 Exterminator: Automatically Correcting Memory Errors with High Probability Gene.
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
DIEHARDER: SECURING THE HEAP. Previously in DieHard…  Increase Reliability by random positioning of data  Replicated Execution detects invalid memory.
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
A Practical Dynamic Buffer Overflow Detector (CRED) Olatunji Ruwase Monica S. Lam Transmeta Corp. Stanford University Network and Distributed Security.
By Emery D. Berger and Benjamin G. Zorn Presented by: David Roitman.
Securing software by enforcing data-flow integrity Manuel Costa Joint work with: Miguel Castro, Tim Harris Microsoft Research Cambridge University of Cambridge.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Run-time Environment and Program Organization
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science PLDI 2006 DieHard: Probabilistic Memory Safety for Unsafe Programming Languages Emery.
1 RISE: Randomization Techniques for Software Security Dawn Song CMU Joint work with Monica Chew (UC Berkeley)
Lecture 16 Buffer Overflow
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 2006 Exterminator: Automatically Correcting Memory Errors Gene Novark, Emery Berger.
Address Obfuscation: An Efficient Approach to Combat a Broad Range of Memory Error Exploits Sandeep Bhatkar, Daniel C. DuVarney, and R. Sekar Stony Brook.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
Address Space Layout Permutation
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Chapter 6 Buffer Overflow. Buffer Overflow occurs when the program overwrites data outside the bounds of allocated memory It was one of the first exploited.
Computer Security and Penetration Testing
A Survey of Dynamic Techniques for Detecting Device Driver Errors Olatunji Ruwase LBA Reading Group 18 th May 2010.
CS533 Concepts of Operating Systems Jonathan Walpole.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
Mitigation of Buffer Overflow Attacks
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
DieHard: Probabilistic Memory Safety for Unsafe Languages Emery D. Berger and Benjamin G. Zorn PLDI'06 Presented by Uri Kanonov
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
Lecture 9: Buffer Ovefflows and ROP EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014,
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
Protecting C Programs from Attacks via Invalid Pointer Dereferences Suan Hsi Yong, Susan Horwitz University of Wisconsin – Madison.
Efficient Software Based Fault Isolation Author: Robert Wahobe,Steven Lucco,Thomas E Anderson, Susan L Graham Presenter: Maitree kanungo Date:02/17/2010.
Buffer overflow and stack smashing attacks Principles of application software security.
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.
Dynamic Taint Analysis for Automatic Detection, Analysis, and Signature Generation of Exploits on Commodity Software Paper by: James Newsome and Dawn Song.
A Survey on Runtime Smashed Stack Detection 坂井研究室 M 豊島隆志.
Group 9. Exploiting Software The exploitation of software is one of the main ways that a users computer can be broken into. It involves exploiting the.
Security Attacks Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Beyond Stack Smashing: Recent Advances In Exploiting Buffer Overruns Jonathan Pincus and Brandon Baker Microsoft Researchers IEEE Security and.
Protecting C and C++ programs from current and future code injection attacks Yves Younan, Wouter Joosen and Frank Piessens DistriNet Department of Computer.
Chapter 10 Buffer Overflow 1. A very common attack mechanism o First used by the Morris Worm in 1988 Still of major concern o Legacy of buggy code in.
@Yuan Xue Worm Attack Yuan Xue Fall 2012.
Memory Protection through Dynamic Access Control Kun Zhang, Tao Zhang and Santosh Pande College of Computing Georgia Institute of Technology.
Translation Lookaside Buffer
Secure Programming Dr. X
Mitigation against Buffer Overflow Attacks
Introduction to Operating Systems
Secure Programming Dr. X
Suman Jana *Original slides from Vitaly Shmatikov
Inline Reference Monitors: SFI, CFI, XFI, WIT, NaCl
High Coverage Detection of Input-Related Security Faults
Introduction to Operating Systems
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Defending against Stack Smashing attacks
Memory Allocation CS 217.
Software Security Lesson Introduction
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2009.
Code-Pointer Integrity
CETS: Compiler-Enforced Temporal Safety for C
Understanding and Preventing Buffer Overflow Attacks in Unix
Presentation transcript:

Memory Safety Through Runtime Analysis Justin Samuel for CSE 504, Spring ‘10 Instructor: Ben Livshits

(A Few) Runtime Safety Approaches ApproachYearSummary SFI1994Software Fault Isolation. Bounds checking C1995Jones and Kelly, CRED. StackGuard1998Canaries. ASLR2001Address Space Layout Randomization (e.g. PAX). Program Shepherding 2002Run through an interpreter and verify branch instructions. PointGuard2003Pointers encrypted in memory and decrypted at time of use. CFI2005Control-Flow Integrity. DieHard2005Multiple, large heaps with different allocation. DFI2006Data-Flow Integrity. WIT2008Write Integrity Testing. NaCL2009Native Client. Uses SFI. Performs CFI Runtime Memory Safety - CSE 5042

CFI: Control-Flow Integrity Ensure execution follows the control-flow graph (CFG). –Statically analyze binary to identify valid destinations of all control transfers. –Instrument code with: Unique IDs at destinations. Checking destination IDs before all instructions that transfer control. Not concerned with read or write destinations Runtime Memory Safety - CSE 5043

DFI: Data-Flow Integrity Restrict reads based on instructions that wrote the data. –Statically analyze source to identify the instructions that are allowed to write values that are read. –Instrument code to: Maintain a table of the last instructions to write memory locations. Check the last-write table on reads against computed allowed write instructions. Not directly concerned with control flow Runtime Memory Safety - CSE 5044

Preventing memory error exploits with WIT Periklis Akritidis, Cristian Cada, Costin Raiciu, Manuel Costa, Miguel Castro Microsoft Research, Cambridge UK

Example Vulnerable Code 1: char cgiCommand[1024]; 2: char cgiDir[1024]; 3: 4: void ProcessCGIRequest(char* msg, int sz) { 5: int i=0; 6: while (i < sz) { 7: cgiCommand[i] = msg[i]; 8: i++; 9: } 10: 11: ExecuteRequest(cgiDir, cgiCommand); 12: } Runtime Memory Safety - CSE 5046

Data-modifying Commands 1: char cgiCommand[1024]; 2: char cgiDir[1024]; 3: 4: void ProcessCGIRequest(char* msg, int sz) { 5: int i=0; 6: while (i < sz) { 7: cgiCommand[i] = msg[i]; 8: i++; 9: } 10: 11: ExecuteRequest(cgiDir, cgiCommand); 12: } Runtime Memory Safety - CSE 5047

Line 7’s Modified Objects 1: char cgiCommand[1024]; 2: char cgiDir[1024]; 3: 4: void ProcessCGIRequest(char* msg, int sz) { 5: int i=0; 6: while (i < sz) { 7: cgiCommand[i] = msg[i]; 8: i++; 9: } 10: 11: ExecuteRequest(cgiDir, cgiCommand); 12: } Runtime Memory Safety - CSE 5048

WIT: Write Integrity Testing Approach: 1.Determine memory locations that individual instructions should legitimately be able to write to. 2.Only allow a given instruction to write to those locations. Memory errors to protect against: –Buffer overflows and underflows –Dangling pointers –Double frees Runtime Memory Safety - CSE 5049

Static Analysis Two stages: 1.Points-to analysis 2.Write safety analysis Goal: Create a color table. –Give each unsafe object a different color. –Give each write instruction the same color as the objects it can write Runtime Memory Safety - CSE 50410

Static Step 1: Points-to Analysis Compute the set of objects that can be modified by each program instruction. In the example: –Set { i } for the instructions at lines 5 and 8 –Set { cgiCommand } for the instruction at line Runtime Memory Safety - CSE : char cgiCommand[1024]; 2: char cgiDir[1024]; 3: 4: void ProcessCGIRequest(char* msg, int sz) { 5: int i=0; 6: while (i < sz) { 7: cgiCommand[i] = msg[i]; 8: i++; 9: } 10: 11: ExecuteRequest(cgiDir, cgiCommand); 12: }

Static Step 2: Write Safety Analysis Purpose: runtime efficiency. For all instructions and objects, determine whether safe or unsafe. –Safe instruction: cannot violate write integrity. No destination operand Operand is temporary, local, or global variable. –Safe object: all instructions that can modify it are safe Runtime Memory Safety - CSE 50412

Safe 1: char cgiCommand[1024]; 2: char cgiDir[1024]; 3: 4: void ProcessCGIRequest(char* msg, int sz) { 5: int i=0; 6: while (i < sz) { 7: cgiCommand[i] = msg[i]; 8: i++; 9: } 10: 11: ExecuteRequest(cgiDir, cgiCommand); 12: } Runtime Memory Safety - CSE 50413

Not Safe 1: char cgiCommand[1024]; 2: char cgiDir[1024]; 3: 4: void ProcessCGIRequest(char* msg, int sz) { 5: int i=0; 6: while (i < sz) { 7: cgiCommand[i] = msg[i]; 8: i++; 9: } 10: 11: ExecuteRequest(cgiDir, cgiCommand); 12: } Runtime Memory Safety - CSE 50414

Example Color Table ColorInstructionsObjects 0Lines 5, 8msg, sz, i 3Line 7cgiCommand 4cgiDir Record the color of each memory location. Color 0 is used for safe objects Runtime Memory Safety - CSE 50415

Function Colors Compute possible indirect function calls. Colors assigned to functions are disjoint from those assigned to objects. Prevents: –Unsafe instructions from overwriting code. –Control transfers outside code regions Runtime Memory Safety - CSE 50416

Instrumentation Use information from static analysis. Add instrumentation during compilation Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation Points-to analysis is imprecise. –False negatives possible Insert guards between unsafe objects. Guard objects have color 0 (safe objects) Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation cgiDir [1024] cgiDir [1024] cgiCommand [1024] cgiCommand [1024] GUARD (8 bytes) Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation Different for the stack, heap, and global data. Heap allocator’s header used as a guard by setting its color to Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation Tricky guard case: –Function arguments written by unsafe instruction. –Solution: Copy argument to local variable, guard that, and rewrite instructions to refer to the copy Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation 8-bit color for each 8-byte memory slot –Space overhead is 12.5% –Pad generated code. Instrument function prologues and epilogues to set and reset color table entries. Wrappers for allocation functions ( malloc, calloc, free ) Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation Only check writes by unsafe instructions. Compare color of instruction to destination operand. –If they do not match, raise an exception Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Instrumentation Lookup the color of the target function. Compare with the color of the indirect call instruction. –If they do not match, raise an exception. Zero last three bits of function pointer value to ensure 16-byte aligned, which should normally be the case Runtime Memory Safety - CSE Insert guards. Maintain color table. Check writes. Check indirect calls.

Prevented Attacks WIT can prevent all attacks that violate write integrity. –Depends on precision of points-to analysis. If two objects have the same color, WIT may fail to detect an attack. Sequential overflow always prevented even if colors match. What about reads? Runtime Memory Safety - CSE 50425

Number of Writable Objects Runtime Memory Safety - CSE 50426

CPU Overhead Runtime Memory Safety - CSE 50427

Memory Overhead Runtime Memory Safety - CSE 50428

Testing with Vulnerabilities Successful against benchmark of 18 control-data attacks that exploit buffer overflows. All but one are detected when guard object overwritten. The other is detected when a corrupted pointer is used to overwrite a return address (color 0). Tested with known vulnerabilities in real apps. All detected when buffer overflow hit a guard object at the end of the buffer. SQL Server sprintf overflow of stack buffer (Slammer). Ghttpd vsprintf overflow of stack buffer. Nullhttpd heap buffer overflow causes heap management data structures to be overwritten. Stunnel vsprintf format string overflow of stack buffer. Libpng stack buffer overflow Runtime Memory Safety - CSE 50429

Limitations Libraries WIT as just described doesn’t work for libraries. WIT for libraries assigns the same well-known color to all unsafe objects allocated by libraries. –Will WIT work without recompiled libraries? Runtime Memory Safety - CSE 50430

DieHard: Probabilistic Memory Safety for Unsafe Languages Emery D. Berger and Benjamin G. Zorn

Non-fatal Memory Errors Existing approaches either: –Abort when memory errors detected. –Continue anyways (!) How about detecting the memory error and allowing the program to continue correctly? Runtime Memory Safety - CSE 50432

DieHard in a Nutshell Randomize object locations in a large heap. Can operate in a replicated mode. – Multiple replicas of the same application are run simultaneously. Require agreement on output Runtime Memory Safety - CSE 50433

Randomized Object Locations Likely that buffer overflows end up overwriting only empty space. Unlikely that a newly-freed object will soon be overwritten by a subsequent allocation Runtime Memory Safety - CSE 50434

Replication Stand-alone DieHard cannot detect uninitialized reads. Solution: execute several replicas simultaneously Runtime Memory Safety - CSE 50435

Detecting Uninitialized Reads 1.Fill allocated object with random values. 2.Execute same program in multiple replicas. 3.Compare outputs Runtime Memory Safety - CSE 50436

Replica Communication DieHard uses pipes and shared memory to communicate with replicas. Each replica receives stdin from and writes stdout to DieHard. DieHard compares output from replicas. Support not implemented for programs that modify filesystems or perform network I/O. How would you support non-deterministic programs? Runtime Memory Safety - CSE 50437

Avoiding Buffer Overflows “…for our analysis, we model a buffer overflow as a write to any location in the heap.” Runtime Memory Safety - CSE 50438

Avoiding Dangling Pointers “…the likelihood that the object’s contents are not overwritten after A intervening allocations” Runtime Memory Safety - CSE 50439

Runtime on Linux Runtime Memory Safety - CSE 50440

Other Approaches Rx: rollback to a checkpoint, re-execute in a modified environment Runtime Memory Safety - CSE 50441

Comparison ApproachProtectionsLimitationsCPU Overhead Memory-safe C (CCured, Cyclone) All memory errors.Source and runtime changes (e.g. garbage collector). High Taint analysisMany memory errors.Accuracy vs. automation.2x WIT Bounds checking CAll buffer overflows.Doesn’t work with all programs. Protection granularity limited by compile-time information. Up to 12x WIT StackGuard, et al.Specific targets (e.g. return address). Only defend against specific attacks.Low CFIControl-flow.Data not protected.15-45% DFISome out-of-bounds reads and writes No guards against imprecise analysis.104% over WIT (so, 20-50%) WITIncorrect writes.Library incompatibility.10-25% DieHardProbabilistic memory safety. Large heap, only supports simple programs %. Dhurjati’s improvements on Jones and Kelly Most out-of-bounds reads and writes. No protection of buffer overflow inside structures or use of freed pointers, % Most numbers from WIT’s paper. Don’t take the numbers too seriously, they’ve been adjusted to have about the same frame of reference. Protections and limitations also require grains of salt Runtime Memory Safety - CSE 50442

Summary: WIT and DieHard WIT –Static analysis + instrumentation to protect writes. –Reasonably practical if everything compiled with WIT. DieHard –Randomize heap object locations and run multiple copies of the program. –Replicas fairly impractical, just an interesting academic idea. (My uneducated opinion, of course.) Runtime Memory Safety - CSE 50443

References Akritidis, P. and Cadar, C. and Raiciu, C. and Costa, M. and Castro, M. Preventing memory error exploits with WIT. (Oakland 2008) Abadi, M. and Budiu, M. and Erlingsson, U. and Ligatti, J. Control-flow integrity. (CCS 2005) Berger, E.D. and Zorn, B.G. DieHard: probabilistic memory safety for unsafe languages. (SIGPLAN 2006) Castro, M. and Costa, M. and Harris, T. Securing software by enforcing data-flow integrity. (OSDI 2006) Runtime Memory Safety - CSE 50444