Commit graph

93 commits

Author SHA1 Message Date
Christopher Ferris
303c6bef77 Fix check for thread unwind.
If a process requires executing fallback unwinder and the thread
crashing is not the main thread, the wrong unwinder is used.
Fix this case, and add a new unit test that causes an abort in
the non main thread.

Bug: 233721755

Test: New unit test passes with fix and fails without.
Test: Ran debuggerd on swcodec process and it still dumps all threads.
Change-Id: I70fffc5d680256ce867e7a1d427593b584259160
Merged-In: I70fffc5d680256ce867e7a1d427593b584259160
(cherry picked from commit 2d5d46ca85)
2022-05-25 13:07:07 -07:00
Mitch Phillips
5411905232 Merge "[GWP-ASan] Enable debuggerd to pull more allocation metadata." 2022-04-21 18:12:43 +00:00
Florian Mayer
b4979293b3 Skip debuggerd tests that do not apply to HWASan.
Change-Id: Ieab61dc61e11c3e55f116a45c37ceb805a6212e0
2022-04-15 15:41:59 -07:00
Mitch Phillips
1e0969997a [GWP-ASan] Enable debuggerd to pull more allocation metadata.
With the addition of runtime-configurable GWP-ASan, there might be many,
many more than 1,000 allocations. Have support for them, but keep a
hopefully-won't-crash-the-device limit.

Bug: 219651032
Test: atest bionic-unit-tests

Change-Id: I7b8e2bf5ab7c723ab6c61365f0dc610e400dbbce
2022-04-14 11:30:05 -07:00
Christopher Ferris
c95047dd20 Update for accurate unreadable elf files.
The functionality moved from the Unwinder object to the MapInfo
object and means that the individual unreadable files can be
displayed now.

Included adding the unreadable elfs per thread in the protobuf.

Updated the unwinder test.

Test: All unit tests pass.
Change-Id: I7140bde16938736da005f926e10bbdb3dbc0f6f5
2022-03-15 09:50:48 -07:00
Christopher Ferris
b999b82eb7 Dump threads in tombstone fallback path.
When dumping a tombstone using the fallback path, only the main
thread was showing up. Modify the code to dump the threads using
a slightly different path for the tombstone generation code.

In addition, while looking at this code, two MTE variables were
not set in the tombstone fallback code. Added those variables
so MTE devices will work properly in this fallback path.

Modified the tombstone unit tests for seccomp to have
multiple threads and verify those threads show up in the tombstone.

Bug: 208933016

Test: Ran unit tests.
Test: Ran debuggerd <PID> on a privileged process and verified
Test: all threads dumped. Also verified that the tagged_addr_ctrl
Test: variable is present on the raven device.
Change-Id: I16eadb0cc2c37a7dbc5cac16af9b5051008b5127
2022-02-16 15:02:38 -08:00
Christopher Ferris
16a7bc2355 Fix typo.
Change use of new_ to old_ to save the old sigaction data. This hasn't
caused any issues, but it's obviously wrong.

Test: Ran unit tests on coral.
Change-Id: I96be5b0980c323c3aeafb422fbc06202577604a2
2022-01-31 13:08:54 -08:00
Elliott Hughes
d13ea523e1 debuggerd: add the PAC keys to the tombstones.
Hard to get otherwise if you're trying to debug PAC issues.

Bug: http://b/214314197
Test: treehugger
Change-Id: I2e5502809f84579bf287364e59d6e7ff67770919
2022-01-13 15:03:19 -08:00
Christopher Ferris
bdea3bb56b Remove non-protobuf path.
It is expensive to keep the non-protobuf path around and it hasn't
been used for an entire release without anyone noticing, so remove it.

Create new end-to-end unit tests that cover tests of the non-proto
code paths that are being deleted.

Bug: 197981919

Test: Unit tests pass.
Change-Id: Ia1c45572300bd63e5f196ad61e5e5386830c8ece
2021-11-19 02:07:30 +00:00
Treehugger Robot
a44f269eba Merge "Improvements to tombstone output." 2021-11-12 00:17:12 +00:00
Peter Collingbourne
773acaa18e Improvements to tombstone output.
- Use "likelihood" instead of "probability" since that has connotations
  of being less precise, and our probability ordering isn't very precise
  anyway.

- Hide the fault address with SEGV_MTEAERR because it is not available.

- Pad the fault address with leading zeroes to make it clearer which
  bits of the top byte (and any following bytes such as PAC signature
  bits) are set.

