Commit graph

293 commits

Author SHA1 Message Date
Dylan Katz
b62e324406 Added fuzzer for Unwinder
Adds a fuzzer for Unwinder. This will likely cover a large portion of the library, as it uses many of the library's features
in the process of setting up the Unwinder. Hopefully this, combined with the calls Unwinder makes internally, will provide
sufficient coverage.

Rough coverage estimate (this is drastically lower than the true number due to shared libraries): 6.6%

Test: Ran on device for a few hours
Signed-off-by: Dylan Katz <dylan.katz@leviathansecurity.com>
Change-Id: I813e204df595ff38dccfb73be7fff5c080aaa043
2020-07-01 16:02:29 -07:00
Victor Khimenko
7428c52ef2 Make libbacktrace buildable for native_bridge
Bug: http://b/153609531

Test: m -j64 libbacktrace.native_bridge

Change-Id: I2b8a881b4e952f3b68dbcaeb14f147a6d955b406
2020-06-18 22:02:46 +02:00
Christopher Ferris
5990a9d442 Add new reparse benchmarks.
Test: Ran benchmarks on host and device.
Change-Id: I41b7d29bfa3468b9b9b8cbdfe94aca830d14f98e
2020-05-19 10:31:53 -07:00
Jiyong Park
16a932a4ef Set apex_available property
The marked library(ies) were available to the APEXes via the
hand-written whitelist in build/soong/apex/apex.go. Trying to remove the
whitelist by adding apex_available property to the Android.bp of the
libraries.

Exempt-From-Owner-Approval: cherry-pick from internal

Bug: 150999716
Test: m
Merged-In: I54db09314c7236a227f04281a439c1d5dc56ef2c
Change-Id: I54db09314c7236a227f04281a439c1d5dc56ef2c
(cherry picked from commit a2606921b2)
2020-05-18 13:30:25 +09:00
Christopher Ferris
5133bbfd34 Merge "Add new LocalUpdatableMaps benchmarks." 2020-05-14 00:18:27 +00:00
Treehugger Robot
c3d30bfdff Merge "Fix GetGlobalVariableOffset with tagged pointer in aarch64" 2020-05-06 05:53:45 +00:00
Christopher Ferris
175747fefa Add new LocalUpdatableMaps benchmarks.
In addition, move a couple of elf benchmarks out of unwind_benchmarks.cpp
to the ElfBenchmarks.cpp file.

Test: Ran benchmarks.
Change-Id: I169f89f7b2dd6735568143f2176301e181fb8262
2020-05-05 11:19:11 -07:00
Sim Sun
a7a194beb4 Fix dangling pointer issue in LocalUpdatbleMaps
Libunwindstack would remove duplicated items and update the `prev_map`
during reparsing `/proc/self/maps`. But we leave `prev_real_map`
pointing toward a MapInfo that will be deleted soon. It will cause a
dangling pointer issue.

Add new tests to cover this dangling pointer issue.

Bug: 155511785

Test: libunwindstack_test
Change-Id: I62e1b97bcb73f07e9349671f0b758f5ec9de16c0
2020-05-01 22:20:01 +00:00
Martin Stjernholm
2e3af867d9 Merge "Reland "bionic_libc_platform_headers is only available when building with Bionic"." 2020-04-30 14:11:50 +00:00
Martin Stjernholm
4a27a81e4e Reland "bionic_libc_platform_headers is only available when building with Bionic".
Relanding unchanged - the build problem was due to a split topic.

Test: m checkbuild
Test: atest libunwindstack_unit_test
Test: lunch fvp-userdebug && mmm system/core/libunwindstack
Bug: 152255951
Change-Id: Ifd1ced65b840ef216630906eec1ec31233e0c5f1
2020-04-29 18:16:46 +01:00
Peter Collingbourne
118c5ee6e6 Switch to new kernel ptrace interface for reading tags.
Bug: 135772972
Change-Id: I506429d7bff79f83828e1f0d5c0ea0468ee1580b
2020-04-29 09:33:53 -07:00
Martin Stjernholm
87bac1a411 Revert "bionic_libc_platform_headers is only available when buil..."
Reason for revert: Breaks rvc-d1-dev-plus-aosp: http://ab/6443190
Reverted Changes:
Ide447b89a:bionic_libc_platform_headers is only available whe...
Ia93cd3ec8:bionic_libc_platform_headers is only available whe...
Icdc495588:Make bionic_platform_headers available only for Bi...
Idfd7c87dc:bionic_libc_platform_headers is only available whe...

