Richard Johnson

Slides:



Advertisements
Similar presentations
Windows Heap Exploitation (Win2KSP0 through WinXPSP2)
Advertisements

More on File Management
Secure Coding in C and C++ Dynamic Memory Management
Dynamic memory allocation
Dynamic Memory Management
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
Note on malloc() and slab allocation CS-502 (EMC) Fall A Note on malloc() and Slab Allocation CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
The Linux Kernel: Memory Management
Kernel memory allocation
Chapter 12. Kernel Memory Allocation
Memory management.
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.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
File Systems.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Advanced topics in X86 assembly by Istvan Haller.
SECURE PROGRAMMING Chapter 4 Dynamic Memory Management.
Memory Allocator Security Yves Younan, Wouter Joosen, Frank Piessens and Hans Van den Eynden DistriNet, Department of Computer Science Katholieke Universiteit.
Week 7 - Friday.  What did we talk about last time?  Allocating 2D arrays.
DIEHARDER: SECURING THE HEAP. Previously in DieHard…  Increase Reliability by random positioning of data  Replicated Execution detects invalid memory.
Security of Memory Allocators for C and C++ Yves Younan, Wouter Joosen, Frank Piessens and Hans Van den Eynden DistriNet, Department of Computer Science.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Heap Management.
Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns Jonathan Pincus Microsoft Research Brandon Baker Microsoft Carl Hartung CSCI 7143:
1 Optimizing Malloc and Free Professor Jennifer Rexford
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
1 Memory Management in Representative Operating Systems.
Memory Allocation CS Introduction to Operating Systems.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Reliable Windows Heap Exploits
BLENDED ATTACKS EXPLOITS, VULNERABILITIES AND BUFFER-OVERFLOW TECHNIQUES IN COMPUTER VIRUSES By: Eric Chien and Peter Szor Presented by: Jesus Morales.
Software attacks Lorenzo Dematté Software attacks Advanced buffer overflow: heap smashing.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
1 File Systems: Consistency Issues. 2 File Systems: Consistency Issues File systems maintains many data structures  Free list/bit vector  Directories.
University of Washington Today Finished up virtual memory On to memory allocation Lab 3 grades up HW 4 up later today. Lab 5 out (this afternoon): time.
Computer Security 2015 – Ymir Vigfusson. 2  We have talked extensively about stack overflows  But those are not as common anymore  Heap overflows 
Author: Gene Novark, Emery D. Berger University of Massachusetts Amherst DieHarder: Securing the Heap ACM CCS’10.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.
Reliable Windows Heap Exploits Matt Conover & Oded Horovitz.
Eusecwest March 2,  Memory corruption vulnerability exposure can be mitigated through memory hardening practices  OS vendors have a unique opportunity.
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
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.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Protecting C and C++ programs from current and future code injection attacks Yves Younan, Wouter Joosen and Frank Piessens DistriNet Department of Computer.
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
9/26/20161 Real World Kernel Pool Exploitation Kostya Kortchinsky Immunity, Inc. SyScan'08 Hong Kong.
Secure Coding Techniques
Chapter 2: The Linux System Part 4
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
CSC 495/583 Topics of Software Security Heap Exploitation (2)
Protecting Memory What is there to protect in memory?
CSC 495/583 Topics of Software Security Heap Exploitation
Trust Boundary Vulnerability Exploitation State of the Exploit
Optimizing Malloc and Free
Dynamic Memory Allocation
CS Introduction to Operating Systems
Advanced Buffer Overflow: Pointer subterfuge
Software Security Lesson Introduction
Lecture 3: Main Memory.
Optimizing Dynamic Memory Management
The future of Software Security Dr. Si Chen
Buddy Allocation CS 161: Lecture 5 2/11/19.
COMP755 Advanced Operating Systems
Week 7 - Friday CS222.
Presentation transcript:

Richard Johnson

The memory manager is responsible for tracking a programs dynamic data storage. Unlike stacks which work based upon a simple FIFO/LIFO concepts, heaps require management routines to track the location of free and allocated memory chunks

What approaches to dynamic memory management have been developed? What are the security profiles of memory managers used in mainstream OSs today? What is the impact of security research on memory manager design?

Today we will consider the following OSs and their memory allocators: Windows Linux Apple OS X OpenBSD

Today we will consider the following OSs and their memory allocators: Windows Windows Heap Manager Rockall Allocator Linux Doug Lea Malloc Apple OS X Poul-Henning Kamp Malloc OpenBSD OpenBSD Malloc

The primary difference between the memory managers is how they track free buffers We will split them into systems that inline management data on each chunk and those that do not Management data inlined in the heap is susceptible to modification when a memory corruption occurs

Heaps with inlined management structs expose user APIs that walk linked lists of buffers to locate the appropriate buffer Doug Lea Windows Heap Manager Heaps without inlined management data try to take advantage of kernel-supplied memory management APIs and utilize array indexing to locate buffers Poul-Henning Kamp OpenBSD Malloc Rockall

Offensive security researchers focus on adding reliability to exploitation methods or finding new ways to manipulate management routines to gain controllable memory corruption Defensive security researchers aim to mitigate known attacks or (rarely) attempt new heap manager designs

dlmalloc 2001 Michel "MaXX" Kaempf / Anonymous 2005 Phantasmal Phantasmagoria Windows Heap 2002 David Litchfield 2004 Matt Conover / Oded Horovitz 2005 SecurityPatrol

PHKMalloc 2005 Yves Younan et al OpenBSD Malloc 2006 Ben Hawkes

Basic mechanics: A region of memory is allocated to contain buffers An array of doubly linked lists tracking free buffers in multiples of a fixed size (usually 8) is created On allocation a free chunk is unlinked from the doubly linked list and the address is returned to the program On free, a 8 byte header is written to the beginning of a buffer and the chunk is added back to the list When two free buffers are adjacent they will be merged into one larger chunk of free memory Lookaside lists*

