Commit graph

2383 commits

Author SHA1 Message Date
Treehugger Robot
37bea4ec73 Merge "Revert^3 "[MTE] remap stacks with PROT_MTE when requested by dlopened library"" into main am: 469568b94a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2957057

Change-Id: Iaa45c5c3038467fbbeaab93d51e96dd11707c6bb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-15 00:22:54 +00:00
Treehugger Robot
469568b94a Merge "Revert^3 "[MTE] remap stacks with PROT_MTE when requested by dlopened library"" into main 2024-02-14 23:48:49 +00:00
Elliott Hughes
976f598cf3 Merge "Fix sysconf(_SC_NGROUPS_MAX)." into main am: b28adb35bd
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2962906

Change-Id: Id7759b3ebaee591c886c680bd4b14db08654bbb1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-14 21:38:18 +00:00
Elliott Hughes
6995b4ae5c Merge "Move three legacy .c files to .cpp." into main am: 5a1f29e6cf
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2962068

Change-Id: Iba01335f37b4f7abbbdd248143fe9b5c315b35f7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-14 21:37:55 +00:00
Elliott Hughes
b28adb35bd Merge "Fix sysconf(_SC_NGROUPS_MAX)." into main 2024-02-14 21:17:29 +00:00
Elliott Hughes
5a1f29e6cf Merge "Move three legacy .c files to .cpp." into main 2024-02-14 20:55:50 +00:00
Florian Mayer
f53e91cc81 Revert^3 "[MTE] remap stacks with PROT_MTE when requested by dlopened library"
This reverts commit a453c2df74.

Reason for revert: b/324568991

Bug: 324568991
Change-Id: Ia6250ebe51c505bd4b77af2b4ff4e95c8b370acd
2024-02-14 18:50:42 +00:00
Florian Mayer
ff5de237b4 Merge "Add API to allow apps to attach extra information to tombstones." into main am: 50f4d83960
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2955867

Change-Id: I7c8fa3892054dc4c069583c5bce8bbc674c61ab5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-14 17:40:42 +00:00
Elliott Hughes
b3877437cd Fix sysconf(_SC_NGROUPS_MAX).
The previous implementation wasn't wrong (it returned the "maximum
maximum"), but we can return the actual runtime value from the kernel.

Noticed while looking at initgroups().

Test: treehugger
Change-Id: I891fe4ff29bd82ee05d9e05ed8299d32c21abd7f
2024-02-13 16:48:30 -08:00
Elliott Hughes
17e4068bda Move three legacy .c files to .cpp.
Test: treehugger
Change-Id: Ic22896d25881fe35f28bad53c5412e3e1d4b2661
2024-02-13 16:36:11 -08:00
Florian Mayer
7c83d09679 Add API to allow apps to attach extra information to tombstones.
Test: atest debuggerd_test
Bug: 155462331
Bug: 309446525
Change-Id: Idc8387307738957dbba3daaae59f605566329f0f
2024-02-13 13:41:12 -08:00
Florian Mayer
5b44bc316a Merge "Reland "[MTE] remap stacks with PROT_MTE when requested by dlopened library"" into main am: a732e2aef5
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2955914

Change-Id: I91f22862517b6c3b41893ac913a282a600a9f398
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-09 05:15:16 +00:00
Florian Mayer
a732e2aef5 Merge "Reland "[MTE] remap stacks with PROT_MTE when requested by dlopened library"" into main 2024-02-09 04:35:03 +00:00
Florian Mayer
a453c2df74 Reland "[MTE] remap stacks with PROT_MTE when requested by dlopened library"
This reverts commit c20e1c2bdf.

Reason for revert: Was not the root-cause of test failure.

Change-Id: I7dcd9fc3cbac47703fa8ecd5aafd7e1c3ed87301
2024-02-09 00:40:45 +00:00
Florian Mayer
e8ea440525 Merge "Revert "[MTE] remap stacks with PROT_MTE when requested by dlopened library"" into main am: cebe1f1351
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2954775