Bug: 152255951
Bug: 155269399
Change-Id: I4e6beba5565e604fde3a51cdce5cc4041caffa4e
2020-04-29 12:18:54 +00:00
Yong Li
fbca300097 Fix GetGlobalVariableOffset with tagged pointer in aarch64
Tagged pointer for aarch64 since Android R would lead top byte to have
random values. For example of a symbol from libart.so in a hwasan
enabled device in Android R:

1490: 8800000000b094a0   144 OBJECT  GLOBAL 24 __dex_debug_descriptor

We need to mask off the top byte so that the address range comparison
would work as intended.

Test: Ran new unit test

Signed-off-by: Yong Li <yongl0722@gmail.com>
Change-Id: Ia8c638e16baff57740c569e9eaf9cfd1f5bd3fad
2020-04-27 21:07:50 +00:00
Martin Stjernholm
03082e6952 bionic_libc_platform_headers is only available when building with Bionic.
Test: m checkbuild
Test: atest libunwindstack_unit_test
Test: lunch fvp-userdebug && mmm system/core/libunwindstack
Bug: 152255951
Change-Id: Idfd7c87dc65db350730fec3ceef8c6bc64acf60b
2020-04-27 19:53:49 +01:00
Christopher Ferris
126b010f15 Merge "Create minimal remap table for symbol binary search." 2020-04-20 23:42:22 +00:00
Christopher Ferris
cec90ea2da Merge "Optimize Memory::ReadString" 2020-04-20 23:35:42 +00:00
David Srbecky
a17c2b694c Optimize Memory::ReadString
This function is responsible for majority of CPU time in prefetto.

