Commit graph

36110 commits

Author SHA1 Message Date
Christopher Ferris
442544d7b4 Merge "Fix possible nullptr dereference." 2022-02-04 00:22:00 +00:00
Pirama Arumuga Nainar
c5418b3eca Merge "Annotate fortify functions with diagnose_as_builtin" am: 37b3d9d705 am: 6ede8410e3 am: 20e85d1d31
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1940574

Change-Id: Ic9812ef9b3542695f88c49c655bd681fa3bb2043
2022-02-04 00:13:15 +00:00
Pirama Arumuga Nainar
20e85d1d31 Merge "Annotate fortify functions with diagnose_as_builtin" am: 37b3d9d705 am: 6ede8410e3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1940574

Change-Id: I64428709d1d1cb83b4892671a72217517750cf1a
2022-02-04 00:01:00 +00:00
Pirama Arumuga Nainar
6ede8410e3 Merge "Annotate fortify functions with diagnose_as_builtin" am: 37b3d9d705
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1940574

Change-Id: I009bb77a29027326ad0da077ac97dec089b0c33c
2022-02-03 23:41:57 +00:00
Pirama Arumuga Nainar
37b3d9d705 Merge "Annotate fortify functions with diagnose_as_builtin" 2022-02-03 23:24:14 +00:00
Pirama Arumuga Nainar
db71defb66 Annotate fortify functions with diagnose_as_builtin
Bug: http://b/197147102
Bug: http://b/214080353

With https://reviews.llvm.org/D77491, clang got stricter when issuing
diagnostics regarding builtin functions.
https://reviews.llvm.org/D112024 adds a diagnose_as_builtin attribute
which lets it diagnose builtins even though their signature is slightly
different.  This patch adds diagnose_as_builtin attribute as needed.

Versioner is built with an older clang so it doesn't recognize this
attribute.  So this is added with a preprocessor check on clang
versions.  We can remove the version check once versioner gets updated
shortly after the compiler update.

Test: mmma bionic/tests with clang-r445002
Change-Id: I3d0d63ecdbea0cffe97eb5110e2d9f2a7595a38e
2022-02-03 11:53:52 -08:00
Colin Cross
fdced95e45 Enable mallinfo tests for musl
We've added mallinfo and mallinfo2 to musl, enable the bionic tests
for it.  Also modify the comparison test to explicitly cast the
mallinfo fields to size_t, as they are ints in musl.

Bug: 190084016
Test: bionic-unit-tests-glibc --gtest_filter=malloc.*
Change-Id: Ib2a1d6cf698de817c314a61fe29fda85edabb9ed
2022-02-03 11:08:30 -08:00
Christopher Ferris
d49ad1e39b Fix possible nullptr dereference.
Test: Unit tests pass.
Change-Id: I046c6e1665de4d941362e2f65605609e77731c97
2022-02-02 17:56:48 -08:00
Colin Cross
daa6b82edf Fix bionic benchmarks and header tests for musl
Fix references to symbols that don't exist in musl in the bionic
benchmarks, and disable the header tests for musl.

Bug: 190084016
Test: m USE_HOST_MUSL=true host-native
Change-Id: I6b1964afa4a7b6e6a4812e9f2605fcfc2fae9691
2022-02-02 12:36:39 -08:00
Eric Miao
fbee3177af Keep allocation of tail_ outside of LinkedList
This change is to allocate `head_` and `tail_` outside of LinkedList
and only keep a readonly pointer there. By doing this, all updates
of the list touches memory other than the LinkedList itself, thus
preventing copy-on-write pages being allocated in child processes
when the list changes.

The other approach is to make the LinkedList a singly-linked list,
however, that approach would cause a full list traversal to add
one item to the list. And preliminary number shows there are ~60K
calls to `soinfo::add_secondary_namespace` during Android bootup
on a wembley device, where a singly-linked approach could be
hurting performance.

NOTE: the header is allocated and initialized upon first use instead
of being allocated in the constructor, the latter ends up in crash.
This is likely caused by static initialization order in the linker,
e.g. g_soinfo_list_allocator is a static object, and if this linked
list is embedded into some other static objects, there's no guarantee
the allocator will be available.