Change-Id: I6a49c246c2415e6ae6c676d129f7d917b47bdf92
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-08 19:30:28 +00:00
Florian Mayer
cebe1f1351 Merge "Revert "[MTE] remap stacks with PROT_MTE when requested by dlopened library"" into main 2024-02-08 18:47:42 +00:00
Sojin Moon
c20e1c2bdf Revert "[MTE] remap stacks with PROT_MTE when requested by dlopened library"
This reverts commit 79c9694c91.

Reason for revert: DroidMonitor: Potential culprit for Bug b/324348078 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Change-Id: I32f7bc824900e18a7d53b025ffe3aaef0ee71802
2024-02-08 07:21:15 +00:00
Kalesh Singh
653bf2a743 Merge changes Ie770320e,I32c05cce,Ia7cb2f40 into main am: 41ed53fac6
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2948920

Change-Id: Id2b075604fa8832f1f4b9729599a28a2276cac87
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-07 20:19:59 +00:00
Kalesh Singh
41ed53fac6 Merge changes Ie770320e,I32c05cce,Ia7cb2f40 into main
* changes:
  bionic: linker_phdr: Introduce kPageSize
  bionic: Introduce ElfReader::ReadPadSegmentNote()
  bionic: Refactor __get_elf_note()
2024-02-07 19:28:40 +00:00
Elliott Hughes
63eb28c589 Merge "Remove treble_linker_namespaces." into main am: aa19eae4c2
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2951946

Change-Id: Icbbd2e8ccac65eb8e69e972258c385edb780b802
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-07 16:47:55 +00:00
Elliott Hughes
aa19eae4c2 Merge "Remove treble_linker_namespaces." into main 2024-02-07 16:05:57 +00:00
Kalesh Singh
f0050fb015 bionic: Refactor __get_elf_note()
Factor out generic __get_elf_note() logic and rename __get_elf_note() to
__find_elf_note(). Expose __get_elf_note() in libc/private/bionic_note.h

This will be used in the subsequent patch to test the presence of
NT_ANDROID_TYPE_PAD_SEGMENT note when loading segments.

Test: atest -c linker-unit-tests [Later patch]
Test: m && launch_cvd
Bug: 316403210
Change-Id: Ia7cb2f40b10cfaef402182a675087c8422b37e4d
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-06 17:58:40 -08:00
Florian Mayer
f252b3fda6 Merge "[MTE] remap stacks with PROT_MTE when requested by dlopened library" into main am: ba5630cede
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2901508

Change-Id: I23578f32fb295e96f6f074f00952e72dd3d9640e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-06 17:00:26 +00:00
Florian Mayer
ba5630cede Merge "[MTE] remap stacks with PROT_MTE when requested by dlopened library" into main 2024-02-06 16:16:03 +00:00
Florian Mayer
79c9694c91 [MTE] remap stacks with PROT_MTE when requested by dlopened library
BYPASS_INCLUSIVE_LANGUAGE_REASON="man" refers to manual not person

Bug: 318749472
Test: atest pthread on MTE enabled device
Test: atest memtag_stack_dlopen_test on MTE enabled device
Test: manual with NDK r26b built app with fsanitize=memtag-stack
Change-Id: Iac191c31b87ccbdc6a52c63ddd22e7b440354202
2024-02-05 18:17:24 -08:00
Elliott Hughes
ddd6bf1bfe Remove treble_linker_namespaces.
This is hard-coded on now.

Bug: http://b/67975799
Test: treehugger
Change-Id: Ifcf79ee3be1917827bbced40359a9f98ff5e7fd9
2024-02-06 00:29:40 +00:00
Treehugger Robot
7995a74a3d Merge "NFC: remove unnecessary branching" into main am: 8e631624e9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2940087