Attacks Unlink Free buffer is removed from doubly linked list with corrupted forward and backward pointers Attacker writes 4 bytes of controlled data to a controlled location Coalesce Manipulating the flag indicating whether the previous chunk is in use can be used with a fake chunk header to cause a 4 byte write to a controlled location Lookaside list The head of a lookaside list can be overwritten to later return a controlled address to the next allocation of that size

Unlink Attack Scenario: Heap-based buffer overflow allows for writing into adjacent free heap block Attack: Overwrite FLINK and BLINK values and wait for next allocation Result: Allows one or more 4-byte writes to controlled locations FREE HEAP BLOCK _HEAP_ENTRY +0x000 Size +0x002 PreviousSize +0x004 SmallTagIndex +0x005 Flags +0x006 UnusedBytes +0x007 SegmentIndex _LIST_ENTRY +0x000 Flink +0x004 Blink mov dword ptr [ecx],eax mov dword ptr [eax+4],ecx EAX = Flink, ECX = Blink

Lookaside Attack Scenario: Heap-based buffer overflow allows for control of lookaside list management structure Attack: First heap overwrite takes control of Flink value in a free chunk with a lookaside list entry Allocation of the corrupted chunk puts the corrupt Flink value into the lookaside list Next HeapAlloc() of the same sized chunk will return the corrupted pointer Result: Returns corrupted pointer from the next allocation from the lookaside list which allows for arbitrary length overwrites

Basic mechanics: Relies on and optimized for kernel provided virtual memory management system Heap manager tracks allocated pages, allocated chunks and free pages in a series of directories All chunks in a page are typically of the same size Adjacent free pages are coalesced

Attacks free() Control of a pointer passed to free can be abused to free memory that contains one of the heap management structures. pginfo / pgfree Manipulate the value returned by an allocation

free() attack Scenario: Heap-based buffer overflow allows for control of pointers later passed to free() Attack: Free pages with control structures on them Result: Later allocations will eventually return the page with the control structures and allow for further exploitation

pginfo attack Scenario: Heap-based buffer overflow allows for control of the pginfo structure leading to arbitrary memory corruption Attack: Heap overflow allows for modification of the pginfo->free page pointer. Overwrite bits array to make pages seem free Result: Allocation requests walk the structs to find the appropriate sized buffers so returning corrupted pointer allows for writes to arbitrary locations. PGFREE struct pgfree { struct pgfree *next; struct pgfree *prev; // free pages void *page; // base page dir void *pdir; // bytes free size_t size; }; PGINFO struct pginfo { struct pginfo *next; void *page; ushort size; ushort shift; ushort free; ushort total; uint bits[]; };

dlmalloc glibc added safe unlinking Windows Heap Safe unlinking Checksum for size and flags XOR size, flags, checksum, and prevsize fields Lookaside list replaced by LFH in Vista

phkmalloc Nada OpenBSD malloc Nada System defenses such as ASLR and NX also apply but are not part of the heap managers architecture

So whats next?

The Month of Kernel Bugs is a serious wake- up call about the vulnerability of the most fundamental element of the operating system. Begin preparing now for more, and more damaging, attacks against the OS kernel. Rich Mogul – Gartner Nov kernel_b_ pdf

2005 SoBeIt How to exploit Windows kernel memory pool Basic unlink() technique applies to the kernel pool

Pools are managed by a pool descriptor, chunks are managed by a pool chunk header lkd> dt -v -r nt!POOL_DESCRIPTOR struct _POOL_DESCRIPTOR, 14 elements, 0x1034 bytes +0x000 PoolType : Enum _POOL_TYPE +0x004 PoolIndex : Uint4B +0x008 RunningAllocs : Int4B +0x00c RunningDeAllocs : Int4B +0x010 TotalPages : Int4B +0x014 TotalBigPages : Int4B +0x018 Threshold : Uint4B +0x01c LockAddress : Ptr32 to Void +0x020 PendingFrees : Ptr32 to Ptr32 to Void +0x024 ThreadsProcessingDeferrals : Int4B +0x028 PendingFreeDepth : Int4B +0x02c TotalBytes : Uint4B +0x030 Spare0 : Uint4B +0x034 ListHeads : [512] struct _LIST_ENTRY, 2 elements, 0x8 bytes +0x000 Flink : Ptr32 to struct _LIST_ENTRY, 2 elements, 0x8 bytes +0x004 Blink : Ptr32 to struct _LIST_ENTRY, 2 elements, 0x8 bytes +0x000 Flink : Ptr32 to struct _LIST_ENTRY, 2 elements, 0x8 bytes +0x004 Blink : Ptr32 to struct _LIST_ENTRY, 2 elements, 0x8 bytes lkd> dt -v -r nt!POOL_HEADER struct _POOL_HEADER, 8 elements, 0x8 bytes +0x000 PreviousSize : Bitfield Pos 0, 9 Bits +0x000 PoolIndex : Bitfield Pos 9, 7 Bits +0x002 BlockSize : Bitfield Pos 0, 9 Bits +0x002 PoolType : Bitfield Pos 9, 7 Bits +0x000 Ulong1 : Uint4B +0x004 PoolTag : Uint4B +0x004 AllocatorBackTraceIndex : Uint2B +0x006 PoolTagHash : Uint2B

The good news Were active researching how to add appropriate mitigations to the kernel memory management code The bad news Unlike user heaps, the kernel pool is globally managed There arent any free bytes to use for checksums and cookies Performance and compatibility concerns sometimes trump security

You can help. Contact us at if you are interested in this research and want your ideas heard!

Questions?