Bug: http://b/206889551
Test: bionic-unit-tests
Change-Id: Ic6f053881f85f9dc5d249bb7d7443d7a9a7f214f
2022-02-01 21:32:30 -08:00
Florian Mayer
2b1f55294f Merge "Fix HWASan crashes in heapprofd initialization." am: 8266380c77 am: a58dd462b1 am: c8089fdc1d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1965516

Change-Id: I01a1c142ace390e42d915e97b2074fb9f02ac590
2022-02-01 21:29:57 +00:00
Florian Mayer
c8089fdc1d Merge "Fix HWASan crashes in heapprofd initialization." am: 8266380c77 am: a58dd462b1
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1965516

Change-Id: I42a4b6c9b05c35cdee3b792468b9b003a2626b0d
2022-02-01 21:13:17 +00:00
Florian Mayer
a58dd462b1 Merge "Fix HWASan crashes in heapprofd initialization." am: 8266380c77
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1965516

Change-Id: Id5d5c1c934955a7e756c81bb67c30fbd8a299589
2022-02-01 20:51:15 +00:00
Florian Mayer
8266380c77 Merge "Fix HWASan crashes in heapprofd initialization." 2022-02-01 20:30:25 +00:00
Florian Mayer
6c1c3422a2 Fix HWASan crashes in heapprofd initialization.
Test: atest perfetto_integrationtests on HWASan build

Bug: 210588740
Change-Id: Iddaa4a7d0dedee541f97bbf0a13958de023bdf59
2022-02-01 17:10:32 +00:00
Treehugger Robot
94c1039259 Merge "Silence -Wnon-power-of-two-alignment for a test" am: 650233457a am: 64a42f33ed am: b6761c1350
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1964751

Change-Id: I5bbc9cbc70d612b729e18bfa1ea03f81493207e4
2022-01-29 01:53:30 +00:00
Treehugger Robot
b6761c1350 Merge "Silence -Wnon-power-of-two-alignment for a test" am: 650233457a am: 64a42f33ed
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1964751

Change-Id: I8272f0800ff3ae1b54dcd2e540d228e4a1c7dec2
2022-01-29 01:38:34 +00:00
Treehugger Robot
64a42f33ed Merge "Silence -Wnon-power-of-two-alignment for a test" am: 650233457a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1964751

Change-Id: I465c037c5bae18733229b1b66ccdda98663d4e4d
2022-01-29 01:20:23 +00:00
Treehugger Robot
650233457a Merge "Silence -Wnon-power-of-two-alignment for a test" 2022-01-29 01:04:50 +00:00
Pirama Arumuga Nainar
44dd9facb2 Silence -Wnon-power-of-two-alignment for a test
Bug: http://b/214080353

The wrong alignment to aligned_alloc() is deliberate.  Silence the
warning around the test.

Test: build with clang-r445002
Change-Id: I73bad7775423c908c2bbe1c550e8ce5aeede129d
2022-01-28 13:27:07 -08:00
Daniele Di Proietto
788a73221a Merge "Fix recursive deadlock inside bionic_systrace" am: f7e721cdc9 am: deb0f9972a am: 9ebbba014a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1958831

Change-Id: I26eb7c09a9cb3c8438ac4c913a6e44b56faec9df
2022-01-27 00:00:14 +00:00
Daniele Di Proietto
9ebbba014a Merge "Fix recursive deadlock inside bionic_systrace" am: f7e721cdc9 am: deb0f9972a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1958831

Change-Id: Ieeba1b3014200bd1fc4491e36d94c65c40ca5f81
2022-01-26 23:49:59 +00:00
Daniele Di Proietto
deb0f9972a Merge "Fix recursive deadlock inside bionic_systrace" am: f7e721cdc9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1958831

Change-Id: I5404720d7dccfc9779fd6fd81f71af23b18fdec4
2022-01-26 23:34:02 +00:00
Daniele Di Proietto
f7e721cdc9 Merge "Fix recursive deadlock inside bionic_systrace" 2022-01-26 23:12:27 +00:00
Daniele Di Proietto
f5f04b19fe Fix recursive deadlock inside bionic_systrace
The first time should_trace() returns true, bionic_trace_begin() calls
open() on trace_marker.

The problem is that open() can call bionic_trace_begin(). We've observed
this happening, for example when:

* fdtrack is enabled. dlopen("libfdtrack.so") can be used to enable
  fdtrack on a process.
