Repository: google/sanitizers Branch: master Commit: 8ecbf396c41d Files: 62 Total size: 865.9 KB Directory structure: gitextract_rrhftrlt/ ├── .github/ │ └── ISSUE_TEMPLATE/ │ └── bug_report.md ├── LICENSE.TXT ├── README.md ├── android/ │ └── app/ │ ├── README.md │ ├── prebuilt-apks/ │ │ ├── app-gwp_asan-release.apk │ │ ├── app-hwasan-release.apk │ │ ├── app-memtag_async-release.apk │ │ ├── app-memtag_sync-release.apk │ │ └── app-none-release.apk │ └── src/ │ ├── .gitignore │ ├── app/ │ │ ├── build.gradle │ │ └── src/ │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── cpp/ │ │ │ ├── CMakeLists.txt │ │ │ └── native-lib.cpp │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── sanitizertest/ │ │ │ └── MainActivity.kt │ │ └── res/ │ │ ├── drawable/ │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build-and-sign.sh │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── buildbot/ │ ├── install_deps.sh │ └── start_script.sh ├── gwp-asan/ │ └── icse2024/ │ └── paper/ │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── acmart.cls │ ├── acmnumeric.bbx │ ├── acmnumeric.cbx │ ├── gwpasan.tex │ ├── ref.bib │ └── tex/ │ ├── abstract.tex │ ├── background.tex │ ├── conclusion.tex │ ├── eval.tex │ ├── future.tex │ ├── gwpasan.tex │ ├── intro.tex │ └── related.tex ├── hwaddress-sanitizer/ │ ├── MarkUs-GC.md │ ├── check_registers/ │ │ ├── README.md │ │ └── check_registers.cc │ ├── create_qemu_image.sh │ ├── dumptags.cc │ ├── kernel-untag.patch │ ├── outlined_calling_convention.h │ ├── prove_hwasanwrap.smt2 │ ├── run_in_qemu_with_lam.sh │ ├── scan.cc │ └── sort_masks.py └── mte-dynamic-carveout/ ├── README.md └── spec.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Create a report to help us improve title: '' labels: '' assignees: '' --- This project has been archived and is no longer actively maintained. The Sanitizers project, which includes AddressSanitizer, MemorySanitizer, ThreadSanitizer, LeakSanitizer, and more, is now archived. The core code for these sanitizers resides within the LLVM repository. This repository will be retained for archival purposes, providing access to historical documentation, bugfixes, and helper code. Important: Please do not file new bug reports in this repository. Refer to https://github.com/google/sanitizers/blob/master/README.md for information on where to file your bugs. ================================================ FILE: LICENSE.TXT ================================================ ============================================================================== The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: ============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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. ---- LLVM Exceptions to the Apache 2.0 License ---- As an exception, if, as a result of your compiling your source code, portions of this Software are embedded into an Object form of such source code, you may redistribute such embedded portions in such Object form without complying with the conditions of Sections 4(a), 4(b) and 4(d) of the License. In addition, if you combine or link compiled forms of this Software with software that is licensed under the GPLv2 ("Combined Software") and if a court of competent jurisdiction determines that the patent provision (Section 3), the indemnity provision (Section 9) or other Section of the License conflicts with the conditions of the GPLv2, you may retroactively and prospectively choose to deem waived or otherwise exclude such Section(s) of the License, but only in their entirety and only with respect to the Combined Software. ============================================================================== Software from third parties included in the LLVM Project: ============================================================================== The LLVM Project contains third party software which is under different license terms. All such code will be identified clearly using at least one of two mechanisms: 1) It will be in a separate directory tree with its own `LICENSE.txt` or `LICENSE` file at the top containing the specific license and restrictions which apply to that software, or 2) It will contain specific license and restriction terms at the top of every file. ============================================================================== Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): ============================================================================== The compiler_rt library is dual licensed under both the University of Illinois "BSD-Like" license and the MIT license. As a user of this code you may choose to use it under either license. As a contributor, you agree to allow your code to be used under both. Full text of the relevant licenses is included below. ============================================================================== University of Illinois/NCSA Open Source License Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT All rights reserved. Developed by: LLVM Team University of Illinois at Urbana-Champaign http://llvm.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. * Neither the names of the LLVM Team, University of Illinois at Urbana-Champaign, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. ============================================================================== Copyright (c) 2009-2015 by the contributors listed in CREDITS.TXT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # sanitizers (Archived) **This _repository_ has been archived and is no longer actively maintained.** The Sanitizers _repository_, which includes AddressSanitizer, MemorySanitizer, ThreadSanitizer, LeakSanitizer, and more, is now archived. The core code for these sanitizers resides within the [LLVM](http://llvm.org) repository. This repository will be retained for archival purposes, providing access to historical documentation, bugfixes, and helper code. **Important:** Please do not file new bug reports in this repository. **Where to Report Bugs:** * **LLVM:** For bugs related to the sanitizer runtimes and instrumentation, please report them to the [LLVM Bug Tracker](https://github.com/llvm/llvm-project/issues/). * **GCC:** For bugs related to the GCC port of the sanitizers, please report them to the [GCC Bugzilla](https://gcc.gnu.org/bugzilla/). * **Linux Kernel:** For bugs related to Kernel AddressSanitizer (KASAN), Kernel MemorySanitizer (KMSAN), or Kernel ConcurrencySanitizer (KCSAN), please report them through the appropriate Linux kernel bug reporting channels, such as the [Linux kernel mailing list](https://vger.kernel.org/vger-lists.html#linux-kernel). * **Linux Distributions:** For bugs related to compiler issues in specific Linux distributions that are not reproducible in trunk compilers, please report them to the respective distribution's bug tracker (e.g., Debian Bug Tracking System, Red Hat Bugzilla). * **Apple and Microsoft:** For bugs related to the compilers provided by Apple (Xcode) or Microsoft (Visual Studio), please report them through the respective vendor's bug reporting channels. * **Android NDK:** For bugs related to Android, please report them to the [NDK issue tracker](https://github.com/android/ndk). **Documentation (Archived):** * [AddressSanitizer](../../wiki/AddressSanitizer) (detects addressability issues) and [LeakSanitizer](../../wiki/AddressSanitizerLeakSanitizer) (detects memory leaks) * ThreadSanitizer (detects data races and deadlocks) for [C++](../../wiki/ThreadSanitizerCppManual) and [Go](../../wiki/ThreadSanitizerGoManual) * [MemorySanitizer](../../wiki/MemorySanitizer) (detects use of uninitialized memory) * [HWASAN](https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html), or Hardware-assisted AddressSanitizer, a newer variant of AddressSanitizer that consumes much less memory * [UBSan](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html), or UndefinedBehaviorSanitizer **Kernel Sanitizers (Archived Documentation):** * [KASAN](https://www.kernel.org/doc/html/v4.12/dev-tools/kasan.html) * [KMSAN](https://github.com/google/kmsan) * [KCSAN](https://github.com/google/kernel-sanitizers/blob/master/KCSAN.md) Thank you for your understanding. ================================================ FILE: android/app/README.md ================================================ # Sanitizer Example Android Apps This repository contains an example Android app that is built with the following memory safety tools: 1. [HWASan](https://developer.android.com/ndk/guides/hwasan), 2. [GWP-ASan](https://developer.android.com/ndk/guides/gwp-asan), 3. [MTE](https://security.googleblog.com/2019/08/adopting-arm-memory-tagging-extension.html) (in both SYNChronous and ASYNChronous modes), or 4. None of the above. Installing the Prebuilt Apps --- Prebuilt apps can be found in the `prebuilt-apks` folder. They can be installed onto your device by `adb install prebuilt-apks/app--release.apk`. Note: If you see errors along the lines of: `Failure [INSTALL_FAILED_VERIFICATION_FAILURE: Package Verification Result]`, you may need to `adb unroot` first. Once installed, the app will be visible in your app drawer under the name "Sanitizer Test App". Uninstalling the App --- You can remove the app on-device by long pressing the app in the app drawer, and dragging it to the top right of the screen, into the "Uninstall" bin. Building the App Yourself --- To build the app yourself, simply `cd src && ./gradlew build`. For each sanitizer, this will build a debug version of the app and place it under `app/build/outputs/apk/gwpAsan/release/app--debug-unsigned.apk`. Installation instructions are the same as the prebuilts. If your device policy doesn't allow for unsigned apps to be installed, you can either use the prebuilt apps - or use the `build-and-sign.sh` script to build and sign your own app. You will likely need to create your own signing certificate, instructions are available in the script. Once the script runs, signed APKs are available in `src/apks`. ================================================ FILE: android/app/src/.gitignore ================================================ .gradle build app/.cxx app/build apks my-release-key.jks ================================================ FILE: android/app/src/app/build.gradle ================================================ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 31 buildToolsVersion "31.0.0" defaultConfig { applicationId "com.example.sanitizertest" minSdkVersion 27 targetSdkVersion 31 versionCode 1 versionName "1.2" manifestPlaceholders = [ gwpAsanMode: 'default', memtagMode: 'default' ] } buildTypes { release { minifyEnabled true debuggable true // Still allow compat features to be flipped. } debug { applicationIdSuffix ".debug" debuggable true } } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" } } flavorDimensions "sanitize" productFlavors { none { applicationIdSuffix ".none" } gwp_asan { applicationIdSuffix ".gwp_asan" manifestPlaceholders = [ gwpAsanMode: 'always' ] } hwasan { applicationIdSuffix ".hwasan" externalNativeBuild { cmake { arguments "-DHWASAN=1" } } } memtag_async { applicationIdSuffix = ".memtag.async" manifestPlaceholders = [ memtagMode: 'async' ] } memtag_sync { applicationIdSuffix = ".memtag.sync" manifestPlaceholders = [ memtagMode: 'sync' ] } } } dependencies { implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.0' } ================================================ FILE: android/app/src/app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: android/app/src/app/src/main/cpp/CMakeLists.txt ================================================ # For more information about using CMake with Android Studio, read the # documentation: https://d.android.com/studio/projects/add-native-code.html # Sets the minimum version of CMake required to build the native library. cmake_minimum_required(VERSION 3.4.1) # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). native-lib.cpp) # Searches for a specified prebuilt library and stores the path as a # variable. Because CMake includes system libraries in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build. find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log) # Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in this # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. native-lib # Links the target library to the log library # included in the NDK. ${log-lib}) if(ANDROID_ABI STREQUAL "arm64-v8a" AND HWASAN) target_compile_options(native-lib PUBLIC -fsanitize=hwaddress -fno-omit-frame-pointer) set_target_properties(native-lib PROPERTIES LINK_FLAGS -fsanitize=hwaddress) endif() ================================================ FILE: android/app/src/app/src/main/cpp/native-lib.cpp ================================================ #include #include #include #include extern "C" JNIEXPORT void JNICALL Java_com_example_sanitizertest_MainActivity_doUseAfterFree( JNIEnv *env, jobject /* this */) { char * volatile p = new char[10]; delete[] p; p[5] = 42; } extern "C" JNIEXPORT void JNICALL Java_com_example_sanitizertest_MainActivity_doHeapBufferOverflow( JNIEnv *env, jobject /* this */) { char * volatile p = new char[16]; p[16] = 42; delete[] p; } extern "C" JNIEXPORT void JNICALL Java_com_example_sanitizertest_MainActivity_doHeapBufferOverflowReadLoop( JNIEnv *env, jobject /* this */) { for (int i = 0; i < 0x10000; ++i) { char * volatile p = new char[16]; volatile char x = p[32]; x++; delete[] p; } } extern "C" JNIEXPORT void JNICALL Java_com_example_sanitizertest_MainActivity_doDoubleFree( JNIEnv *env, jobject /* this */) { char * volatile p = new char[16]; delete[] p; delete[] p; } extern "C" JNIEXPORT void JNICALL Java_com_example_sanitizertest_MainActivity_doNullDeref( JNIEnv *env, jobject /* this */) { char * volatile p = (char *)nullptr; p[42] = 1; } static void RunUAFLoop() { constexpr int kLoopCount = 100; constexpr int kAllocCount = 1000; volatile char sink; char **p = new char*[kAllocCount]; for (int j = 0; j < kLoopCount; ++j) { for (int i = 0; i < kAllocCount; ++i) p[i] = new char[128]; for (int i = 0; i < kAllocCount; ++i) delete[] p[i]; for (int i = 0; i < kAllocCount; ++i) sink = p[i][42]; } delete[] p; } extern "C" JNIEXPORT void JNICALL Java_com_example_sanitizertest_MainActivity_doUseAfterFreeLoop( JNIEnv *env, jobject /* this */) { std::thread t(RunUAFLoop); t.detach(); } ================================================ FILE: android/app/src/app/src/main/java/com/example/sanitizertest/MainActivity.kt ================================================ package com.example.sanitizertest import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) button_uaf.setOnClickListener { _ -> doUseAfterFree(); } button_uaf_loop.setOnClickListener { _ -> doUseAfterFreeLoop(); } button_oob.setOnClickListener { _ -> doHeapBufferOverflow(); } button_oob_read_loop.setOnClickListener { _ -> doHeapBufferOverflowReadLoop(); } button_double_free.setOnClickListener { _ -> doDoubleFree(); } button_null_deref.setOnClickListener { _ -> doNullDeref(); } } external fun doUseAfterFree() external fun doUseAfterFreeLoop() external fun doHeapBufferOverflow() external fun doHeapBufferOverflowReadLoop() external fun doDoubleFree() external fun doNullDeref() companion object { // Used to load the 'native-lib' library on application startup. init { System.loadLibrary("native-lib") } } } ================================================ FILE: android/app/src/app/src/main/res/drawable/ic_launcher_background.xml ================================================ ================================================ FILE: android/app/src/app/src/main/res/drawable-v24/ic_launcher_foreground.xml ================================================ ================================================ FILE: android/app/src/app/src/main/res/layout/activity_main.xml ================================================