Commit graph

42606 commits

Author SHA1 Message Date
Zheng Pan
92a7e1c55c Revert "bionic: loader: Extend LOAD segment VMAs"
Revert submission 2803156-loader_crt_pad_segment

Reason for revert: b/324952273

Reverted changes: /q/submissionid:2803156-loader_crt_pad_segment

Change-Id: I8af115c426c0113914abbf8fbd3e74c0d89408d1
2024-02-14 00:04:10 +00:00
Zheng Pan
9535c32e1c Revert "bionic: loader: Extend GNU_RELRO protection"
Revert submission 2803156-loader_crt_pad_segment

Reason for revert: b/324952273

Reverted changes: /q/submissionid:2803156-loader_crt_pad_segment

Change-Id: I22d4ae1972c5de7da908eb090a2fea5565ead88b
2024-02-14 00:04:10 +00:00
Treehugger Robot
92f515bb72 Merge "llvm-readelf only accepts --headers." into main am: 704cd26c33
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2961462

Change-Id: I15a6f69b9b932b8b28856f0a4342b3d114282528
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-13 23:04:08 +00:00
Elliott Hughes
e4066859e4 Merge "Admit to another LP32 bug." into main am: 4674a3fe36
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2959270

Change-Id: I3928e3107bce86b10fd99d78678ec8f7bb8d406f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-13 23:03:32 +00:00
Treehugger Robot
704cd26c33 Merge "llvm-readelf only accepts --headers." into main 2024-02-13 22:26:51 +00:00
Elliott Hughes
4674a3fe36 Merge "Admit to another LP32 bug." into main 2024-02-13 22:24:48 +00:00
Florian Mayer
e2aefc46e7 Allow to re-use the same crash_detail.
This is for advanced use-cases that have high performance demands and
know they will repeatedly re-use the crash_detail.

Bug: 155462331
Change-Id: Ib15dac70d1d598f78b74b539aeadf88b0ca32bc7
2024-02-13 13:44:32 -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
Elliott Hughes
8e4e6f9805 llvm-readelf only accepts --headers.
GNU readelf accepts both `--header` and `--headers`, but we don't ship
that in the NDK any more, so anyone on macOS or Windows will hit this
incompatibility (even though Linux users are probably still using GNU
readelf).

Test: treehugger
Change-Id: I61eb389d4d9c0bc4f5d75ceefeb5709345299585
2024-02-13 15:25:13 +00:00
Elliott Hughes
8880cab65c Admit to another LP32 bug.
But explain why we're not going to bother fixing it.

Test: treehugger
Change-Id: Ib7358fceff10f80b9e359ea3f4d088c64d440021
2024-02-13 00:43:24 +00:00
Nick Desaulniers
2add976832 Merge "libc/Android.bp: make libc_headers visible to llvm-libc" into main am: d74f255a50
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2957803

Change-Id: Ic4dcd7b9d032cc775057b5e3cc5306d50452be26
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-12 22:03:07 +00:00
Elliott Hughes
048c52b92b Merge "libc/Android.bp: more cleanup." into main am: 16da14df14
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2956138

Change-Id: I287684dfd59d42abcc479886ceac6ace76257060
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-12 21:19:56 +00:00
Nick Desaulniers
d74f255a50 Merge "libc/Android.bp: make libc_headers visible to llvm-libc" into main 2024-02-12 21:13:33 +00:00
Elliott Hughes
16da14df14 Merge "libc/Android.bp: more cleanup." into main 2024-02-12 20:40:48 +00:00
Nick Desaulniers
942ae55dc4 libc/Android.bp: make libc_headers visible to llvm-libc
llvm-libc will reuse parts of the existing system headers for types that have
implications on the ABI.

Fixes:
    error: external/llvm-libc/Android.bp:3:1: module "llvmlibc" variant
    "android_recovery_riscv64_static": depends on //bionic/libc:libc_headers
    which is not visible to this module You may need to add
    "//external/llvm-libc" to its visibility

Test: TH
Bug: 321313756
Change-Id: I33b93d8e1617a480249641dc2cdf4bbee9f9e19d
2024-02-12 10:28:40 -08:00
Kalesh Singh
d985b390d6 Merge "bionic: ReadPadSegmentNote: Skip empty PT_NOTEs" into main am: d90d990468
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2954562

