Commit graph

9699 commits

Author SHA1 Message Date
Christopher Ferris
c5d3a4348a Make tls related header files platform accessible.
There are places in frameworks and art code that directly included
private bionic header files. Move these files to the new platform
include files.

This change also moves the __get_tls.h header file to tls.h and includes
the tls defines header so that there is a single header that platform
code can use to get __get_tls and the defines.

Also, simplify the visibility rules for platform includes.

Bug: 141560639

Test: Builds and bionic unit tests pass.
Change-Id: I9e5e9c33fe8a85260f69823468bc9d340ab7a1f9
Merged-In: I9e5e9c33fe8a85260f69823468bc9d340ab7a1f9
(cherry picked from commit 44631c919a)
2019-09-27 12:14:24 -07:00
Balaram Makam
0e670e26a2 ASCII fastpath for towupper and towlower.
This change elides unnecessary calls to __find_icu_symbol
for ASCII chars and improves PUBG mobile game loading time by 7% on
hikey620(Cortex-A53):

name                old time/op  new time/op  delta
PUBG_0.13.0_Launch   41.5s ± 2%   37.7s ± 3%  -9.24%  (p=0.008 n=5+5)

Below are the bionic benchmark results on a Pixel 2 XL for 64-bit,
showing a large speedup for ASCII and only a small slowdown for non-ASCII.

Before:

  BM_wctype_towlower_ascii_n         10.5 ns         10.4 ns     61973065
  BM_wctype_towlower_ascii_y         10.2 ns         10.2 ns     70158659
  BM_wctype_towlower_unicode_n       10.3 ns         10.3 ns     67719478
  BM_wctype_towlower_unicode_y       10.6 ns         10.5 ns     67841545
  BM_wctype_towupper_ascii_n         10.8 ns         10.8 ns     63456778
  BM_wctype_towupper_ascii_y         10.9 ns         10.9 ns     65116910
  BM_wctype_towupper_unicode_n       10.7 ns         10.7 ns     67463276
  BM_wctype_towupper_unicode_y       10.4 ns         10.4 ns     66467890

After:

  BM_wctype_towlower_ascii_n         3.35 ns         3.34 ns    205567652
  BM_wctype_towlower_ascii_y         3.30 ns         3.29 ns    214108746
  BM_wctype_towlower_unicode_n       10.9 ns         10.8 ns     65007743
  BM_wctype_towlower_unicode_y       10.6 ns         10.6 ns     63819060
  BM_wctype_towupper_ascii_n         3.53 ns         3.53 ns    195944444
  BM_wctype_towupper_ascii_y         3.48 ns         3.48 ns    199233248
  BM_wctype_towupper_unicode_n       11.1 ns         11.1 ns     62760216
  BM_wctype_towupper_unicode_y       11.0 ns         11.0 ns     61608872

Test: bionic unit tests on device
Test: bionic benchmarks on device
Signed-off-by: Balaram Makam <b.makam@samsung.com>
Change-Id: I77ab7efb66d7bcb35d00467663607535e5c1992f
2019-09-27 16:41:03 +00:00
John Cater
e86e505b85 Fix gensyscalls.py to actually use the input argument provided in
bionic/libc/Android.bp.

Test: Built and tested bionic.
Change-Id: Ibb25990b2b1b5c18edfdaaab4f1593fa8d95f338
2019-09-26 15:02:04 -04:00
Evgeny Eltsin
8a18af52d9 Make more pthread functions weak for native bridge
These are using __pthread_internal_*.

Test: run bionic-unit-tests on cuttlefish
Change-Id: Idbb2503f03bd9f1f2a20fced34b734f573c1c0ad
2019-09-25 16:55:47 +02:00
Elliott Hughes
1db8fdb76e Merge "Remove global seccomp list." 2019-09-18 18:10:13 +00:00
Elliott Hughes
fa43309a59 Merge "ifuncs: start sharing." 2019-09-18 18:01:54 +00:00
Elliott Hughes
ae03b12925 Remove global seccomp list.
Never used, and incompatible with having bionic in a mainline module.

