summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuy Truong <duytruong@google.com>2021-10-27 22:22:13 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-10-27 22:22:13 +0000
commitced436b3eeb11c59ca12e7832c4c21bea0d237ea (patch)
treef572728ef5ab98e1cbbe53fa911888ae796b1cc4
parent2cbf082f28fb5edadc5e312fe1e0541e07a332b3 (diff)
parent4d00ea85033584c721f676abcd9e09f5d51b05aa (diff)
downloadplatform_testing-ced436b3eeb11c59ca12e7832c4c21bea0d237ea.tar.gz
CP from aosp/1853861 am: 4d00ea8503
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/16125753 Change-Id: I4272cc13647449b91bddc732014507c8d088fb5f
-rw-r--r--libraries/compatibility-common-util/src/com/android/compatibility/common/util/CrashUtils.java84
-rw-r--r--libraries/compatibility-common-util/tests/assets/logcat.txt29
-rw-r--r--libraries/compatibility-common-util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java492
3 files changed, 579 insertions, 26 deletions
diff --git a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/CrashUtils.java b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/CrashUtils.java
index 9bd1c610b..785139595 100644
--- a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/CrashUtils.java
+++ b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/CrashUtils.java
@@ -53,6 +53,9 @@ public class CrashUtils {
public static final String PID = "pid";
public static final String TID = "tid";
public static final String FAULT_ADDRESS = "faultaddress";
+ public static final String FILENAME = "filename";
+ public static final String METHOD = "method";
+ public static final String BACKTRACE = "backtrace";
// Matches the smallest blob that has the appropriate header and footer
private static final Pattern sCrashBlobPattern =
Pattern.compile("DEBUG\\s+?:( [*]{3})+?.*?DEBUG\\s+?:\\s+?backtrace:", Pattern.DOTALL);
@@ -67,6 +70,20 @@ public class CrashUtils {
// Matches the abort message line
private static Pattern sAbortMessagePattern =
Pattern.compile("(?i)Abort message: (.*)");
+ // Matches one backtrace NOTE line, exactly as tombstone_proto_to_text's print_thread_backtrace
+ private static Pattern sBacktraceNotePattern =
+ Pattern.compile("[0-9\\-\\s:.]+[A-Z] DEBUG\\s+:\\s+NOTE: .*");
+ // Matches one backtrace frame, exactly as tombstone_proto_to_text's print_backtrace
+ // Two versions, because we want to exclude the BuildID section if it exists
+ private static Pattern sBacktraceFrameWithBuildIdPattern =
+ Pattern.compile(
+ "[0-9\\-\\s:.]+[A-Z] DEBUG\\s+:\\s+#[0-9]+ pc [0-9a-fA-F]+ "
+ + "(?<filename>[^\\s]+)(\\s+\\((?<method>.*)\\))?"
+ + "\\s+\\(BuildId: .*\\)");
+ private static Pattern sBacktraceFrameWithoutBuildIdPattern =
+ Pattern.compile(
+ "[0-9\\-\\s:.]+[A-Z] DEBUG\\s+:\\s+#[0-9]+ pc [0-9a-fA-F]+ "
+ + "(?<filename>[^\\s]+)(\\s+\\((?<method>.*)\\))?");
public static final String SIGSEGV = "SIGSEGV";
public static final String SIGBUS = "SIGBUS";
@@ -185,6 +202,7 @@ public class CrashUtils {
String process = null;
String signal = null;
String abortMessage = null;
+ List<BacktraceFrameInfo> backtraceFrames = new ArrayList<BacktraceFrameInfo>();
Matcher pidtidNameMatcher = sPidtidNamePattern.matcher(crashStr);
if (pidtidNameMatcher.find()) {
@@ -214,6 +232,46 @@ public class CrashUtils {
abortMessage = abortMessageMatcher.group(1);
}
+ // Continue on after the crash block to find all the stacktrace entries.
+ // The format is from tombstone_proto_to_text.cpp's print_thread_backtrace()
+ // This will scan the logcat lines until it finds a line that does not match,
+ // or end of log.
+ int currentIndex = crashBlobFinder.end();
+ while (true) {
+ int firstEndline = input.indexOf('\n', currentIndex);
+ int secondEndline = input.indexOf('\n', firstEndline + 1);
+ currentIndex = secondEndline;
+ if (firstEndline == -1 || secondEndline == -1) break;
+
+ String nextLine = input.substring(firstEndline + 1, secondEndline);
+
+ Matcher backtraceNoteMatcher = sBacktraceNotePattern.matcher(nextLine);
+ if (backtraceNoteMatcher.matches()) {
+ continue;
+ }
+
+ Matcher backtraceFrameWithBuildIdMatcher =
+ sBacktraceFrameWithBuildIdPattern.matcher(nextLine);
+ Matcher backtraceFrameWithoutBuildIdMatcher =
+ sBacktraceFrameWithoutBuildIdPattern.matcher(nextLine);
+
+ Matcher backtraceFrameMatcher = null;
+ if (backtraceFrameWithBuildIdMatcher.matches()) {
+ backtraceFrameMatcher = backtraceFrameWithBuildIdMatcher;
+
+ } else if (backtraceFrameWithoutBuildIdMatcher.matches()) {
+ backtraceFrameMatcher = backtraceFrameWithoutBuildIdMatcher;
+
+ } else {
+ break;
+ }
+
+ backtraceFrames.add(
+ new BacktraceFrameInfo(
+ backtraceFrameMatcher.group("filename"),
+ backtraceFrameMatcher.group("method")));
+ }
+
try {
JSONObject crash = new JSONObject();
crash.put(PID, pid);
@@ -224,12 +282,38 @@ public class CrashUtils {
faultAddress == null ? null : faultAddress.toString(16));
crash.put(SIGNAL, signal);
crash.put(ABORT_MESSAGE, abortMessage);
+ JSONArray backtrace = new JSONArray();
+ for (BacktraceFrameInfo frame : backtraceFrames) {
+ backtrace.put(
+ new JSONObject()
+ .put(FILENAME, frame.getFilename())
+ .put(METHOD, frame.getMethod()));
+ }
+ crash.put(BACKTRACE, backtrace);
crashes.put(crash);
} catch (JSONException e) {}
}
return crashes;
}
+ public static class BacktraceFrameInfo {
+ private final String filename;
+ private final String method;
+
+ public BacktraceFrameInfo(String filename, String method) {
+ this.filename = filename;
+ this.method = method;
+ }
+
+ public String getFilename() {
+ return this.filename;
+ }
+
+ public String getMethod() {
+ return this.method;
+ }
+ }
+
public static class Config {
private boolean checkMinAddress;
private BigInteger minCrashAddress;
diff --git a/libraries/compatibility-common-util/tests/assets/logcat.txt b/libraries/compatibility-common-util/tests/assets/logcat.txt
index ffb28ad5c..9807a69f3 100644
--- a/libraries/compatibility-common-util/tests/assets/logcat.txt
+++ b/libraries/compatibility-common-util/tests/assets/logcat.txt
@@ -332,4 +332,33 @@
06-15 19:57:33.678 26192 26192 F DEBUG : #14 pc 00019e3d /system/lib/libc.so (__start_thread+6)
06-15 19:57:33.839 934 2991 W NativeCrashListener: Couldn't find ProcessRecord for pid 12736
06-15 19:57:33.846 934 952 I BootReceiver: Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE)
+--------- beginning of main
+10-01 10:04:58.301 8937 8937 E DEBUG : failed to read /proc/uptime: Permission denied
+--------- beginning of crash
+10-01 10:04:58.337 8937 8937 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
+10-01 10:04:58.338 8937 8937 F DEBUG : Build fingerprint: 'generic/cf_x86_64_phone/vsoc_x86_64:12/SC/eng.duytru.20210930.171415:userdebug/dev-keys'
+10-01 10:04:58.338 8937 8937 F DEBUG : Revision: '0'
+10-01 10:04:58.338 8937 8937 F DEBUG : ABI: 'x86_64'
+10-01 10:04:58.338 8937 8937 F DEBUG : Timestamp: 2021-10-01 10:04:58.301278442-0700
+10-01 10:04:58.338 8937 8937 F DEBUG : Process uptime: 0s
+10-01 10:04:58.338 8937 8937 F DEBUG : Cmdline: /data/local/tmp/CVE-2021-0684
+10-01 10:04:58.338 8937 8937 F DEBUG : pid: 8925, tid: 8925, name: CVE-2021-0684 >>> /data/local/tmp/CVE-2021-0684 <<<
+10-01 10:04:58.338 8937 8937 F DEBUG : uid: 2000
+10-01 10:04:58.338 8937 8937 F DEBUG : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7e772b8cfbe0
+10-01 10:04:58.338 8937 8937 F DEBUG : rax 0000000000000001 rbx 00007e776addf910 rcx 0000000000000010 rdx 00000000000002f0
+10-01 10:04:58.338 8937 8937 F DEBUG : r8 0000000000000010 r9 0000000000000000 r10 0000000000000001 r11 0000000000000206
+10-01 10:04:58.338 8937 8937 F DEBUG : r12 00007e772b995bd0 r13 00007e772b996000 r14 00007e772b8cfbd0 r15 00000000000004d2
+10-01 10:04:58.338 8937 8937 F DEBUG : rdi 00007e772b8cfbd0 rsi 00007e772b995bd0
+10-01 10:04:58.338 8937 8937 F DEBUG : rbp 0000000000000000 rsp 00007fff3ba711e0 rip 00007e77a1fcd285
+10-01 10:04:58.339 8937 8937 F DEBUG : backtrace:
+10-01 10:04:58.339 8937 8937 F DEBUG : NOTE: Function names and BuildId information is missing for some frames due
+10-01 10:04:58.339 8937 8937 F DEBUG : NOTE: to unreadable libraries. For unwinds of apps, only shared libraries
+10-01 10:04:58.339 8937 8937 F DEBUG : NOTE: found under the lib/ directory are readable.
+10-01 10:04:58.339 8937 8937 F DEBUG : NOTE: On this device, run setenforce 0 to make the libraries readable.
+10-01 10:04:58.339 8937 8937 F DEBUG : #00 pc 000000000007e285 /system/lib64/libinputreader.so (android::TouchInputMapper::assignPointerIds(android::TouchInputMapper::RawState const*, android::TouchInputMapper::RawState*)+37) (BuildId: b406aecf0bd895d134334367c8cf5f84)
+10-01 10:04:58.339 8937 8937 F DEBUG : #01 pc 000000000007e20d /system/lib64/libinputreader.so (android::TouchInputMapper::sync(long, long)+285) (BuildId: b406aecf0bd895d134334367c8cf5f84)
+10-01 10:04:58.339 8937 8937 F DEBUG : #02 pc 0000000000073c1e /system/lib64/libinputreader.so (android::MultiTouchInputMapper::process(android::RawEvent const*)+14) (BuildId: b406aecf0bd895d134334367c8cf5f84)
+10-01 10:04:58.339 8937 8937 F DEBUG : #03 pc 000000000000af84 /data/local/tmp/CVE-2021-0684
+10-01 10:04:58.339 8937 8937 F DEBUG : #04 pc 000000000000b256 /data/local/tmp/CVE-2021-0684
+10-01 10:04:58.339 8937 8937 F DEBUG : #05 pc 000000000004faf6 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+86) (BuildId: 284d864ffe434d73dc722b84a1d3d9ca)
diff --git a/libraries/compatibility-common-util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java b/libraries/compatibility-common-util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java
index 2d80509ca..78e78be64 100644
--- a/libraries/compatibility-common-util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java
+++ b/libraries/compatibility-common-util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java
@@ -16,6 +16,7 @@
package com.android.compatibility.common.util;
+import com.google.common.collect.ImmutableList;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -27,6 +28,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import java.util.List;
import java.util.regex.Pattern;
/** Unit tests for {@link CrashUtils}. */
@@ -53,31 +55,449 @@ public class CrashUtilsTest {
@Test
public void testGetAllCrashes() throws Exception {
JSONArray expectedResults = new JSONArray();
- expectedResults.put(createCrashJson(
- 11071, 11189, "AudioOut_D", "/system/bin/audioserver", "e9380000", "SIGSEGV", null));
- expectedResults.put(createCrashJson(
- 12736, 12761, "Binder:12736_2", "/system/bin/audioserver", "0", "SIGSEGV", null));
- expectedResults.put(createCrashJson(
- 26201, 26227, "Binder:26201_3", "/system/bin/audioserver", "0", "SIGSEGV", null));
- expectedResults.put(createCrashJson(
- 26246, 26282, "Binder:26246_5", "/system/bin/audioserver", "0", "SIGSEGV", null));
- expectedResults.put(createCrashJson(
- 245, 245, "installd", "/system/bin/installd", null, "SIGABRT",
- "'utils.cpp:67] Check failed: is_valid_package_name(package_name) == 0 '"));
- expectedResults.put(createCrashJson(
- 6371, 8072, "media.codec", "omx@1.0-service", "ed000000", "SIGSEGV", null));
- expectedResults.put(createCrashJson(
- 8373, 8414, "loo", "com.android.bluetooth", null, "SIGABRT",
- "'[FATAL:allocation_tracker.cc(143)] Check failed: map_entry != allocations.end()."));
- expectedResults.put(createCrashJson(
- 8080, 11665, "generic", "/system/bin/mediaserver", null, "SIGABRT",
- "'frameworks/av/media/libstagefright/MPEG4Extractor.cpp:6853 CHECK_EQ( (unsigned)ptr[0],1u) failed: 129 vs. 1'"));
- expectedResults.put(createCrashJson(
- 11071, 11189, "synthetic_thread", "synthetic_process_0", "e9380000", "SIGSEGV", null));
- expectedResults.put(createCrashJson(
- 12736, 12761, "synthetic_thread", "synthetic_process_1", "0", "SIGSEGV", null));
-
- Assert.assertEquals(expectedResults.toString() + "\n" + mCrashes.toString() + "\n", expectedResults.toString(), mCrashes.toString());
+ expectedResults.put(
+ createCrashJson(
+ 11071,
+ 11189,
+ "AudioOut_D",
+ "/system/bin/audioserver",
+ "e9380000",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame(
+ "/system/lib/libaudioutils.so",
+ "memcpy_to_float_from_i16+5"),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+140"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+22"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 12736,
+ 12761,
+ "Binder:12736_2",
+ "/system/bin/audioserver",
+ "0",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame("/system/lib/libc.so", "strlen+71"),
+ stackFrame("/system/lib/libc.so", "__strlen_chk+4"),
+ stackFrame(
+ "/system/lib/libutils.so", "_ZN7android7String8C2EPKc+12"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZNK7android18HwModuleCollection19getDeviceDescriptorEjPKcS2_b+458"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZN7android18AudioPolicyManager27setDeviceConnectionStateIntEj24"
+ + "audio_policy_dev_state_tPKcS3_+178"),
+ stackFrame("/system/lib/libaudiopolicyservice.so", null),
+ stackFrame(
+ "/system/lib/libmedia.so",
+ "_ZN7android20BnAudioPolicyService10onTransactEjRKNS_6ParcelEPS1_j+1256"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android7BBinder8transactEjRKNS_6ParcelEPS1_j+70"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14executeCommandEi+702"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState20getAndExecuteCommandEv+114"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14joinThreadPoolEb+46"),
+ stackFrame("/system/lib/libbinder.so", null),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+140"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+22"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 26201,
+ 26227,
+ "Binder:26201_3",
+ "/system/bin/audioserver",
+ "0",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame("/system/lib/libc.so", "strlen+71"),
+ stackFrame("/system/lib/libc.so", "__strlen_chk+4"),
+ stackFrame(
+ "/system/lib/libutils.so", "_ZN7android7String8C2EPKc+12"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZNK7android18HwModuleCollection19getDeviceDescriptorEjPKcS2_b+458"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZN7android18AudioPolicyManager27setDeviceConnectionStateIntEj24"
+ + "audio_policy_dev_state_tPKcS3_+178"),
+ stackFrame("/system/lib/libaudiopolicyservice.so", null),
+ stackFrame(
+ "/system/lib/libmedia.so",
+ "_ZN7android20BnAudioPolicyService10onTransactEjRKNS_6ParcelEPS1_j+1256"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android7BBinder8transactEjRKNS_6ParcelEPS1_j+70"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14executeCommandEi+702"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState20getAndExecuteCommandEv+114"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14joinThreadPoolEb+46"),
+ stackFrame("/system/lib/libbinder.so", null),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+140"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+22"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 26246,
+ 26282,
+ "Binder:26246_5",
+ "/system/bin/audioserver",
+ "0",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame("/system/lib/libc.so", "strlen+71"),
+ stackFrame("/system/lib/libc.so", "__strlen_chk+4"),
+ stackFrame(
+ "/system/lib/libutils.so", "_ZN7android7String8C2EPKc+12"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZNK7android18HwModuleCollection19getDeviceDescriptorEjPKcS2_b+458"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZN7android18AudioPolicyManager27setDeviceConnectionStateIntEj24"
+ + "audio_policy_dev_state_tPKcS3_+178"),
+ stackFrame("/system/lib/libaudiopolicyservice.so", null),
+ stackFrame(
+ "/system/lib/libmedia.so",
+ "_ZN7android20BnAudioPolicyService10onTransactEjRKNS_6ParcelEPS1_j+1256"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android7BBinder8transactEjRKNS_6ParcelEPS1_j+70"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14executeCommandEi+702"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState20getAndExecuteCommandEv+114"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14joinThreadPoolEb+46"),
+ stackFrame("/system/lib/libbinder.so", null),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+140"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+22"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 245,
+ 245,
+ "installd",
+ "/system/bin/installd",
+ null,
+ "SIGABRT",
+ "'utils.cpp:67] Check failed: is_valid_package_name(package_name) == 0 '",
+ ImmutableList.of(
+ stackFrame("/system/lib64/libc.so", "tgkill+8"),
+ stackFrame("/system/lib64/libc.so", "pthread_kill+64"),
+ stackFrame("/system/lib64/libc.so", "raise+24"),
+ stackFrame("/system/lib64/libc.so", "abort+52"),
+ stackFrame(
+ "/system/lib64/libbase.so",
+ "_ZN7android4base10LogMessageD1Ev+1084"),
+ stackFrame("/system/bin/installd", null),
+ stackFrame("/system/bin/installd", null),
+ stackFrame("/system/bin/installd", null),
+ stackFrame("/system/bin/installd", null),
+ stackFrame("/system/lib64/libc.so", "__libc_init+88"),
+ stackFrame("/system/bin/installd", null))));
+ expectedResults.put(
+ createCrashJson(
+ 6371,
+ 8072,
+ "media.codec",
+ "omx@1.0-service",
+ "ed000000",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame("/system/lib/libstagefright_soft_hevcdec.so", null))));
+ expectedResults.put(
+ createCrashJson(
+ 8373,
+ 8414,
+ "loo",
+ "com.android.bluetooth",
+ null,
+ "SIGABRT",
+ "'[FATAL:allocation_tracker.cc(143)] Check failed: map_entry !="
+ + " allocations.end().",
+ ImmutableList.of(
+ stackFrame("/system/lib64/libc.so", "abort+120"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "base::debug::BreakDebugger()+20"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "logging::LogMessage::~LogMessage()+1068"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "allocation_tracker_notify_free(unsigned char, void*)+720"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "osi_free(void*)+20"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "l2c_fcr_cleanup(t_l2c_ccb*)+92"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "l2cu_release_ccb(t_l2c_ccb*)+176"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "l2c_csm_execute(t_l2c_ccb*, unsigned short, void*)+1852"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "L2CA_DisconnectRsp(unsigned short)+92"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "sdp_disconnect_ind(unsigned short, bool)+52"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "l2c_csm_execute(t_l2c_ccb*, unsigned short, void*)+3600"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "l2c_rcv_acl_data(BT_HDR*)+3980"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "base::debug::TaskAnnotator::RunTask(char const*, "
+ + "base::PendingTask const&)+188"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "base::MessageLoop::RunTask(base::PendingTask const&)+444"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "base::MessageLoop::DeferOrRunPendingTask(base::PendingTask)+52"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "base::MessageLoop::DoWork()+356"),
+ stackFrame(
+ "/system/lib64/libchrome.so",
+ "base::MessagePumpDefault::Run(base::MessagePump::Delegate*)+220"),
+ stackFrame(
+ "/system/lib64/libchrome.so", "base::RunLoop::Run()+136"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "btu_message_loop_run(void*)+248"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "work_queue_read_cb(void*)+92"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "run_reactor(reactor_t*, int)+320"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "reactor_start(reactor_t*)+84"),
+ stackFrame(
+ "/system/lib64/hw/bluetooth.default.so",
+ "run_thread(void*)+184"),
+ stackFrame("/system/lib64/libc.so", "__pthread_start(void*)+36"),
+ stackFrame("/system/lib64/libc.so", "__start_thread+68"))));
+ expectedResults.put(
+ createCrashJson(
+ 8080,
+ 11665,
+ "generic",
+ "/system/bin/mediaserver",
+ null,
+ "SIGABRT",
+ "'frameworks/av/media/libstagefright/MPEG4Extractor.cpp:6853 CHECK_EQ("
+ + " (unsigned)ptr[0],1u) failed: 129 vs. 1'",
+ ImmutableList.of(
+ stackFrame("/system/lib/libc.so", "tgkill+12"),
+ stackFrame("/system/lib/libc.so", "pthread_kill+32"),
+ stackFrame("/system/lib/libc.so", "raise+10"),
+ stackFrame("/system/lib/libc.so", "__libc_android_abort+34"),
+ stackFrame("/system/lib/libc.so", "abort+4"),
+ stackFrame("/system/lib/libcutils.so", "__android_log_assert+86"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor25avcc_getCodecSpecificInfo"
+ + "ERNS_2spINS_7ABufferEEEPKcj+392"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor15checkConfigDataEjRKNS_2spINS_8MetaDataEEE+218"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor12checkSupportEjRKNS_2spINS_8MetaDataEEE+136"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+13060"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+12508"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+6174"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+6174"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+6174"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+6174"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor10parseChunkEPxi+6174"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor12readMetaDataEv+94"),
+ stackFrame(
+ "/system/lib/libstagefright.so",
+ "_ZN7android14MPEG4Extractor11getMetaDataEv+10"),
+ stackFrame(
+ "/system/lib/libmediaplayerservice.so",
+ "_ZN7android8NuPlayer13GenericSource18initFromDataSourceEv+386"),
+ stackFrame(
+ "/system/lib/libmediaplayerservice.so",
+ "_ZN7android8NuPlayer13GenericSource14onPrepareAsyncEv+238"),
+ stackFrame(
+ "/system/lib/libstagefright_foundation.so",
+ "_ZN7android8AHandler14deliverMessageERKNS_2spINS_8AMessageEEE+16"),
+ stackFrame(
+ "/system/lib/libstagefright_foundation.so",
+ "_ZN7android8AMessage7deliverEv+54"),
+ stackFrame(
+ "/system/lib/libstagefright_foundation.so",
+ "_ZN7android7ALooper4loopEv+224"),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+112"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+30"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 11071,
+ 11189,
+ "synthetic_thread",
+ "synthetic_process_0",
+ "e9380000",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame(
+ "/system/lib/libaudioutils.so",
+ "memcpy_to_float_from_i16+5"),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame("/system/lib/libaudioflinger.so", null),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+140"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+22"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 12736,
+ 12761,
+ "synthetic_thread",
+ "synthetic_process_1",
+ "0",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame("/system/lib/libc.so", "strlen+71"),
+ stackFrame("/system/lib/libc.so", "__strlen_chk+4"),
+ stackFrame(
+ "/system/lib/libutils.so", "_ZN7android7String8C2EPKc+12"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZNK7android18HwModuleCollection19getDeviceDescriptorEjPKcS2_b+458"),
+ stackFrame(
+ "/system/lib/libaudiopolicymanagerdefault.so",
+ "_ZN7android18AudioPolicyManager27setDeviceConnectionStateIntEj24"
+ + "audio_policy_dev_state_tPKcS3_+178"),
+ stackFrame("/system/lib/libaudiopolicyservice.so", null),
+ stackFrame(
+ "/system/lib/libmedia.so",
+ "_ZN7android20BnAudioPolicyService10onTransactEjRKNS_6ParcelEPS1_j+1256"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android7BBinder8transactEjRKNS_6ParcelEPS1_j+70"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14executeCommandEi+702"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState20getAndExecuteCommandEv+114"),
+ stackFrame(
+ "/system/lib/libbinder.so",
+ "_ZN7android14IPCThreadState14joinThreadPoolEb+46"),
+ stackFrame("/system/lib/libbinder.so", null),
+ stackFrame(
+ "/system/lib/libutils.so",
+ "_ZN7android6Thread11_threadLoopEPv+140"),
+ stackFrame("/system/lib/libc.so", "_ZL15__pthread_startPv+22"),
+ stackFrame("/system/lib/libc.so", "__start_thread+6"))));
+ expectedResults.put(
+ createCrashJson(
+ 8925,
+ 8925,
+ "CVE-2021-0684",
+ "/data/local/tmp/CVE-2021-0684",
+ "7e772b8cfbe0",
+ "SIGSEGV",
+ null,
+ ImmutableList.of(
+ stackFrame(
+ "/system/lib64/libinputreader.so",
+ "android::TouchInputMapper::assignPointerIds("
+ + "android::TouchInputMapper::RawState const*, "
+ + "android::TouchInputMapper::RawState*)+37"),
+ stackFrame(
+ "/system/lib64/libinputreader.so",
+ "android::TouchInputMapper::sync(long, long)+285"),
+ stackFrame(
+ "/system/lib64/libinputreader.so",
+ "android::MultiTouchInputMapper::process(android::RawEvent"
+ + " const*)+14"),
+ stackFrame("/data/local/tmp/CVE-2021-0684", null),
+ stackFrame("/data/local/tmp/CVE-2021-0684", null),
+ stackFrame(
+ "/apex/com.android.runtime/lib64/bionic/libc.so",
+ "__libc_init+86"))));
+
+ Assert.assertEquals(
+ expectedResults.toString() + "\n" + mCrashes.toString() + "\n",
+ expectedResults.toString(),
+ mCrashes.toString());
+ }
+
+ /** Helper method to shorten code for readability. */
+ private JSONObject stackFrame(String filename, String method) throws JSONException {
+ return new JSONObject().put(CrashUtils.FILENAME, filename).put(CrashUtils.METHOD, method);
}
public JSONObject createCrashJson(
@@ -88,6 +508,19 @@ public class CrashUtilsTest {
String faultaddress,
String signal,
String abortMessage) {
+ return createCrashJson(
+ pid, tid, name, process, faultaddress, signal, abortMessage, ImmutableList.of());
+ }
+
+ public JSONObject createCrashJson(
+ int pid,
+ int tid,
+ String name,
+ String process,
+ String faultaddress,
+ String signal,
+ String abortMessage,
+ List<JSONObject> stacktrace) {
JSONObject json = new JSONObject();
try {
json.put(CrashUtils.PID, pid);
@@ -97,6 +530,12 @@ public class CrashUtilsTest {
json.put(CrashUtils.FAULT_ADDRESS, faultaddress);
json.put(CrashUtils.SIGNAL, signal);
json.put(CrashUtils.ABORT_MESSAGE, abortMessage);
+
+ JSONArray stacktraceJson = new JSONArray();
+ for (JSONObject stackframe : stacktrace) {
+ stacktraceJson.put(stackframe);
+ }
+ json.put(CrashUtils.BACKTRACE, stacktraceJson);
} catch (JSONException e) {}
return json;
}
@@ -155,7 +594,8 @@ public class CrashUtilsTest {
@Test
public void testNullFaultAddress() throws Exception {
JSONArray crashes = new JSONArray();
- crashes.put(createCrashJson(8373, 8414, "loo", "com.android.bluetooth", null, "SIGSEGV", ""));
+ crashes.put(
+ createCrashJson(8373, 8414, "loo", "com.android.bluetooth", null, "SIGSEGV", ""));
Assert.assertTrue(CrashUtils.securityCrashDetected(crashes, new CrashUtils.Config()
.checkMinAddress(true)
.setProcessPatterns(Pattern.compile("com\\.android\\.bluetooth"))));