diff options
-rw-r--r-- | build/art.go | 11 | ||||
-rw-r--r-- | runtime/Android.bp | 1 | ||||
-rw-r--r-- | runtime/dex_file_tracking_registrar.cc | 52 | ||||
-rw-r--r-- | runtime/dex_file_tracking_registrar.h | 32 | ||||
-rw-r--r-- | runtime/oat_file_manager.cc | 11 | ||||
-rw-r--r-- | tools/add_package_property.sh | 29 | ||||
-rw-r--r-- | tools/asan.sh | 21 |
7 files changed, 157 insertions, 0 deletions
diff --git a/build/art.go b/build/art.go index b33b565899..9de2b05793 100644 --- a/build/art.go +++ b/build/art.go @@ -170,12 +170,23 @@ func globalDefaults(ctx android.LoadHookContext) { } Cflags []string Asflags []string + Sanitize struct { + Recover []string + } } p := &props{} p.Cflags, p.Asflags = globalFlags(ctx) p.Target.Android.Cflags = deviceFlags(ctx) p.Target.Host.Cflags = hostFlags(ctx) + + if envTrue(ctx, "ART_DEX_FILE_ACCESS_TRACKING") { + p.Cflags = append(p.Cflags, "-DART_DEX_FILE_ACCESS_TRACKING") + p.Sanitize.Recover = []string { + "address", + } + } + ctx.AppendProperties(p) } diff --git a/runtime/Android.bp b/runtime/Android.bp index 7f27e33e6a..c5508e32d4 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -54,6 +54,7 @@ cc_defaults { "compiler_filter.cc", "debugger.cc", "dex_file.cc", + "dex_file_tracking_registrar.cc", "dex_file_annotations.cc", "dex_file_verifier.cc", "dex_instruction.cc", diff --git a/runtime/dex_file_tracking_registrar.cc b/runtime/dex_file_tracking_registrar.cc new file mode 100644 index 0000000000..cfbca3d00f --- /dev/null +++ b/runtime/dex_file_tracking_registrar.cc @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2017 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. + */ + +#include "dex_file_tracking_registrar.h" + +// For dex tracking through poisoning. Note: Requires forcing sanitization. This is the reason for +// the ifdefs and early include. +#ifdef ART_DEX_FILE_ACCESS_TRACKING +#ifndef ART_ENABLE_ADDRESS_SANITIZER +#define ART_ENABLE_ADDRESS_SANITIZER +#endif +#endif +#include "base/memory_tool.h" + +#include "base/logging.h" + +namespace art { +namespace dex { +namespace tracking { + +// If true, poison dex files to track accesses. +static constexpr bool kDexFileAccessTracking = +#ifdef ART_DEX_FILE_ACCESS_TRACKING + true; +#else + false; +#endif + +void RegisterDexFile(const DexFile* const dex_file) { + if (kDexFileAccessTracking && dex_file != nullptr) { + LOG(ERROR) << dex_file->GetLocation() + " @ " << std::hex + << reinterpret_cast<uintptr_t>(dex_file->Begin()); + MEMORY_TOOL_MAKE_NOACCESS(dex_file->Begin(), dex_file->Size()); + } +} + +} // namespace tracking +} // namespace dex +} // namespace art diff --git a/runtime/dex_file_tracking_registrar.h b/runtime/dex_file_tracking_registrar.h new file mode 100644 index 0000000000..7d5d78d6df --- /dev/null +++ b/runtime/dex_file_tracking_registrar.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 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. + */ + +#ifndef ART_RUNTIME_DEX_FILE_TRACKING_REGISTRAR_H_ +#define ART_RUNTIME_DEX_FILE_TRACKING_REGISTRAR_H_ + +#include "dex_file.h" + +namespace art { +namespace dex { +namespace tracking { + +void RegisterDexFile(const DexFile* const dex_file); + +} // namespace tracking +} // namespace dex +} // namespace art + +#endif // ART_RUNTIME_DEX_FILE_TRACKING_REGISTRAR_H_ diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index 6fb4e5eecb..630945a829 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -29,6 +29,7 @@ #include "base/systrace.h" #include "class_linker.h" #include "dex_file-inl.h" +#include "dex_file_tracking_registrar.h" #include "gc/scoped_gc_critical_section.h" #include "gc/space/image_space.h" #include "handle_scope-inl.h" @@ -737,6 +738,11 @@ std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat( // Successfully added image space to heap, release the map so that it does not get // freed. image_space.release(); + + // Register for tracking. + for (const auto& dex_file : dex_files) { + dex::tracking::RegisterDexFile(dex_file.get()); + } } else { LOG(INFO) << "Failed to add image file " << temp_error_msg; dex_files.clear(); @@ -756,6 +762,11 @@ std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat( if (!added_image_space) { DCHECK(dex_files.empty()); dex_files = oat_file_assistant.LoadDexFiles(*source_oat_file, dex_location); + + // Register for tracking. + for (const auto& dex_file : dex_files) { + dex::tracking::RegisterDexFile(dex_file.get()); + } } if (dex_files.empty()) { error_msgs->push_back("Failed to open dex files from " + source_oat_file->GetLocation()); diff --git a/tools/add_package_property.sh b/tools/add_package_property.sh new file mode 100644 index 0000000000..e9294a9ed2 --- /dev/null +++ b/tools/add_package_property.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Copyright (C) 2017 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. +# +# Sets the property of an Android package + +if [ "$#" -ne 2 ] ; then + echo "USAGE: sh add_package_property.sh [PACKAGE_NAME] [PROPERTY_SCRIPT_PATH]" + exit 1 +fi +PACKAGE_NAME=$1 +PROPERTY_SCRIPT_PATH=$2 +PROPERTY_SCRIPT_NAME=`basename $PROPERTY_SCRIPT_PATH` +adb push $PROPERTY_SCRIPT_PATH /data/data/$PACKAGE_NAME/ +adb shell chmod o+x /data/data/$PACKAGE_NAME/$PROPERTY_SCRIPT_NAME +adb shell restorecon /data/data/$PACKAGE_NAME/$PROPERTY_SCRIPT_NAME +adb shell setprop wrap.$PACKAGE_NAME /data/data/$PACKAGE_NAME/$PROPERTY_SCRIPT_NAME diff --git a/tools/asan.sh b/tools/asan.sh new file mode 100644 index 0000000000..b74954510f --- /dev/null +++ b/tools/asan.sh @@ -0,0 +1,21 @@ +#!/system/bin/sh +# +# Copyright (C) 2017 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. +# +# NOTE: This script is used by add_package_property.sh and not meant to be executed directly +# +# This script contains the property and the options required to log poisoned +# memory accesses (found in logcat) +ASAN_OPTIONS=halt_on_error=0:verbosity=0:print_legend=0:print_full_thread_history=0:print_stats=0:print_summary=0:suppress_equal_pcs=0:fast_unwind_on_fatal=1 asanwrapper $@ |