By Emery D. Berger and Benjamin G. Zorn Presented by: David Roitman.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Lectures on File Management
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.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Virtual Memory Operating System Concepts chapter 9 CS 355
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Dynamic Memory Management Emery Berger and Mark Corner.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 2007 Exterminator: Automatically Correcting Memory Errors with High Probability Gene.
DIEHARDER: SECURING THE HEAP. Previously in DieHard…  Increase Reliability by random positioning of data  Replicated Execution detects invalid memory.
By Gene Novark, Emery D. Berger and Benjamin G. Zorn Presented by Matthew Kent Exterminator: Automatically Correcting Memory Errors with High Probability.
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Chapter 15 : Attacking Compiled Applications Alexis Kirat - International Student.
ARRAYS AND POINTERS Although pointer types are not integer types, some integer arithmetic operators can be applied to pointers. The affect of this arithmetic.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science PLDI 2006 DieHard: Probabilistic Memory Safety for Unsafe Programming Languages Emery.
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 2006 Exterminator: Automatically Correcting Memory Errors Gene Novark, Emery Berger.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
15-740/ Oct. 17, 2012 Stefan Muller.  Problem: Software is buggy!  More specific problem: Want to make sure software doesn’t have bad property.
Computer Security and Penetration Testing
CNIT 133 Interactive Web Pags – JavaScript and AJAX Advanced topic - variable.
DieHard: Probabilistic Memory Safety for Unsafe Languages Emery D. Berger and Benjamin G. Zorn PLDI'06 Presented by Uri Kanonov
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
Chapter 4 Memory Management Virtual Memory.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
C Programming Day 4. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 More on Pointers Constant Pointers Two ways to.
Dynamic Memory. We will follow different order from Course Book We will follow different order from Course Book First we will cover Sect The new.
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Author: Gene Novark, Emery D. Berger University of Massachusetts Amherst DieHarder: Securing the Heap ACM CCS’10.
CS333 Intro to Operating Systems Jonathan Walpole.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
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.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Free Transactions with Rio Vista Landon Cox April 15, 2016.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Virtual Memory.
Non Contiguous Memory Allocation
Free Transactions with Rio Vista
Module 11: File Structure
Advanced OS Concepts (For OCR)
Main Memory Management
Chapter 8: Main Memory.
O.S Lecture 13 Virtual Memory.
Main Memory Background Swapping Contiguous Allocation Paging
Free Transactions with Rio Vista
Lecture 3: Main Memory.
CSE451 Virtual Memory Paging Autumn 2002
CS703 - Advanced Operating Systems
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

By Emery D. Berger and Benjamin G. Zorn Presented by: David Roitman

2 If so, DieHard comes to save you….

Index Un/Safe Languages and DieHard Un/Safe Languages and DieHard Probabilistic security and the Infinite Heap. The M-Heap as an approximation Implementation Results Conclusions Questions 3

What is a safe program? For the purpose of this article, a program is fully memory safe if it satisfies the following criterias: It never reads uninitialized memory. Performs no illegal operations on the heap No invalid or double frees Does not access freed memory No dangling pointer errors. 4

Problems with Unsafe Languages Unsafe languages like C and C++ are vulnerable to: Dangling pointers Mistakinly freeing a live object, which might be overwritten. Buffer overflows Writing more data then the target has room for. Can corrupt the contents of live objects on the heap. The iPhone and the PS3 were both hacked by exploiting this. Heap metadata overwrites If heap metadata is stored near heap objects, a buffer overflow can corrupt it. 5

Problems – Cont. Unsafe languages like C and C++ are vulnerable to: Uninitialized reads Reading from newly-allocated or unallocated memory leads to undefined behavior. Invalid frees Passing illegal addresses to free can corrupt the heap. Double frees Repeated calls to free of objects that have already been freed cause freelist-based allocators to fail. 6

Current Approaches to safe programming Failure oblivious – Does everything it can to avoid aborting. Drops illegal writes Makes up values for invalid reads Unsound – Correct execution isn’t guaranteed. Fail-Stop – Aborts any computation that might violate one of the safe program conditions Provides soundness but crashes a lot. This is how most safe C compilers work. 7

