Commit graph

2411 commits

Author SHA1 Message Date
Josh Gao
ba40ff657f Don't filter reserved signals in sigaction.
If a signal handler is blocking all of their signals, we should
probably respect that and not silently unblock bionic's reserved
signals for them. Otherwise, user code can deadlock, run out of stack,
etc. through no fault of their own, if one of the reserved signals
comes in while they've pivoted onto their signal stack.

Bug: http://b/122939726
Test: treehugger
Change-Id: I6425a3e7413edc16157b35dffe632e1ab1d76618
2019-01-24 13:21:18 -08:00
Ryan Savitski
ecc37e3877 conditional zygote child heap profiling + android_internal_mallopt
On user builds, heapprofd should only be allowed to profile apps that
are either debuggable, or profileable (according to the manifest). This
change exposes extra zygote-specific knowledge to bionic, and makes the
dedicated signal handler check for the special case of being in a zygote child.

With this & the corresponding framework change, we should now be
handling the 4 combinations of:
  {java, native} x {profile_at_runtime, profile_at_startup}.

See internal go/heapprofd-java-trigger for further context.

Test: on-device unit tests (shared & static) on blueline-userdebug.
Test: flashed blueline-userdebug, confirmed that java profiling activates from startup and at runtime.
Bug: 120409382
Change-Id: Ic251afeca4324dc650ac1d4f46976b526eae692a
(cherry picked from commit 998792e2b6)
Merged-In: Ic251afeca4324dc650ac1d4f46976b526eae692a
2019-01-23 18:30:54 +00:00
Ryan Prichard
e4ee12f813 Add tests for static ELF TLS
Bug: http://b/78026329
Test: bionic unit tests
Merged-In: I806f2bd193998dfe352372476104876edb27aebf
Change-Id: I806f2bd193998dfe352372476104876edb27aebf
2019-01-18 22:44:55 +00:00
Ryan Prichard
c85a8823ca Merge "Turn off XOM on libnstest_root.so" 2019-01-18 21:44:27 +00:00
Elliott Hughes
0159b64aa5 Allow more leeway to fix sys_time.gettimeofday flakiness.
Bug: http://b/121156651
Test: ran tests
Change-Id: Ieb8ee481ea3572533823e6cb0eab4ec089a38e44
2019-01-18 08:20:55 -08:00
Ryan Prichard
cd4e5ba559 Turn off XOM on libnstest_root.so
The dlext.ns_anonymous test copies the loaded segments of this shared
object into a new mapping, so every segment must be readable. Turn off
eXecute-Only-Memory.

Bug: http://b/123034666
Test: bionic-unit-tests --gtest_filter=dlext.ns_anonymous
Change-Id: I2d427feb81d353e0403c7ef251a55afb4d8729b4
2019-01-18 01:15:44 -08:00
Ryan Prichard
9a238653c1 Merge changes Ia08e1b5c,I60e589dd,Ib7edb665,Ibf1bf5ec,Ibd623857
* changes:
  Handle R_GENERIC_TLS_TPREL relocations
  Avoid a dlopen abort on an invalid TLS alignment
  Initialize static TLS memory using module list
  Record TLS modules and layout static TLS memory
  StaticTlsLayout: add exe/tcb and solib layout
2019-01-17 23:10:51 +00:00
Treehugger Robot
1f6adf5863 Merge "Allow more leeway to fix time.clock_gettime flakiness." 2019-01-17 22:15:33 +00:00
Martijn Coenen
de70b72b4f Merge "Update getpwnam() tests to correctly handle new app zygote uids." 2019-01-17 20:49:19 +00:00
Elliott Hughes
8dff0bb66b Allow more leeway to fix time.clock_gettime flakiness.
Bug: http://b/121156651
Test: ran tests
Change-Id: Ic949763e56c46f05ed2565ca4465a15c7ecf768c
2019-01-17 12:32:32 -08:00
Martijn Coenen
f9d2299ee2 Update getpwnam() tests to correctly handle new app zygote uids.
The UID range [90000..98999] is used for isolated processes that are
spawned from an application zygote. Otherwise they are identical to
regular isolated processes in the [99000..99999] range. Fix the tests to
match the new range.