Bug: 206015287
Change-Id: I5e1e99b7f3e967c44781d8550bbd7158eb421b64
2021-11-11 15:05:47 -08:00
Peter Collingbourne
57e19ac46e Merge "Add a human readable description of the tagged_addr_ctrl value to tombstones." 2021-11-10 18:56:59 +00:00
Peter Collingbourne
47d784e9f2 Add a human readable description of the tagged_addr_ctrl value to tombstones.
Change-Id: Ib9860b282cf749891e0f6ef7697669b94235c236
2021-11-05 18:59:26 -07:00
Christopher Ferris
2038cc7633 Add a test to verify the dex_pc is correct.
The libunwindstack code will attempt to dlopen the libdexfile.so
when a dex pc is found. Unfortunately, this failed since that
library was not properly listed as a runtime library. To make
sure this doesn't happen again, add an end to end test that
will create a dex pc frame, and will verify the correct
dex function name is in that frame.

Bug: 199043576

Test: Unit test passes on arm/aarch64/x86/x86_64.
Test: Removed the runtime_libs of libdexfile from libunwindstack
Test: and verified the new test fails.
Change-Id: I3a11f9ee44e06e37a547d193b04f7fbb90ccfe0a
2021-09-15 22:14:28 +00:00
Christopher Ferris
7e4c2a8ccc Add fault address marker in proto to tombstone.
When the switch was made to dump the tombstone from the protobuf,
the fault address marker in the maps section went missing. Re-add
that logic and add new unit tests to verify all of the different
behaviors.

Bug: 193935960

Test: All unit tests pass.
Test: All unit tests pass when setprop debug.debuggerd.translate_proto_to_text 0
Test: The above on cuttlefish, 32 bit and 64 bit.
Test: The above on a flame, 32 bit and 64 bit.
Change-Id: I098bb6ab4bacacae2ca0fc5ec9a73549ed0b9489
2021-08-23 16:25:13 -07:00
Christopher Ferris
e8891458e5 Remove trailing newlines from abort message.
The tombstone will add a newline after the abort message, so remove
any trailing newlines before saving/printing.

Bug: 196414062

Test: Unit tests pass.
Test: Set system property debug.debuggerd.translate_proto_to_text to 0
test: and unit tests still pass.
Change-Id: I0d3dc215eb5d8be93d99e5b9d4f0a14b1d61396d
2021-08-18 14:13:02 -07:00
Christopher Ferris
a3e9a0b2e1 Always use main thread pid for manual dumping.
When running debuggerd from the command line, it's possible that
the signal will happen on a side thread. The original intercept
in tombstoned is set to only handle crashes from the main thread
pid, so in this case, the intercept doesn't occur. To fix this,
modify the code so that running debuggerd always sends the signal
to the main pid. In addition, modify the signal handler is entered
due to the BIONIC_SIGNAL_DEBUGGER signal, then the crashing tid is
set to the main thread pid instead of the current thread.

Add unit test to cover this case.

Bug: 194346289

Test: All unit tests pass.
Test: Verify the new unit test is getting the signal on the non-main
Test: thread and still properly handling the intercept.
Test: Modify the debuggerd code to send the signal to the non main pid
Test: and verify the dump still occurs correctly.

Change-Id: I2dd1bd11fc8ef4a6fe87f05ecc67ae349a101c82
2021-07-30 14:08:03 -07:00
Mitch Phillips
5ddcea2924 [MTE] Add a HWASan-style tag dump to tombstones.
We already dump the tags in the regigster dump section by appending the
tag to the memory address. You only get 2 granules before each register
and 13 after.

The HWASan-style tag dump is extremely useful for debugging, as it gives
a pretty comprehensive overview of the memory subsystem. It also
provides enough context bytes (256) to give you a reasonable intuition
about a particular bug.

The tag dump shows up only if PTRACE_PEEKTAGS returns at least one value
in the 256 requested. If the start of end of the region is untagged,
it's omitted. The tag dump looks like this:

Change-Id: Icc33fb97542d9b1fa3ae9e58aba34d524c6ba7b5

---
Memory tags around the fault address (0x60000704414d340), one tag per 16 bytes:
      0x704414d000: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d100: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d200: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
    =>0x704414d300: 0  0  0  0 [2] 2  0  0  0  0  0  0  0  0  0  0
      0x704414d400: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d500: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d600: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d700: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d800: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414d900: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      0x704414da00: 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
---

Bug: 183992164
Test: atest debuggerd_test on MTE+QEMU and sunfish.