* ThreadA is busy unwinding inside fdtrack and is holding an fdtrack
  internal mutex.
* ThreadB calls bionic_trace_begin() for the first time since the
  property "debug.atrace.tags.enableflags" contains ATRACE_TAG_BIONIC.
* ThreadB calls open("/sys/kernel/tracing/trace_marker"). Since fdtrack
  is enabled, ThreadB tries to do unwinding as well.
* ThreadB, inside fdtrack's unwinding tries to grab the same mutex that
  ThreadA is holding.
* Mutex contention is reported using bionic_systrace, therefore
  bionic_trace_begin() is called again on ThreadB.
* ThreadB tries to grab g_lock in bionin_systrace.cpp, but that's
  already held by ThreadB itself, earlier on the stack. Therefore
  ThreadB is stuck.

I managed to reproduce the above scenario by manually pausing ThreadA
inside unwinding with a debugger and letting ThreadB hitting
bionic_trace_begin() for the first time.

We could avoid using g_lock while calling open() (either by releasing
g_lock and reacquiring it later, or by using atomics), but
bionic_trace_begin() would try to call open() again. In my tests, open()
does not call bionic_trace_begin() a third time, because fdtrack has
reentrancy protection, but there might be another code path inside open
that calls bionic_trace_begin again (it could be racy or only happen in
certain configurations).

This commit fixes the problem by implementing reentrancy protection in
bionic_systrace.

Sample callstack from ThreadA deadlocked before the fix:
```
  * frame #0: 0x0000007436db077c libc.so`syscall at syscall.S:41
    frame #1: 0x0000007436db0ba0 libc.so`bionic_trace_begin(char const*) [inlined] __futex(ftx=0x000000743737a548, op=<unavailable>, value=2, timeout=0x0000000000000000, bitset=-1) at bionic_futex.h:45:16
    frame #2: 0x0000007436db0b8c libc.so`bionic_trace_begin(char const*) [inlined] __futex_wait_ex(ftx=0x000000743737a548, value=2) at bionic_futex.h:66:10
    frame #3: 0x0000007436db0b78 libc.so`bionic_trace_begin(char const*) [inlined] Lock::lock(this=0x000000743737a548) at bionic_lock.h:67:7
    frame #4: 0x0000007436db0b74 libc.so`bionic_trace_begin(char const*) [inlined] should_trace() at bionic_systrace.cpp:38:10
    frame #5: 0x0000007436db0b74 libc.so`bionic_trace_begin(message="Contending for pthread mutex") at bionic_systrace.cpp:59:8
    frame #6: 0x0000007436e193e4 libc.so`NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*) [inlined] NonPI::NormalMutexLock(mutex=0x0000007296cae9f0, shared=0, use_realtime_clock=false, abs_timeout_or_null=0x0000000000000000) at pthread_mutex.cpp:592:17
    frame #7: 0x0000007436e193c8 libc.so`NonPI::MutexLockWithTimeout(mutex=0x0000007296cae9f0, use_realtime_clock=false, abs_timeout_or_null=0x0000000000000000) at pthread_mutex.cpp:719:16
    frame #8: 0x0000007436e1912c libc.so`::pthread_mutex_lock(mutex_interface=<unavailable>) at pthread_mutex.cpp:839:12 [artificial]
    frame #9: 0x00000071a4e5b290 libfdtrack.so`std::__1::mutex::lock() [inlined] std::__1::__libcpp_mutex_lock(__m=<unavailable>) at __threading_support:256:10
    frame #10: 0x00000071a4e5b28c libfdtrack.so`std::__1::mutex::lock(this=<unavailable>) at mutex.cpp:31:14
    frame #11: 0x00000071a4e32634 libfdtrack.so`unwindstack::Elf::Step(unsigned long, unwindstack::Regs*, unwindstack::Memory*, bool*, bool*) [inlined] std::__1::lock_guard<std::__1::mutex>::lock_guard(__m=0x0000007296cae9f0) at __mutex_base:104:27
    frame #12: 0x00000071a4e32618 libfdtrack.so`unwindstack::Elf::Step(this=0x0000007296cae9c0, rel_pc=66116, regs=0x0000007266ca0470, process_memory=0x0000007246caa130, finished=0x0000007ff910efb4, is_signal_frame=0x0000007ff910efb0) at Elf.cpp:206:31
    frame #13: 0x00000071a4e2b3b0 libfdtrack.so`unwindstack::LocalUnwinder::Unwind(this=0x00000071a4ea1528, frame_info=<unavailable>, max_frames=34) at LocalUnwinder.cpp:102:22
    frame #14: 0x00000071a4e2a3ec libfdtrack.so`fd_hook(event=<unavailable>) at fdtrack.cpp:119:18
    frame #15: 0x0000007436dbf684 libc.so`::__open_2(pathname=<unavailable>, flags=<unavailable>) at open.cpp:72:10
    frame #16: 0x0000007436db0a04 libc.so`bionic_trace_begin(char const*) [inlined] open(pathname=<unavailable>, flags=524289) at fcntl.h:63:12
    frame #17: 0x0000007436db09f0 libc.so`bionic_trace_begin(char const*) [inlined] get_trace_marker_fd() at bionic_systrace.cpp:49:25
    frame #18: 0x0000007436db09c0 libc.so`bionic_trace_begin(message="pthread_create") at bionic_systrace.cpp:63:25
