1*795d594fSAndroid Build Coastguard WorkerDexFuzz 2*795d594fSAndroid Build Coastguard Worker======= 3*795d594fSAndroid Build Coastguard Worker 4*795d594fSAndroid Build Coastguard WorkerDexFuzz is primarily a tool for fuzzing DEX files. Fuzzing is the introduction of 5*795d594fSAndroid Build Coastguard Workersubtle changes ("mutations") to a file to produce a new test case. These test cases 6*795d594fSAndroid Build Coastguard Workercan be used to test the various modes of execution available to ART (Interpreter, 7*795d594fSAndroid Build Coastguard WorkerOptimizing compiler) to check for bugs in these modes of execution. 8*795d594fSAndroid Build Coastguard WorkerThis is done by differential testing - each test file is executed with each mode of 9*795d594fSAndroid Build Coastguard Workerexecution, and any differences between the resulting outputs may be an indication of 10*795d594fSAndroid Build Coastguard Workera bug in one of the modes. 11*795d594fSAndroid Build Coastguard Worker 12*795d594fSAndroid Build Coastguard WorkerFor a wider overview of DexFuzz, see: 13*795d594fSAndroid Build Coastguard Worker 14*795d594fSAndroid Build Coastguard Workerhttp://community.arm.com/groups/android-community/blog/2014/11/26/the-art-of-fuzz-testing 15*795d594fSAndroid Build Coastguard Worker 16*795d594fSAndroid Build Coastguard WorkerIn typical operation, you provide DexFuzz with a set of DEX files that are the "seeds" 17*795d594fSAndroid Build Coastguard Workerfor mutation - e.g. some tests taken from the ART test suite - and point it at an 18*795d594fSAndroid Build Coastguard WorkerADB-connected Android device, and it will fuzz these seed files, and execute the 19*795d594fSAndroid Build Coastguard Workerresulting new tests on the Android device. 20*795d594fSAndroid Build Coastguard Worker 21*795d594fSAndroid Build Coastguard WorkerHow to run DexFuzz 22*795d594fSAndroid Build Coastguard Worker================== 23*795d594fSAndroid Build Coastguard Worker 24*795d594fSAndroid Build Coastguard WorkerDexFuzz can run its test programs on either an ADB-connected device, or a host-build of 25*795d594fSAndroid Build Coastguard WorkerART locally. 26*795d594fSAndroid Build Coastguard Worker 27*795d594fSAndroid Build Coastguard WorkerExecution on an ADB-connected device 28*795d594fSAndroid Build Coastguard Worker------------------------------------ 29*795d594fSAndroid Build Coastguard Worker 30*795d594fSAndroid Build Coastguard Worker1. Build dexfuzz with mmma tools/dexfuzz from within art/. 31*795d594fSAndroid Build Coastguard Worker2. Make sure you have an Android device connected via ADB, that is capable of 32*795d594fSAndroid Build Coastguard Worker having DEX files pushed to it and executed with the dalvikvm command. 33*795d594fSAndroid Build Coastguard Worker3. Make sure you're in the Android build environment! 34*795d594fSAndroid Build Coastguard Worker (That is, . build/envsetup.sh && lunch) 35*795d594fSAndroid Build Coastguard Worker4. Create a new directory, and place some DEX files in here. These are the seed files 36*795d594fSAndroid Build Coastguard Worker that are mutated to form new tests. 37*795d594fSAndroid Build Coastguard Worker5. Create a directory on your device that mutated test files can be pushed to and 38*795d594fSAndroid Build Coastguard Worker executed in, using dalvikvm. For example, /data/art-test/ 39*795d594fSAndroid Build Coastguard Worker6. If you currently have multiple devices connected via ADB, find out the name of 40*795d594fSAndroid Build Coastguard Worker your device using "adb devices -l". 41*795d594fSAndroid Build Coastguard Worker7. Run this command: 42*795d594fSAndroid Build Coastguard Worker 43*795d594fSAndroid Build Coastguard Workerdexfuzz --inputs=<seeds dir> --execute --repeat=<attempts> \ 44*795d594fSAndroid Build Coastguard Worker --dump-output <combination of ISA(s) and and backend(s)> 45*795d594fSAndroid Build Coastguard Worker 46*795d594fSAndroid Build Coastguard WorkerYou MUST specify one of the following ISAs: 47*795d594fSAndroid Build Coastguard Worker --arm 48*795d594fSAndroid Build Coastguard Worker --arm64 49*795d594fSAndroid Build Coastguard Worker --x86 50*795d594fSAndroid Build Coastguard Worker --x86_64 51*795d594fSAndroid Build Coastguard Worker 52*795d594fSAndroid Build Coastguard WorkerAnd also at least two of the following backends: 53*795d594fSAndroid Build Coastguard Worker --interpreter 54*795d594fSAndroid Build Coastguard Worker --optimizing 55*795d594fSAndroid Build Coastguard Worker 56*795d594fSAndroid Build Coastguard WorkerNote that if you wanted to test both ARM and ARM64 on an ARM64 device, you can use 57*795d594fSAndroid Build Coastguard Worker--allarm. Also in this case only one backend is needed, if i.e., you wanted to test 58*795d594fSAndroid Build Coastguard WorkerARM Optimizing Backend vs. ARM64 Optimizing Backend. 59*795d594fSAndroid Build Coastguard Worker 60*795d594fSAndroid Build Coastguard WorkerSome legal examples: 61*795d594fSAndroid Build Coastguard Worker --arm --optimizing --interpreter 62*795d594fSAndroid Build Coastguard Worker --x86 --optimizing --interpreter 63*795d594fSAndroid Build Coastguard Worker --allarm --optimizing 64*795d594fSAndroid Build Coastguard Worker 65*795d594fSAndroid Build Coastguard WorkerAdd in --device=<device name, e.g. device:generic> if you want to specify a device. 66*795d594fSAndroid Build Coastguard WorkerAdd in --execute-dir=<dir on device> if you want to specify an execution directory. 67*795d594fSAndroid Build Coastguard Worker (The default is /data/art-test/) 68*795d594fSAndroid Build Coastguard Worker 69*795d594fSAndroid Build Coastguard WorkerHost Execution 70*795d594fSAndroid Build Coastguard Worker-------------- 71*795d594fSAndroid Build Coastguard Worker 72*795d594fSAndroid Build Coastguard WorkerDexFuzz now supports execution on your host machine. 73*795d594fSAndroid Build Coastguard WorkerFollow steps 1, 3, 4, and 7 as above, but also observe the following: 74*795d594fSAndroid Build Coastguard Worker - instead of specifying an ISA, use --host 75*795d594fSAndroid Build Coastguard Worker - ANDROID_DATA must be set, pointing to a location where dex2oat will place 76*795d594fSAndroid Build Coastguard Worker OAT files after compilation. 77*795d594fSAndroid Build Coastguard Worker - Files will always be executed in the same directory where you are executing DexFuzz. 78*795d594fSAndroid Build Coastguard Worker 79*795d594fSAndroid Build Coastguard WorkerFuzzer Operation 80*795d594fSAndroid Build Coastguard Worker---------------- 81*795d594fSAndroid Build Coastguard Worker 82*795d594fSAndroid Build Coastguard WorkerAs the fuzzer works, you'll see output like: 83*795d594fSAndroid Build Coastguard Worker 84*795d594fSAndroid Build Coastguard Worker|-----------------------------------------------------------------| 85*795d594fSAndroid Build Coastguard Worker|Iterations|VerifyFail|MutateFail|Timed Out |Successful|Divergence| 86*795d594fSAndroid Build Coastguard Worker|-----------------------------------------------------------------| 87*795d594fSAndroid Build Coastguard Worker| 48 | 37 | 4 | 0 | 6 | 1 | 88*795d594fSAndroid Build Coastguard Worker 89*795d594fSAndroid Build Coastguard WorkerIterations - number of attempts we've made to mutate DEX files. 90*795d594fSAndroid Build Coastguard WorkerVerifyFail - the number of mutated files that ended up failing to verify, either 91*795d594fSAndroid Build Coastguard Worker on the host, or the target. 92*795d594fSAndroid Build Coastguard WorkerMutateFail - because mutation is a random process, and has attempt thresholds to 93*795d594fSAndroid Build Coastguard Worker avoid attempting to mutate a file indefinitely, it is possible that 94*795d594fSAndroid Build Coastguard Worker an attempt to mutate a file doesn't actually mutate it. This counts 95*795d594fSAndroid Build Coastguard Worker those occurrences. 96*795d594fSAndroid Build Coastguard WorkerTimed Out - mutated files that timed out for one or more backends. 97*795d594fSAndroid Build Coastguard Worker Current timeouts are: 98*795d594fSAndroid Build Coastguard Worker Optimizing - 5 seconds 99*795d594fSAndroid Build Coastguard Worker Interpreter - 30 seconds 100*795d594fSAndroid Build Coastguard Worker (use --short-timeouts to set all backends to 2 seconds.) 101*795d594fSAndroid Build Coastguard WorkerSuccessful - mutated files that executed and all backends agreed on the resulting 102*795d594fSAndroid Build Coastguard Worker output. NB: if all backends crashed with the same output, this would 103*795d594fSAndroid Build Coastguard Worker be considered a success - proper detection of crashes is still to come. 104*795d594fSAndroid Build Coastguard WorkerDivergence - mutated files that executed and some backend disagreed about the 105*795d594fSAndroid Build Coastguard Worker resulting output. Divergent programs are run multiple times with a 106*795d594fSAndroid Build Coastguard Worker single backend, to check if they diverge from themselves, and these are 107*795d594fSAndroid Build Coastguard Worker not included in the count. If multiple architectures are being used 108*795d594fSAndroid Build Coastguard Worker (ARM/ARM64), and the divergences align with different architectures, 109*795d594fSAndroid Build Coastguard Worker these are also not included in the count. 110*795d594fSAndroid Build Coastguard Worker 111*795d594fSAndroid Build Coastguard Worker8. Check report.log for the full report, including input file and RNG seed for each 112*795d594fSAndroid Build Coastguard Worker test program. This allows you to recreate a bad program with, e.g.: 113*795d594fSAndroid Build Coastguard Worker 114*795d594fSAndroid Build Coastguard Workerdexfuzz --input=<input file> --seed=<seed value> 115*795d594fSAndroid Build Coastguard Worker 116*795d594fSAndroid Build Coastguard WorkerCheck dexfuzz --help for the full list of options. 117*795d594fSAndroid Build Coastguard Worker 118*795d594fSAndroid Build Coastguard WorkerNOTE: DEX files with unicode strings are not fully supported yet, and DEX files with 119*795d594fSAndroid Build Coastguard WorkerJNI elements are not supported at all currently. 120*795d594fSAndroid Build Coastguard Worker 121*795d594fSAndroid Build Coastguard WorkerMutation Likelihoods 122*795d594fSAndroid Build Coastguard Worker==================== 123*795d594fSAndroid Build Coastguard Worker 124*795d594fSAndroid Build Coastguard WorkerEach bytecode mutation has a chance out of 100% of firing. Following is the listing 125*795d594fSAndroid Build Coastguard Workerof each mutation's probability. If you wish to easily adjust these values, copy 126*795d594fSAndroid Build Coastguard Workerthese values into a file called likelihoods.txt, and run dexfuzz with 127*795d594fSAndroid Build Coastguard Worker--likelihoods=likelihoods.txt. 128*795d594fSAndroid Build Coastguard Worker 129*795d594fSAndroid Build Coastguard WorkerArithOpChanger 75 130*795d594fSAndroid Build Coastguard WorkerBranchShifter 30 131*795d594fSAndroid Build Coastguard WorkerCmpBiasChanger 30 132*795d594fSAndroid Build Coastguard WorkerConstantValueChanger 70 133*795d594fSAndroid Build Coastguard WorkerConversionRepeater 50 134*795d594fSAndroid Build Coastguard WorkerFieldFlagChanger 40 135*795d594fSAndroid Build Coastguard WorkerInstructionDeleter 40 136*795d594fSAndroid Build Coastguard WorkerInstructionDuplicator 80 137*795d594fSAndroid Build Coastguard WorkerInstructionSwapper 80 138*795d594fSAndroid Build Coastguard WorkerInvokeChanger 30 139*795d594fSAndroid Build Coastguard WorkerNewArrayLengthChanger 50 140*795d594fSAndroid Build Coastguard WorkerNewInstanceChanger 10 141*795d594fSAndroid Build Coastguard WorkerNewMethodCaller 10 142*795d594fSAndroid Build Coastguard WorkerNonsenseStringPrinter 10 143*795d594fSAndroid Build Coastguard WorkerOppositeBranchChanger 40 144*795d594fSAndroid Build Coastguard WorkerPoolIndexChanger 30 145*795d594fSAndroid Build Coastguard WorkerRandomBranchChanger 30 146*795d594fSAndroid Build Coastguard WorkerRandomInstructionGenerator 30 147*795d594fSAndroid Build Coastguard WorkerRegisterClobber 10 148*795d594fSAndroid Build Coastguard WorkerSwitchBranchShifter 30 149*795d594fSAndroid Build Coastguard WorkerTryBlockShifter 40 150*795d594fSAndroid Build Coastguard WorkerValuePrinter 40 151*795d594fSAndroid Build Coastguard WorkerVRegChanger 60 152