DieHard – A new approach A runtime system that tolerates errors while probabilistically maintaining soundness. Provides correct execution in the face of errors with high probability. 8

DieHard’s Modes of operation Stand alone Replaces the default memory manager. Provides substantial protection against memory errors. Replicated – An expansion of the stand alone mode. Runs multiple replicas simultaneously, votes on results. Detects crashing & non-crashing errors. Adds detection of errors caused by illegal reads. Both rely on the DieHard randomized memory manager. 9

The DieHard randomized memory manager Places objects randomly across a heap whose size is M times the maximum required. Separates all heap metadata from the heap Avoiding most heap metadata overwrites Ignores attempts to free already freed or invalid objects. 10

How does it help? Reduces likeliness of crashes due to buffer overflows The spacing between objects makes it likely that buffer overflows end up overwriting only empty space. Helps avoid dangling pointer errors Randomized allocation makes it unlikely that a newly freed object will soon be overwritten by a subsequent allocation. 11

The replicated mode Buffer overflows are likely to overwrite different areas of memory in the different replicas. In this mode only, the heap and every allocated object is filled with random values. An uninitialized read will return different results across the replicas. 12 Increases protection and adds detection of uninitialized reads.

Where we are? Un/Safe Languages and DieHard Probabilistic security and the Infinite Heap. Probabilistic security and the Infinite Heap. The M-Heap as an approximation Implementation Results Conclusions Questions 13

The infinite heap memory manager Is an ideal, unrealizable runtime system that allows programs containing memory errors to execute soundly and to completion. In such a system, the heap area is infinitely large and can never be exhausted. All objects are allocated fresh, infinitely far away from each other, and are never deallocated. 14

What’s so good about it? Buffer overflows become benign Objects are so far apart that they never overwrite live data. Dangling pointers vanish Objects are never deallocated or reused. However, uninitialized reads remain undefined. This requires the replicated version. This of course, is impossible to build! DieHard approximates this behavior by using an M- heap. 15

The M-Heap An M-heap is a heap that is M times larger than needed. By placing objects uniformly randomly across an M- heap, we get an expected separation between any two objects of M-1 objects Any overflow smaller than that becomes benign, with high probability. 16

The M-Heap – Cont. Increasing the heap expansion factor (M) increases the probability of correct execution in the presence of memory error. This heap thus provides probabilistic memory safety, a probabilistic guarantee that memory errors occurring in the program are benign during its execution. 17

Organizing the Heap The heap is logically partitioned into twelve regions, one for each power-of-two size class from 8 bytes to 16 kilobytes. Each region is allowed to become at most 1/M full. 18

Larger then 16k? DieHard allocates larger objects directly using mmap and places guard pages without read or write access on either end of these regions. Object requests are rounded up to the nearest power of two. Significantly speeds allocation by allowing bit shifting operations instead of divides. These regions were created in order to prevent the fragmentation that would occur if all objects would be spread throughout the heap. 19

The heap Metadata Includes a bitmap for each heap region One bit always stands for one object. All bits are initially zero, indicating that every object is free. Also includes the number of objects allocated to each region (inUse). Ensures less than 1/M objects per partition. 20

Location of the heap Metadata Most allocators store heap metadata in areas immediately adjacent to allocated objects. These are known as boundary tags. A buffer overflow of just one byte past an allocated space can corrupt the metadata and thus the heap. DieHard keeps all of the heap metadata separate from the heap, and thus protects it from buffer overflows. 21

Where we are? Un/Safe Languages and DieHard Probabilistic security and the Infinite Heap. The M-Heap as an approximation Implementation Implementation Results Conclusions Questions 22

Part 1 - Initialization The initialization phase obtains free memory from the system using mmap. The size allocated is M times larger then needed. The random number generator’s seed is initialized with a true random number. For example /dev/urandom in Linux For the replicated version only, the initialization phase then uses its random number generator to fill the heap with random values. 23