Change-Id: I436a3a87b36753b944fc1a95e18b3f5d83e0d071
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-01 20:19:01 +00:00
Florian Mayer
d541611c77 NFC: remove unnecessary branching
Change-Id: Iac82f1fdc30261be262810de0d86369f0071044f
2024-01-31 23:09:39 +00:00
Xin Li
d70a5f022c Merge Android 24Q1 Release (ab/11220357)
Bug: 319669529
Merged-In: I884a78b67679c1f0b90a6c0159b17ab007f8cc60
Change-Id: Ie7928dbaee63c4e4d4b4f3854017933cbc3072a3
2024-01-29 10:10:43 -08:00
Elliott Hughes
20a3661d6c Clarify which architectures do/don't need sa_restorer.
In particular: 32-bit x86 doesn't need sa_restorer either.

I still don't fully understand why arm32 and x86-64 do, so I've left the
comments in those .S files alone. I haven't (knowingly) tested
compiler-rt since we switched from libgcc (which is what the comments
refer to), but I have tested libunwindstack since we switched from
libunwind, and that does fail existing bionic tests for unwinds through
signal frames --- I just don't know why, or whether there's a better fix.

Anyway, local testing suggests that the 32-bit x86 code is vestigial, so
let's get rid of it.

Test: treehugger
Change-Id: I3e2616f736d27a8463814356e5adb52fd76a90cc
2024-01-24 14:25:00 -08:00
Ryan Prichard
72507e4ed5 WriteProtected: std::atomic<T> is no longer POD
std::atomic<T>'s default constructor is no longer trivial, because it
now does value-initialization. As a result, the class is no longer
trivial, so libc_globals is no longer trivial, so it is no longer POD.
(FWIW, the "POD" notion has been deprecated in favor of "trivial" and
"standard layout" concepts: POD == trivial + stdlayout.)

See https://cplusplus.github.io/LWG/issue2334 and wg21.link/p0883r2.

Mark __libc_globals as constinit, because that seems closer to
something we actually care about, AFAICT.

Bug: http://b/175635923
Test: m libc_malloc_debug
Change-Id: I338589bce03d06f20752bca342eeb86a42fc1ee7
2024-01-08 15:17:35 -08:00
Elliott Hughes
4fe4f10069 Merge "Microoptimize the strtol() family." into main 2024-01-02 21:26:41 +00:00
Andy Hung
46f0ddb29f Merge "bionic: fix pthread_mutex_timedlock for PI mutexes" into main 2023-12-14 17:52:55 +00:00
Andy Hung
5e19b185fd bionic: fix pthread_mutex_timedlock for PI mutexes
FUTEX_LOCK_PI uses CLOCK_REALTIME so adjust clock timebase
accordingly.

FUTEX_WAIT_BITSET, FUTEX_WAIT_REQUEUE_PI, FUTEX_LOCK_PI2
are updated to check the presence of FUTEX_CLOCK_REALTIME flag.

Test: atest bionic-unit-tests
Bug: 312787238
Bug: 315897315
Change-Id: I2d93286cf22d3b3d9f3757d49b46f7ee9ea5490c
2023-12-13 12:10:50 -08:00
Elliott Hughes
ca89b33108 Microoptimize the strtol() family.
The main change here is to remember that we arm64/x86-64 have flags, and
__builtin_<op>_overflow() lets us look at them. There's a clear saving
for arm64, and x86-64 is better too, though interestingly there the
unsigned case doesn't work out as well as the signed case because both
unsigned __builtin_mul_overflow and unsigned __builtin_add_overflow are
less efficient than the signed multiply and subtract on that
architecture, but the new code still beats the old code even so.

There's a very tiny microoptimization of the hex path that takes
advantage of the fact that conversion to lowercase is a single
instruction on all our architectures when we already know we're dealing
with a letter.

This also merges the signed and unsigned variants of the code. Not
entirely successfully, but the vast majority of the code benefits.

