Traffic Server Debugging using ASAN / TSAN Brian Geffon.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
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.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
CS510 Advanced OS Seminar Class 10 A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy.
Honors Compilers Addressing of Local Variables Mar 19 th, 2002.
C and Data Structures Baojian Hua
Microprocessors Frame Pointers and the use of the –fomit-frame-pointer switch Feb 25th, 2002.
Memory Layout C and Data Structures Baojian Hua
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Outline Midterm results Static variables Memory model
Dynamic Memory Allocation Conventional array and other data declarations An incorrect attempt to size memory dynamically Requirement for dynamic allocation.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
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.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
CNIT 127: Exploit Development Ch 4: Introduction to Heap Overflows
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Debugging of # P. Hristov 04/03/2013. Introduction Difficult problem – The behavior is “random” and depends on the “history” – The debugger doesn’t.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 10 – C: the heap and manual memory management.
C++ 程序语言设计 Chapter 12: Dynamic Object Creation. Outline  Object creation process  Overloading new & delete.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
1 Debugging (Part 2). “Programming in the Large” Steps Design & Implement Program & programming style (done) Common data structures and algorithms Modularity.
Debugging: Tips and Tools Also, Aloha Recitation Wednesday, February 7th, 2007.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Today: –Two simple binding examples. –Function Hiding.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 1.
Announcements Partial Credit Due Date for Assignment 2 now due on Sat, Feb 27 I always seem to be behind and get tons of daily. If you me and.
Overview of OpenPegasus Debugging Hints and Tips Karl Schopmeyer Project Coordinator, Pegasus Open Source Project October 2013.
Debugging using By: Samuel Ashby. What is debugging?  A bug is an error in either a program or the hardware itself.  Debugging is first locating and.
CMon Application Monitor & Exception Manager. If I use CMon what benefits do I get? You can fix the application bugs easily. Fixing the errors in a short.
Background Survey Answers Operating Systems CS 550 Spring 2016 Kenneth Chiu.
a.k.a how we test Your code
Dynamic Allocation in C
YongChul Kwon CSE451 Section 1: Spring 2006 YongChul Kwon
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Presented by: Daniel Taylor
About Me I'm a software Committer on HDFS
YAHMD - Yet Another Heap Memory Debugger
Overview 4 major memory segments Key differences from Java stack
Debugging Memory Issues
CSE 374 Programming Concepts & Tools
Experience with jemalloc
Checking Memory Management
Lab: ssh, scp, gdb, valgrind
CSC 253 Lecture 8.
Lab: ssh, scp, gdb, valgrind
Kernel AddressSanitizer
CSC 253 Lecture 8.
Overview 4 major memory segments Key differences from Java stack
Jihyun Park, Changsun Park, Byoungju Choi, Gihun Chang
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Debugging Taken from notes by Dr. Neil Moore
Chien-Chung Shen CIS/UD
Debugging Taken from notes by Dr. Neil Moore
CETS: Compiler-Enforced Temporal Safety for C
CSE 303 Concepts and Tools for Software Development
Makefiles, GDB, Valgrind
Dynamic Binary Translators and Instrumenters
Presentation transcript:

Traffic Server Debugging using ASAN / TSAN Brian Geffon

What exactly is ASAN ASAN : Address Sanitizer – ASAN is a Memory Error Detector for C/C++ – Created by Google

What can I use ASAN to find? Use after free (dangling pointer reference) Heap Buffer Overflow

What can I use ASAN to find? Stack buffer overflow Global buffer overflow

What can I use ASAN to find? Use after return

What can I use ASAN to find? Initialization Order Bugs (aka. Static Initialization Order Fiasco)

What can I use ASAN to find? Memory Leaks!

How does it work? The tool consists of a compiler instrumentation module and a runtime library that replaces malloc / free / new / delete / etc. The memory around the malloc-ed regions (red zones) is poisoned. The free-ed memory is placed in quarantine and also poisoned.

How does it work? Before After Not too different from Valgrind or other tools, ASAN is great because it’s FAST.

Don’t tools like this slow things down? YES, Yes they do! Valgrind typically introduces a slowdown of 10 to 20x. ASAN introduces a slowdown of roughly 2x

Performance of ASAN

Getting / Using ASAN ASAN is included in LLVM versions > 3.1 ASAN is included with GCC versions > 4.8 Unfortunately, you cannot just LD_PRELOAD the library like TCMALLOC or JEMALLOC. You’ll have to recompile.

Using ASAN You need to compile and link with the -fsanitize=address switch. To get the best possible stack traces make sure to also include - fno-omit-frame-pointer ASAN will require around 20TB of Virtual Memory (YES, 20TB). So you’ll likely need to enable memory overcommit if you have hard limits: sudo sysctl –w vm.overcommit_memory=1

But what about freelists? Given that Traffic Server uses freelist the memory is never out of scope…so once we suspect a memory bug we’ll need to disable freelist + enable ASAN../configure –disable-freelist \ CXXFLAGS=“-fsanitize=address –fno-omit- frame-pointer …”

Memory Corruption masked by Freelists These bugs are very difficult to find Because it’s a race condition. It requires the object to be returned to the freelist early and another thread to pick it up and starting using it in such a way that causes one of the two threads to crash. These are almost always dangling encapsulated pointers.

When to suspect memory problems w/ Freelists Typically it will look like a random crash, it won’t be entirely clear why memory has become corrupted Frequently you’ll spot an inconsistency between a code path and a variable value.

Variable / Codepath Mismatch A common example might be: if (close_connection) { a->boom(); // something weird happens here } (gdb) p close_connection close_connection = false // WTF? It appears the object has been recycled and is being used by two different threads, it’s clearly been reinitalized.

Let’s see the power of ASAN This example is based on a REAL bug. I’ll demo what we actually saw in a production environment (using a fake server). What we’ll see from the crash is something that is very very hard to explain…

Debug Builds Please consider running your internal integration / unit tests w/ ASAN. This extra coverage might uncover memory corruption bugs. Most plugins rely on malloc / new / etc, so you’ll actually be able to catch plugin bugs too.

Debug Production Builds Because ASAN doesn’t hurt performance too much please consider deploying a debug production build to help unmask these type of bugs. Every has a slightly different use case. We found 2 bugs between 5.0 and 5.2 that were of these type. docs.trafficserver.apache.org has an ASAN build: but it simply doesn’t get enough load to uncover most of these race conditions.

Using ASAN w/ GDB (gdb) break __asan_report_error Otherwise you’ll exit gdb before you have a chance to inspect the frame