diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index 35c632c039..0e84f51647 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -155,6 +155,17 @@ ifeq ($(filter memtag_heap, $(my_sanitize)),) endif endif +# Enable HWASan in included paths. +ifeq ($(filter hwaddress, $(my_sanitize)),) + combined_include_paths := $(HWASAN_INCLUDE_PATHS) \ + $(PRODUCT_HWASAN_INCLUDE_PATHS) + + ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_include_paths)),\ + $(filter $(dir)%,$(LOCAL_PATH)))),) + my_sanitize := hwaddress $(my_sanitize) + endif +endif + # If CFI is disabled globally, remove it from my_sanitize. ifeq ($(strip $(ENABLE_CFI)),false) my_sanitize := $(filter-out cfi,$(my_sanitize)) diff --git a/core/product.mk b/core/product.mk index 32eeca66b0..e90e27b003 100644 --- a/core/product.mk +++ b/core/product.mk @@ -244,6 +244,9 @@ _product_list_vars += PRODUCT_CFI_INCLUDE_PATHS # Whether any paths are excluded from sanitization when SANITIZE_TARGET=cfi _product_list_vars += PRODUCT_CFI_EXCLUDE_PATHS +# Whether any paths should have HWASan enabled for components +_product_list_vars += PRODUCT_HWASAN_INCLUDE_PATHS + # Whether the Scudo hardened allocator is disabled platform-wide _product_single_value_vars += PRODUCT_DISABLE_SCUDO diff --git a/core/soong_config.mk b/core/soong_config.mk index a52ebd9b25..b3e2303134 100644 --- a/core/soong_config.mk +++ b/core/soong_config.mk @@ -120,6 +120,7 @@ $(call add_json_bool, EnableCFI, $(call invert_bool,$(fi $(call add_json_list, CFIExcludePaths, $(CFI_EXCLUDE_PATHS) $(PRODUCT_CFI_EXCLUDE_PATHS)) $(call add_json_list, CFIIncludePaths, $(CFI_INCLUDE_PATHS) $(PRODUCT_CFI_INCLUDE_PATHS)) $(call add_json_list, IntegerOverflowExcludePaths, $(INTEGER_OVERFLOW_EXCLUDE_PATHS) $(PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS)) +$(call add_json_list, HWASanIncludePaths, $(HWASAN_INCLUDE_PATHS) $(PRODUCT_HWASAN_INCLUDE_PATHS)) $(call add_json_list, MemtagHeapExcludePaths, $(MEMTAG_HEAP_EXCLUDE_PATHS) $(PRODUCT_MEMTAG_HEAP_EXCLUDE_PATHS)) $(call add_json_list, MemtagHeapAsyncIncludePaths, $(MEMTAG_HEAP_ASYNC_INCLUDE_PATHS) $(PRODUCT_MEMTAG_HEAP_ASYNC_INCLUDE_PATHS))