Autocorrelation-Based Detection of Infinite Loops at Runtime

Autocorrelation-Based Detection of Infinite Loops at Runtime

Autocorrelation-Based Detection of Infinite Loops at Runtime Andreas Ibing, Julian Kirsch and Lorenz Panny Chair for IT Security TU Munchen¨ Boltzmannstrasse 3, 85748 Garching, Germany Abstract—We present a new algorithm for the detection of implemented with a watchdog timer in embedded systems: infinite loop bugs in software. Source code is not needed. The A watchdog timer has to be actively reset by the software algorithm is based on autocorrelation of a program execution’s perpetually, otherwise the watchdog triggers a system restart. branch target address sequence. We describe the implementa- tion of the algorithm in a dynamic binary instrumentation tool; A more recent example is found in dynamic symbolic the result is lightweight enough to be applied continuously at execution tools [3], [4]. Dynamic symbolic execution is a runtime. Functionality of the tool is evaluated with infinite testing approach where program execution is automatically loop bug test cases from the Juliet test suite for program driven into different program paths. The corresponding analyzers. Applicability of the algorithm to production software program input is automatically generated with a constraint is demonstrated by using the tool to detect previously known infinite loop bugs in cgit, Avahi and PHP. solver, typically a Satisfiability Modulo Theories (SMT, [5]) solver. These symbolic execution tools also set a maximum Keywords-Program analysis; infinite loops; dynamic binary duration of unresponsiveness, after which an infinite loop instrumentation bug is reported. The second approach is to prove termination or non- I. INTRODUCTION termination using an automated theorem prover, again typ- Infinite loop bugs are both an issue of software safety and ically an SMT solver. While (non-)termination can not be of software security. A program that runs into an infinite decided for all loops in general, it can be decided often loop becomes unresponsive, which violates safety properties. enough to be of practical use. Prominent tools include [6]– If an infinite loop can be triggered with program input by [11]. Because these tools are not perfect, there is still an an attacker, the program is vulnerable to a denial of service interest in detecting infinite loops at runtime. The process of attack. Under the common weakness enumeration [1], infinite translating a program into logic equations and especially loops are known as CWE-835 (‘loop with unreachable exit theorem proving itself is too complex to be applicable condition’). continuously at runtime. In [12] it is proposed to connect a Possible mitigation approaches to infinite loop bugs include symbolic execution tool called Looper at a user’s request the usage of testing tools in order to detect and remove to an unresponsive process. The tool would then single-step bugs before deployment, or to use light-weight program with symbolic execution and try to prove that an infinite loop instrumentation to catch an infinite loop when in occurs at is executed. runtime. The third approach uses hash values of concrete program The problem of finding infinite loops in programs is states to verify the execution of an infinite loop by finding a as old as computing itself. A perfect bug checker would recurrence program state [13]. The tool presented in [13] is detect all infinite loops in any program without false connected at a user’s request to an unresponsive process negative detections, without false positive detections, and and single-steps this process. At branches, the program with bounded runtime. Because the Halting Problem is known state including register and memory contents is hashed and to be undecidable in general [2], such a perfect bug checker compared to previous hash values. If a hash appears more can not exist. Any real detection algorithm must therefore than once, an infinite loop is reported. drop at least one of the three properties and tolerate either This paper presents a new algorithm for automated false positive detections, false negative detections, or running detection of infinite loops. It is sufficiently lightweight into non-termination itself. to be applied continuously at runtime. It does not need Nevertheless, three principle approaches to automated constraint solver, program source code or hash values over infinite loop detection have been developed and are in program states. The algorithm is based on autocorrelation, practical use today. The oldest one is to set a maximum a computation commonly used in many areas of applied duration after which an unresponsive program is assumed statistics: One example is in time series analysis to identify to be stuck in an infinite loop. This approach is most often periodic changes. Another example is in signal processing, 1 i n t main ( i n t argc , char ∗∗ argv ) f where p is the period length. The autocorrelation function 2 unsigned int i , j , k = 0 ; 3 /∗ I n f i n i t e loop: incrementi instead ofj ∗/ Rff (l) always has a peak value for l = 0. For a periodic 4 f o r ( j = 1 ; j < 0x10000; i++) function of period p, the autocorrelation also peaks at the 5 f o r ( i = 0 ; i < 0x10 ; i ++) 6 k ++; period length l = p and its integer multiples. For the 7 g detection of infinite loops in programs, we slightly adapt the autocorrelation as described in the following sections. Figure 1: Sample C program containing an infinite loop A. Detecting periodic infinite loops A path through a program can be represented by the 1 004004 b6 <main >: 2 004004 b6 : push rbp corresponding sequence of branches, i.e., the sequence 3 004004 b7 : mov rbp,rsp of branch target addresses. The branches comprise both 4 5 004004 ba : mov DWORD PTR [rbp −0x14 ] ,edi conditional branches and unconditional branches (jumps). 6 004004 bd : mov QWORD PTR [rbp −0x20 ] ,rsi A branch target address sequence is denoted as: 7 004004 c1 : mov DWORD PTR [rbp −0x8 ] , 0 x1 8 004004 c8 : jmp 4004 e5 <main+0 x2f> b(n) n 2 [0; m] 9 004004 ca : mov DWORD PTR [rbp −0x4 ] , 0 x0 10 004004 d1 : jmp 4004 db <main+0x25> 11 where b(0) is the first branch after the program’s entry point, 12 004004 d3 : add DWORD PTR [rbp −0xc ] , 0 x1 and b(m) is the last taken branch, leading to the current 13 004004 d7 : add DWORD PTR [rbp −0x4 ] , 0 x1 14 004004 db : cmp DWORD PTR [rbp −0x4 ] , 0 xf program execution state. The basic idea is to detect an infinite 15 004004 df : jbe 4004 d3 <main+0x1d> loop through the branch sequence, which is assumed to 16 004004 d7 : add DWORD PTR [rbp −0x4 ] , 0 x1 17 become periodic. To this end, the autocorrelation of the 18 004004 e5 : cmp DWORD PTR [rbp −0x8],0xffff branch sequence is computed on-the-fly during program 19 004004 ec : jbe 4004 ca <main+0x14> 20 004004 ee : mov eax,0x0 execution. 21 004004 f3 : pop rbp m 22 004004 f4 : r e t X Rbb(l; m) = b(n)b(n − l) ; l = 0::m n=1 Figure 2: Compiled version of the sample program The value for l = 0 is not of interest and not computed, because an infinite loop has a positive period length. If the program runs into an infinite loop with period length p, the for synchronization in communication systems. We apply autocorrelation will show a peak at Rbb(l = p; m), where autocorrelation as an efficient way to identify suspicious the peak value increases with the number of branches m. branch sequences on-the-fly. Unlike in other applications of autocorrelation where a The remainder of this paper is organized as follows. periodic function undergoes some time variance due to noise, Section II describes and illustrates the algorithm in detail. here we have identical periods. Therefore, we replace the Section III presents an implementation using dynamic binary multiplication with Kronecker’s delta function: instrumentation. Algorithm properties are described in detail ( in Section IV. Experiments with the resulting tool are 1 if i = j δ(i; j) = i; j 2 Z described in section V. The tool is evaluated with infinite 0 else loop test cases from the Juliet suite [14], and it is used to That yields: detect known infinite loop bugs in Avahi, cgit and PHP. m Related work is reviewed in section VI. Results of the tool X evaluation are discussed in section VII. Rbb(l; m) = δ b(n); b(n − l) ; l = 0::m n=1 II. ALGORITHM: MODIFIED AUTOCORRELATION FOR i.e., the autocorrelation value is only increased if the branch BRANCH TARGET ADDRESS SEQUENCE ANALYSIS target address is identical to the target address of l branches Autocorrelation is the correlation of a function f(n) with before. The recursive version for on-the-fly computation is: itself at different points in time. It computes the similarity R (l; m) = R (l; m − 1) + δ b(m); b(m − l) between the function and a time-lagged version of itself, bb bb where the time lag l is variable. The (discrete) autocorrelation We also want to consider the falsification of an infinite Rff at lag l for a real-valued function f(n) is: loop hypothesis. If a periodic sequence is broken, we reset the X corresponding correlation value(s). The recursive computation Rff (l) = f(n)f(n − l) becomes: n2Z ( Rbb(l; m − 1) + 1 if b(m) = b(m − l) For a periodic function f(n) we have: Rbb(l; m) = 0 else f(n + p) = f(n) (1) Figure 3: A static snapshot of the autocorrelation val- Figure 4: A selected time frame observing two dynamically ues Rbb(l; lmax ) at forcibly induced program termination changing values (Rbb(18; lmax ), Rbb(19; lmax )) during pro- (Rbb(18; lmax ) ≥ T ) gram execution An infinite loop candidate is identified if the correlation exceeds a pre-defined threshold value T : p which are non-zero multiples of 19 clearly indicate the periodicity of the generated assembly code: To perform Rbb(l; m) > T for any l (2) one complete iteration of the outer loop, the conditional 0x4004df the period of the infinite loop is p = l, i.e., the index of branch at corresponding to the inner loop is the correlation value that first exceeds the threshold T .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 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