Added write only sanitizer for ASAN and HWASAN

Bug: 162024969
Test: Successfully builds targets for both host and device

"writeonly" flag in SANITIZE_(HOST|TARGET) enables it with "address"
and "hwaddress"

Change-Id: Ia89d43230deef15a67dee09ed015fea14f0717ff
This commit is contained in:
Jasraj Bedi
2020-07-23 22:58:17 +00:00
parent afdd267ff7
commit bb4511df94

View File

@@ -158,6 +158,9 @@ type SanitizeProperties struct {
Scudo *bool `android:"arch_variant"`
Scs *bool `android:"arch_variant"`
// A modifier for ASAN and HWASAN for write only instrumentation
Writeonly *bool `android:"arch_variant"`
// Sanitizers to run in the diagnostic mode (as opposed to the release mode).
// Replaces abort() on error with a human-readable error message.
// Address and Thread sanitizers always run in diagnostic mode.
@@ -279,6 +282,15 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
s.Hwaddress = boolPtr(true)
}
if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil {
// Hwaddress and Address are set before, so we can check them here
// If they aren't explicitly set in the blueprint/SANITIZE_(HOST|TARGET), they would be nil instead of false
if s.Address == nil && s.Hwaddress == nil {
ctx.ModuleErrorf("writeonly modifier cannot be used without 'address' or 'hwaddress'")
}
s.Writeonly = boolPtr(true)
}
if len(globalSanitizers) > 0 {
ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0])
}
@@ -456,6 +468,10 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
flags.Local.CFlags = append(flags.Local.CFlags, asanCflags...)
flags.Local.LdFlags = append(flags.Local.LdFlags, asanLdflags...)
if Bool(sanitize.Properties.Sanitize.Writeonly) {
flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-asan-instrument-reads=0")
}
if ctx.Host() {
// -nodefaultlibs (provided with libc++) prevents the driver from linking
// libraries needed with -fsanitize=address. http://b/18650275 (WAI)
@@ -475,6 +491,9 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
if Bool(sanitize.Properties.Sanitize.Hwaddress) {
flags.Local.CFlags = append(flags.Local.CFlags, hwasanCflags...)
if Bool(sanitize.Properties.Sanitize.Writeonly) {
flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-hwasan-instrument-reads=0")
}
}
if Bool(sanitize.Properties.Sanitize.Fuzzer) {