Before (arm64):
```
----------------------------------------------------------------
Benchmark                      Time             CPU   Iterations
----------------------------------------------------------------
BM_inttypes_strtoimax       44.6 ns         44.3 ns     15807654
BM_inttypes_strtoumax       43.1 ns         42.8 ns     16348848
BM_stdlib_strtol            44.6 ns         44.3 ns     15805384
BM_stdlib_strtol_hex        85.5 ns         85.0 ns      8235487
BM_stdlib_strtoll           44.5 ns         44.2 ns     15833137
BM_stdlib_strtoul           43.1 ns         42.8 ns     16353963
BM_stdlib_strtoul_hex       83.1 ns         82.6 ns      8477732
BM_stdlib_strtoull          43.1 ns         42.8 ns     16353015
```

After (arm64):
```
----------------------------------------------------------------
Benchmark                      Time             CPU   Iterations
----------------------------------------------------------------
BM_inttypes_strtoimax       37.9 ns         37.6 ns     17657577
BM_inttypes_strtoumax       35.9 ns         35.7 ns     19597727
BM_stdlib_strtol            36.9 ns         36.7 ns     19093037
BM_stdlib_strtol_hex        70.7 ns         70.3 ns      9961626
BM_stdlib_strtoll           36.9 ns         36.7 ns     19093032
BM_stdlib_strtoul           35.9 ns         35.7 ns     19617784
BM_stdlib_strtoul_hex       67.7 ns         67.3 ns     10113521
BM_stdlib_strtoull          35.9 ns         35.7 ns     19621828
```

Test: treehugger
Change-Id: Ibf53b29e34d63ac31520c6d27ef80ff281899d61
2023-12-13 10:46:42 -08:00
Elliott Hughes
94c2369f4a Merge "Microoptimize vdso lookup." into main am: 18a6fa2d2f am: ad27b8618e am: e4ceb066c3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2871814

Change-Id: Ia737938236828928f5a88a1e9cfd21b16265386f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-13 17:30:41 +00:00
Elliott Hughes
cbcccd53eb Microoptimize vdso lookup.
Actually reusing the hash table stuff from the linker would be a lot of
work (and the benefit unclear for so few symbols), but we can at least
break out of loops as soon as we have what we need.

Test: treehugger
Change-Id: I9cbe4636a3e3163bd302c3676eb674a4278dbf2e
2023-12-12 15:13:03 -08:00
Florian Mayer
7e52c94edc Merge "Plumb scudo_stack_depot_size to debuggerd_process_info" into main am: 7fdb49f129 am: cbc2c8859f am: 62691e69d9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2858031

Change-Id: I22c12ca855ca68310466132940f5bb52a8881674
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-12 00:48:46 +00:00
Florian Mayer
7fdb49f129 Merge "Plumb scudo_stack_depot_size to debuggerd_process_info" into main 2023-12-11 23:38:13 +00:00
Evgenii Stepanov
cd0c908065 Merge changes from topic "revert-2709995-VVPYYBKIHY" into main am: 73a867a203 am: 3f54874625 am: 76a20d12f3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2862867

Change-Id: Iaeda56f0cb0a6f3fc21dcb10f26bc3fb5f78e647
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-07 03:38:50 +00:00
Evgenii Stepanov
73a867a203 Merge changes from topic "revert-2709995-VVPYYBKIHY" into main
* changes:
  Revert "Linker support for MTE globals."
  Revert "Add a memtag-globals test to bionic"
2023-12-07 01:36:49 +00:00
Elliott Hughes
2cbd262cf1 Merge "riscv64: pass a pointer to __riscv_hwprobe() to ifunc resolvers." into main am: 75539ab928 am: 978c235f51 am: 53adad316c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2860689

Change-Id: I86a97139f856341ab257b5092b72e00abf2b0bed
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-06 20:27:53 +00:00
Elliott Hughes
f70a74d1a5 Merge "arm32 __bionic_call_ifunc_resolver: let the compiler handle initialization." into main am: 20738af50e am: c4ad7fa2fb am: 507dbf28b9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2860690

