Concolic Testing on Embedded Software - Case Studies on Mobile Platform Programs
Total Page:16
File Type:pdf, Size:1020Kb
Concolic Testing on Embedded Software - Case Studies on Mobile Platform Programs Yunho Kim†, Moonzoo Kim†, Yoonkyu Jang∗ † ∗ Computer Science Department Digital Media and Communication Department Korea Advanced Institute of Science and Technology Samsung Electronics [email protected], [email protected] [email protected] ABSTRACT ciency must be investigated further through case studies. Current industrial testing practices often build test cases in a man- This paper reports case studies on the application of CREST [2] ual manner, which degrades both the effectiveness and efficiency (an open-source concolic testing tool) to mobile platform C pro- of testing. To alleviate this problem, concolic testing generates test grams developed by Samsung Electronics. Through the project, we cases that can achieve high coverage in an automated fashion. This have detected new faults in the Samsung Linux Platform (SLP) file paper describes case studies of applying concolic testing to mobile manager and the security library: an infinite loop fault was detected platform C programs that have been developed by Samsung Elec- in the SLP file manager and an invalid memory access fault was de- tronics. Through this work, we have detected new faults in the tected in the security library functions that handle large integers. Samsung Linux Platform (SLP) file manager and security library. 2. PROJECT BACKGROUND 1. INTRODUCTION In this project, the Samsung Linux Platform (SLP) file manager and a security library were selected as target programs, because In industry, testing is a standard method to improve the quality they are important in the mobile phone products and proper targets of software. However, conventional testing methods frequently fail for C-based concolic testing tool in terms of size and complexity. to detect faults in target programs. One reason is that a program The SLP file manager is 18,000 lines long containing 85 functions. can have an enormous number of different execution paths due to The security library consists of 62 functions and is 8,000 lines long. conditional and loop statements. Thus, it is infeasible for a test en- Our team consisted of one professor, one graduate student, and gineer to manually create test cases sufficient to detect subtle errors one senior SQA engineer from Samsung Electronics. The original in specific execution paths. In addition, it is technically challenging developers for the SLP file manager and the security library could to generate effective test cases in an automated manner. not join this project due to other release deadlines. In addition, These limitations are manifested in many industrial projects in- there were no documents on the SLP file manager and the security cluding the mobile platform software for Samsung smartphones. library. Thus, our team had to understand the target code from Since the smartphone market requires short time-to-market and scratch, which took almost half the time of the project. high reliability of software, Samsung Electronics decided to apply We used CREST [2] as a concolic testing tool in the project for advanced testing techniques to overcome the aforementioned lim- the following reasons. First, we needed an open source concolic itations. As a consequence, Samsung Electronics and KAIST set testing tool for C programs that can be modified for mobile plat- out to investigate the practical application of Concolic testing tech- 1 form C programs. KLEE [3] and CREST satisfy this requirement. niques to the mobile software domain for three years (2010-2012). Second, from our experience on other embedded software such as a Concolic (CONCrete + symbOLIC) [10] testing (also known as dy- flash memory device driver, KLEE is an order of magnitude slower namic symbolic execution [11] or white-box fuzzing [5]) combines than CREST due to the overhead of the LLVM virtual machine concrete dynamic analysis and static symbolic analysis to automat- and the underlying bit-vector SMT solver. In contrast, CREST in- ically generate test cases to explore execution paths of a program. serts probes in a target program to record symbolic path formulas A drawback of concolic testing, however, is that the coverage drops at runtime and uses a linear integer arithmetic SMT solver, which if the target program has external binary libraries or complex oper- achieves faster testing speed compared to KLEE. Last, we had rich ations such as pointer arithmetic. Thus, its effectiveness and effi- experience with CREST in other industrial case studies [6, 7]. 1In addition to concolic testing, we considered random testing and We performed experiments on a VMware 2.5 virtual machine genetic algorithm-based testing [8]. However, in our experience, that runs 32 bit Ubuntu 9.04, whose host machines were Windows the former rarely generates effective test cases for exceptional sce- XP SP3 machines equipped with Intel i5 2.66 GHz and 4 GBytes narios and the latter consumes huge time and requires manual tun- memory for the SLP file manager, and Intel Core2Duo 2 GHz and ing for performance. 2 GBytes memory for the security library. We could not run Linux on a real machine due to Samsung’s security policy for visitors. Permission to make digital or hard copies of all or part of this work for 3. SLP FILE MANAGER personal or classroom use is granted without fee provided that copies are Figure 1 shows an overview of the SLP file manager. The file not made or distributed for profit or commercial advantage and that copies manager (FM) monitors a file system and notifies corresponding bear this notice and the full citation on the first page. To copy otherwise, to applications of events in the file system. FM uses an inotify republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. system call to register directories/files to monitor. When the direc- Copyright 20XX ACM X-XXXXX-XX-X/XX/XX ...$10.00. tories and files that are being monitored change, the Linux kernel 1 wd indicates the watch for which this event occurs. mask contains bits that describe the type of an event that occurred such as MOVE_IN (a file moved in the watched directory). cookie is a unique integer that connects related events (e.g., pair- # ing IN_MOVE_FROM and IN_MOVE_TO). name[] represents a len file/directory path name for which the current event occurs and ! indicates a length of the file/directory path name. Among the five " fields, we specified wd, mask, and cookie as symbolic variables, since name and len are optional fields. We built a symbolic envi- ronment to provide an inotify_event queue that contains up to two symbolic inotify_events. Figure 1: Overview of the SLP file manager 3.3 Results generates inotify events and adds these events to an inotify Two persons of our team worked to apply CREST to FM for queue. FM reads an event from the queue and notifies correspond- five weeks, but only two days per week. KAIST visited Samsung ing programs of the event through a D-BUS inter-process commu- Electronics every week to analyze target code, since Samsung Elec- nication interface. For example, when a user adds an MP3 file to a tronics could not release the target code to KAIST for intellectual file system, FM notifies a music player to update its playlist auto- property issues. By using CREST, we detected an infinite loop fault matically. A fault in FM can cause serious problems in SLP, since in FM in one second. After FM reads an inotify_event in the many applications depend on FM. queue, the event should be removed from the queue to process the other events in the queue. For a normal event, the wd field of the 3.1 Difficulties of Concolic Testing For FM event is positive. Otherwise, the event is abnormal. We found that FM did not remove an abnormal event from the queue and caused Embedded software such as FM often has different develop- an infinite loop when an abnormal event was added to the queue. ment/runtime environments from those of non-embedded soft- The FM code in Figure 2 handles inotify_events. FM ware. Due to limited computational power, embedded software has moves BUF_LEN bytes from the inotify_event queue unique characteristics in its development/runtime environments, (event_queue)tobuf (line 1). Then, it processes all events in which causes difficulties for concolic testing. We observed the fol- buf through the while loop (lines 3-13). Line 7 checks whether lowing difficulties when we applied CREST to FM: or not a current event (ev) is normal. If ev is normal (line 10), Complex build process: To instrument FM, we had to modify FM sends notifications to corresponding programs (line 11) and re- the build process to use a compiler wrapper tool for CREST. The moves ev by increasing i to indicate the next event (line 12). If ev wrapper tool, however, had limitations to handle the build process is abnormal, line 9 continues the loop without increasing i. Thus, for embedded software. For performance improvement, a build at the next iteration of the loop, FM reads the same abnormal ev process for embedded software utilizes complex optimization tech- again, which causes an infinite loop. The original developers of FM niques that are not normally used for non-embedded software. One confirmed that this fault was real and fixed it. They had failed to de- example was that a build script of FM enforced a specific order tect this fault for long time, because they had created only a dozen of library linking options to optimize the FM binary. The CREST test cases for FM in a manual manner. Those manual test cases did wrapper tool, however, did not keep the order of given options, be- not include test cases with abnormal events that were difficult to cause the order of options for compilers/linkers does not affect the generate for a real file system.