Bug: 111434506
Test: atest bionic-unit-tests-static
Change-Id: Id0352f2cf0d21edb04d95f01ea2548e95b62317a
2019-01-17 13:36:47 +01:00
Ryan Prichard
fb8730d495 Handle R_GENERIC_TLS_TPREL relocations
This relocation is used for static TLS's initial-exec (IE) accesses.

A TLS symbol's value is its offset from the start of the ELF module's
TLS segment. It doesn't make sense to add the load_bias to this value,
so skip the call to soinfo::resolve_symbol_address.

Allow TLS relocations to refer to an unresolved weak symbol. In that case,
sym will be non-zero, but lsi will be nullptr. The dynamic linker resolves
the TPREL relocation to 0, making &missing_weak_symbol equal the thread
pointer.

Recognize Gold-style relocations to STB_LOCAL TLS symbols/sections and
issue an error.

Remove the "case R_AARCH64_TLS_TPREL64", because the R_GENERIC_TLS_TPREL
case handles it.

Remove the no-op R_AARCH64_TLSDESC handler. It's better to issue an error.
dlopen_library_with_ELF_TLS now fails with a consistent error about an
unimplemented dynamic TLS relocation.

Bug: http://b/78026329
Test: bionic unit tests (elftls tests are added in a later CL)
Change-Id: Ia08e1b5c8098117e12143d3b4ebb4dfaa5ca46ec
2019-01-17 00:45:55 -08:00
Ryan Prichard
073fffde09 Provide a stub aeabi.read_tp on other archs
Using "#if defined(...)" inside the test body seems to be the convention.

Bug: none
Test: bionic-unit-tests
Change-Id: Icb348a1184e630c5e199129bbe2090fd1e490fa5
2019-01-16 01:11:26 -08:00
Ryan Prichard
45d1349c63 Reorganize static TLS memory for ELF TLS
For ELF TLS "local-exec" accesses, the static linker assumes that an
executable's TLS segment is located at a statically-known offset from the
thread pointer (i.e. "variant 1" for ARM and "variant 2" for x86).
Because these layouts are incompatible, Bionic generally needs to allocate
its TLS slots differently between different architectures.

To allow per-architecture TLS slots:
 - Replace the TLS_SLOT_xxx enumerators with macros. New ARM slots are
   generally negative, while new x86 slots are generally positive.
 - Define a bionic_tcb struct that provides two things:
    - a void* raw_slots_storage[BIONIC_TLS_SLOTS] field
    - an inline accessor function: void*& tls_slot(size_t tpindex);

For ELF TLS, it's necessary to allocate a temporary TCB (i.e. TLS slots),
because the runtime linker doesn't know how large the static TLS area is
until after it has loaded all of the initial solibs.

To accommodate Golang, it's necessary to allocate the pthread keys at a
fixed, small, positive offset from the thread pointer.

This CL moves the pthread keys into bionic_tls, then allocates a single
mapping per thread that looks like so:
 - stack guard
 - stack [omitted for main thread and with pthread_attr_setstack]
 - static TLS:
    - bionic_tcb [exec TLS will either precede or succeed the TCB]
    - bionic_tls [prefixed by the pthread keys]
    - [solib TLS segments will be placed here]
 - guard page

As before, if the new mapping includes a stack, the pthread_internal_t
is allocated on it.

At startup, Bionic allocates a temporary bionic_tcb object on the stack,
then allocates a temporary bionic_tls object using mmap. This mmap is
delayed because the linker can't currently call async_safe_fatal() before
relocating itself.

Later, Bionic allocates a stack-less thread mapping for the main thread,
and copies slots from the temporary TCB to the new TCB.
(See *::copy_from_bootstrap methods.)

Bug: http://b/78026329
Test: bionic unit tests
Test: verify that a Golang app still works
Test: verify that a Golang app crashes if bionic_{tls,tcb} are swapped
Merged-In: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3
Change-Id: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3
(cherry picked from commit 1e660b70da)
2019-01-11 15:34:22 -08:00
Treehugger Robot
98564b8c74 Merge changes from topic "move_bionic_to_apex"
* changes:
  Expose more symbols temporarily
  Add stubs variants for bionic libs