```

Bug: 213642769
Change-Id: I10d331859045cb4a8609b007f5c6cf2577ff44df
2022-01-25 20:50:12 +00:00
Peter Collingbourne
40ad232da5 Merge changes from topic "sc-dev-I3030c47be9d02a27505bd4775c1982a20755758c-sc-v2-dev" into sc-v2-dev-plus-aosp
* changes:
  [automerged blank] Disable pointer authentication in app processes. 2p: b81b50bf2c
  Disable pointer authentication in app processes.
2022-01-25 19:26:39 +00:00
Evgenii Stepanov
8cfae0f65e Merge "Fix MemtagNoteTest and make it runnable on non-MTE devices." am: 97ec0e312b am: d474cf97f4 am: 9b37f30d06
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1957287

Change-Id: I5a08e586acb4b294b9126bf51a6fed2d03985d12
2022-01-25 19:14:05 +00:00
Evgenii Stepanov
9b37f30d06 Merge "Fix MemtagNoteTest and make it runnable on non-MTE devices." am: 97ec0e312b am: d474cf97f4
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1957287

Change-Id: I25350de3bd1dc1cebea0291eaa2a3f444dc35134
2022-01-25 18:55:49 +00:00
Evgenii Stepanov
d474cf97f4 Merge "Fix MemtagNoteTest and make it runnable on non-MTE devices." am: 97ec0e312b
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1957287

Change-Id: I0832697c3a4c7c8aa7803fb62a0d56f3f39e6d93
2022-01-25 18:42:34 +00:00
Yi Kong
aaf506a5da Merge "Move linker from sampling PGO to AFDO pipeline" am: fb946fd873 am: 92897479bb am: 4a1f39412c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1959003

Change-Id: Iedbbe3c254b319de0eff2eb50d7450a42be5782f
2022-01-25 18:42:15 +00:00
Evgenii Stepanov
97ec0e312b Merge "Fix MemtagNoteTest and make it runnable on non-MTE devices." 2022-01-25 18:27:16 +00:00
Yi Kong
4a1f39412c Merge "Move linker from sampling PGO to AFDO pipeline" am: fb946fd873 am: 92897479bb
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1959003

Change-Id: I28ae67646e700fbed0b21d784ca0f4d6d4372bf2
2022-01-25 18:23:25 +00:00
Yi Kong
92897479bb Merge "Move linker from sampling PGO to AFDO pipeline" am: fb946fd873
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1959003

Change-Id: Ic2e3cf27cad7295def30689939b8f5eb6ca70e21
2022-01-25 18:06:25 +00:00
Yi Kong
fb946fd873 Merge "Move linker from sampling PGO to AFDO pipeline" 2022-01-25 17:50:09 +00:00
Peter Collingbourne
17d479e556 [automerged blank] Disable pointer authentication in app processes. 2p: b81b50bf2c
Blank merge reason: Change-Id I3030c47be9d02a27505bd4775c1982a20755758c with SHA-1 bf52e88596 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/16712509

Bug: 212660282
Change-Id: I84a696428027b46edb2432918eab6aa300085440
2022-01-25 01:42:46 +00:00
Peter Collingbourne
b81b50bf2c Disable pointer authentication in app processes.
Unfortunately we have discovered that some applications in the wild
are using PAC instructions incorrectly. To keep those applications
working on PAC enabled devices, disable PAC in application processes
for now.

Bug: 212660282
Change-Id: I3030c47be9d02a27505bd4775c1982a20755758c
Merged-In: I3030c47be9d02a27505bd4775c1982a20755758c
2022-01-25 01:42:40 +00:00
Peter Collingbourne
ba40c147dd Merge "Disable pointer authentication in app processes." am: ccae7efeed am: 659885327f am: 63df57402e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1955116

Change-Id: Ia8d42dfbf976865bc3626c5bde8f020394ea78f2
2022-01-24 22:05:51 +00:00
Peter Collingbourne
63df57402e Merge "Disable pointer authentication in app processes." am: ccae7efeed am: 659885327f
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1955116

Change-Id: I9bb71131ecc94b3b42807022f92c7da25ebd18ac
2022-01-24 21:50:23 +00:00
Peter Collingbourne
659885327f Merge "Disable pointer authentication in app processes." am: ccae7efeed
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1955116

Change-Id: I8236ec524fc14f950e84c371346d820ddcb2b2df
2022-01-24 21:33:43 +00:00
Peter Collingbourne
ccae7efeed Merge "Disable pointer authentication in app processes." 2022-01-24 21:17:30 +00:00
Yi Kong
e20a1d9060 Move linker from sampling PGO to AFDO pipeline
Sampling PGO is being replaced by AFDO.

Test: presubmit
Change-Id: I23e4dace5f2c2d1f2499daba99a28b2a1bc0f22d
2022-01-25 03:19:58 +08:00
Evgenii Stepanov
e37ca53157 Fix MemtagNoteTest and make it runnable on non-MTE devices.
Update the path to the helper binary, and run the test on non-MTE
hardware with the expectation that the bug is not detected.

Test: bionic-unit-tests
Bug: none
Change-Id: I34eb4dc46d0bacd83824d307398f7891d4806686
2022-01-21 19:55:54 +00:00
Peter Collingbourne
bf52e88596 Disable pointer authentication in app processes.
Unfortunately we have discovered that some applications in the wild
are using PAC instructions incorrectly. To keep those applications
working on PAC enabled devices, disable PAC in application processes
for now.

Bug: 212660282
Change-Id: I3030c47be9d02a27505bd4775c1982a20755758c
2022-01-19 13:35:54 -08:00
Elliott Hughes
598ad1f6b8 Merge "libm: sync with upstream." am: b838fbda2a am: 3eaf9ab52f am: c75c0a466e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1947706

Change-Id: I7ea5100c75ede84363b8065fd044355a0abacb09
2022-01-18 23:16:12 +00:00
Elliott Hughes
c75c0a466e Merge "libm: sync with upstream." am: b838fbda2a am: 3eaf9ab52f
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1947706

Change-Id: I7b361b3b77412dd1e3b80490a1230609f206ed34
2022-01-18 22:55:21 +00:00
Elliott Hughes
3eaf9ab52f Merge "libm: sync with upstream." am: b838fbda2a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1947706

Change-Id: I28981febb0e79bad47c921024ef25e0ade9c540f
2022-01-18 22:36:00 +00:00
Elliott Hughes
b838fbda2a Merge "libm: sync with upstream." 2022-01-18 22:21:25 +00:00
Treehugger Robot
7b8c09c804 Merge "Update the status for S and T." am: 095509f80a am: 815b9e5447 am: 8fb504a69f
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1950404

Change-Id: I60b7fe6bc88f2a9b34617c52c93c9ec7b7e5c515
2022-01-16 05:37:55 +00:00
Treehugger Robot
8fb504a69f Merge "Update the status for S and T." am: 095509f80a am: 815b9e5447
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1950404

Change-Id: I10f786c00bfe1c0d1582cd5c59acc0757515d375
2022-01-16 05:20:43 +00:00
Treehugger Robot
815b9e5447 Merge "Update the status for S and T." am: 095509f80a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1950404

Change-Id: Ie2a176a93447dcedaad7d8be3051c8aed1685ae7
2022-01-16 05:02:55 +00:00