Efficiently Detecting All Dangling Pointer Uses in Production Servers

Efficiently Detecting All Dangling Pointer Uses in Production Servers

Efficiently Detecting All Dangling Pointer Uses in Production Servers∗ Dinakar Dhurjati Vikram Adve University of Illinois at Urbana-Champaign 201 N. Goodwin Avenue Urbana, IL - 61801, U.S.A. {dhurjati, vadve}@cs.uiuc.edu Abstract gling pointer errors can also be exploited in much the same way as buffer overruns to compromise system security [21]. In this paper, we propose a novel technique to detect all In fact, many exploits that take advantage of a subclass of dangling pointer uses at run-time that is efficient enough these errors (double free vulnerabilities) in server programs for production use in server codes. One idea (previously have been reported in bugtraq (e.g., CVS server double free used by Electric Fence, PageHeap) is to use a new virtual exploit [7], MIT Kerberos 5 double free exploit [2], MySQL page for each allocation of the program and rely on page double free vulnerability [1]). Efficient detection of all such protection mechanisms to check dangling pointer accesses. errors in servers during deployment (rather than just during This naive approach has two limitations that makes it im- development) is crucial for security. practical to use in production software: increased physical Unfortunately, detecting dangling pointer errors in pro- memory usage and increased address space usage. We pro- grams has proven to be an extremely difficult problem. De- pose two key improvements that alleviate both these prob- tecting such errors statically in any precise manner is un- lems. First, we use a new virtual page for each allocation decidable. Detecting them efficiently at run-time while still of the program but map it to the same physical page as the allowing safe reuse of memory can be very expensive and original allocator. This allows using nearly identical physi- we do not know of any practical solution that has overheads cal memory as the original program while still retaining the low enough for use in production code. dangling pointer detection capability. We also show how to A number of approaches (including [3, 8, 9, 13, 16, 15, implement this idea without requiring any changes to the 17, 19, 20]) have been proposed that use some combination underlying memory allocator. Our second idea alleviates of static and run-time techniques to detect several kinds of the problem of virtual address space exhaustion by using memory errors, including buffer overflow errors and some a previously developed compiler transformation called Au- dangling pointer errors. All of these techniques either have tomatic Pool Allocation to reuse many virtual pages. The prohibitively high run-time overheads (2x - 100x) or mem- transformation partitions the memory of the program based ory overheads (or both) and are unsuitable for production on their lifetimes and allows us to reuse virtual pages when software. Purify [8] and Valgrind [17], two of the most portions of memory become inaccessible. Experimentally widely used tools for debugging memory access errors, we find that the run-time overhead for five unix servers is often have overheads in excess of 1000% and can some- less than 4%, for other unix utilities less than 15%. How- times be too slow even for debugging long-running pro- ever, in case of allocation intensive benchmarks, we find our grams. Moreover, most of these approaches (except Fish- overheads are much worse (up to 11x slowdown). erPatil [15], Xu et al [19] and Electric Fence [16]) employ only heuristics to detect dangling pointer errors and do not provide any guarantees about absence of such errors. Fish- 1 Introduction erPatil and Xu et al, detect all dangling pointer errors but perform software run-time checks on all individual loads Uses of pointers to freed memory (“dangling pointer er- and stores, incurring overheads up to 300% and also caus- rors”) are an important class of memory errors responsible ing substantial increases in virtual and physical memory for poor reliability of systems written in C/C++ languages. consumption (1.6x-4x). Electric Fence uses page protec- These errors are often difficult and time consuming to find tion mechanisms to detect all dangling pointer errors but and diagnose during debugging. Furthermore, these dan- does so at the expense of several fold increase in virtual and physical memory consumption of the applications. ∗This work is supported in part by the NSF Embedded Systems pro- gram (award CCR-02-09202), the NSF Next Generation Software Program (award CNS 04-06351), and an NSF CAREER award (EIA-0093426). 1.1 Our approach and deallocation), and do not perform any checks on indi- vidual memory accesses themselves. In this paper, we propose a new technique that can de- Our approach has several practical strengths. First, we tect dangling pointers in server code with very low over- do not use fat pointers or meta-data for individual pointers. heads, low enough that we believe they can be used in pro- Use of such meta-data complicates interfacing with existing duction code (though theyare also useful for debugging). libraries and requires significant effort to port programs to work with libraries. Second, if reuse of address space is not Our approach builds on the naive idea (previously used in 1 Electric Fence [16], PageHeap [13]) of using a a new vir- important , particularly during debugging, our technique tual and physical page for each allocation of the program. can be directly applied on the binaries and does not require Upon deallocation, we change the permissions on the indi- source code; we just need to intercept all calls to malloc vidual virtual pages and rely on the memory management and free from the program. Finally, we do not change the unit (MMU) to detect all dangling pointer accesses. This cache behavior of the program; so carefully memory-tuned naive idea has two problems that make it impractical for any applications can benefit from our approach without having use other than debugging: increased address space usage to retune to a new memory management scheme. (one virtual page for each allocation) and increased phys- There are two main limitations to our approach. First, ical page usage (one page for each allocation). Our tech- since we use a system call on every memory allocation, ap- nique is based on two key insights that alleviates both these plications that do in fact perform a lot of allocations and problems. Our first insight is based on the observation that deallocations will have a big performance penalty (our ap- even when using a new virtual page for each allocation we proach can still be used for debugging such applications). can still use the underlying physical page using a different However, we expect many security critical server software virtual page that maps to that physical page. Our approach to not exhibit this behavior. Second, since each allocation exploits this idea by using a new virtual page for each allo- has a new virtual page, our approach has more TLB (“trans- cation of the program but mapping it to the same physical lation lookaside buffer”) misses than the original program. page as the original program (thus using the same amount We are currently investigating simple architectural improve- of physical memory as the original program). Upon deal- ments that can mitigate both of these problems by changing location, we can change the permissions on the individual the TLB structure. virtual pages but still use the underlying physical memory We briefly summarize the contributions of this paper: via different virtual pages. We rely on the memory man- • agement unit (MMU) just like in the naive idea to detect We propose a new technique that can effectively de- all dangling pointer accesses without any software checks. tect all dangling pointer errors by making use of the If the goal is to guarantee absence of undetected dangling MMU, while still using the same physical memory as pointer dereferences, then this basic scheme will not allow the original program. us to reuse a virtual page ever again for any other alloca- • tion in the program. Our second insight is that we can build We propose the use of previously developed compiler on a previously developed compiler transformation called transformation called Automatic Pool Allocation to re- Automatic Pool Allocation [11] to alleviate the problem of duce the problem of address space exhaustion. address space exhaustion. The transformation essentially • partitions the memory used by the program in to pools (sub We evaluate our approach on five unix utilities, five heaps) and is able to infer when a partition or a pool is daemons and on an allocation intensive benchmark no longer accessible (using a standard compiler analysis suite. Our overheads on unix utilities are less than 15% known as escape analysis that is much simpler, but can be and on server applications are less than 4%. However, less precise, than that required for static detection of dan- our overheads on allocation intensive benchmark suite gling pointer references). We leverage this information, to are much worse (up to 11x slowdown). safely reuse address space belonging to a pool, when the memory corresponding to a pool becomes inaccessible. The rest of this paper is organized as follows. The next section gives the necessary background for the rest of the As our experimental results indicate, our approach works paper. Section 3 contains a detailed description of our over- extremely well for server programs. This is because most all approach and our implementation. Section 4 gives ex- server programs seem to follow a simple memory allocation perimental evaluation of our approach. Section 5 discusses and usage paradigm: They have low or moderate frequency related work and Section 6 concludes with possible future of allocations and deallocations but do have many memory directions of this work.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us