Change-Id: I559d9b791801f0fc8be16515cf2343121c389184
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-12 18:00:22 +00:00
Kalesh Singh
d90d990468 Merge "bionic: ReadPadSegmentNote: Skip empty PT_NOTEs" into main 2024-02-12 17:28:57 +00:00
Kalesh Singh
13fb3cfb23 bionic: ReadPadSegmentNote: Skip empty PT_NOTEs
Some obfuscated ELFs may containe "empty" PT_NOTEs (p_memsz == 0).
Attempting to mmap these will cause a EINVAL failure since the requested
mapping size is zero.

Skip these phrogram headers when parsing notes.

Also improve the failure log with arguments to the mmap syscall.

Test: Platinum Tests
Bug: 324468126
Change-Id: I7de4e55c6d221d555faabfcc33bb6997921dd022
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-09 16:57:49 -08:00
Treehugger Robot
fde8cd20d7 Merge "Update linker/NOTICE." into main am: 3da4f9d7ad
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2956137

Change-Id: I80f5d82d22d4818491663c8c887e12b87d3f0d70
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-09 23:47:32 +00:00
Treehugger Robot
3da4f9d7ad Merge "Update linker/NOTICE." into main 2024-02-09 23:14:27 +00:00
Elliott Hughes
69bd8e9da2 libc/Android.bp: more cleanup.
These files were segregated because they were lacking a little cleanup.
Unfortunately that means this change has to do some of the cleanup, but
that's probably for the best.

Test: treehugger
Change-Id: I2dd33504787fc3313995de99e0745a0df22915b3
2024-02-09 10:04:26 -08:00
Elliott Hughes
68b3833262 Update linker/NOTICE.
Someone's been skipping repo's preupload hooks...

Test: treehugger
Change-Id: Id5e473c883bde47da17baa7576bc0e9c045403e8
2024-02-09 09:27:33 -08:00
Elliott Hughes
8ca76a29b7 Merge "libc/Android.bp: merge libc_openbsd_ndk." into main am: e3f09effb3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2954357

Change-Id: Icb53f37f8ba36fcc93d820b4ae8b5aedaf87bbce
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-09 16:49:54 +00:00
Elliott Hughes
e3f09effb3 Merge "libc/Android.bp: merge libc_openbsd_ndk." into main 2024-02-09 16:09:54 +00: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
Kalesh Singh
b7826c5cf0 Merge changes from topic "loader_crt_pad_segment" into main am: 61a90188e5
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2803156

Change-Id: I11864554c6f64f04221fe1e3d6220537a9062876
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-09 01:22:38 +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
Kalesh Singh
61a90188e5 Merge changes from topic "loader_crt_pad_segment" into main
* changes:
  bionic: loader: Extend GNU_RELRO protection
  bionic: loader: Extend LOAD segment VMAs
2024-02-09 00:39:50 +00:00
Elliott Hughes
968adf951c libc/Android.bp: merge libc_openbsd_ndk.
Test: treehugger
Change-Id: I313f8ecc28f1d0129e2b6d65ace3b6a1e05c906a
2024-02-08 13:15:53 -08:00
Kalesh Singh
33f89709bc bionic: loader: Extend GNU_RELRO protection
If the LOAD segment VMAs are extended to prevent creating additional
VMAs, the the protection extent of the GNU_RELRO segment must also
be updated to match. Otherwise, the partial mprotect will reintroduce
an additional VMA due to the split protections.

Update the GNU_RELRO protection range when the ELF was loaded by the
bionic loader. Be careful not to attempt any fix up for ELFs not loaded
by us (e.g. ELF loaded by the kernel) since these don't have the
extended VMA fix to begin with.

Consider a system with 4KB page size and the ELF files with 64K
alignment. e.g:

$ readelf -Wl /system/lib64/bootstrap/libc.so | grep 'Type\|LOAD'

Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x0441a8 0x0441a8 R   0x10000
LOAD           0x0441b0 0x00000000000541b0 0x00000000000541b0 0x091860 0x091860 R E 0x10000
LOAD           0x0d5a10 0x00000000000f5a10 0x00000000000f5a10 0x003d40 0x003d40 RW  0x10000
LOAD           0x0d9760 0x0000000000109760 0x0000000000109760 0x0005c0 0x459844 RW  0x10000

