Skip to content

Commit f4141bb

Browse files
authored
Merge pull request #650 from rlopez3d/main
Pull request for new Learning Path Memory Tagging Extension on Google pixel 8.
2 parents 83cf0f8 + e0d7570 commit f4141bb

22 files changed

+280
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Memory Tagging Extension on Google Pixel 8
3+
4+
minutes_to_complete: 10
5+
6+
who_is_this_for: This is an introductory topic for developers interested in learning how to enable Arm Memory Tagging Extension (MTE) on Google Pixel 8 smartphone and how to access a memory bug report.
7+
8+
learning_objectives:
9+
- Enable MTE on your Google Pixel 8 smartphone
10+
- Understand how MTE works and learn how to make an application crash when it encounters a memory bug
11+
- Access the memory bug report
12+
- Interpret the memory bug report
13+
14+
prerequisites:
15+
- A Google Pixel 8 smartphone
16+
- A USB cable to connect your Google Pixel 8 to your desktop machine
17+
- Android Debug Bridge (adb) installed on your device. Follow the steps in https://developer.android.com/tools/adb to install Android SDK Platform Tools. The adb tool is included in this package.
18+
19+
author_primary: Roberto Lopez Mendez
20+
21+
### Tags
22+
skilllevels: Introductory
23+
subjects: Performance and Architecture
24+
armips:
25+
- Cortex-A
26+
tools_software_languages:
27+
- Memory Bug Report
28+
operatingsystems:
29+
- Android
30+
31+
32+
### FIXED, DO NOT MODIFY
33+
# ================================================================================
34+
weight: 1 # _index.md always has weight of 1 to order correctly
35+
layout: "learningpathall" # All files under learning paths have this same wrapper
36+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
37+
---
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
next_step_guidance: >
3+
If you are interested in learning more about MTE, follow this learning path:
4+
5+
recommended_path: "/learning-paths/smartphones-and-mobile/mte/"
6+
7+
further_reading:
8+
- resource:
9+
title: MTE User Guide for Android OS
10+
link: https://developer.arm.com/documentation/108035/latest/
11+
type: documentation
12+
- resource:
13+
title: Arm Memory Tagging Extension
14+
link: https://developer.android.com/ndk/guides/arm-mte
15+
type: website
16+
- resource:
17+
title: AArch64 TAGGED ADDRESS ABI
18+
link: https://www.kernel.org/doc/Documentation/arm64/tagged-address-abi.rst
19+
type: documentation
20+
- resource:
21+
title: Enhanced Security Through MTE
22+
link: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enhanced-security-through-mte
23+
type: documentation
24+
25+
26+
# ================================================================================
27+
# FIXED, DO NOT MODIFY
28+
# ================================================================================
29+
weight: 21 # set to always be larger than the content in this path, and one more than 'review'
30+
title: "Next Steps" # Always the same
31+
layout: "learningpathall" # All files under learning paths have this same wrapper
32+
---
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
review:
3+
- questions:
4+
question: >
5+
Can MTE be enabled on my Google Pixel 8?
6+
answers:
7+
- "Yes"
8+
- "No"
9+
correct_answer: 1
10+
explanation: >
11+
MTE option is part of Developer options. Developer options need to be enabled first on your Google Pixel 8 phone to access MTE.
12+
13+
- questions:
14+
question: >
15+
Which of the statements below is false?
16+
answers:
17+
- MTE working principle is based on a Lock and Key model.
18+
- Tagging memory implements the lock.
19+
- Pointers are modified to contain the key.
20+
- At runtime the CPU checks that the pointer and the metadata tags match. If so, the application crashes in any device.
21+
correct_answer: 4
22+
explanation: >
23+
At runtime the CPU checks that the pointer and the metadata tags match, on each load and store. Android apps that incorrectly store information in the top byte of the pointer are guaranteed to break on an MTE-enabled device.
24+
25+
- questions:
26+
question: >
27+
Which of the statements below is true?
28+
answers:
29+
- The bug report is automatically generated everytime the application crashes.
30+
- You need to trigger the creation of the bug report using the Bug report option in Developer options.
31+
- The bug report is a single file you can visualize directly in our phone.
32+
correct_answer: 2
33+
explanation: >
34+
You have to tap Bug report option in Developer options to capture the bug report.
35+
36+
37+
38+
# ================================================================================
39+
# FIXED, DO NOT MODIFY
40+
# ================================================================================
41+
title: "Review" # Always the same title
42+
weight: 20 # Set to always be larger than the content in this path
43+
layout: "learningpathall" # All files under learning paths have this same wrapper
44+
---
61.7 KB
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Enabling MTE on Pixel 8
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Enabling Memory Tagging Extension on Pixel 8
10+
11+
Google Pixel 8 is the first smartphone supporting MTE out-of-the-box.
12+
To enable MTE on your Pixel 8 you first need to enable Developer options.
13+
14+
Follow the steps below to enable Developer Options on your Pixel 8:
15+
* On your device, find the Build number option in Settings -> About phone -> Build number.
16+
17+
* Tap the Build number option seven times until you see the message "You are now a developer!" This enables Developer options on your device.
18+
19+
* Return to the previous screen and tap the System option. The just enabled Developer options will be at the bottom.
20+
21+
[This is a comment that will be hidden.]: #
22+
23+
MTE is now available as part of Developer options. Tap on Developer options and next tap on Memory Tagging Extension option. You will see in your screen the picture below:
24+
25+
![alt-text-2](pictures/02_mte_option.png "MTE option")
26+
27+
28+
29+
30+
31+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Understanding MTE
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Memory Tagging Extension: working principle
10+
11+
According to Google, memory bugs are the top contributor to Android security vulnerabilities. Memory bugs are also responsible for higher lifetime costs in software development and poor user experience.
12+
Additionally, developers know finding memory bugs can be difficult.
13+
14+
The Memory Tagging Extension developed by Google and Arm is aimed at providing developers with the right tool to easily detect memory bugs, and as a result help improve robustness and security of Android apps.
15+
16+
The MTE working principle is based on a Lock and Key model. Memory locations are tagged by adding four bits of metadata to each 16 bytes of physical memory. Tagging memory implements the lock. Pointers, and therefore virtual addresses, are modified to contain the key.
17+
In order to implement the key bits without requiring larger pointers, MTE uses the Top Byte Ignore feature of the Armv8-A Architecture. This allows the top byte to store metadata. In MTE four bits of the top byte are used to provide the key.
18+
19+
At runtime the CPU checks that the pointer and the metadata tags match on each load and store. Android apps that incorrectly store information in the top byte of the pointer are guaranteed to break on an MTE-enabled device.
20+
21+
![alt-text-2](pictures/03_mte_lock_and_key_model.png "MTE Lock and Key underlying model.")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Testing MTE
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## MTE Test Application
10+
11+
`MTE_test.apk` is an application that implements the most common types of memory bugs. By pressing any buttons on this application shown below, you can execute code containing a memory bug. If MTE is enabled on your device, MTE will detect the memory violation and make the application crash. You can then retrieve a bug report. This report contains useful information to identify the cause of the crash and where it happened.
12+
13+
![alt-text-2](pictures/04_mte_test_app.png "MTE test application implementing most comon memory bugs.")
14+
15+
## Installing MTE Test Application
16+
17+
Follow the steps below to install `MTE_test.apk` on your Google Pixel 8.
18+
19+
20+
* Navigate to [this repository](https://github.com/rlopez3d/mte_test_app). Open the "apk" folder and click on "MTE_test.apk" file. Use the download icon on the right to download the apk to your desktop machine.
21+
22+
* Connect your Pixel 8 to the USB port.
23+
24+
* Open a console and change directory `cd` to where you downloaded the apk.
25+
26+
* Execute the command `adb devices`. The console should display the list of atached devices.
27+
28+
* Execute the command `adb install MTE_test.apk`. The console should display that the apk has been installed succesfully.
29+
30+
* You should see the Android icon of the app with the name `MTE_test` on your phone.
31+
32+
33+
34+
35+
36+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Creating the Bug Report
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Capturing the Bug Report
10+
A bug report contains device logs, stack traces, and other diagnostic information to help you find and fix bugs in your application. If MTE is enabled on the device, the bug report will contain specific additional information about the memory bug. To capture a bug report on your Google Pixel 8, use the Bug report option available in Developer options menu, as shown below.
11+
12+
![alt-text-2](pictures/05_bug_report_option.png "Bug report option in Developer options menu.")
13+
14+
Tap Bug report option to capture the bug report. Leave the Interactive report option selected on the next screen and tap Report at the bottom.
15+
16+
![alt-text-2](pictures/06_creating_bug_report.png "Creating the bug report.")
17+
18+
At this point the bug report generation starts. You can see the progress of the bug report generation by sliding down the notification panel as shown below. By tapping on the drop-down icon on the right you can set a name for the bug report, and add a useful comment that will help you identify it later.
19+
20+
![alt-text-2](pictures/07_bug_report_is_being_generated.png "Bug report is being generated.")
21+
22+
Once the bug report generation has completed, you can share it by tapping on the notification.
23+
24+
![alt-text-2](pictures/08_bug_report_captured.png "Bug report is captured.")
25+
26+
The bug report is a big text file containing useful information about the cause of the crash and where it happened. The phone screen is not best suited for viewing this file. It is better to do it in your desktop machine on a big screen. You can send the report using any of the available options on your phone.
27+
28+
![alt-text-2](pictures/09_sharing_bug_report.png "Sharing the bug report.")
29+
30+
31+
YOUR CONTENT GOES HERE
32+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: The Bug Report
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Bug Report Content
10+
The bug report is a zip file. Once you have it on your desktop machine, you need to decompress it to access the content. After unzipping the file, you will see the folder structure below and the bug report txt file. Husky is the code name for Gooogle Pixel 8 Pro and it is used when generating the name of the bug report file.
11+
12+
![alt-text-2](pictures/10_unzipped_bug_report.png "Unzipped bug report file.")
13+
14+
More detailed information is written to a tombstone file located in `FS/data/tombstones` folder as shown below:
15+
16+
![alt-text-2](pictures/11_tombstone_filepath_in_bug_report.png "Tombstone file in bug report.")
17+
18+
## Interpreting the Bug Report
19+
20+
The bug report contains diagnostic output for system services, error logs, and system message logs (logcat). The system messages include stack traces when the device throws an error. When running MTE in SYNC mode, the Android allocator records stack traces for all allocations and deallocations and uses them to produce the bug report.
21+
22+
When a tag mismatch is encountered, the processor aborts execution immediately and terminates the process with SIGSEGV, using code SEGV_MTESERR, logging full information about the memory access and the faulting address. In addition, the crash report shows the process ID, the thread ID, and the cause of the crash.
23+
24+
![alt-text-2](pictures/12_header_of_tombstone_file.png "Header of tombstone file.")
25+
26+
The line comencing with "signal 11 (SIGSEGV)" shows that an abort signal was received, with code SEGV_MTESERR, caused by an access to memory address `0x0b000073c323d595`.
27+
28+
More detailed information is written to the tombstone file. It contains detailed data about the crashed process, including the following:
29+
* Stack traces for all the threads in the crashed process, including the thread that caught the signal
30+
* A full memory map
31+
* A list of all open file descriptors
32+
33+
The tombstone file includes an explanation of each memory error, such as use-after-free, or buffer overflow, and the stack traces of the relevant memory events. These reports provide more contextual information and make bugs easier to trace and fix.
34+
35+
![alt-text-2](pictures/13_tombstone_cause_of_memory_bug.png "Tombstone - cause of memory bug and output from the unwinder.")
36+
37+
For more information about how to interpret bug reports, refer to the following Android documentation resources:
38+
* [MTE User Guide for Android OS](https://developer.arm.com/documentation/108035/latest/)
39+
* [Android OS Documentation: Diagnosing Native Crashes](https://source.android.com/docs/core/tests/debug/native-crash)
40+
* [Android OS Documentation: Debugging Native Android Platform Code](https://source.android.com/docs/core/tests/debug)
41+
42+
43+
44+
45+
46+
YOUR CONTENT GOES HERE
47+
68.8 KB
Loading

0 commit comments

Comments
 (0)