Commit graph

27700 commits

Author SHA1 Message Date
Treehugger Robot
f3df0dae0b Merge "Add missing #include." 2019-03-16 06:56:14 +00:00
Peter Collingbourne
149ce93056 Add missing #include.
Fixes sanitizer build.

Test: walleye_hwasan-userdebug builds
Change-Id: If7890dbf2e715ca89b68f5c39c6ffbd24f15f2c2
2019-03-15 22:45:06 -07:00
Peter Collingbourne
9d69d4ccae Merge "Add a platform API for setting an allocation limit." 2019-03-15 21:51:46 +00:00
Elliott Hughes
ea6c19a44b Merge "Remove __INTRODUCED_IN_FUTURE." 2019-03-15 19:54:57 +00:00
Christopher Ferris
1fc5ccfe76 Add a platform API for setting an allocation limit.
Introduce an M_SET_ALLOCATION_LIMIT enumerator for android_mallopt(),
which can be used to set an upper bound on the total size of all
allocations made using the memory allocation APIs.

This is useful for programs such as audioextractor and mediaserver
which need to set such a limit as a security mitigation. Currently
these programs are using setrlimit(RLIMIT_AS) which isn't exactly
what these programs want to control. RLIMIT_AS is also problematic
under sanitizers which allocate large amounts of address space as
shadow memory, and is especially problematic under shadow call stack,
which requires 16MB of address space per thread.

Add new unit tests for bionic.

Add new unit tests for malloc debug that verify that when the limit
is enabled, malloc debug still functions for nearly every allocation
function.

Bug: 118642754
Test: Ran bionic-unit-tests/bionic-unit-tests-static.
Test: Ran malloc debug tests and perfetto integration tests.
Change-Id: I735403c4d2c87f00fb2cdef81d00af0af446b2bb
2019-03-15 10:54:55 -07:00
Jiyong Park
ac74615c1c Merge "Clean /bionic" 2019-03-15 16:41:13 +00:00
Jiyong Park
80c5e623f7 Clean /bionic
The path has gone

Test: m
Change-Id: Iecbde545f84357706da55e4fdb7b421433f945d0
2019-03-16 01:27:07 +09:00
Treehugger Robot
412d49349e Merge "Don't install *.mountpoint targets" 2019-03-15 09:02:18 +00:00
Treehugger Robot
4c95542fdf Merge "Reduce reserved size for DlExtTest.ReservedRecursiveTooSmall test" 2019-03-15 02:49:15 +00:00
Yi Kong
1e7a150339 Reduce reserved size for DlExtTest.ReservedRecursiveTooSmall test
When built with clang-r353983, the ReservedRecursiveTooSmall test fail
due to the reserved memory is now large enough for android_dlopen_ext.
Reduce the reserved memory size to agree with ReservedTooSmall test.

Test: bionic-unit-tests
Bug: 126457671
Change-Id: I3e311a3f35b0de5d028fa1b9b3681d5ec32faee8
2019-03-14 16:25:45 -07:00
Elliott Hughes
5270017ab3 Remove __INTRODUCED_IN_FUTURE.
This hasn't been particularly useful, we haven't used it consistently,
and it has caused trouble.