Test: builds
Change-Id: If377f66cc105fd3a1ec4d9c92330fa6a2d2c145c
2019-09-17 16:37:05 -07:00
Treehugger Robot
e6c3f0628c Merge "fortify: account for new clang diagnostics" 2019-09-17 20:11:51 +00:00
Elliott Hughes
a4c7876c01 ifuncs: start sharing.
We're going to have to add ifuncs to libm, and there will be some SVE
ones for arm64 soon too, so let's start sharing the absolute minimum...

Test: builds
Change-Id: Idbb9dd9477291ed3c15dc3902f65e593b766dfb9
2019-09-17 12:44:41 -07:00
George Burgess IV
36926f4ca8 fortify: account for new clang diagnostics
Clang recently grew its own diagnostics for memcpy and such. These are
generally higher-quality than what we can do with diagnose_if, since
clang is happy to include e.g., sizes of things per-callsite. Move to
those instead where applicable.

Bug: 131861088, 123644155
Test: blueline internal-master checkbuild; treehugger
Change-Id: I701f5a8b247ba2948ca47fdc60ff5198b564c03e
2019-09-16 12:48:04 -07:00
Christopher Ferris
2b0638ef29 Make bionic_malloc.h a platform header.
Instead of having platform directories directly include the
private header, create a platform header directory and export it.

Bug: 130763340

Test: Builds.
Change-Id: Ie0f092b3fe077a3de8b90266c0b28bfbc20d0dfa
Merged-In: Ie0f092b3fe077a3de8b90266c0b28bfbc20d0dfa
(cherry picked from commit 8f582ef2f8)
2019-09-16 12:27:33 -07:00
Ryan Prichard
85be9725c7 crtbegin: replace TPREL with R_*_NONE relocs
Bug: https://bugs.llvm.org/show_bug.cgi?id=41527
Test: bionic unit tests
Change-Id: Ia66c969b209c0f72d1e37573949f3fb59817ca71
2019-09-04 20:31:06 +00:00
Christopher Ferris
e2c10d8de0 Merge "Update to kernel headers v5.2.11." 2019-09-04 19:44:24 +00:00
Treehugger Robot
d0494b368e Merge "Test for ns_parserr() and got a heap-buffer-overflow" 2019-09-04 02:21:43 +00:00
Logan Chien
2fb9a03b9c Merge "versioner: Fix bzero/bcopy fortify" 2019-09-03 23:12:43 +00:00
Christopher Ferris
e892fd6b17 Update to kernel headers v5.2.11.
Test: Build and boots on taimen.
Test: Bionic unit tests all pass on taimen.
Change-Id: I80abb6f9abbff9ca20ce6c7c912a259b5ca86fa2
2019-09-03 15:56:49 -07:00
Elliott Hughes
37ff081e88 Merge "Support statvfs on API levels before 19." 2019-09-03 22:28:36 +00:00
Christopher Ferris
add3a4ae70 Merge "Add EFD_SEMAPHORE flag for eventfd." 2019-09-03 19:16:55 +00:00
Christopher Ferris
2c4cb0d760 Add EFD_SEMAPHORE flag for eventfd.
Add a test for the new flag and add a test for the EFD_CLOEXEC flag.

Test: New unit tests pass on glibc and target.
Change-Id: Ib7a6ea4aadbd67ba8a523b6114a49fb8d6a43f12
2019-09-03 09:35:51 -07:00
Logan Chien
8292d04da5 Merge "versioner: Fix C11 threads.h" 2019-09-03 16:22:02 +00:00
Logan Chien
b33952c777 versioner: Fix bzero/bcopy fortify
This commit replaces `bzero` with `__bionic_bzero` and `bcopy` with
`__bionic_bcopy` because `bzero` and `bcopy` are partially defined in
`libc.map.txt`.  Bionic versioner raises errors because versioner treats
static inline functions as exported function definitions then it
compares the availability with the information specified in
`libc.map.txt`.