2019-01-11 16:59:15 +00:00
Ryan Prichard
45024fefe7 Add ARM EABI function __aeabi_read_tp
By default, Clang uses this arm32 function to read the thread pointer,
either for ELF TLS or via __builtin_thread_pointer(). It's probably better
to inline the cp15 access using -mtp=cp15, but that's not the default yet.

See https://reviews.llvm.org/D34878?id=114573.

Bug: http://b/78026329
Test: bionic unit tests
Change-Id: I93b8926075f0b2cea8df9ef518d54f2820a8ff5b
2019-01-07 20:30:35 -08:00
Jiyong Park
c45fe9f7bd Add stubs variants for bionic libs
Bionic libs are part of the runtime APEX (com.android.runtime). In order
to be able to update the runtime APEX independetly from the platform, we
have to prevent things outside of the APEX from using bionic symbols
that are not guaranteed to be stable. Otherwise, platform could break
when a symbol is removed from the libs via the APEX update.

To achive this goal, this change adds stubs variant to the bionic libs.
With this, things outside of the runtime APEX (i.e. other APEXes and the
platform) are built with the stubs variants that provide only the
symbols that are guaranteed to be stable.

The set of symbols are basically the same as the symbols available to
NDK clients. However, there are a few additional symbols that are not
available for NDK but should be made available for platform components.
They are marked with "# apex" tag. Symbols with that tag are not exposed
to apps (via NDK stubs) or vendors (via LLNDK stubs).

Note that the stubs is a build-time only artifact. It is used just to
break the build when private symbols are used outside of the runtime
APEX. At runtime, the real library in the APEX is used.

Bug: 120266448
Test: m
Test: m bionic-unit-tests
Change-Id: I7b8d75830c81d7d7d54e2fca21a85b3417531b47
2019-01-04 22:29:36 +09:00
Chih-hung Hsieh
07468a811e Merge "Fix/suppress bionic google-explicit-constructor warnings" 2019-01-02 22:29:13 +00:00
Chih-Hung Hsieh
770032ddfa Fix/suppress bionic google-explicit-constructor warnings
* Add explicit to conversion constructors/operators

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Id1ad0327c1b8c6f094bcbb3ae599bc1f716b3f2f
2019-01-02 11:04:05 -08:00
Ryan Prichard
76e7fd4e26 Fix modify_stack_protector flake
The previous test would fail to crash if the first byte of the canary was
already NUL (1 of 256 runs assuming uniform canary distribution).

Bug: http://b/121156651
Test: bionic unit tests
2019-01-01 19:46:41 -08:00
Elliott Hughes
727a6ebcfb Merge "Make stdlib.getloadavg more resiliant." 2018-12-19 01:33:36 +00:00
Elliott Hughes
910a2a83a4 Fix sys_prctl.pr_cap_ambient.
This test didn't clear errno before testing it, so was sensitive to
whatever code had run before. Since I'd already added the code to dump
the exact kernel version before realizing the actual bug, I've left that
in too.

Bug: http://b/121156651
Test: ran tests
Change-Id: I38482036cb6f035c0c98c27eb64d17829f29b09a
2018-12-18 15:19:40 -08:00
Elliott Hughes
72a54a41a7 Make stdlib.getloadavg more resiliant.
Using rint(3) gave us a step where if one side was 1.4 and the other
was 1.5, that would be 1 and 2 respectively. So instead use a simple
difference. Also log more detail in case this doesn't fix the flakiness.