Before this patch:

$ cat /proc/1/maps | grep -A1 libc.so

7f468f069000-7f468f0bd000 r--p 00000000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f0bd000-7f468f15e000 r-xp 00044000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f15e000-7f468f163000 r--p 000d5000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f163000-7f468f172000 rw-p 000da000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f172000-7f468f173000 rw-p 000d9000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f173000-7f468f5c4000 rw-p 00000000 00:00 0                          [anon:.bss]

1 extra RW VMA at offset 0x000da000 (3 RW mappings in total)

After this patch:

$ cat /proc/1/maps | grep -A1 libc.so

7f5a50225000-7f5a50279000 r--p 00000000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f5a50279000-7f5a5031a000 r-xp 00044000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f5a5031a000-7f5a5032e000 r--p 000d5000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f5a5032e000-7f5a5032f000 rw-p 000d9000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f5a5032f000-7f5a50780000 rw-p 00000000 00:00 0                          [anon:.bss]

Removed RW VMA at offset 0x000da000 (2 RW mappings in total)

Bug: 316403210
Bug: 300367402
Bug: 307803052
Bug: 312550202
Test: atest -c linker-unit-tests [ Later patch ]
Test: atest -c bionic-unit-tests
Change-Id: If1d99e8b872fcf7f6e0feb02ff33503029b63be3
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-08 13:07:06 -08:00
Kalesh Singh
4b4fb6f439 bionic: loader: Extend LOAD segment VMAs
When the page_size < p_align of the ELF load segment, the loader
will end up creating extra PROT_NONE gap VMA mappings between the
LOAD segments. This problem is exacerbated by Android's zygote
model, where the number of loaded .so's can lead to ~30MB increase
in vm_area_struct unreclaimable slab memory.

Extend the LOAD segment VMA's to cover the range between the
segment's end and the start of the next segment, being careful
to avoid touching regions of the extended mapping where the offset
would overrun the size of the file. This avoids the loader
creating an additional gap VMA for each LOAD segment.

Consider a system with 4KB page size and the ELF files with 64K
alignment. e.g:

$ readelf -Wl /system/lib64/bootstrap/libc.so | grep 'Type\|LOAD'

Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x0441a8 0x0441a8 R   0x10000
LOAD           0x0441b0 0x00000000000541b0 0x00000000000541b0 0x091860 0x091860 R E 0x10000
LOAD           0x0d5a10 0x00000000000f5a10 0x00000000000f5a10 0x003d40 0x003d40 RW  0x10000
LOAD           0x0d9760 0x0000000000109760 0x0000000000109760 0x0005c0 0x459844 RW  0x10000

Before this patch:

$ cat /proc/1/maps | grep -A1 libc.so

7fa1d4a90000-7fa1d4ad5000 r--p 00000000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7fa1d4ad5000-7fa1d4ae4000 ---p 00000000 00:00 0
7fa1d4ae4000-7fa1d4b76000 r-xp 00044000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7fa1d4b76000-7fa1d4b85000 ---p 00000000 00:00 0
7fa1d4b85000-7fa1d4b8a000 r--p 000d5000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7fa1d4b8a000-7fa1d4b99000 ---p 00000000 00:00 0
7fa1d4b99000-7fa1d4b9a000 rw-p 000d9000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7fa1d4b9a000-7fa1d4feb000 rw-p 00000000 00:00 0                          [anon:.bss]

3 additional PROT_NONE (---p) VMAs for gap mappings.

After this patch:

$ cat /proc/1/maps | grep -A1 libc.so

7f468f069000-7f468f0bd000 r--p 00000000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f0bd000-7f468f15e000 r-xp 00044000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f15e000-7f468f163000 r--p 000d5000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f163000-7f468f172000 rw-p 000da000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f172000-7f468f173000 rw-p 000d9000 fe:09 20635520                   /system/lib64/bootstrap/libc.so
7f468f173000-7f468f5c4000 rw-p 00000000 00:00 0                          [anon:.bss]

No additional gap VMAs. However notice there is an extra RW VMA at
offset 0x000da000. This is caused by the RO protection of the
GNU_RELRO segment, which causes the extended RW VMA to split.
The GNU_RELRO protection extension is handled in the subsequent
patch in this series.

