2020-02-11 14:24:25 +01:00
|
|
|
// Copyright 2020 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
2021-07-22 21:05:08 +02:00
|
|
|
"android/soong/fuzz"
|
2020-02-11 14:24:25 +01:00
|
|
|
"android/soong/rust/config"
|
2023-11-15 21:39:40 +01:00
|
|
|
"path/filepath"
|
2020-02-11 14:24:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterModuleType("rust_fuzz", RustFuzzFactory)
|
2023-07-27 16:40:52 +02:00
|
|
|
android.RegisterModuleType("rust_fuzz_host", RustFuzzHostFactory)
|
2020-02-11 14:24:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type fuzzDecorator struct {
|
|
|
|
*binaryDecorator
|
|
|
|
|
2023-02-06 19:31:02 +01:00
|
|
|
fuzzPackagedModule fuzz.FuzzPackagedModule
|
2023-04-06 00:08:46 +02:00
|
|
|
sharedLibraries android.RuleBuilderInstalls
|
2023-02-06 19:31:02 +01:00
|
|
|
installedSharedDeps []string
|
2020-02-11 14:24:25 +01:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:13:25 +01:00
|
|
|
var _ compiler = (*fuzzDecorator)(nil)
|
2020-02-11 14:24:25 +01:00
|
|
|
|
|
|
|
// rust_binary produces a binary that is runnable on a device.
|
|
|
|
func RustFuzzFactory() android.Module {
|
|
|
|
module, _ := NewRustFuzz(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2023-07-27 16:40:52 +02:00
|
|
|
func RustFuzzHostFactory() android.Module {
|
|
|
|
module, _ := NewRustFuzz(android.HostSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:24:25 +01:00
|
|
|
func NewRustFuzz(hod android.HostOrDeviceSupported) (*Module, *fuzzDecorator) {
|
|
|
|
module, binary := NewRustBinary(hod)
|
|
|
|
fuzz := &fuzzDecorator{
|
|
|
|
binaryDecorator: binary,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the defaults for the binaryDecorator's baseCompiler
|
|
|
|
fuzz.binaryDecorator.baseCompiler.dir = "fuzz"
|
|
|
|
fuzz.binaryDecorator.baseCompiler.dir64 = "fuzz"
|
|
|
|
fuzz.binaryDecorator.baseCompiler.location = InstallInData
|
|
|
|
module.sanitize.SetSanitizer(cc.Fuzzer, true)
|
2023-08-23 20:20:25 +02:00
|
|
|
|
|
|
|
// The fuzzer runtime is not present for darwin or bionic host modules, so disable rust_fuzz modules for these.
|
|
|
|
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
|
|
|
|
|
|
|
|
extraProps := struct {
|
|
|
|
Target struct {
|
|
|
|
Darwin struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
|
|
|
Linux_bionic struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}{}
|
|
|
|
extraProps.Target.Darwin.Enabled = cc.BoolPtr(false)
|
|
|
|
extraProps.Target.Linux_bionic.Enabled = cc.BoolPtr(false)
|
|
|
|
ctx.AppendProperties(&extraProps)
|
|
|
|
})
|
|
|
|
|
2020-02-11 14:24:25 +01:00
|
|
|
module.compiler = fuzz
|
|
|
|
return module, fuzz
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fuzzer *fuzzDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = fuzzer.binaryDecorator.compilerFlags(ctx, flags)
|
|
|
|
|
|
|
|
// `../lib` for installed fuzz targets (both host and device), and `./lib` for fuzz target packages.
|
|
|
|
flags.LinkFlags = append(flags.LinkFlags, `-Wl,-rpath,\$$ORIGIN/lib`)
|
|
|
|
|
2023-02-06 19:31:02 +01:00
|
|
|
if ctx.InstallInVendor() {
|
|
|
|
flags.LinkFlags = append(flags.LinkFlags, `-Wl,-rpath,\$$ORIGIN/../../lib`)
|
|
|
|
} else {
|
|
|
|
flags.LinkFlags = append(flags.LinkFlags, `-Wl,-rpath,\$$ORIGIN/../lib`)
|
|
|
|
|
|
|
|
}
|
2020-02-11 14:24:25 +01:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fuzzer *fuzzDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
2021-04-13 00:52:29 +02:00
|
|
|
if libFuzzerRuntimeLibrary := config.LibFuzzerRuntimeLibrary(ctx.toolchain()); libFuzzerRuntimeLibrary != "" {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, libFuzzerRuntimeLibrary)
|
|
|
|
}
|
2020-02-11 14:24:25 +01:00
|
|
|
deps.SharedLibs = append(deps.SharedLibs, "libc++")
|
|
|
|
deps.Rlibs = append(deps.Rlibs, "liblibfuzzer_sys")
|
|
|
|
|
|
|
|
deps = fuzzer.binaryDecorator.compilerDeps(ctx, deps)
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fuzzer *fuzzDecorator) compilerProps() []interface{} {
|
|
|
|
return append(fuzzer.binaryDecorator.compilerProps(),
|
2021-07-07 23:00:07 +02:00
|
|
|
&fuzzer.fuzzPackagedModule.FuzzProperties)
|
2020-02-11 14:24:25 +01:00
|
|
|
}
|
|
|
|
|
2022-10-05 01:35:39 +02:00
|
|
|
func (fuzzer *fuzzDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
|
|
|
|
|
2023-02-06 19:31:02 +01:00
|
|
|
out := fuzzer.binaryDecorator.compile(ctx, flags, deps)
|
2022-10-05 01:35:39 +02:00
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:24:25 +01:00
|
|
|
func (fuzzer *fuzzDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
|
|
|
return RlibLinkage
|
|
|
|
}
|
|
|
|
|
2021-01-26 15:18:53 +01:00
|
|
|
func (fuzzer *fuzzDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
|
2020-02-11 14:24:25 +01:00
|
|
|
return rlibAutoDep
|
|
|
|
}
|
2021-04-29 21:50:47 +02:00
|
|
|
|
|
|
|
func (fuzz *fuzzDecorator) install(ctx ModuleContext) {
|
2023-02-06 19:31:02 +01:00
|
|
|
fuzz.fuzzPackagedModule = cc.PackageFuzzModule(ctx, fuzz.fuzzPackagedModule, pctx)
|
|
|
|
|
|
|
|
installBase := "fuzz"
|
|
|
|
|
|
|
|
// Grab the list of required shared libraries.
|
|
|
|
fuzz.sharedLibraries, _ = cc.CollectAllSharedDependencies(ctx)
|
|
|
|
|
2023-04-06 00:08:46 +02:00
|
|
|
for _, ruleBuilderInstall := range fuzz.sharedLibraries {
|
|
|
|
install := ruleBuilderInstall.To
|
|
|
|
|
2023-02-06 19:31:02 +01:00
|
|
|
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
|
|
|
|
cc.SharedLibraryInstallLocation(
|
fuzz packaging: implement system/vendor split
This wasn't needed when fuzzers had their own
lib directories, but because the lib directories
were combined, this caused interactions because
system and vendor libraries were mixed in the
same folder, sometimes overriding each other.
Comments are left with some details about
future issues. Bug has a series of recommendations
to prevent issue again.
The main goal of this patch is to get the fuzzers
working, not fix every issue here.
Bug: 307611931
Test: run vendor fuzzer and check lsof:
android.hardwar 22719 root txt REG 254,94 4350056 3455 /data/fuzz/x86_64/android.hardware.drm-service.<name>.aidl_fuzzer/vendor/android.hardware.drm-service.<name>.aidl_fuzzer
android.hardwar 22719 root mem REG 254,94 4350056 3455 /data/fuzz/x86_64/android.hardware.drm-service.<name>.aidl_fuzzer/vendor/android.hardware.drm-service.<name>.aidl_fuzzer
android.hardwar 22719 root mem REG 254,94 1047232 3464 /data/fuzz/x86_64/lib/vendor/libbase.so
android.hardwar 22719 root mem REG 254,94 4027304 3460 /data/fuzz/x86_64/lib/vendor/libcrypto.so
android.hardwar 22719 root mem REG 254,94 4021632 3467 /data/fuzz/x86_64/lib/vendor/libbinder.so
android.hardwar 22719 root mem REG 254,94 329408 3466 /data/fuzz/x86_64/lib/vendor/libcutils.so
android.hardwar 22719 root mem REG 254,94 508968 3463 /data/fuzz/x86_64/lib/vendor/libutils.so
android.hardwar 22719 root mem REG 254,94 592944 3465 /data/fuzz/x86_64/lib/vendor/libclang_rt.ubsan_standalone-x86_64-android.so
android.hardwar 22719 root mem REG 254,94 2328616 3462 /data/fuzz/x86_64/lib/vendor/libc++.so
and run a system fuzzer
servicemanager_ 27878 root txt REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 4390560 4074 /data/fuzz/x86_64/lib/libvintf.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 11584 4086 /data/fuzz/x86_64/lib/libdl.so
and run a system fuzzer
servicemanager_ 27878 root txt REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 4390560 4074 /data/fuzz/x86_64/lib/libvintf.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 11584 4086 /data/fuzz/x86_64/lib/libdl.so
Change-Id: I91a51d2f1cb537cfaae8379998078188f2b10a98
2023-12-28 02:09:40 +01:00
|
|
|
install, ctx.Host(), ctx.InstallInVendor(), installBase, ctx.Arch().ArchType.String()))
|
2023-02-06 19:31:02 +01:00
|
|
|
|
|
|
|
// Also add the dependency on the shared library symbols dir.
|
|
|
|
if !ctx.Host() {
|
|
|
|
fuzz.installedSharedDeps = append(fuzz.installedSharedDeps,
|
fuzz packaging: implement system/vendor split
This wasn't needed when fuzzers had their own
lib directories, but because the lib directories
were combined, this caused interactions because
system and vendor libraries were mixed in the
same folder, sometimes overriding each other.
Comments are left with some details about
future issues. Bug has a series of recommendations
to prevent issue again.
The main goal of this patch is to get the fuzzers
working, not fix every issue here.
Bug: 307611931
Test: run vendor fuzzer and check lsof:
android.hardwar 22719 root txt REG 254,94 4350056 3455 /data/fuzz/x86_64/android.hardware.drm-service.<name>.aidl_fuzzer/vendor/android.hardware.drm-service.<name>.aidl_fuzzer
android.hardwar 22719 root mem REG 254,94 4350056 3455 /data/fuzz/x86_64/android.hardware.drm-service.<name>.aidl_fuzzer/vendor/android.hardware.drm-service.<name>.aidl_fuzzer
android.hardwar 22719 root mem REG 254,94 1047232 3464 /data/fuzz/x86_64/lib/vendor/libbase.so
android.hardwar 22719 root mem REG 254,94 4027304 3460 /data/fuzz/x86_64/lib/vendor/libcrypto.so
android.hardwar 22719 root mem REG 254,94 4021632 3467 /data/fuzz/x86_64/lib/vendor/libbinder.so
android.hardwar 22719 root mem REG 254,94 329408 3466 /data/fuzz/x86_64/lib/vendor/libcutils.so
android.hardwar 22719 root mem REG 254,94 508968 3463 /data/fuzz/x86_64/lib/vendor/libutils.so
android.hardwar 22719 root mem REG 254,94 592944 3465 /data/fuzz/x86_64/lib/vendor/libclang_rt.ubsan_standalone-x86_64-android.so
android.hardwar 22719 root mem REG 254,94 2328616 3462 /data/fuzz/x86_64/lib/vendor/libc++.so
and run a system fuzzer
servicemanager_ 27878 root txt REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 4390560 4074 /data/fuzz/x86_64/lib/libvintf.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 11584 4086 /data/fuzz/x86_64/lib/libdl.so
and run a system fuzzer
servicemanager_ 27878 root txt REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 609736 67408 /data/fuzz/x86_64/servicemanager_fuzzer/servicemanager_fuzzer
servicemanager_ 27878 root mem REG 254,94 4390560 4074 /data/fuzz/x86_64/lib/libvintf.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 13872 4077 /data/fuzz/x86_64/lib/libvndksupport.so
servicemanager_ 27878 root mem REG 254,94 11584 4086 /data/fuzz/x86_64/lib/libdl.so
Change-Id: I91a51d2f1cb537cfaae8379998078188f2b10a98
2023-12-28 02:09:40 +01:00
|
|
|
cc.SharedLibrarySymbolsInstallLocation(install, ctx.InstallInVendor(), installBase, ctx.Arch().ArchType.String()))
|
2023-02-06 19:31:02 +01:00
|
|
|
}
|
2021-04-29 21:50:47 +02:00
|
|
|
}
|
2023-11-15 21:39:40 +01:00
|
|
|
|
|
|
|
var fuzzData []android.DataPath
|
|
|
|
for _, d := range fuzz.fuzzPackagedModule.Corpus {
|
|
|
|
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, RelativeInstallPath: "corpus", WithoutRel: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, d := range fuzz.fuzzPackagedModule.Data {
|
|
|
|
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, RelativeInstallPath: "data"})
|
|
|
|
}
|
|
|
|
|
|
|
|
if d := fuzz.fuzzPackagedModule.Dictionary; d != nil {
|
|
|
|
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, WithoutRel: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
if d := fuzz.fuzzPackagedModule.Config; d != nil {
|
|
|
|
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, WithoutRel: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
fuzz.binaryDecorator.baseCompiler.dir = filepath.Join(
|
|
|
|
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
|
|
|
|
fuzz.binaryDecorator.baseCompiler.dir64 = filepath.Join(
|
|
|
|
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
|
|
|
|
fuzz.binaryDecorator.baseCompiler.installTestData(ctx, fuzzData)
|
|
|
|
|
|
|
|
fuzz.binaryDecorator.baseCompiler.install(ctx)
|
|
|
|
|
2021-04-29 21:50:47 +02:00
|
|
|
}
|