Initialization – Pseudo code 24 Setting the random seed Resetting the bitmap in the metadata Allocating the heap In replicated mode - Filling the heap with random values

Part 2 - Malloc Diehard overrides the native malloc and free functions with it’s own version. The allocator first checks to see whether the request is for a large object (>16K). If so, it calls allocateLargeObject() which Allocates the object Using mmap. Stores the address in a table for validity checking by DieHard’s Free. 25

Malloc If <16K Finds which class it belongs to using If the class is not full it looks for an empty space similarly to probing a hash table. It then marks the object as allocated and increments the allocated counter. Again, for the replicated version, fills the object with randomized values. 26

Malloc – Pseudo code 27 If >16K allocate large Check if full Probe for empty slot If found, mark allocated In replicated mode - Filling the object with random values

Part 3 - Free DieHard’s Free takes several steps to ensure that any object given to it is in fact valid: Checks if the address is inside the heap area. If not, it might be a large object and is sent to freeLargeObject() which checks the large address table. The object must also be currently marked as allocated. Only if both conditions are met, the object is freed from the heap. 28

Free – Pseudo code 29 If not in heap area, it’s large Checks both conditions before freeing Mark as unallocated

Fixing strcpy() Another change DieHard does is replace the error prone strcpy() function with it’s own variant. Strcpy() does no checks to verify that the target has enough room for the string. DieHard also replaces its “safe” counterpart, strncpy. Same as strcpy but also requires the size of the string to copy. Still does no checks to verify the target has room for it. DieHard’s version checks the destination’s actual available space and uses that value as the upper bound. 30

Where we are? Un/Safe Languages and DieHard Probabilistic security and the Infinite Heap. The M-Heap as an approximation Implementation Results Results Conclusions Questions 31

A little probability Definitions: M - heap expansion factor. K – Number of replicas. H – The maximum heap size. L - The maximum live size. F - The remaining free space. F=H-L O – The number of object’s worth of bytes overflowed. 32

33 Masking Buffer Overflows

34 Masking Dangling Pointers

Performance on Linux For allocation-intensive benchmarks, DieHard suffers a performance penalty ranging from 16.5% to 63%. geometric mean: 40% However, DieHard’s runtime overhead is substantially lower for most of the SPECint2000 benchmarks. The geometric mean of DieHard’s overhead is 12%. 35

36

Performance on Windows XP The results on Windows XP are much better and are effectively the same as with the default allocator. These results can be attributed to two factors: The default Windows XP allocator is substantially slower than the Lea allocator. Visual Studio produces much faster code for DieHard than g++ does. 37

38

Replication overhead performance Running 16 replicas on 16 different cores simultaneously Increases runtime by approximately 50%. 39

Error Avoidance Errors were injected into running benchmarks and results were compared between the regular allocator and Diehard. For injection of a dangling pointer for every other free The espresso benchmark could not run to completion with the default allocator in all runs. With DieHard it ran correctly for 9 out of 10 runs. The same for 1 out of every 100: With the default allocator, espresso crashes in 9 out of 10 runs and enters an infinite loop in the tenth. With DieHard, it runs successfully in all 10 of 10 runs. 40

Real application testing Version 2.3s5 of the Squid web cache server has a buffer overflow error. Running it using the default allocator crashed with a seg-fault. Running it under DieHard in stand-alone mode was completed successfully. 41

Where we are? Un/Safe Languages and DieHard Probabilistic security and the Infinite Heap. The M-Heap as an approximation Implementation Results Conclusions Conclusions Questions 42

Conclusions DieHard is a runtime system that effectively tolerates memory errors and provides probabilistic memory safety. DieHard uses randomized allocation to give the application an approximation of an infinite-sized heap. Uses replication to further increase error tolerance and detect uninitialized memory reads. 43

Conclusions – Cont. DieHard allows an explicit trade-off between memory usage and error tolerance. Is useful for programs in which memory footprint is less important than reliability and security. Like garbage collection, DieHard represents a new and interesting alternative in the broad design space that trades off CPU performance, memory utilization, and program correctness. 44

Questions? 45