Bug: 316403210
Bug: 300367402
Bug: 307803052
Bug: 312550202
Test: atest -c linker-unit-tests [Later patch]
Test: atest -c bionic-unit-tests
Change-Id: I3363172c02d5a4e2b2a39c44809e433a4716bc45
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-08 13:07:04 -08: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
Kalesh Singh
776c8a98af Merge "bionic: loader: Don't bail out if reading pad_segment note fails" into main am: df2b4658d3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2955880

Change-Id: I948c73a910b1dd4a18d5890d5158ef24fbd89e27
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-08 18:11:25 +00:00
Elliott Hughes
cd0b553f42 Merge "More libc/Android.bp simplification." into main am: 8259120694
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2955183

Change-Id: Ie4b1c4d6bf7c3803a7066323464749b9b33bc58d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-08 18:11:12 +00:00
Elliott Hughes
7cc715a7d0 Merge "Address review comments on previous change." into main am: 246df70204
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2954810

Change-Id: I94df5f8ab9d9d1f476438137581190cd7b2e2707
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-08 18:09:52 +00:00
Kalesh Singh
df2b4658d3 Merge "bionic: loader: Don't bail out if reading pad_segment note fails" into main 2024-02-08 17:40:19 +00:00
Elliott Hughes
8259120694 Merge "More libc/Android.bp simplification." into main 2024-02-08 17:20:20 +00:00
Elliott Hughes
246df70204 Merge "Address review comments on previous change." into main 2024-02-08 17:18:03 +00:00
Kalesh Singh
fb5440baee bionic: loader: Don't bail out if reading pad_segment note fails
The PAD_SEGMENT note is used to optimize memory usage of the loader.

If the note parsing fails, skip the optimization and continue
loading the ELF normally.

Bug: 324309329
Bug: 316403210
Change-Id: I2aabc9f399816c53eb33ff303208a16022571edf
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-08 08:51:39 -08:00
Kalesh Singh
69166f247a Merge "bionic: linker-unit-tests: Add crt_pad_segment tests" into main am: 07694f8f47
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2948921

Change-Id: Iff6b400d74a7daed8173f9418980b917e72e63f8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-08 08:19:45 +00:00
Kalesh Singh
07694f8f47 Merge "bionic: linker-unit-tests: Add crt_pad_segment tests" into main 2024-02-08 07:23:52 +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
Elliott Hughes
8f288d8f42 Merge "Stop defining __STDC_*_MACROS macros." into main am: 78714d102f
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2955173

Change-Id: Ib3e56635f538694635a3b54aa193f7c899399062
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-08 00:32:39 +00:00
Kalesh Singh
0396f87858 bionic: linker-unit-tests: Add crt_pad_segment tests
Test crt_pad_segment note parsing.

Test: atest -c linker-unit-tests
Bug: 316403210
Bug: 300367402
Bug: 307803052
Bug: 312550202
Change-Id: I0a7db8113a8b1df72696906bdd48a6ab6b6715f7
2024-02-07 16:20:48 -08:00
Elliott Hughes
2e2b9bcf3d More libc/Android.bp simplification.
Merge libc_bionic_ndk into libc_bionic.

Test: treehugger
Change-Id: I07dbb7e20e12000a2c18ff6fab2d5bd81db0cfcd
2024-02-07 16:10:23 -08:00
Elliott Hughes
78714d102f Merge "Stop defining __STDC_*_MACROS macros." into main 2024-02-07 23:53:17 +00:00
Elliott Hughes
66abb0a039 Address review comments on previous change.
A different way to silence the build warnings...

Test: treehugger
Change-Id: I3fec02ceb0dc2ea22fe1769c948db6c20f458614
2024-02-07 22:43:15 +00:00
Elliott Hughes
3bb9880a57 Stop defining __STDC_*_MACROS macros.
The libcs we use don't need these any more (if they ever did), and we
were setting these globally in the build system anyway.

Also remove the -D_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS from versioner
which doesn't seem needed any more either.

Test: treehugger
Change-Id: I9fb225b085906a02918c5847401d6c59f7779581
2024-02-07 21:05:44 +00:00