This commit fixes the problem by replacing static inline functions into
`__bionic_{bzero,bcopy}` and defining aliases for source-level
compatibility.

Test: PATH=$(pwd)/prebuilts/clang-tools/linux-x86/bin:$PATH \
      bionic/tools/versioner/run_tests.py
Bug: 140110040

Change-Id: I97f2f0dc0abccd0a9fcfe5bb02f4e918362d35cc
2019-08-30 10:17:36 -07:00
Elliott Hughes
261bd745ee Support statvfs on API levels before 19.
Split statfs and statvfs. The former has been available forever, and the
latter is implemented in terms of the former. The implementation has
been moved into headers so that it can be used at low API levels.

There's no reason for any Android or Linux code to use statvfs rather
than statfs, but code that needs to build on Darwin too will want to use
statvfs because Darwin's statfs is very spartan.

Bug: https://github.com/android-ndk/ndk/issues/609
Test: treehugger
Change-Id: Icf3d5723a260099fddb2d9f902e3047b0f041647
2019-08-29 21:57:58 -07:00
Logan Chien
235aad1981 versioner: Fix C11 threads.h
This commit annotates C11 Thread APIs so that bionic versioner won't
report errors.

This commit also adds a guard before `mtx_timedlock` because
`pthread_mutex_timedlock` was introduced in Android L.

Test: PATH=$(pwd)/prebuilts/clang-tools/linux-x86/bin:$PATH \
      bionic/tools/versioner/run_tests.py
Bug: 140110040

Change-Id: I3c6ce0831f613ffd3a7bf1c1972fd3548195cc56
2019-08-29 16:40:34 -07:00
Martin Stjernholm
6d5277dbaa Update references to the new com.android.art APEX.
Test: Flash & boot
Test: atest CtsJniTestCases CtsBionicTestCases
Bug: 135753770
Exempt-From-Owner-Approval: Approved internally
Change-Id: I1c16a798edc494e75b9d703990de08e60686a3ea
Merged-In: I1c16a798edc494e75b9d703990de08e60686a3ea
2019-08-29 18:07:50 +01:00
chenbruce
2cc76462e5 Test for ns_parserr() and got a heap-buffer-overflow
In ns_name_skip of ns_name.c, there is a possible out of bounds read due to
a missing bounds check. This could lead to remote denial of service with no
additional execution privileges needed. User interaction is not needed for
exploitation.