Change-Id: Ia9e6e2af1b5d6251428326905004fe0d16e45635
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-06 19:15:12 +00:00
Evgenii Stepanov
6bbb75aa77 Revert "Linker support for MTE globals."
Revert submission 2709995

Reason for revert: linker crash in soinfo::apply_relr_reloc

Reverted changes: /q/submissionid:2709995

Bug: 314038442
Change-Id: I2c6ad7f46fb1174f009253602ad08ceb36aa7d71
2023-12-06 19:01:46 +00:00
Elliott Hughes
4d06786ea8 arm32 __bionic_call_ifunc_resolver: let the compiler handle initialization.
I don't think we need this, and we're not doing it for the equivalent
code in riscv64. So either we do need it, and this will help us find out
quicker and make the corresponding riscv64 change, or we don't need it,
and this is a free cleanup.

Test: treehugger
Change-Id: Ie97492ea8bb4d1bc69f926980d9d4db798884285
2023-12-06 00:39:17 +00:00
Elliott Hughes
561e804ffb riscv64: pass a pointer to __riscv_hwprobe() to ifunc resolvers.
This way, callees don't need to worry about whether or not their
reference to __riscv_hwprobe() has been resolved before their ifunc
resolver is called.

This matches the current glibc proposal from rivos.

Test: treehugger
Change-Id: I0d5244aa837d0d1f0e6bd7d22091dfedb8a55bdb
2023-12-05 16:31:59 -08:00
Florian Mayer
af06759667 Plumb scudo_stack_depot_size to debuggerd_process_info
This is a no-op but will be used in upcoming scudo changes that allow to
change the depot size at process startup time, and as such we will no
longer be able to call __scudo_get_stack_depot_size in debuggerd.

We already did the equivalent change for the ring buffer size in
https://r.android.com/q/topic:%22scudo_ring_buffer_size%22

Bug: 309446692
Change-Id: Icdcf4cd0a3a486d1ea07a8c616cae776730e1047
2023-12-04 16:49:35 -08:00
Mitch Phillips
7734bbfc48 Merge changes I2fc4fc9d,Id7b1a925 into main am: 456ce1e7ce am: dd504fc03a am: a41c2c0646
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2709995

Change-Id: I16a166cb9e31b3555ae75954b83f50647ac2ea5b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-28 11:29:39 +00:00
Mitch Phillips
456ce1e7ce Merge changes I2fc4fc9d,Id7b1a925 into main
* changes:
  Add a memtag-globals test to bionic
  Linker support for MTE globals.
2023-11-28 09:31:57 +00:00
Mitch Phillips
e8139f585a Linker support for MTE globals.
This patch adds the necessary bionic code for the linker to protect
global data using MTE.

The implementation is described in the MemtagABI addendum to the
AArch64 ELF ABI:
https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst

In summary, this patch includes:

1. When MTE globals is requested, the linker maps writable SHF_ALLOC
   sections as anonymous pages with PROT_MTE (copying the file contents
   into the anonymous mapping), rather than using a file-backed private
   mapping. This is required as file-based mappings are not necessarily
   backed by the kernel with tag-capable memory. For sections already
   mapped by the kernel when the linker is invoked via. PT_INTERP, we
   unmap the contents, remap a PROT_MTE+anonymous mapping in its place,
   and re-load the file contents from disk.

2. When MTE globals is requested, the linker tags areas of global memory
   (as defined in SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC) with random tags,
   but ensuring that adjacent globals are never tagged using the same
   memory tag (to provide detemrinistic overflow detection).

3. Changes to RELATIVE, ABS64, and GLOB_DAT relocations to load and
   store tags in the right places. This ensures that the address tags are
   materialized into the GOT entries as well. These changes are a
   functional no-op to existing binaries and/or non-MTE capable hardware.

Bug: N/A
Test: atest bionic-unit-tests CtsBionicTestCases --test-filter=*Memtag*

Change-Id: Id7b1a925339b14949d5a8f607dd86928624bda0e
2023-11-20 15:53:06 +01:00