Test: builds
Change-Id: Ic5b5b5124af98aa8301e602fd75b0eb72a5fc7f6
2019-03-14 13:34:21 -07:00
Treehugger Robot
0ab20442e4 Merge "The future is now (2019 edition)." 2019-03-14 20:13:27 +00:00
Elliott Hughes
78e9ebc3b9 The future is now (2019 edition).
This year, we accidentally shipped NDK r20beta1 first :-(

Bug: https://github.com/android-ndk/ndk/issues/932
Test: builds
Change-Id: Id66a16ea09e7928843e61612fbdef09e72610d49
2019-03-14 09:29:52 -07:00
Jiyong Park
036e09c36e Don't install *.mountpoint targets
The *.mountpoint targets that installs /bionic/lib/lib*.so and
/bionic/bin/linker* are no longer needed.

Now, /system/lib/lib*.so and /system/bin/linker* are simply symlinks to
the corresponding files in the runtime apex. For example,

/system/lib/libc.so -> /apex/com.android.runtime/lib/bionic/libc.so

This is made possible because we now activate APEXes even before the
data partition is mounted. Before the data partition mounting, the
APEXes from the system partition are ativated. After the data partition
is mounted, updated APEXes in the partition (if any) are activated. As a
result, the symlink always points to the valid path regardless of
whether /data is mounted or not.

Bug: 125549215
Test: device boots
Change-Id: Ie7d83686abe00b3c436f9f9db75d4244200a0fc9
2019-03-14 07:35:52 +09:00
Ryan Prichard
10935e063d Merge changes Ia880cd5a,I899c7801
* changes:
  Cosmetic changes to linker allocator and config
  Allow building the linker with -O0
2019-03-12 22:08:32 +00:00
Ryan Prichard
92b3e1b37b Cosmetic changes to linker allocator and config
Make the num_free_blocks calculation clearer. There are
sizeof(page->bytes) bytes available for blocks, which is equal to
(kAllocateSize - 16). The previous calculation overestimates the amount
of space by 8 or 12 bytes, but that doesn't change the result because
both kAllocateSize and block_size_ are multiples of 16.

Bug: none
Test: boot device, bionic unit tests
Change-Id: Ia880cd5abc2a7bb4e9e6a8c0441d985f4df8fdc4
2019-03-12 01:11:24 +00:00
Ryan Prichard
b0e2dd090b Allow building the linker with -O0
The tlsdesc_resolver_dynamic function is only defined on arm64, but the
code was taking its address on all targets. (Apparently the optimizer was
removing the entire deferred_tlsdesc_relocs loop?)

Bug: none
Test: bionic unit tests
Test: add -O0 to cc_defaults in linker/Android.bp, device boots
Change-Id: I899c78018cbe82aeaca7856c9f7b04300c1d3196
2019-03-11 17:53:21 -07:00
Treehugger Robot
7a15aa83f4 Merge "DO NOT MERGE - Skip PPRL.190305.001 into master" 2019-03-11 19:43:56 +00:00
The Android Open Source Project
de207c6fee DO NOT MERGE - Skip PPRL.190305.001 into master
Bug: 127812889
Change-Id: I79cd8227796b7512ecb33f917c6cf19a97d58584
2019-03-11 11:13:13 -07:00
Treehugger Robot
432db6cfaf Merge "linker: Handle libraries with disjoint mappings correctly." 2019-03-09 05:40:03 +00:00
Peter Collingbourne
b39cb3c31d linker: Handle libraries with disjoint mappings correctly.
It's possible and sometimes beneficial for a library to have disjoint mappings
and for other libraries to be mapped into the gap between the mappings using
ANDROID_DLEXT_RESERVED_ADDRESS. See for example the proposal for partitioning
in lld [1].

Because the find_containing_library and do_dl_unwind_find_exidx functions use
a simple bounds check to figure out whether a pointer belongs to a library
they will, given a pointer into a library mapped into the gap of a library
with disjoint mappings, return a pointer to the soinfo for the outer library
instead of the inner one, because the outer library will appear before the
inner one in the solist.

From a user perspective this means that we won't be able to unwind the inner
library's frames on 32-bit ARM with libgcc, dladdr() will return information
for the outer library given a pointer to the inner one and dlopen() et al will
use the linker namespace of the outer library when called from the inner one
(although they will usually be the same).

To make this work correctly, make it so that once find_containing_library
sees a match for the bounds check, it examines the library's PT_LOADs to
make sure that there is a mapping for the given address. This is similar
to how libgcc and libunwind_llvm already handle finding the PT_GNU_EH_FRAME
on non-ARM32 platforms [2,3]. do_dl_unwind_find_exidx is reimplemented in
terms of find_containing_library.

[1] http://lists.llvm.org/pipermail/llvm-dev/2019-February/130583.html
[2] e739ac0e25/libunwind/src/AddressSpace.hpp (L523)
[3] https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libgcc/unwind-dw2-fde-dip.c#294

Test: /data/nativetest{,64}/bionic-unit-tests/bionic-unit-tests on walleye-userdebug
Change-Id: I368fe6ad3c470b3dff80f7d9b04253566d63a7d2
2019-03-08 18:34:34 -08:00
Christopher Ferris
a838c2d163 Merge "Update to v5.0 kernel headers." 2019-03-08 21:28:16 +00:00
Christopher Ferris
27c6ada3ad Merge "Malloc debug: fix mutex deadlock issue" 2019-03-08 21:25:53 +00:00
Christopher Ferris
3c40463c65 Merge "Add malloc_info for sanitizer." 2019-03-08 21:24:57 +00:00
Christopher Ferris
fa10a3aa9a Add malloc_info for sanitizer.
Test: hwasan builds.
Change-Id: I39267c642af75b1ebb99633f25959638cc39628c
2019-03-08 11:11:27 -08:00
android-build-team Robot
1863ecbca3 Snap for 5240760 from 68f7efc044 to pi-platform-release
Change-Id: Iac928067526678a9d70c44466d67cdf477332e64
2019-03-08 18:38:43 +00:00
Iris Chang
76dcc478d3 Malloc debug: fix mutex deadlock issue
When we enable free_track option, one thread is in AddFreed->RemoveBacktrace
flow (hold free_pointer_mutex_ first and try to lock frame_mutex_), and
other thread do fork and enter PrepareFork flow (hold frame_mutex_ first
and try to lock free_pointer_mutex_), this situation may result in mutex
deadlock issue.

Bug: 127733115
Test: build pass and stress test pass
Change-Id: Ie5fcc4ef6c169372ad73d81978cfb2a726b6c03e
2019-03-08 11:04:36 +08:00
Christopher Ferris
d842e43e1d Update to v5.0 kernel headers.
Test: Builds and boots on taimen.
Change-Id: I13843bf1ab30ea89a50852adc88f2cba8401bded
2019-03-07 11:19:22 -08:00
Christopher Ferris
ff16c0b89b Merge "Refactor the malloc_info code." 2019-03-07 17:49:28 +00:00
Christopher Ferris
6c619a0da3 Refactor the malloc_info code.
malloc_info needs to be per native allocator, but the code treated it
like a global function that doesn't depend on the native memory allocator.

Update malloc debug to dump the actual pointers that it has been tracking.

Test: bionic-unit-tests pass.
Test: malloc debug tests pass.
Test: malloc hook tests pass.
Change-Id: I3b0d4d748489dd84c16d16933479dc8b8d79013e
Merged-In: I3b0d4d748489dd84c16d16933479dc8b8d79013e
(cherry picked from commit a3656a98b1)
2019-03-07 08:39:55 -08:00
vichang
4e167f35d6 Merge "bionic-unit-tests should depend on libandroidicu instead" 2019-03-06 23:05:24 +00:00
Victor Chang
ddcf488ef6 bionic-unit-tests should depend on libandroidicu instead
bionic has been moved to use libandroidicu instead of libicuuc.
This CL updates the unit test

Bug: 120659668
Test: m bionic-unit-tests && adb push out/target/product/walleye/data/nativetest/* /data/nativetest && adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
Change-Id: I59a0589d18bfd6753215dc07874f3c472bd64cca
2019-03-06 18:29:55 +00:00
Christopher Ferris
b8ef55a4f8 Merge "Make aligned_alloc match the standard." 2019-03-02 19:11:22 +00:00
Christopher Ferris
a22f5d5175 Make aligned_alloc match the standard.
Jemalloc does not verify that the size parameter is a multiple of
alignment. Fix this since it only went into P.

Fix the unit tests, and fix malloc debug/malloc hooks to handle this
new restrictive behavior.

Bug: 126944692

Test: Ran bionic unit tests.
Test: Ran bionic unit tests with malloc hooks enabled (no new tests fail).
Test: Ran bionic unit tests with malloc debug enabled (no new tests fail).
Test: Ran malloc debug unit tests.
Change-Id: I4d50785928815679c781ca729f998454d76b9192
2019-03-01 23:56:23 -08:00
Treehugger Robot
0771b752f1 Merge "Workaround string-plus-int warning" 2019-03-01 02:21:16 +00:00
Nick Kralevich
36501ba189 Merge "Ensure STDIN/STDOUT/STDERR always exist" 2019-03-01 00:46:47 +00:00
Yi Kong
4ca9a6b576 Workaround string-plus-int warning
The upcoming compiler warns against adding string and int:
In file included from bionic/libc/bionic/strsignal.cpp:41:
  bionic/libc/private/bionic_sigdefs.h:58:1: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
  __BIONIC_SIGDEF(SIGWINCH,  "Window size changed")
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  bionic/libc/bionic/strsignal.cpp:40:83: note: expanded from macro '__BIONIC_SIGDEF'
  #define __BIONIC_SIGDEF(signal_number, unused) [ signal_number ] = #signal_number + 3,
                                                                     ~~~~~~~~~~~~~~~^~~

Use array indexing index to avoid this warning.

Test: m checkbuild
Change-Id: Ib5e20edbf5bac76352df0484dd233d0621beb4e9
2019-02-28 15:54:58 -08:00
Nick Kralevich
7fa3b47813 Ensure STDIN/STDOUT/STDERR always exist
File descriptor confusion can result if a process is exec()d and
STDIN/STDOUT/STDERR do not exist. In those situations, the first,
second, and third files opened by the exec()d application will have FD
0, 1, and 2 respectively. Code which reads / writes to these STD* file
descriptors may end up reading / writing to unintended files.

To prevent this, guarantee that FDs 0, 1, and 2 always exist. Bionic
only currently guarantees this for AT_SECURE programs (eg, a setuid
binary, setgid binary, filesystem capabilities, or SELinux domain
transition).

Extending this to all exec()s adds robustness against this class of
bugs. Additionally, it allows a caller to do:

  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);

and know that the exec()d process will reopen these file descriptors on
its own. This has the potential to simplify other parts of Android, eg
https://android-review.googlesource.com/c/platform/system/apex/+/915694

Steps to reproduce:

  sleep 100 <&- >&- 2>&- & BGPID=$! && ls -la /proc/$BGPID/fd && kill $BGPID

Expected:

  $ sleep 100 <&- >&- 2>&- & BGPID=$! && ls -la /proc/$BGPID/fd && kill $BGPID
  [1] 3154
  total 0
  dr-x------ 2 shell shell  0 1970-04-17 12:15 .
  dr-xr-xr-x 9 shell shell  0 1970-04-17 12:15 ..
  lrwx------ 1 shell shell 64 1970-04-17 12:15 0 -> /dev/null
  lrwx------ 1 shell shell 64 1970-04-17 12:15 1 -> /dev/null
  lrwx------ 1 shell shell 64 1970-04-17 12:15 2 -> /dev/null
  $
  [1] + Terminated           \sleep 100 <&- >&- 2>&-

Actual:

  $ sleep 100 <&- >&- 2>&- & BGPID=$! && ls -la /proc/$BGPID/fd && kill $BGPID
  [1] 16345
  total 0
  dr-x------ 2 shell shell 0 2019-02-28 20:22 .
  dr-xr-xr-x 9 shell shell 0 2019-02-28 20:22 ..
  $
  [1] + Terminated           \sleep 100 <&- >&- 2>&-

Test: manual (see above)
Change-Id: I3e05700a1e8ebc7fc9d192211dd9fc030cc40139
2019-02-28 13:06:07 -08:00
Elliott Hughes
6b65e07809 Merge "Log when malloc functions fail." 2019-02-27 01:37:35 +00:00
Elliott Hughes
a21f6cca06 Log when malloc functions fail.
This shouldn't happen often, and resulting failures can be hard to debug.

From the bionic unit tests now:

  W libc    : malloc(18446744073709551615) failed: returning null pointer
  W libc    : calloc(18446744073709551615, 100) failed: returning null pointer
  W libc    : calloc(1, 18446744073709551615) failed: returning null pointer
  W libc    : calloc(18446744073709551615, 18446744073709551615) failed: returning null pointer
  W libc    : calloc(2, 18446744073709551615) failed: returning null pointer
  W libc    : calloc(18446744073709551615, 2) failed: returning null pointer
  W libc    : memalign(4096, 18446744073709551615) failed: returning null pointer
  W libc    : realloc(0x0, 18446744073709551615) failed: returning null pointer
  W libc    : realloc(0x75d7526070, 18446744073709551615) failed: returning null pointer
  W libc    : reallocaray(0x0, 9223372036854775812, 2) failed: returning null pointer
  W libc    : reallocaray(0x0, 2, 9223372036854775812) failed: returning null pointer

Bug: http://b/12821450
Test: ran tests
Change-Id: Ib176814404f4ba1297416dd3e1edd721bf59aeed
2019-02-26 12:22:38 -08:00
Yi Kong
e65558a0a4 Merge changes I070d3a26,Ie9176587
* changes:
  Turn on XOM for libm
  Switch libm to libcrt.builtins
2019-02-23 02:16:08 +00:00
Christopher Ferris
68e4f49c06 Merge "Fix wrong variable reference." 2019-02-23 01:38:27 +00:00
Yi Kong
1ac113dc6b Turn on XOM for libm
Test: bionic-unit-tests
Bug: 122993571
Bug: 123241361
Change-Id: I070d3a2627ee64124ff415a646ddfbcc767b54d1
2019-02-22 14:03:15 -08:00
Yi Kong
e3d90de50b Switch libm to libcrt.builtins
After switching libm from libgcc to libcrt.builtins, some of the symbols
are no longer getting included in libm, causing the compiler to complain
about missing symbols from the version script. Explicitly export them in
libc (since libm depends on libc).

Bug: 122993571
Test: m checkbuild
Test: bionic-unit-tests
Change-Id: Ie91765874d20df605f557b1a8c4236619553c549
2019-02-22 13:33:15 -08:00
Christopher Ferris
503c17bae7 Fix wrong variable reference.
Bug: 125891203

Test: Verify that setting the program property to "" doesn't trigger
Test: heapprofd.
Change-Id: Id27cbb92c7a120d02151e29be993f369230c2de8
2019-02-22 12:47:23 -08:00
Treehugger Robot
58239d0020 Merge "Revert "Revert "Turn on XOM for libc""" 2019-02-22 20:46:27 +00:00
Jeffrey Vander Stoep
dced8138d8 Revert "Revert "Turn on XOM for libc""
This reverts commit d119269c1c.

Reason for revert: b/124792601 fixed

Change-Id: I8603231042b0e70772fc174f5493db4ef0587323
Test: bionic-unit-tests
Bug: 122993569
Bug: 123241361
2019-02-21 23:13:52 +00:00
Dan Albert
5e15f34c50 Merge "Make static ifunc resolvers optional." 2019-02-21 21:14:09 +00:00
Treehugger Robot
7cdbd0d477 Merge "linker: allow using reserved space for multiple libraries." 2019-02-21 16:06:17 +00:00
Torne (Richard Coles)
efbe9a5eef linker: allow using reserved space for multiple libraries.
Introduce a new flag ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE which
instructs the linker to use the reserved address space to load all of
the newly-loaded libraries required by a dlopen() call instead of only
the main library. They will be loaded consecutively into that region if
they fit. The RELRO sections of all the loaded libraries will also be
considered for reading/writing shared RELRO data.

This will allow the WebView implementation to potentially consist of
more than one .so file while still benefiting from the RELRO sharing
optimisation, which would otherwise only apply to the "root" .so file.

Test: bionic-unit-tests (existing and newly added)
Bug: 110790153
Change-Id: I61da775c29fd5017d9a1e2b6b3757c3d20a355b3
2019-02-20 17:29:36 -05:00