Bug: 137346580
Test: built, flashed, booted
Test: ns_parserr_fuzzer test
Change-Id: Ib023bd9b2ae97795d64195de9922a6a32d7b2f37
2019-08-29 22:18:37 +08:00
Ryan Savitski
9db3486a12 Add arm32 case to BIONIC_STOP_UNWIND to correctly stop unwinders
The arm32 case was omitted when the macro was originally added due to
clang issues (b/15469122#comment5).

Testing at ToT master, ".cfi_undefined r14" appears to compile & work as
expected. This is the same directive as used by the linker's begin.S.

Test: ran a 32 bit binary on crosshatch-userdebug, verified that
"debuggerd -b" (which uses libunwindstack) stops at __libc_init as in
the arm64 case (before it would unwind past _start_main, with an
erroneous frame at the bottom).

Test: ran unwind_reg_info tool on /system/lib/libc.so with an address
within __libc_init, confirmed that the "debug_frame" section includes
"r14 = undefine" (arm exidx still contains "r14 = [cfa - 4]", but that
looked correct to cferris@).

Bug: 140008396
Change-Id: I6eb0bc6cf516fddee2df40492350678a0547fee3
2019-08-27 22:50:21 +01:00
Vic Yang
f1fde773e1 Move __dso_handle to RELRO
Most DSOs have a RELRO segment, but some of them have nothing except
__dso_handle in their .data section.  This means __dso_handle is taking
up a page as well as a vm_area_struct in kernel slabs for those DSOs.

Let's move it to the RELRO segment to save memory.

On a 32-bit device I tested on, I saw ~400 KB less slab usage on
vm_area_struct.  To control for difference in number of cached
processes, I also measured with Android stopped, and I saw ~100 KB less
slab usage.  Summing up all dirty pages attributed to shared libraries,
I saw 5.6 MB less dirty pages.

Test: Build and boot.
Change-Id: Ib88e49f1c72352e610affc19623895d954110d4e
2019-08-26 20:35:00 -07:00
Ryan Prichard
665e98edf7 Merge "Add additional dl_phdr_info fields" 2019-08-23 20:45:54 +00:00
Ryan Prichard
a2e83ab348 Add additional dl_phdr_info fields
Previously, Bionic's dl_phdr_info only included the first four
dl_iterate_phdr fields. Several other libc's have these additional fields:

    unsigned long long dlpi_adds -- incremented when a library is loaded
    unsigned long long dlpi_subs -- incremented when a library is unloaded
    size_t dlpi_tls_modid -- TLS module ID
    void* dlpi_tls_data -- pointer to current thread's TLS block or NULL

These extra fields are also exposed by glibc, musl, and FreeBSD. The
unwinder in libgcc.a, linked into shipping Android DSOs, has a
PC->eh_frame cache that activates if dl_phdr_info has the dlpi_adds and
dlpi_subs fields (indicated at run-time by a sufficiently-large size
argument to the callback).

Bug: https://github.com/android-ndk/ndk/issues/1062
Test: bionic unit tests
Change-Id: I6f0bab548cf8c828af2ddab9eb01c5c6d70cd81f
2019-08-22 12:43:17 -07:00
Treehugger Robot
74e56438bb Merge "Link libc++demangle." 2019-08-21 23:54:48 +00:00
Treehugger Robot
28cf07f93d Merge "Reland "fdsan: make fatal by default."" 2019-08-21 07:57:28 +00:00
Josh Gao
6a51013728 Reland "fdsan: make fatal by default."
The two tests known to be failing (installd_dexopt_test and BpfMapTest)
have been fixed, so let's try this again.

This reverts commit 76351e3e3f.

Bug: http://b/137788030
Bug: http://b/139092341
Bug: http://b/139175951
Test: treehugger
2019-08-20 17:59:14 -07:00
Elliott Hughes
f69d852f27 Automatically include <android/ndk-version.h> from every header.
(Via <sys/cdefs.h>, which is where we get <android/api-level.h> from.)

Not super helpful today, but when NDK r21 is the oldest NDK anyone cares
about, they'll be able to stop worrying about this specific header as
long as they've included _something_.

Test: builds
Change-Id: Ia5bc42f89b7025d8e3963e4fd590f0e3723157be
2019-08-20 13:18:57 -07:00
Peter Collingbourne
3952113d90 Merge "Fix a few bionic test failures caused by hwasan global instrumentation." 2019-08-16 17:26:05 +00:00
Peter Collingbourne
191ecdc49b Fix a few bionic test failures caused by hwasan global instrumentation.
The call to the load hook needs to be moved before the call to link_image()
because the latter calls ifunc resolvers which might access global
variables. This fixes a bunch of ifunc tests.

The dlfcn.segment_gap test is currently failing. One problem is that the name
of the .bss.end_of_gap section changes as a result of global instrumentation.
Add some wildcards in so that we match both names. The other problem seems
to be the same as b/139089152.

It turns out that we need to untag pointers in a few more places. Since we have
quite a few of these now it seems worth creating a function for it.

Test: bionic-unit-tests
Change-Id: I44e2b0904faacdda7cc0c5e844ffc09de01dea2d
2019-08-15 09:21:34 -07:00
Treehugger Robot
2fbbc253f6 Merge "Fix OOB read in fortify str[np]cpy implementations found by hwasan." 2019-08-15 05:26:43 +00:00
Tom Cherry
a960142fe3 Fix timespec.h documentation
There are 1,000,000,000 nanoseconds in a second.

Test: n/a
Change-Id: I8ce622ce3c60d7d5b06a056cfd0e6bea976b5aab
2019-08-12 13:34:03 -07:00
Pete Gillin
c6c17ac1e8 Merge "Revert "fdsan: make fatal by default."" 2019-08-09 11:29:36 +00:00
Pete Gillin
76351e3e3f Revert "fdsan: make fatal by default."
This reverts commit 66b5e3ca19.

Reason for revert: Causes installd_dexopt_test to fail. Presumably there is an existing issue which this change is turning into a hard fail, so that needs to be fixed before this can be rolled forwards. See b/139092341.

Bug: 139092341
Bug: 137788030
Change-Id: I1beccddff64c86541bc003b9b009f4046ec9cbf1
2019-08-09 11:18:39 +00:00
Peter Collingbourne
a51bded572 Fix OOB read in fortify str[np]cpy implementations found by hwasan.
The fortify implementations of stpncpy and strncpy read out of bounds and
only then check that they did so. This causes newer versions of hwasan
to complain during the fortify tests as a result of the new support for
byte-precise error checks. Move the bounds check into the loop so that it
is detected before the load.

Test: bionic-unit-tests
Change-Id: Id990a4a0217f6c4b39bba60ff41776875615fcb4
2019-08-08 18:54:31 -07:00
Tom Cherry
5dea560e4c Merge "Remove now unneeded #undef in __cxa_guard.cpp" 2019-08-07 23:04:50 +00:00
Josh Gao
592b5f52fd Merge "fdsan: make fatal by default." 2019-08-07 19:53:40 +00:00
Josh Gao
66b5e3ca19 fdsan: make fatal by default.
Make fdsan fatal by default on native processes, and Java processes that
target R or later.

Bug: http://b/137788030
Test: manual
Change-Id: I5900efc606fc0d47b69223574ad7dca89afe4eda
2019-08-07 19:53:14 +00:00
Tom Cherry
08baac348c Remove now unneeded #undef in __cxa_guard.cpp
Before aosp/1086558, this was needed, since we would have
_USING_LIBCXX defined, yet <atomic> was not available, so we'd run
into compiler issues.  After that change, we're using
__has_include(<atomic>) so this is no longer an issue.

Test: build
Change-Id: Ia81d343000e7d90f07422120fc1e1eb5becb01aa
2019-08-07 11:10:22 -07:00
Elliott Hughes
da32ff104b Merge "Add memfd_create(2) and mlock2(2)." 2019-08-06 17:08:13 +00:00
Christopher Ferris
5d3ba4ed9d Merge "Update to kernel headers v5.2.6." 2019-08-06 04:30:52 +00:00
Peter Collingbourne
6533208aaa linker: Add library load and unload hooks for HWASan.
These hooks notify the HWASan runtime library whenever a library is loaded
or unloaded so that it can update its shadow memory.

Bug: 138159093
Test: walleye_hwasan-userdebug boots with+without https://reviews.llvm.org/D65770
Change-Id: I6caf2a6540ed2c0d94db444e806a3c7ba504cabb
2019-08-05 16:51:01 -07:00
Elliott Hughes
3d24d2b088 Add memfd_create(2) and mlock2(2).
These are old enough now that the latest devices will have kernels that
support them.

Also add basic doc comments to <sys/mman.h>.

Test: treehugger
Change-Id: I1b5ff5db0b6270f5c374287cac1d6a751a0259f5
2019-08-05 16:31:08 -07:00
Christopher Ferris
fa59a10bcd Update to kernel headers v5.2.6.
Also, fix a bug in update_all.py when the syscalls file does not change.

Test: Builds and boots on a taimen.
Change-Id: If85b00daef2c176f804a0861894f5bbca9c6d5df
2019-08-05 12:59:58 -07:00
Elliott Hughes
9a5bdd6d45 Update seccomp whitelist.
renameat2 is now exposed, my comment about timerfd was nonsense, and
it's worth documenting when and where the various syscalls appeared.

Bug: http://b/127675384
Test: treehugger
Change-Id: I84662398d39678df3ee7ce39add670337ff8abea
2019-08-05 08:56:40 -07:00