Change-Id: I8d5842e4803ca30b407e866c99eef56f2cb36600
2021-06-28 15:53:10 -07:00
Mitch Phillips
78f0670dda [MTE] Print cause and alloc/dealloc traces to logcat.
This information clearly meets the bar for being dumped to logcat. If we
omit the info, we may confuse the user into thinking that it's not
available at all, especially if it's their first time seeing an MTE
report.

This also adds some functionality to the integration testing library to
pull logcat messages and scan them to make sure the contents are in both
places.

Bug: 187881237
Test: atest debuggerd_test # on QEMU w/ MTE.
Change-Id: Icc17ea45bda7628331cc4812eaad3bc5c949b7a7
2021-06-01 18:12:22 -07:00
Peter Collingbourne
93406da189 Merge "Run MTE tests on zero-sized allocations." 2021-05-14 03:58:13 +00:00
Peter Collingbourne
aa544796ae Run MTE tests on zero-sized allocations.
Bug: 187879470
Change-Id: I9547f3032af9d1a921f8597a53389d25af33b369
2021-05-13 14:08:41 -07:00
Peter Collingbourne
fc7852b741 Merge "Test that out-of-bounds UAF is not detected with MTE." 2021-05-13 02:53:23 +00:00
Peter Collingbourne
dc47634ec4 Test that out-of-bounds UAF is not detected with MTE.
This type of error is unlikely and attempting to detect it with MTE
is likely to produce false positive reports. Make sure that this type
of error is not detected by the allocator.

Change-Id: I90676d1a031411d6b725890311317802bc24b459
2021-05-12 15:56:43 -07:00
Christopher Ferris
fe751c5a61 Re-add backtrace note about unreadable elf.
When moving to the proto-ized tombstones, the note about unreadable
elf files in a backtrace got lost. This re-adds it and adds a test
to verify that the note properly shows up.

Bug: 185428454

Test: Ran unit tests.
Change-Id: I1150cc737772e1b79fd73ec5c782caadc4629421
2021-05-03 15:21:11 -07:00
Christopher Ferris
6702256e0c Allow another prctl call.
A change was made so that pthread_create is calling
prctl(PR_PAC_RESET_KEYS, ...) on aarch64. It's possible that other
seccomp policies might need to change to allow this.

Test: CrasherTest.seccomp_backtrace passes on aarch64.
Change-Id: I9c4d1b3dca5f19a6285bf904bb942f1f52e42bd0
2021-04-16 13:35:16 -07:00
Peter Collingbourne
f4a40c0edd Merge "Support MTE and GWP-ASan features in proto tombstones." 2021-03-19 23:42:23 +00:00
Peter Collingbourne
d0f5eb5716 Merge "[GWP-ASan] Add debuggerd end-to-end tests and remove unique wording." 2021-03-19 23:42:23 +00:00
Elliott Hughes
e4781d54a5 debuggerd: prepare to abandon ship^Wgdb.
Talk of "gdb" when we currently mean "gdb or lldb" and will soon mean
"lldb" is starting to confuse people. Let's use the more neutral
"debugger" in places where it really doesn't matter.

The switch from gdbclient.py to lldbclient.py is a change for another
day...

Test: treehugger
Change-Id: If39ca7e1cdf4c8bb9475f1791cdaf201fbea50e0
2021-03-17 10:03:25 -07:00
Peter Collingbourne
1a1f7d79a4 Support MTE and GWP-ASan features in proto tombstones.
Proto tombstones were missing tagged fault addresses, tagged_addr_ctrl,
tags in memory dumps and Scudo and GWP-ASan error reports. Since text
tombstones now go via protos, all of these features broke when we
switched to text tombstones generated from protos by default. Fix
the features by adding support for them to the proto format,
tombstone_proto and tombstone_proto_to_text.

Bug: 135772972
Bug: 182489365
Change-Id: I3ca854546c38755b1f6410a1f6198a44d25ed1c5
2021-03-16 10:59:39 -07:00
Mitch Phillips
7168a217b9 [GWP-ASan] Add debuggerd end-to-end tests and remove unique wording.
Looks like we unintentionally had a breakage after aosp/1595302, where
both GWP-ASan and MTE tests started failing because the extra
information wasn't plumbed through the tombstones. MTE has end-to-end
tests but aren't run continuously, and GWP-ASan was missing the e2e
tests.

Also remove some unique wording for GWP-ASan, a UaF on the free'd
pointer is now "0 bytes into a 16-byte allocation" instead of "on a
16-byte allocation". The former is more descriptive and is more
ubiquitously used in our tooling.

This patch adds the E2E tests, but the underlying problem needs to be
fixed as well, before this patch can land.