Bug: http://b/121156651
Test: ran tests
Change-Id: Ib5b2eb05d2b1eb8c4a10b182a8703510a3ef0cea
2018-12-18 14:47:25 -08:00
Elliott Hughes
0dafa8a3a5 Increase 2ms to 5ms to reduce flake.
Bug: http://b/121156651
Test: ran tests
Change-Id: Ief699cacf920b144bf66821cf0ac73930fae9274
2018-12-17 16:04:45 -08:00
Chih-Hung Hsieh
c2edae3f86 Fix cert-dcl16-c clang-tidy warnings in tests.
Bug: 120614316
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-dcl16-c
Change-Id: I2606dc4cdfff9c2691ed60d529971e16adb3a9ae
2018-12-11 15:16:24 -08:00
Ryan Prichard
5a66490e3b Use shared globals so getauxval works earlier
Make getauxval() work in .preinit_array. It still won't be usable for
ifuncs unless we can guarantee that the __loader_shared_globals relocation
is resolved before the ifunc calls [__bionic_]getauxval.

Define __bionic_getauxval for use in replacing calls to
KernelArgumentBlock::getauxval, which doesn't (and sometimes isn't allowed
to) access TLS variables like errno.

Bug: http://b/25751302
Test: bionic unit tests
Change-Id: I461feeaed7f43cfa2a2b6c34147194f0df82b516
Merged-In: I461feeaed7f43cfa2a2b6c34147194f0df82b516
(cherry picked from commit bdab4a2b97)
2018-12-04 13:51:46 -08:00
Elliott Hughes
eebf5fddf3 Reduce strerror(3)'s impact on .data.rel.ro.
Test: tests pass
Change-Id: I60b15dfac6ca7dce45f4858ad10b8255e2f1b66d
2018-12-03 08:46:21 -08:00
Ryan Prichard
48b1159bb8 Use shared globals to init __progname + environ
Initialize the __progname and environ global variables using
libc_shared_globals rather than KernelArgumentBlock.

Also: suppose the linker is invoked on an executable:

    linker prog [args...]

The first argument passed to main() and constructor functions is "prog"
rather than "linker". For consistency, this CL changes the BSD
__progname global from "linker" to "prog".

Bug: none
Test: bionic unit tests
Change-Id: I376d76953c9436706dbc53911ef6585c1acc1c31
2018-11-28 14:26:14 -08:00
Christopher Ferris
7f92fbe064 Merge "Add test for mallinfo." 2018-11-27 02:33:15 +00:00
Peter Collingbourne
8d849ffbad Merge "Allocate a small guard region around the shadow call stack." 2018-11-19 20:44:03 +00:00
Peter Collingbourne
734beec3d4 Allocate a small guard region around the shadow call stack.
This lets us do two things:

1) Make setjmp and longjmp compatible with shadow call stack.
   To avoid leaking the shadow call stack address into memory, only the
   lower log2(SCS_SIZE) bits of x18 are stored to jmp_buf. This requires
   allocating an additional guard page so that we're guaranteed to be
   able to allocate a sufficiently aligned SCS.

2) SCS overflow detection. Overflows now result in a SIGSEGV instead
   of corrupting the allocation that comes after it.

Change-Id: I04d6634f96162bf625684672a87fba8b402b7fd1
Test: bionic-unit-tests
2018-11-16 14:37:08 -08:00
Christopher Ferris
09a19aa0e7 Add test for mallinfo.
Bug: 119580449

Test: Test passes.
Change-Id: Ib605e550b7d6d8fd2336ad61b678a7e63f8ecffb
2018-11-16 13:34:36 -08:00
Elliott Hughes
ae471db4a9 Merge "Make android_get_application_target_sdk_version available to the NDK." 2018-11-15 23:04:41 +00:00
Elliott Hughes
c0f4656452 Make android_get_application_target_sdk_version available to the NDK.
Also move this and android_get_device_api_level into <android/api-level.h>
so that they're always available.

This involves cleaning up <sys/cdefs.h> slightly.

Bug: N/A
Test: builds
Change-Id: I25435c55f3549cd0d827a7581bee75ea8228028b
2018-11-15 11:07:30 -08:00
Mark Salyzyn
ba1a723ad1 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I664fb32522d01909c603d7b903475c4e9aea9223
2018-11-14 15:46:49 -08:00
Elliott Hughes
8359068064 Merge "Move API levels from uint32_t to int." 2018-11-14 19:50:59 +00:00
Elliott Hughes
ff1428a48e Move API levels from uint32_t to int.
(cherrypick of a6c71a09670ca636cca5cfea9d74b03a951e2b5e.)

