diff options
author | 2022-08-08 14:24:16 +0000 | |
---|---|---|
committer | 2022-08-08 14:24:16 +0000 | |
commit | edadcdb17c6e3a84824f23d9b4282904280be7e7 (patch) | |
tree | e1261acd5419f5edca608c88db9f69d6ba6d1da6 /fuzz/fuzz_common.go | |
parent | 8e77db3b36991d14ee15c74191251e0c9bd97203 (diff) | |
parent | cecb7546db96e5c8fdb280b6a57fd5f7fbcf7503 (diff) |
Merge "Updated the way we build AFL++ fuzz binaries"
Diffstat (limited to 'fuzz/fuzz_common.go')
-rw-r--r-- | fuzz/fuzz_common.go | 78 |
1 files changed, 68 insertions, 10 deletions
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go index 2474cbc9e..c8cd21b7e 100644 --- a/fuzz/fuzz_common.go +++ b/fuzz/fuzz_common.go @@ -27,13 +27,21 @@ import ( "android/soong/android" ) -type FuzzType string +type Lang string const ( - Cc FuzzType = "" - Rust FuzzType = "rust" - Java FuzzType = "java" - AFL FuzzType = "AFL" + Cc Lang = "cc" + Rust Lang = "rust" + Java Lang = "java" +) + +type Framework string + +const ( + AFL Framework = "afl" + LibFuzzer Framework = "libfuzzer" + Jazzer Framework = "jazzer" + UnknownFramework Framework = "unknownframework" ) var BoolDefault = proptools.BoolDefault @@ -48,7 +56,6 @@ type FuzzPackager struct { Packages android.Paths FuzzTargets map[string]bool SharedLibInstallStrings []string - FuzzType FuzzType } type FileToZip struct { @@ -146,6 +153,12 @@ type FuzzConfig struct { IsJni *bool `json:"is_jni,omitempty"` } +type FuzzFrameworks struct { + Afl *bool + Libfuzzer *bool + Jazzer *bool +} + type FuzzProperties struct { // Optional list of seed files to be installed to the fuzz target's output // directory. @@ -155,6 +168,10 @@ type FuzzProperties struct { Data []string `android:"path"` // Optional dictionary to be installed to the fuzz target's output directory. Dictionary *string `android:"path"` + // Define the fuzzing frameworks this fuzz target can be built for. If + // empty then the fuzz target will be available to be built for all fuzz + // frameworks available + Fuzzing_frameworks *FuzzFrameworks // Config for running the target on fuzzing infrastructure. Fuzz_config *FuzzConfig } @@ -169,6 +186,49 @@ type FuzzPackagedModule struct { DataIntermediateDir android.Path } +func GetFramework(ctx android.LoadHookContext, lang Lang) Framework { + framework := ctx.Config().Getenv("FUZZ_FRAMEWORK") + + if lang == Cc { + switch strings.ToLower(framework) { + case "": + return LibFuzzer + case "libfuzzer": + return LibFuzzer + case "afl": + return AFL + } + } else if lang == Rust { + return LibFuzzer + } else if lang == Java { + return Jazzer + } + + ctx.ModuleErrorf(fmt.Sprintf("%s is not a valid fuzzing framework for %s", framework, lang)) + return UnknownFramework +} + +func IsValidFrameworkForModule(targetFramework Framework, lang Lang, moduleFrameworks *FuzzFrameworks) bool { + if targetFramework == UnknownFramework { + return false + } + + if moduleFrameworks == nil { + return true + } + + switch targetFramework { + case LibFuzzer: + return proptools.BoolDefault(moduleFrameworks.Libfuzzer, true) + case AFL: + return proptools.BoolDefault(moduleFrameworks.Afl, true) + case Jazzer: + return proptools.BoolDefault(moduleFrameworks.Jazzer, true) + default: + panic("%s is not supported as a fuzz framework") + } +} + func IsValid(fuzzModule FuzzModule) bool { // Discard ramdisk + vendor_ramdisk + recovery modules, they're duplicates of // fuzz targets we're going to package anyway. @@ -267,7 +327,7 @@ func (f *FuzzConfig) String() string { return string(b) } -func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, fuzzType FuzzType, pctx android.PackageContext) { +func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs map[ArchOs][]FileToZip, fuzzType Lang, pctx android.PackageContext) { var archOsList []ArchOs for archOs := range archDirs { archOsList = append(archOsList, archOs) @@ -286,9 +346,7 @@ func (s *FuzzPackager) CreateFuzzPackage(ctx android.SingletonContext, archDirs if fuzzType == Java { zipFileName = "fuzz-java-" + hostOrTarget + "-" + arch + ".zip" } - if fuzzType == AFL { - zipFileName = "fuzz-afl-" + hostOrTarget + "-" + arch + ".zip" - } + outputFile := android.PathForOutput(ctx, zipFileName) s.Packages = append(s.Packages, outputFile) |