Bug: 182489365
Test: atest debuggerd_test
Change-Id: I0fe8aba7ea443b3071724987f46b19a6525cda3c
2021-03-11 15:56:35 -08:00
Peter Collingbourne
90947d442c Merge "Teach debuggerd to pass the secondary ring buffer to __scudo_get_error_info()." 2021-03-11 01:15:49 +00:00
Treehugger Robot
3f24fefe29 Merge "Untag addresses in registers before looking up the mapping." 2021-03-06 02:41:05 +00:00
Christopher Ferris
35da288199 Don't hard-code number of tombstones.
On cuttlefish, the number of tombstones allowed is much larger
than 50, so change the algorithm to search for any tombstone
file.

Test: Ran unit tests on cuttlefish with > 50 tombstones.
Test: Ran unit tests on device.
Change-Id: Ia1d885fe19a7f7751fe3386d40b48750d1e21bd5
2021-02-18 15:29:13 -08:00
Peter Collingbourne
bb4b49c63c Teach debuggerd to pass the secondary ring buffer to __scudo_get_error_info().
With this change we can report memory errors involving secondary
allocations. Update the existing crasher tests to also test
UAF/overflow/underflow on allocations with sizes sufficient to trigger
the secondary allocator.

Bug: 135772972
Change-Id: Ic8925c1f18621a8f272e26d5630e5d11d6d34d38
2021-02-12 12:30:52 -08:00
Peter Collingbourne
0ea08c2f0b Untag addresses in registers before looking up the mapping.
Otherwise we can fail to find map entries for tagged addresses,
such as those of heap objects.

Bug: 135772972
Change-Id: Ia626b0587c8461eb575b2de5c08562c73ba4a66e
2021-02-05 15:01:12 -08:00
Peter Collingbourne
939d074236 Fix CrasherTest.smoke in debuggerd_test.
Now that we default to sync MTE in tests, the default tagged_addr_ctrl
in this test needs to be updated.

Bug: 135772972
Change-Id: I9bf6fb29df9799d1ed8c0d8b66f4d2891f487d80
2021-02-02 19:00:48 -08:00
Josh Gao
76e1e30f16 Reland protobuf tombstones.
This reverts the following commits:
    e156ede145.
    eda96eddcb.
    5ec54d1e84.
    1e45d3f223.
    a50f61f8fa.

Test: treehugger
Test: atest -c CtsSeccompHostTestCases:android.seccomp.cts.SeccompHostJUnit4DeviceTest#testAppZygoteSyscalls
Change-Id: Ic2b1f489ac9f1fec7d7a33c845c29891f4306bbd
2021-01-26 17:55:17 -08:00
Jerome Gaillard
eda96eddcb Revert "tombstoned: make it easier to add more types of outputs."
Revert "Let crash_dump read /proc/$PID."

Revert submission 1556807-tombstone_proto

Reason for revert: b/178455196, Broken test: android.seccomp.cts.SeccompHostJUnit4DeviceTest#testAppZygoteSyscalls on git_master on cf_x86_64_phone-userdebug

Reverted Changes:
Ide6811297:tombstoned: switch from goto to RAII.
I8d285c4b4:tombstoned: make it easier to add more types of ou...
Id0f0fa285:tombstoned: support for protobuf fds.
I6be6082ab:Let crash_dump read /proc/$PID.
Id812ca390:Make protobuf vendor_ramdisk_available.
Ieeece6e6d:libdebuggerd: add protobuf implementation.

Change-Id: Ib2403c1b61f6cf0513b76361440fbc5909d7554a
2021-01-26 12:42:03 +00:00
Jerome Gaillard
5ec54d1e84 Revert "tombstoned: support for protobuf fds."
Revert "Let crash_dump read /proc/$PID."

Revert submission 1556807-tombstone_proto

Reason for revert: b/178455196, Broken test: android.seccomp.cts.SeccompHostJUnit4DeviceTest#testAppZygoteSyscalls on git_master on cf_x86_64_phone-userdebug

Reverted Changes:
Ide6811297:tombstoned: switch from goto to RAII.
I8d285c4b4:tombstoned: make it easier to add more types of ou...
Id0f0fa285:tombstoned: support for protobuf fds.
I6be6082ab:Let crash_dump read /proc/$PID.
Id812ca390:Make protobuf vendor_ramdisk_available.
Ieeece6e6d:libdebuggerd: add protobuf implementation.