Bug: N/A
Test: builds
Change-Id: I9c414e30e3c4fe2a4e16a2fe4ce18eae85fe4844
2018-11-13 21:25:07 -08:00
Mark Salyzyn
68a3bcc249 bionic tests: switch to using android-base/file.h for TemporaryFile
A matching definition of TemporaryFile exists in libbase now.

Test: compile
Bug: 119313545
Change-Id: I6f84dbf3af9a9c4b270a2532a36c9cb4c0f6bb8f
2018-11-13 10:57:28 -08:00
Yi Kong
d495e0b777 Merge "Don't build bionic-unit-tests-static with libcrt_builtins" 2018-11-08 18:23:56 +00:00
Yi Kong
b011d59a7f Don't build bionic-unit-tests-static with libcrt_builtins
libcrt_builtins does not work with libm, which is statically linked in
bionic-unit-tests-static. Opt it out of libcrt_builtins for now.

Bug: 119207651
Bug: 117167374
Test: run bionic-unit-test-static
Change-Id: I20067c9841beb9de2b73342847aaa945dbadbff8
2018-11-08 05:33:15 +00:00
Elliott Hughes
52d7749335 Merge "ART isn't using the ART-specific linker features any more." 2018-11-08 03:09:53 +00:00
Christopher Ferris
6689b4f258 Merge "Add a force fail for non-bionic xfail test." 2018-11-08 03:01:34 +00:00
Christopher Ferris
af1b8ddaa9 Add smoke tests for mallopt options.
Test: Unit tests pass.
Change-Id: If213f4338078011ff12996c1b2a6f6858b51d824
2018-11-07 17:11:42 -08:00
Christopher Ferris
01db9bde05 Add a force fail for non-bionic xfail test.
Test: xfail test passes on host.
Change-Id: I6c4ddd3f3dc5541b126d9dd31b1fcff9d34819e6
2018-11-07 14:39:43 -08:00
Treehugger Robot
5e099173da Merge "Revert "Do not use clang lld with -z,global"" 2018-11-07 21:43:24 +00:00
Evgenii Stepanov
acd6f4f9f5 Disable a few bionic tests under HWASan.
* HWASan report invalid use of the allocator api (like alignment not
being power of two, or allocation size too large) in a way tests do not
expect.
* Code in .preinit_array runs before HWASan shadow is initialized and
needs to be excluded from instrumentation.
* It looks that mm system calls (mmap/mprotect/etc) will not allow
tagged pointers. In fact, the use of mprotect on malloc()ed memory is
doubtful - one can imagine some kind of speculative load from such
memory, as compiler knows that it is addressable.

Bug: 114279110
Test: bionic-unit-tests with hwasan

Change-Id: I6ba4b46a0d554de77c923ad134cf156ce4ddba1b
2018-11-06 16:59:25 -08:00
Evgenii Stepanov
96bd339c51 Remove timer_delete_multiple test.
According to posix, this test invokes undefined behavior by deleting
a timer twice.

According to hwasan, the second call to timer_delete loads
kernel_timer_id from previously deallocated PosixTimer (i.e.
heap-use-after-free).

Bug: 114279110
Test: bionic-unit-tests with hwasan

Change-Id: Ic54579e3bb41d3f38282b8822dafaba51efd003a
2018-11-06 16:59:21 -08:00
Chih-hung Hsieh
08a0cd082f Revert "Do not use clang lld with -z,global"
This reverts commit 8e462d411a.

Reason for revert: this lld bug has been fixed upstream and in AOSP prebuilts

Bug: 80109858
Change-Id: Ied600324201e1a014a1d4e6742767e2ddd94999a
2018-11-07 00:12:56 +00:00
Elliott Hughes
8178c417f6 ART isn't using the ART-specific linker features any more.
Bug: N/A
Test: ran tests
Change-Id: Ide3c295035687019608a2c4716a4a21cb889d121
2018-11-06 11:15:17 -08:00
Christopher Ferris
9ffd39cdea Merge "Add test for malloc_iterate." 2018-11-02 15:20:54 +00:00