Commit graph

42541 commits

Author SHA1 Message Date
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
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
1dd6858349 bionic: linker_phdr: Introduce kPageSize
kPageSize is needed to determine whether the loader needs to
extend VMAs to avoid gaps in the memory map when loading the ELF.

While at it, use kPageSize to generically deduce the PMD size and
replace the hardcoded 2MB PMD size.

Bug: 316403210
Test: atest -c linker-unit-tests [Later patch]
Test: m && launch_cvd
Change-Id: Ie770320e629c38149dc75dae1deb1e429dd1acf2
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-06 17:59:16 -08:00
Kalesh Singh
377f0b9138 bionic: Introduce ElfReader::ReadPadSegmentNote()
ReadPadSegmentNote() finds the elf note of type
NT_ANDROID_TYPE_PAD_SEGMENT and checks that the desc value
is 1, to decided whether the LOAD segment mappings should
be extended (padded) to avoid gaps.

Cache the result of this operation in ElfReader and soinfo
for use in the subsequent patch which handles the extension
of the segment mappings.

Test: atest -c linker-unit-tests [Later patch]
Test: m && launch_cvd
Bug: 316403210
Change-Id: I32c05cce741d221c3f92835ea09d932c40bdf8b1
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2024-02-06 17:59:01 -08: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
Aditya Choudhary
72f82334d5 Merge "Migrate Test Targets to New Android Ownership Model" into main am: d7144fcdf0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2946528

Change-Id: I0c73cc7b9392f70936f629fe4a712569462cf237
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-04 21:29:43 +00:00
Aditya Choudhary
d7144fcdf0 Merge "Migrate Test Targets to New Android Ownership Model" into main 2024-02-04 20:48:36 +00:00
Treehugger Robot
9f62087758 Merge "Silence the -Wdeprecated-volatile warnings from our atomic benchmarks." into main am: a0d0355105
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2948795

Change-Id: I3ab84cef19ebff8bc4647753110946c4892cd593
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-02-03 02:17:20 +00:00
Treehugger Robot
a0d0355105 Merge "Silence the -Wdeprecated-volatile warnings from our atomic benchmarks." into main 2024-02-03 01:43:17 +00:00