Reduce the number of memory reads (don't read strings byte-by-byte).

Update all calls of ReadString to include the third parameter to have
a max read.

Add an Elf creation benchmark since this function is on the elf
creation path.

Test: libunwindstack_unit_test
Change-Id: Ia36e1f1a5ba76c9e9f13c43fb9e3691dde7897f2
2020-04-16 15:03:19 -07:00
David Srbecky
af41960acb Create minimal remap table for symbol binary search.
ELF symbols are not sorted by address. Create remap table
which reshuffles the indices into sorted-by-address order.

This saves over 6x of memory (the remap table needs just
uint32_t per entry, as opposed the FuncInfo cache entry).

ART symbols are sorted.  Make use of that fact.

Bug: 110133331
Test: libunwindstack_test
Test: art/test.py -b --host -r -t 137-cfi
Change-Id: I1812d2dd3ad6a69ae93ed50ca387749c649289b9
2020-04-16 18:17:45 +01:00
Peter Collingbourne
c71e0a652c libunwindstack: Add Memory::ReadTag() function for reading memory tags.
This uses an experimental Linux kernel API for reading the tags across
processes using ptrace.

Bug: 135772972

Test: Unit tests pass.
Change-Id: Ib1a09d9219166011de80cf250b756bb8a4bcdb0a
2020-04-16 00:23:45 -07:00
Christopher Ferris
a9e19097ed Add benchmarks for symbol reading.
Add a number of benchmarks to time how long it takes to look
up symbols.

Test: Ran benchmarks on device.
Change-Id: Iab7aab3f60c2c7056395beca3d36263420bcb5dc
2020-04-15 14:03:21 -07:00
Sim Sun
273d3f08aa Avoid re-mapping dex file that's in local memory.
If the Dex file we're trying to examine is already within the unwinder's
address space, we don't need to load it from disk or copy it across
processes.

This avoids using up virtual address space to map in dex files, and
also should be a bit faster to read since it won't go out to the file.

Patch by Chris Sarbora

Test: Ran new unit tests.
Test: Ran 137-cfi art test.
Change-Id: I949457856f051cca11b9020e9da3a41bbf6e5c8e
2020-04-07 18:07:38 -07:00
Peter Collingbourne
a7b4c5d25a Fix off-by-one in ReadBuildIDFromMemory.
This was sometimes causing build ids to be truncated, probably because
of memory corruption in std::string. A similar off-by-one was fixed in
ReadBuildID in aosp/939619.

Bug: 129873279
Change-Id: I401fe7f991dbd135f5b4836381b48ea3c6a2243f
2020-03-31 10:29:38 -07:00
Mitch Phillips
b9c072c551 Move PC-only unwind frame generation to libunwindstack.
GWP-ASan uses frame-pointer based unwinding internally on
allocation/deallocation to collect stack traces that are used when
crashes are reported.

This should be generic, so pull it out into libunwindstack so it can be
used by MTE as well.

Bug: 152412331
Test: atest debuggerd_test
Change-Id: I27b32263aac63446f5fe398af108676b70cd3971
2020-03-26 13:39:05 -07:00
Martin Stjernholm
6d4e47a165 Merge "Remove use of static libdexfile to avoid linking in ART internal code." 2020-03-23 20:15:14 +00:00
Christopher Ferris
a010ddbb88 Merge "Fix memory leak of DexFile handle after release" 2020-03-23 18:20:00 +00:00
Yong Li
489c3a8b35 Fix memory leak of DexFile handle after release
The DexFile handle is allocated from heap in OpenFromFd/OpenFromMemory.
After releasing the unique_ptr, the DexFile handle itself is no longer
managed by the smart pointer. However, the DexFile handle is not freed
in the constructor of DexFileFromFile/DexFileFromMemory.

This change uses get() method to get the DexFile pointer while allowing
it to be managed by smart pointer so that it can be freed after method
end.

Added new unit tests to detect leaks.

Bug: 151966190

Test: Unwinding can still retrieve dex frame information during crash.
Test: Ran new unit tests before change and verified they fail, ran them
Test: after the change and verified they don't fail.

Signed-off-by: Yong Li <yongl0722@gmail.com>
Change-Id: I0627e1e255eb6644aba51e940c1a79ff78d568d7
2020-03-20 16:46:11 -07:00
Peter Collingbourne
5ac3927878 Make GetPcAdjustment a free function.
We're now using it in contexts that don't have all of the registers available,
such as GWP-ASan and soon MTE, so it doesn't make sense to have it be a
member function of Regs.

Bug: 135772972
Change-Id: I18b104ea0adb78588d7e475d0624cefc701ba52c
2020-03-19 17:51:20 -07:00
Martin Stjernholm
a2cc893044 Remove use of static libdexfile to avoid linking in ART internal code.
- Create a static library libunwindstack_no_dex without DEX support.
- Use it in libdebuggerd_handler_fallback, whose only use is in the
  linker, which shouldn't need that support.
- Use it in init_first_stage, which doesn't need DEX support either.
- Also need a libbacktrace_no_dex since it's in the dependency chain
  from init_first_stage to libunwindstack_no_dex.

Also restrict the *_no_dex libs and libdebuggerd_handler_fallback as
much as possible to avoid inadvertent use of these reduced
functionality libs.

Test: m init_first_stage on Cuttlefish
  where BOARD_BUILD_SYSTEM_ROOT_IMAGE=false
Test: m system_image com.android.runtime
Test: Build & boot
Test: atest linker-unit-tests libunwindstack_unit_test debuggerd_test
Bug: 142944931
Bug: 151466650
Change-Id: Iaacb29bfe602f3ca12a00a712e2a64c45ff0118b
2020-03-19 22:23:54 +00:00
Elliott Hughes
49e6ee928f Remove mips build.
For now this leaves the ability to cross-unwind a mips process, but we
should probably clean that up too. We need to remove the build remnants so
that we can clean up the build system itself (otherwise it sees us talking
about an architecture it doesn't know about, and assumes that something's
wrong).

Test: treehugger
Change-Id: I2862c630cec95dbdd474e34c3568d0e1a6d44b16
2020-03-06 22:02:09 -08:00
David Srbecky
a6617cb179 Rewrite DwarfSectionImpl::InsertFde
Simplify and fix the algorithm.

For consecutive functions (eg [10,20] [20,30]) without
padding in between, the old algorithm would drop FDEs.

Test: libunwindstack_test
Change-Id: Ie886922bec262fb64d4b2ecf01c2961d0652dcdb
2020-02-22 11:45:42 -08:00
Yabin Cui
15778b7439 Merge "libunwindstack: add simpleperf presumit test." 2020-01-28 03:51:44 +00:00
Yabin Cui
f667bf7b19 libunwindstack: add simpleperf presumit test.
Bug: none
Test: run `atest --test-mapping system/core/libunwindstack`.
Change-Id: I62521f63ca748bb1980282ed6399328573d4de41
2020-01-24 11:51:30 -08:00
Ryan Savitski
92237bad6a unwindstack: RegsArm64: fix harmless off by 1 + iterate GPRs contiguously
The memcpy should be for 31 GPRs, [x0, x30]. Currently it (accidentally)
also copies over the SP register (which ends up being harmless, as the
layouts match, and the value is reassigned again anyway).

Separately, I'm including an optional change for the iteration order,
since LR is the x30 GPR, it makes slightly more sense to print it
immediately after x29. However, this is a change in behaviour, so I can
undo the change if you think it's not worth it.

Tested: atest libunwindstack_unit_test
Change-Id: Ib6b81f8ee3a9a526bfabe4b09b327f083c855fb8
2020-01-24 19:50:45 +00:00
Christopher Ferris
0f40a05309 Properly handle empty map after read-only map.
Recently, the maps for an elf in memory might show up looking like:

  f0000-f1000 0 r-- /system/lib/libc.so
  f1000-f2000 0 ---
  f2000-f3000 1000 r-x /system/lib/libc.so
  f3000-f4000 2000 rw- /system/lib/libc.so

The problem is that there is logic in the code that assumed that the
map before the execute map must be the read-only map. In the case
above, this is not true. Add a new prev_real_map that will point
to the previous map that is not one of these empty maps.

This will fix the backtraces that look like this:

  #00  pc 0000000000050d58  /apex/com.android.runtime/lib64/bionic/libc.so!libc.so (offset 0x50000) (syscall+24) (BuildId: 5252408bf30e395d49ee270b54c77ca4)

To get rid of the !libc.so and the offset value, which is not correct.

Added new unit tests to verify this.
Added new offline test which an empty map between read-only and execute
map. Before this change, the backtraces had lines like
libc.so!libc.so (offset XXX) would be present.

Bug: 148075852

Test: Ran unit tests.
Change-Id: Ie04bfc96b8f91ed885cb1e655cf1e346efe48a45
2020-01-22 18:30:12 -08:00
Christopher Ferris
de5cd8ccd4 Fix global finding logic.
Recently, the maps for an elf in memory might show up looking like:

  f0000-f1000 0 r-- /system/lib/libc.so
  f1000-f2000 0 ---
  f2000-f3000 1000 r-x /system/lib/libc.so
  f3000-f4000 2000 rw- /system/lib/libc.so

That empty map was confusing the logic when looking for a global
variable. Now this case is handled properly.

New unit test added for this case.

Bug: 147910661

Test: Ran unit tests.
Test: Ran original failing test 137-cfi.
Change-Id: Ida2e96d1da5e1bf61f41646949fe5a2d405c0d61
2020-01-21 18:00:57 -08:00
Christopher Ferris
8726d3a448 Fix handling of possible bad gnu_debugdata_size.
Rather than use a std::vector for backing memory, allocate the memory
using a new with nothrow, and in MemoryBuffer use realloc. Since
the size field is coming from the elf, it could be corrupted or
intentionally crafted to cause problems.

In addition, add some other protections to make sure that overflows
don't occur.

Bug: 146215949

Test: Ran unit tests with jemalloc and scudo to verify that they
Test: both behave the same way.
Change-Id: If14243ce382ba5403a6bacd0ec673452c6b7c3be
2019-12-19 16:48:15 -08:00
Treehugger Robot
b773897b01 Merge "Add a name for all test suites" 2019-12-12 02:44:26 +00:00
Haibo Huang
0c01bb6edf Add a name for all test suites
(for the new googletest

Test: run tests
Change-Id: I3856a4a8f3ed23bcfcc59bec7624595e91740be0
2019-12-11 12:46:20 -08:00
Treehugger Robot
6e0a0dad52 Merge "unwindstack: fix dangling pointer in LocalUpdatableMaps." 2019-12-06 03:16:07 +00:00
Christopher Ferris
f0c82e7bad Use elf offset in signal step check.
The function StepIfSignalHandler assumed that the rel_pc passed
to it was actually an elf offset. A new version of clang created a libc.so
that has a load bias, so tests unwinding through a signal handler
would fail on arm. On other ABIs, there is unwind information that could
be used instead, so the unwind still worked.

The fix is to subtract the load bias from the rel_pc to get an elf
offset to pass to the Register StepIfSignalHandler functions. Change all
of the Register funtions to make it clear what the first parameter means.

Add a unit test for this new code. Also, add an offline test for
this case.

Bug: 145683525

Test: Ran unit tests using the new clang and the old clang.
Change-Id: I3e249653b79bcad6d3a56411a7911fde4888e9d6
2019-12-04 22:29:59 +00:00
Christopher Ferris
df683b7439 Fix support finding global variables.
The code was not properly getting the variable addresses and using
the offset and address fields of the .data section.

Fix all of that, and update the tests.

Bug: 145162678

Test: Unit tests pass.
Test: ./art/test/run-test --dex2oat-jobs 4 --host --prebuild --compact-dex-level fast --jit --no-relocate --runtime-option -Xcheck:jni  137-cfi
Test: ./art/test/testrunner/testrunner.py -t 137 --host
Change-Id: Ic61c4487334fd2273cda9c56eb1a3b525a03edb7
2019-12-03 17:35:00 -08:00
Christopher Ferris
456df6929f Move the dexfile support to implementation.
No longer require that NO_LIBDEXFILE_SUPPORT be defined or not
defined when including the header files. Move all of the different
behavior to the implementation, and keep all of the classes the
exact same whether dexfiles are supported or not.

Bug: 144470551

Test: Ran libunwindstack unit tests, libbacktrace unit tests, and
Test: debuggerd unit tests.
Test: Ran host art 137-cfi tests.
Change-Id: I4a04cfbc5d4f1bf765ef154881046c85057006c8
2019-11-20 14:59:55 -08:00
Treehugger Robot
ba5351692e Merge "Include PSTATE in tombstones on arm64." 2019-11-19 14:07:37 +00:00
Peter Collingbourne
bb2f941f57 Include PSTATE in tombstones on arm64.
A thread's PSTATE can sometimes be critical for understanding a crash,
especially with MTE and other new features that store per-thread state
in PSTATE.

Bug: 135772972
Change-Id: I1bee25bffe7eea395f04b6449dc9227298cf866e
2019-11-18 17:57:37 -08:00
Josh Gao
8a243118db unwindstack: fix dangling pointer in LocalUpdatableMaps.
Previously, when reparsing /proc/self/maps, we would remove duplicate
MapInfo entries, but leave the following entry's prev_map pointing
toward the soon-to-be-deleted MapInfo, leading to explosions.

Test: libunwindstack_test
Test: booted with libfdtrack.so preloaded
Change-Id: Ibfb7a8712540fe3aaadc10e9c31938f6ecddf17b
2019-11-14 18:12:57 -08:00
Haibo Huang
cf8a5b0e0e Fix build with new googletest
The new googletest requires prefix to be non-empty.

Exempt-From-Owner-Approval: fix test
Change-Id: Ic039cb657b455919e429a3ec2107893b1734e8a1
2019-11-10 04:08:25 +00:00
Christopher Ferris
4ca98e18a4 Fix potential bad info in eh_frame_hdr.
Due to a bug, an elf can have FDEs with a length of zero, while still
having another FDE for the same pc with a non-zero length. The
eh_frame_hdr can sometimes point to the zero length FDE, but it should
have pointed to the non-zero length FDE. In order to fix this, if the
eh_frame_hdr points at the zero length FDE then try and find the real FDE
directly from eh_frame.

The change cleans up and removes unused variables from DwarfEhFrameWithHdr
and changes the objects so that all of the DwarfSection objects and
DwarfEhFrameWithHdr object inherit from the same class.

Add new unit tests to verify this functionality.

Bug: 142483624

Test: Unit tests all pass.
Change-Id: I128a916e3ba378931de7d44ee15e57e24d4073df
2019-10-29 18:39:30 -07:00
Christopher Ferris
5838e53b97 Fix handling of PT_GNU_EH_FRAME.
The bias for the PT_GNU_EH_FRAME was using the paddr instead of vaddr.
This doesn't match the way the load bias is calculated, which always
use vaddr - offset, so change to use vaddr.

Found on an old x86 device that has a vdso that sets vaddr differently
from paddr.

Add a new offline test to catch this case and update the elf interface
unit tests.

Also, fix a small bug in the unwind_for_offline tool.

Bug: 142365899

Test: Unit tests pass.
Change-Id: I5f0bf062dd8ee45aa8553189ba493ec962e0b059
2019-10-21 19:11:22 -07:00
Christopher Ferris
07bef8ff7b Add document of changes between Android versions.
This document does not list every change in the unwinder between
Android versions. Instead it attempts to only include information
that someone building an app targeting a specific version of Android
might need to know to make sure their app can unwind properly.
It also tries to describe the way that stacktraces might be displayed
differently between Android versions.

Test: NA
Change-Id: I4029053f763f3471f7ddb5da9b1de2d325ead455
2019-10-15 18:33:11 -07:00
Christopher Ferris
baf058bbf7 Replace MOCK_METHODN with MOCK_METHOD macro.
Test: Builds and unit tests pass.
Change-Id: I64e0034359c213f37c098d1c97be260bd955ca0f
2019-10-11 14:30:18 -07:00