Change-Id: I0c4f3a17e8b06d6c65255388c571ebf11d371dbb
2021-01-26 12:41:52 +00:00
Josh Gao
6bf6a9fc61 Merge changes from topic "tombstone_proto"
* changes:
  libdebuggerd: add protobuf implementation.
  tombstoned: support for protobuf fds.
  tombstoned: make it easier to add more types of outputs.
  tombstoned: switch from goto to RAII.
2021-01-25 22:18:48 +00:00
Elliott Hughes
03b283a65f Move debuggerd_test over to mallopt().
Bug: http://b/135772972
Test: treehugger
Change-Id: I178f2a753b5608d9e72cee8874524ad4faf701d7
2021-01-15 11:34:26 -08:00
Josh Gao
1091d24c16 tombstoned: support for protobuf fds.
Test: debuggerd_test
Change-Id: Id0f0fa2856e4b8e57d7dc0e1495134e943b289da
2021-01-13 13:35:45 -08:00
Josh Gao
e2aa621c83 tombstoned: make it easier to add more types of outputs.
While we're at it, switch to unlinkat.

Test: debuggerd_test
Change-Id: I8d285c4b4e94effa1acb8f69ac3af4ff8c37defb
2021-01-13 13:35:45 -08:00
Peter Collingbourne
cd27807bfe Remove ANDROID_EXPERIMENTAL_MTE.
Now that the feature guarded by this flag has landed in Linux 5.10
we no longer need the flag, so we can remove it.

Bug: 135772972
Change-Id: I02fa50848cbd0486c23c8a229bb8f1ab5dd5a56f
2021-01-11 10:55:51 -08:00
Peter Collingbourne
71ad49554f Change the android_mallopt(M_SET_HEAP_TAGGING_LEVEL) API.
- Make it apply to every thread, and thus remove the restriction
  that it must be called while the program is single threaded.
- Make it change TCF0 itself (on all threads), instead of requiring
  callers to do it themselves, which can be error prone.

And update all of the call sites.

Change the implementation of
android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) to call
android_mallopt(M_SET_HEAP_TAGGING_LEVEL) internally. This avoids
crashes during startup that were observed when the two mallopts
updated TCF0 unaware of each other.

I wouldn't expect there to be any out-of-tree callers at this point,
but it's worth noting that the new interface is backwards compatible
with the old one because it strictly expands the set of situations in
which the API can be used (i.e. situations where there are multiple
threads running or where TCF0 hadn't been updated beforehand).

Bug: 135772972
Change-Id: I7746707898ff31ef2e0af01c4f55ba90b72bef51
2020-11-18 10:24:29 -08:00
Peter Collingbourne
2b6764a625 Fix the expected tagged_addr_ctrl in a test.
It turns out that I had originally written the test with a local
patch applied that forces TCF0 to SYNC, so it was testing for the
wrong tagged_addr_ctrl value. Fix it.

Bug: 135772972
Change-Id: Ibb9b25e5f5635372ad5de7825c31d7264ff02590
2020-11-02 16:00:08 -08:00
Peter Collingbourne
864f15dd6d Dump the per-thread TAGGED_ADDR_CTRL value if available.
This value indicates whether memory tagging is enabled on a thread,
the mode (sync or async) and the set of excluded tags. This information
can sometimes be important for understanding an MTE related crash,
so include it in the per-thread tombstone output.

Bug: 135772972
Change-Id: I25a16e10ac7fbb2b1ab2a961a5279f787039000b
2020-09-15 21:32:36 -07:00
Peter Collingbourne
fe8997aff8 Include memory tags in memory dump output.
Tags appear in the addresses printed in the memory dump, which seems
like a reasonable place to put them because tagged addresses will
also appear in other places in the tombstone, such as registers and
the fault address.

Bug: 135772972
Change-Id: I52da338347ff6b7503cf5ac80763c540695dc061
2020-07-21 19:05:16 -07:00
Peter Collingbourne
10e428dd77 Fix dumping of heap memory.
After r.android.com/1288984 we started failing to dump memory contents
for heap addresses because the tag started causing any addresses to
fail this bounds check. Add an untag_address() call to the bounds check
so that the tag is ignored.

Bug: 154272452
Change-Id: I3a6d1a078b21871bd93164150a123549f83289f6
2020-07-17 17:35:49 -07:00
Peter Collingbourne
bbe6905d7e Add stack trace coverage to MTE tests.
It's impractical to test the contents of the stack trace, but we
should at least test that *a* stack trace is present, which would
have caught the bug fixed by r.android.com/1306754 .

Bug: 135772972
Change-Id: Ic5e0b997caa53c7eeec4e5185df5c043c9d4fe3d
2020-05-08 10:14:47 -07:00