Testing Error Handling Code in Device Drivers Using Characteristic
Total Page:16
File Type:pdf, Size:1020Kb
Testing Error Handling Code in Device Drivers Using Characteristic Fault Injection Jia-Ju Bai, Yu-Ping Wang, Jie Yin, and Shi-Min Hu, Tsinghua University https://www.usenix.org/conference/atc16/technical-sessions/presentation/bai This paper is included in the Proceedings of the 2016 USENIX Annual Technical Conference (USENIX ATC ’16). June 22–24, 2016 • Denver, CO, USA 978-1-931971-30-0 Open access to the Proceedings of the 2016 USENIX Annual Technical Conference (USENIX ATC ’16) is sponsored by USENIX. Testing Error Handling Code in Device Drivers Using Characteristic Fault Injection Jia-Ju Bai, Yu-Ping Wang, Jie Yin, and Shi-Min Hu Department of Computer Science and Technology, Tsinghua University Abstract tion [34]. For example, “bad address” (EFAULT) is a Device drivers may encounter errors when communi- common error should be handled, but it happens only cating with OS kernel and hardware. However, error when the memory or I/O address is invalid. Another handling code often gets insufficient attention in driver example is hardware error, which happens only when development and testing, because these errors rarely the hardware malfunctions. Triggering these errors in occur in real execution. For this reason, many bugs are real environment is very hard and uncontrollable. hidden in error handling code. Previous approaches for To simulate software and hardware errors at runtime, testing error handling code often neglect the characteris- software fault injection (SFI) is often used in driver tics of device drivers, so their efficiency and accuracy testing. This technique mutates the code to inject specif- are limited. In this paper, we first study the source code ic errors into the program, and enforces error handling of Linux drivers to find useful characteristics of error code to be executed at runtime. Linux Fault Injection handling code. Then we use these characteristics in fault Capabilities Infrastructure (LFICI) [43] is a well-known injection testing, and propose a novel approach named project integrated in Linux kernel. It can simulate com- EH-Test, which can efficiently test error handling code mon errors, such as memory-allocation failures and bad in drivers. To improve the representativeness of injected data requests. Inspired by LFICI, other fault injection faults, we design a pattern-based extraction strategy to approaches [7, 13, 23, 32] have been proposed in recent automatically and accurately extract target functions years, and they have shown promising results in driver which can actually fail and trigger error handling code. testing and bug detection. However, these approaches During execution, we use a monitor to record runtime still have some limitations in practical use. information and pair checkers to check resource usages. The representativeness of injected faults is often We have evaluated EH-Test on 15 real Linux device neglected, and most injected faults are random or drivers and found 50 new bugs in Linux 3.17.2. The manually selected. Random faults can not reflect code coverage is also effectively increased. Comparison real errors well. Manually selected faults often omit experiments to previous related approaches also show representative injected faults. the effectiveness of EH-Test. Numerous redundant test cases are generated. In fact, many generated test cases may cover the same error handling code, but they all need to be actually 1. Introduction tested at runtime. For this reason, they often spend As important components of the operating system, de- much time in runtime testing. vice drivers control hardware and provide fundamental Only several kinds of faults can be injected, such as supports for high-level programs. During driver execu- memory-allocation failures. But these faults can not tion, different kinds of occasional errors may occur, cover most error handling code in drivers. such as kernel exceptions and hardware malfunctions Much manual effort is needed. The kinds and plac- [31]. Therefore, device drivers need error handling code es of injected faults are often manually decided. to assure reliability. But in some drivers, error handling In fact, previous fault injection approaches aim to code is incorrect or even missed. In these drivers, seri- support general software, but they neglect the character- ous problems like system crashes and hangs may occur istics of target programs. To relieve their limitations, we when occasional errors are triggered. According to our should consider the key driver characteristics in SFI. study on Linux driver patches, more than 40% of ac- For example, because drivers are often written in C, so cepted patches add or update corresponding error han- built-in error handling mechanisms (such as “try-catch”) dling code. It shows that error handling code in device are not supported. For this reason, the developers often drivers is not reliable enough, so testing error handling use an if check to decide whether the error handling code and detecting bugs inside are very necessary. code should be triggered in device drivers. This charac- A challenge of testing error handling code is that oc- teristic can help to decide which functions can actually casional errors are infrequent to happen in real execu- fail and should be fault-injected. 1 USENIX Association 2016 USENIX Annual Technical Conference 635 n his aer, e firs sudy inux drier code, and 4) High automation and scalability. os orking ind hree useul characerisics in error handling code procedure o H-Tes is auomaed, including arge- function return value trigger few branches and check funcion eracion, aul injecion and es-case eecu decision. hen ased on hese characerisics and SFI, ion. nd i can suppor many inds of eising driers. we ropose a racical aproach named EH-Tes 1 o In his aer, e mae he following conriuions: eficienl es error handling code and deec ugs in We sudy he source code of inux deice driers, side irsly, EH-Tes uses a pattern-based extraction and ind hree useul characerisics in error han strategy o eract arge uncions hich can fail rom dling code he capured runime races of normal eecuion. This Based on he paerns of error handling code in srategy can auomaicall and accurael eract real driers, e design a paern-based eracion srae arge funcions o improve he reresenaieness of gy o auomaicall and accurael real arge func injec auls Then, we generae es cases by corrupting ions as reresenaie injeced auls. he reurn values of arge functions. et, e run each Based on he characerisics, e design a pracical es case on he real hardare and use a monior o rec aproach named EH-Tes which can eficienl es ord runime informaion and air checkers o check re error handling code in deice driers and deec source-usage violaions. hese air checers conain he bugs inside basic informaion of resource-acquiring and resource- We ealuae EH-Tes on 15 deice driers in inux releasing uncions, hich can be obained from specii 3.1. and .17.2, and reseciel find 32 and 50 caion mining echniues 18, 38] and user con bugs. All he deeced bugs in .17.2 hae been figuraion. During drier eecuion sysem crashes and confirmed y deelopers. he code coverage is also hangs can e easil ideniied hrough kernel crash logs efeciel increased in runime esing e also or user observaion. Afer drier eecuion, H-Tes perform comparison eperimens o preious ap- can reor resource-release omissions. We hae imple proaches, and ind ha EH-Tes can deect the ugs mened H-Tes using LLVM, and ealuaed i on 15 which are missed y hem. he eperimenal resuls Linux driers o hree classes. he resuls show ha show ha EH-Tes can eficienl erform drier esing and accurael ind real ugs. EH-Tes can accurael ind real bugs in error handling The res of his aer is organied as ollows. ecion code and improve code coverage in runime esing. 2 inroduces he moiaion ecion presens he hree Comarison eperimens o reious aproaches also characerisics of deice driers found y our sudy on sho is efecieness. Linux drier code ecion 4 presens our aern-based Compared o reious I aproaches or esing exracion sraegy. ecion inroduces EH-Tes in driers, our aproach hae our advanages deail ecion shows our ealuation on 5 Linu de 1) Representative injected faults. We design a at- vice driers and comarison eperiments o reious ern-based eracion sraegy o auomaicall and ac aproaches ecion 7 inroduces he relaed ork and curael eract real arge functions as reresenaie ecion 8 concludes his paer. injeced auls. uses code paerns o decide wheher a funcion can acuall fail in drier eecuion. This srat- 2. Motivation eg can largel improve the efecieness of I. 2) Efficient test cases. According o our sudy, many To ensure he reliailiy of deice driers, error han driers hae fe ranches in error handling code so dling code should be correcl implemened o handle injecting a single faul in each es case is enough o diferen inds of occasional errors. u in act error cover mos error handling code oreoer, our paern- handling code is incorrec or een missed in some driv- based eracion sraegy can iler many unreresenta ers so hard-o-find ugs ma occur during eecuion. n ie injeced auls. herefore he es cases generaed his secion, e irst reeal his roblem using a con b H-Tes are eficien and he ime usage of runime cree eample and our sudy on inux drier aches esing can e largel shortened. and hen e skech he software faul injecion ech 3) Accurate bug detection. By injecing reresenta nique used in his aer ie fauls, H-Tes can realisicall simulae differen 2.1 Motivating Example kinds of occasional errors o cover error handling code We firs moiae our ork using a real Linux drier oreover, H-Tes runs on he real hardware and uses bnx2 his drier manages roadcom eXreme I eac eecuion informaion o perform analsis.