Commit graph

10616 commits

Author SHA1 Message Date
Treehugger Robot
6fe4daaa16 Merge "iconv(3): ignore src_bytes_left if src_bytes is null." 2021-02-19 18:09:17 +00:00
Jingwen Chen
0b1611e637 bp2build: convert more cc_objects.
This CL also discovered that a couple of cc_objects include headers from the bionic subdir, without declaring them in the local_include_dirs.

Test: build/bazel/scripts/milestone-2/demo.sh full && build/bazel/scripts/milestone-2/demo.sh cleanup
Change-Id: I943980b1d1c6dab39d3c27da8037e587f97f76e3
2021-02-19 09:29:41 -05:00
Jingwen Chen
5daf8f9c3f bp2build: mark crt_beginso1 as bp2build_available.
This leaf module is selected as the first cc_object module to be converted by
the bp2build converter.

Test: GENERATE_BAZEL_FILES=true m nothing && bp2build-sync write && bazel build //bionic/libc:crt_beginso1
Change-Id: Idf752e7b5251161a4fbd58ba52b52dd85c8fc92b
2021-02-19 00:27:32 +00:00
Elliott Hughes
3abde068bd Inline the raise(SIGABRT) for x86-64 too.
This matches what we do for arm and arm64. 32-bit x86 is too big a mess
to warrant the effort still, but the more testing is done on cuttlefish,
the more value there is to making every stack frame count.

Before:

   #00 pc 00000000000596d8 .../libc.so (syscall+24)
   #01 pc 000000000005d072 .../libc.so (abort+194)
   #02 pc 000000000005f1f0 .../libc.so (__fortify_fatal(char const*, ...)+160)

After:

   #00 pc 000000000005d07d .../libc.so (abort+205)
   #01 pc 000000000005f1e0 .../libc.so (__fortify_fatal(char const*, ...)+160)

Test: crasher64 fortify
Change-Id: Ib74cb8b36341093c268872e26020f35eb2d8ef66
2021-02-18 15:16:39 -08:00
Elliott Hughes
20c023fdb2 iconv(3): ignore src_bytes_left if src_bytes is null.
This is undefined behavior, but glibc and macOS are both lenient, and
someone hit this in the wild, so we may as well be lenient too. (The
only cost is that it's now slightly easier to write code that works on
everything except old versions of Android.)

Bug: https://issuetracker.google.com/180598400
Test: treehugger
Change-Id: Ia217169ea6283cc53f4fbf71e5abfa08356c2049
2021-02-18 10:37:22 -08:00
Pirama Arumuga Nainar
7b89be78f4 Move __libc_int0x80 to an assembly file
Bug: http://b/157081822

If __libc_int0x80 is in a C/C++ file, Clang's coverage instrumentation
adds instructions to count the number of times it gets executed [1].
With coverage instrumentation, __libc_sysinfo, used on 32-bit x86, is
initialized to the wrong value, causing dl.preinit_system_calls to fail.

Moving the function to an assembly file leaves __libc_sysinfo properly
initialized.

[1] We could change clang so it doesn't instrument functions marked
__attribute__((naked)) as a followup.

Test: `m CLANG_COVERAGE=true NATIVE_COVERAGE_PATHS=bionic` and run
bionic-unit-tests

Change-Id: I73558253512392d345de8d5b66d38bb14b308fdf
2021-02-18 09:52:59 -08:00
Elliott Hughes
332065d57e Merge "Fix/update notices." 2021-02-17 17:51:06 +00:00
Rupert Shuttleworth
9432c923b1 Merge "Mark cc_library_headers targets as being bp2build_available." 2021-02-17 08:57:19 +00:00
Bob Badour
22801c7c8d Merge "Revert "[LSC] Add LOCAL_LICENSE_KINDS to bionic"" 2021-02-17 01:59:45 +00:00
Christopher Ferris
05667cd66a Update to v5.11 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-5.11

Test: Built cuttlefish and flame images. Ran bionic unit tests on both.
Change-Id: Ie60337aafad4bda55af99b6c8fe9f56bf2fa787f
2021-02-16 16:01:34 -08:00
Elliott Hughes
aa8db1b9d1 Fix/update notices.
Auto-generate NOTICE files for all the directories, and for each one
individually rather than mixing libc and libm together.

Test: N/A
Change-Id: I7e251194a8805c4ca78fcc5675c3321bcd5abf0a
2021-02-16 15:06:50 -08:00
Elliott Hughes
51166f4f56 Merge "Rename __ANDROID_UNGUARDED_AVAILABILITY__ -> __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__." 2021-02-16 21:26:12 +00:00
Elliott Hughes
5e44c22ebf Revert "[LSC] Add LOCAL_LICENSE_KINDS to bionic"
This reverts commit 48d43034d7.

Reason for revert: bionic is multiple projects, not just one.

Change-Id: Ib31e1bb8888cc85c6e7736c4e2a1d4652fd23935
2021-02-16 20:02:47 +00:00
Rupert Shuttleworth
fd64868a92 Mark cc_library_headers targets as being bp2build_available.
Test: build/bazel/scripts/bp2build-sync.sh write.
Change-Id: I78a491d20779f50757b55c8e5305b588bf613839
2021-02-16 03:39:20 +00:00
Bob Badour
48d43034d7 [LSC] Add LOCAL_LICENSE_KINDS to bionic
Added SPDX-license-identifier-Apache-2.0 to:
  libdl/Android.bp
  tools/versioner/src/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  benchmarks/Android.bp
  libc/malloc_debug/Android.bp
  libc/system_properties/Android.bp
  linker/Android.bp
  tests/Android.bp
  tests/libs/Android.bp
  tests/libs/Android.build.dlext_testzip.mk
  tests/make_fortify_compile_test.mk

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-ISC SPDX-license-identifier-MIT
    legacy_notice legacy_unencumbered
to:
  Android.bp
  libc/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-ISC SPDX-license-identifier-MIT
    legacy_unencumbered
to:
  tools/Android.bp
  tools/versioner/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-MIT legacy_unencumbered
to:
  libm/Android.bp

Added SPDX-license-identifier-Apache-2.0 legacy_unencumbered
to:
  libc/tools/Android.bp

Added SPDX-license-identifier-BSD
to:
  benchmarks/linker_relocation/Android.bp
  benchmarks/spawn/Android.bp
  libc/async_safe/Android.bp
  libc/malloc_hooks/Android.bp
  libfdtrack/Android.bp
  tests/headers/Android.bp
  tests/headers/posix/Android.bp

Added legacy_notice
to:
  apex/Android.bp
  benchmarks/linker_relocation/gen/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: I76cad00578b9b99180ee5dd1e04b4646d5c5fedf
2021-02-12 17:51:24 -08:00
Peter Collingbourne
2753fc8ee5 Teach debuggerd to pass the secondary ring buffer to __scudo_get_error_info().
With this change we can report memory errors involving secondary
allocations. Update the existing crasher tests to also test
UAF/overflow/underflow on allocations with sizes sufficient to trigger
the secondary allocator.

Bug: 135772972
Change-Id: Ic8925c1f18621a8f272e26d5630e5d11d6d34d38
2021-02-12 12:30:52 -08:00
Elliott Hughes
a37b18133d Rename __ANDROID_UNGUARDED_AVAILABILITY__ -> __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__.
Also reduce some of the duplication in the macros.

Bug: http://b/179067538
Test: treehugger
Change-Id: I81ab341731b0faad6c7c5f00037feff8576abafb
2021-02-11 12:56:39 -08:00
Elliott Hughes
d3915c7b53 Make fd overflow an abort.
On LP32, just abort if we're asked to handle an fd that's too big for
the `short` field in `struct FILE`. This is unreachable anyway because
the ulimit is 32Ki, and this will make issues far more noticeable if we
ever do increase that limit (which seems unlikely for LP32 devices).

Also rename __finit() to __FILE_init() to match __FILE_close().

Test: treehugger
Change-Id: I5db4d6c4529a1f558aff135b4dea071d73666be5
2021-02-09 17:13:09 -08:00
Elliott Hughes
6d5662d22a Merge "Fix freopen() where the path is null." 2021-02-08 20:07:12 +00:00
Jingwen Chen
d6a3b780de Mark //bionic filegroups/genrules as bp2build_available.
Test: GENERATE_BAZEL_FILES=true m nothing && build/bazel/scripts/bp2build-sync.sh write && bazel build //bionic/...
Change-Id: Ie3e0092a3a03ddc6228a9191e5b78ab206072dde
2021-02-08 01:44:35 -05:00
Elliott Hughes
f9cfecf3d4 Fix freopen() where the path is null.
This has been in the standard since C99, but we've never supported it
before. It's apparently used by SPIRV-Tools.

I tried implementing this the other way (with fcntl(2)) first, but
eventually realized that that's more complicated and gives worse
results. This implementation assumes that /proc is mounted, but so much
of libc relies on that at this point that I don't think there's any
realistic case where the fcntl(2) implementation would be preferable,
and there are many where it's not.

The fact that no-one's mentioned this until now suggests that it's not a
heavily used feature anyway.

I've also replaced AssertCloseOnExec() with a CloseOnExec()
boolean-valued function instead, because it's really annoying getting
assertion failures that don't point you at the test line in question,
and instead point to some common helper code.

Test: treehugger
Change-Id: Ia2e53bf2664a4f782581042054ecd492830e2aed
2021-02-04 17:01:55 -08:00
Chih-hung Hsieh
78ad991425 Merge "Fix "deprecated instruction in IT block" warning" 2021-02-04 19:41:06 +00:00
Chih-Hung Hsieh
5cb4d9cef9 Fix "deprecated instruction in IT block" warning
Bug: 179266557
Test: make with new clang compiler
Change-Id: I963609861659cbb2be8ed467654109938185c747
2021-02-03 20:54:52 -08:00
Dan Albert
ffa5cbeb86 Convert generate-NOTICE.py to Python 3, fix name.
Python module names should be lower case and not use hyphens (the
former is a convention, the latter is a requirement for importable
modules).

Also updates the shell script to always use Python 3 so we don't need
to maintain Python 2 compatibility.

Test: repo upload, in both a python 2 and python 3 virtualenv
Bug: None
Change-Id: I486e54a12686b4e528dc6c9c47af5c7a52a7b790
2021-02-03 17:26:59 -08:00
Dan Albert
1dffb86205 Convert genfunctosyscallnrs to Python 3.
Test: treehugger
Test: pytest libc/tools
Bug: None
Change-Id: Idda7161bbd2e2f351e0750874dc4d766ef98cc2b
2021-02-03 16:32:10 -08:00
Elliott Hughes
bc6999f1c4 Convert gensecomp.py to Python 3.
The genseccomp tests haven't been run since at least 2018. Deleted the
ones that are testing APIs that no longer exist or have been
refactored to take very different inputs.

Test: treehugger
Test: pytest tools
Bug: None
Change-Id: Iaf6b6b6a2e922b181a457a74eb4b5abe90425dfb
2021-02-03 16:15:17 -08:00
Jingwen Chen
ca36633eba Move gensseccomp and genfunctosyscallnrs next to their sources.
This is a manual refactoring to ensure that the modules respect package boundaries for input files.

Test: m gensseccomp genfunctosyscallnrs
Change-Id: I8ca6cbe85a50e41bfe874a899653c2309c59a822
2021-02-02 07:24:24 -05:00
Ryan Prichard
15ade069b1 Merge changes from topic "builtins-exported"
* changes:
  Use exported variants of arm32/x86 builtins
  Fix -Wl,--exclude-libs typo: x86->i686
2021-02-02 00:30:03 +00:00
Mitch Phillips
bfa3688606 Merge "[MemInit] Remove old API, introduce new MemInit API." 2021-02-01 23:32:24 +00:00
Dan Albert
eae41f8eeb Fix __VERSIONER_NO_GUARD cases for availability.
libc++ still depends on these being declared even if they are
unavailable. This results in a worse error message (a link error
rather than a compiler diagnostic) if these functions end up being
used, but without the decl headers like libc++'s math.h can't be
included because it refers to an undeclared function.

For the cases where weak symbols aren't being used, don't annotate
these functions with their availability information.

Also need to avoid using __builtin_available for this case because the
NDK doesn't have __isOSVersionAtLeast yet.

__ANDROID_UNGUARDED_AVAILABILITY__ is being used as a proxy for
"building for the NDK" here because we don't have a good signal for
that which works for both the NDK proper and the NDK-in-the-platform
case.

Test: imported into the NDK, built and tested NDK
Bug: None
Change-Id: I9ef3e19a8fa083bca0be47b80dfef7ba52a94866
2021-02-01 12:53:22 -08:00
Treehugger Robot
c09fe61889 Merge "Sync libm with upstream FreeBSD." 2021-01-29 20:07:15 +00:00
Ryan Prichard
c22562ce6f Use exported variants of arm32/x86 builtins
For backwards compatibility (e.g. with old apps), arm32 libc.so and
libm.so export some of the builtins. On 32-bit x86, libc.so also
exports some of the builtins.

The non-exported variant of the builtins will eventually have hidden
symbols but doesn't currently because D93431 hasn't been merged into
our toolchain yet. See:
 - https://reviews.llvm.org/D93431
 - I44ec79728db92c089e2f39823c35b6f97d24c1ab in toolchain/llvm_android

Bug: http://b/153025717
Test: bionic unit tests
Change-Id: Ic489cb06a07ef61412502fc65a21b0cf630c11ed
2021-01-28 15:42:37 -08:00
Treehugger Robot
cdebaffea4 Merge "[MTE] Change scudo init order to get correct PROT_MTE pages." 2021-01-27 21:09:27 +00:00
Elliott Hughes
bac0ebbf90 Sync libm with upstream FreeBSD.
Upstream SHA 78599c32efed3247d165302a1fbe8d9203e38974.

Test: treehugger
Change-Id: Ib103d211315e320df89a6f0bcb30cd8ba67dd603
2021-01-26 14:19:25 -08:00
Edgar Arriaga
cf81e7ca6a Merge changes from topic "proc_madvise_framework"
* changes:
  Add bionic headers for process_madvise
  Add a flag to distinguish shared VMAs
2021-01-26 19:29:37 +00:00
Mitch Phillips
9cad8424ff [MemInit] Remove old API, introduce new MemInit API.
Introduces new heap-zero-init API. We've realised that it's better to be
able to individually control MTE and heap zero-init. Having
heap-zero-init not be controllable without affecting MTE affects our
ability to turn off heap-zero-init in zygote-forked applications.

Bug: 135772972
Test: On FVP: atest -s localhost:5555 malloc#zero_init \
Test: malloc#disable_mte heap_tagging_level
Change-Id: I8c6722502733259934c699f4f1269eaf1641a09f
2021-01-25 15:19:31 -08:00
Elliott Hughes
69d44fd55b Merge "PAC/BTI: no need to keep using hint." 2021-01-25 18:30:20 +00:00
Elliott Hughes
3e1d5563b6 PAC/BTI: no need to keep using hint.
The toolchain is new enough that should be able to use the actual
instructions now...

Test: treehugger
Change-Id: I30aafcdc5386268344c40dc6cc9a22caf591915a
2021-01-25 08:49:01 -08:00
Tamas Petz
ebfba5f8c1 [libc] Change literal value in macro
"#" there is incorrect: macro parameter is expected following a hashmark.

Test: build libc with -mbranch-protection=standard
Change-Id: Ib8e7ddf260b4cdbd36246cc70f69970f33dee200
2021-01-25 11:54:25 +01:00
Jiyong Park
7cff764f3c Merge changes from topic "future_symbol"
* changes:
  crtbegin_static is built with min_sdk_version: "current"
  Guard __libc_current_sigrtmin/max with __builtin_available
  __INTRODUCED_IN macros add the availability attribute
2021-01-21 16:33:05 +00:00
Mitch Phillips
347b01b583 [MTE] Change scudo init order to get correct PROT_MTE pages.
scudo_malloc_* for fill contents in __libc_init_scudo calls scudo's
initializers. We haven't told Scudo whether we want MTE-capable (i.e.
mapped with PROT_MTE) size class regions yet, which happens in
SetDefaultHeapTaggingLevel. This can lead to inconsistent mappings,
where processes without ELF notes get the base region with PROT_MTE
(which is undesirable because the performance implications are not
known).

Make sure that scudo is informed of whether regions need to be mapped
PROT_MTE or not by hoising the tagging level up.

Bug: 135772972
Bug: 172365548
Test: On FVP - 'adb shell MEMTAG_OPTIONS=off sanitizer-status' should
have no PROT_MTE mappings (validation by looking for no 'mt' under
'VmFlags:' in /proc/smaps').

Change-Id: Idad64479c4a9459cb40dd211fe942437f8ca16fd
2021-01-20 12:45:07 -08:00
Colin Cross
d65b31fad6 Merge "Don't set native_bridge_supported: true for ndk libraries" 2021-01-20 17:49:36 +00:00
Ryan Prichard
fcd9c78534 Merge "Switch libc.so and linker to prebuilt LLVM libunwind" 2021-01-20 00:10:58 +00:00
Colin Cross
d9a9622c31 Don't set native_bridge_supported: true for ndk libraries
Native bridge modules will never compile against stubs, remove
native_bridge_supported: true.

Test: m checkbuild
Change-Id: I0eb93fe1a2c3f6ca34ce4dab17edda8807132ce8
2021-01-19 14:58:25 -08:00
Elliott Hughes
73366636e1 Remove the now-unnecessary android_mallopt() options.
These are available from mallopt() now, and all callers have been
switched over.

Bug: http://b/135772972
Test: treehugger
Change-Id: I90c7a7573b261c27001a2dfd4589b23861ad613b
2021-01-15 18:08:25 -08:00
Edgar Arriaga
128ef8e981 Add bionic headers for process_madvise
Test: atest bionic-unit-tests-static
Bug: 173258203
Change-Id: I396945b95de364055b87cc53321aed4fad4ebc70
2021-01-14 19:34:40 -08:00
Jiyong Park
268a60019d crtbegin_static is built with min_sdk_version: "current"
crtbegin_static is used by static exectuables which are guaranteed to be
with the latest library regardless of their target API level.

This change is in fact not a regression as crtbegin_static has been
built with __ANDROID_API__=10000 before
I645e6bb1234c27ae0a69b7b87a59206cfd350744 when __ANDROID_API__ tracked
sdk_version, not min_sdk_version. sdk_version was not set for crtbegin_*
objects and therefore the default "current" was (incorrectly) used.

With this change, we are recovering the original behavior for the static
variant, while the building of the dynamic variant becomes more correct
- it's now with __ANDROID_API__=16.

Without this change, several static executables fail to build as 1)
crtbegin_static for them is built with __ANDROID_API__=16 and 2)
libc_init_common.cpp uses pthread_atfork which is available only after
API level 23. We hit undefined symbol error when linking.

Bug: 134795810
Test: m

Change-Id: I1430e57302951df33530ea0ae91b0d7a0609bf3d
2021-01-15 10:40:51 +09:00
Jiyong Park
bb19208d66 Guard __libc_current_sigrtmin/max with __builtin_available
The two APIs were added for the API level 21 and beyond. Currently, its
existence is tested using the null check which is done regardless of the
min sdk version of the compilation unit. (which in turn required us to
mark the API symbol weak regardless of the min sdk version.)

Now, we have a better way of testing the API availability;
__builtin_available. The null check is replaced with the call to the
compiler-provided macro which determines if the code is running in a
version of OS where the API is known to exist.

Bug: 150860940
Bug: 134795810
Test: m
Change-Id: Ib96c78f8d3cc71d7e755d1eab86051517bbbcc44
2021-01-15 10:40:51 +09:00
Jiyong Park
23bfed2a10 __INTRODUCED_IN macros add the availability attribute
__INTRODUCED_IN (and its variants) macro is used to mark the
availability of an API symbol. The macros were used by the versioner
tool for the NDK clients. When the Bionic headers are processed by the
tool, APIs with the macros are guarded with __ANDROID_API__. e.g.,

void foo() __INTRDUCED_IN(30);

is processed into

\#if __ANDROID_API__ >= 30
void foo();
\#endif

by the versioner.

The macros however didn't play a role for other cases, e.g. OS
components.

This is too strict for NDK clients and too loose for the non-NDK
clients. For the former, this completely hides the APIs that are newer
than the min sdk version (__ANDROID_API__). For the latter, a call to
such an API can be made without being guarded.

This change is the first step towards a better way of handling the
native APIs availability. The plan is that every NDK APIs are annotated
with the availability attribute and callers are required to guard their
API calls with a runtime check if the API is newer than the min sdk
version of the caller.

In this change, the macros now emits the availability attribute for the
non-NDK clients (i.e. when not processed by versioner).

Bug: 163288375
Bug: 134795810
Test: m
Change-Id: I6eb2bce2bc2770cbfd69815e6816b6f25b3d6127
2021-01-15 10:40:47 +09:00
Ryan Prichard
cdf7175fa5 Switch libc.so and linker to prebuilt LLVM libunwind
For libc.so, use a special build of libunwind.a whose symbols aren't
hidden ("libunwind-exported"), because libc.so exports the _Unwind_*
APIs.

Bug: http://b/153025717
Test: bionic unit tests
Change-Id: I7435e076ec8cc4410e3e6086d3cf5d2c6011c80c
2021-01-14 17:35:05 -08:00
Elliott Hughes
e925485acd Merge "Make "disable memory mitigations" and "set heap tagging level" more available." 2021-01-15 00:49:45 +00:00
Mitch Phillips
a867371afa Merge "[MTE] Add MEMTAG_OPTIONS and arm64.memtag.process.* sysprop parsing." 2021-01-14 23:46:12 +00:00
Elliott Hughes
446b4dde72 Make "disable memory mitigations" and "set heap tagging level" more available.
These were only available internally via android_mallopt(), but they're
likely to be needed by more code in future, so move them into mallopt().

This change leaves the android_mallopt() options for now, but I plan on
coming back to remove them after I've switched the handful of callers
over to mallopt() instead.

Bug: http://b/135772972
Test: treehugger
Change-Id: Ia154614069a7623c6aca85975a91e6a156f04759
2021-01-14 13:34:20 -08:00
Mitch Phillips
4cded9729b [MTE] Add MEMTAG_OPTIONS and arm64.memtag.process.* sysprop parsing.
These two options allow for ARM MTE to be enabled dynamically (instead
of at compile time via the ELF note). They are settable from a non-root
shell to allow device owners to test system binaries with MTE.

The following values may be set:
  1. 'off' -> No MTE, uses TBI on compatible devices.
  2. 'sync' -> SYNC MTE.
  3. 'async' -> ASYNC MTE.

The following methods can be used to launch a process (sanitizer-status)
with configurable values:
  1. adb shell MEMTAG_OPTIONS=async sanitizer-status
  2. adb shell setprop arm64.memtag.process.sanitizer-status async && \
     adb shell sanitizer-status

Note: The system server will require some special handing in the zygote
pre-fork to check the sysprops. The zygote should always have the ELF
note. TODO in a subsequent patch.

Bug: 135772972
Bug: 172365548
Test: Launching sanitizer-status above using both the settings.
Change-Id: Ic1dbf3985a3f23521ec86725ec482c8f6739c182
2021-01-14 13:13:17 -08:00
Maciej Żenczykowski
eb76022557 removing ro.kernel.ebpf.supported property
Android S devices must support eBPF.

Test: builds, atest, TreeHugger
Bug: 167500195
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I84a8d00f786fca8113dd3d555af279a1029f66f2
2021-01-11 18:10:58 -08:00
Elliott Hughes
b1ba762e34 Merge "Fewer copies of ALIGN()/ALIGNBYTES." 2021-01-11 21:50:40 +00:00
Peter Collingbourne
4e67866510 Merge "Remove ANDROID_EXPERIMENTAL_MTE." 2021-01-11 20:42:44 +00:00
Elliott Hughes
e1dc4f62eb Fewer copies of ALIGN()/ALIGNBYTES.
Noticed while updating fts.c.

Bug: http://b/177003648
Test: treehugger
Change-Id: Ic3625c1c3af47c4dafb8ad686bbbddbc82b69b70
2021-01-11 11:51:29 -08:00
Elliott Hughes
08959d98b1 Merge "Sync upstream fts.c." 2021-01-11 19:19:22 +00:00
Peter Collingbourne
7e20117a36 Remove ANDROID_EXPERIMENTAL_MTE.
Now that the feature guarded by this flag has landed in Linux 5.10
we no longer need the flag, so we can remove it.

Bug: 135772972
Change-Id: I02fa50848cbd0486c23c8a229bb8f1ab5dd5a56f
2021-01-11 10:55:51 -08:00
Elliott Hughes
03ac158cab Sync upstream fts.c.
I realize that we can probably clean up more of our half-forked code by
reusing the same *-compat.h headers we use for the clean upstream code,
but I'll come back and do that later.

Bug: http://b/177003648
Test: treehugger
Change-Id: I081255aaafd62718b85956c5502911a1cc80225d
2021-01-11 08:43:48 -08:00
Adam Barth
b19fc79350 Merge "Make the atomic load explicit" 2021-01-09 04:33:15 +00:00
Elliott Hughes
771af5efc6 Merge "Fix things so that <features.h> can be used from assembler again." 2021-01-08 20:29:06 +00:00
Evgenii Stepanov
5e466b63ae Suppress SetHeapTaggingLevel warning under hwasan.
This is expected behavior.

Bug: b/135772972
Test: logcat on any hwasan device

Change-Id: I38b235859000ca271f1b1beaeab6ed6645ec6a08
2021-01-08 17:30:37 +00:00
Treehugger Robot
bd84f549fc Merge "Fix -Wnewline-eof" 2021-01-08 01:42:28 +00:00
Elliott Hughes
43978a0a34 Fix things so that <features.h> can be used from assembler again.
Bug: https://github.com/android/ndk/issues/1422
Test: builds
Change-Id: I1b94ffe688f3d420533074c94f7ffed606ca923f
2021-01-07 17:32:39 -08:00
Adam Barth
651f1fa509 Make the atomic load explicit
Technically, std::atomic does not have an operator(). Previously, this
code was relying on an implicit behavior of our C++ standard library in
order to compile. When compiling this code against a different C++
standard library, I encountered a compiler error on these lines.

This CL makes the std::atomic load() operation explicit, makes it
clearer what this code is actually doing and makes it conform better to
the C++ standard library spec rather than a particular implmentation.

Change-Id: I7f255dffc0a3d8e07c973c18e9ba4098c4b5843e
2021-01-08 01:21:52 +00:00
Adam Barth
e9efd05fe4 Fix -Wnewline-eof
Technically, C requires that all source files end with a newline. In
practice, most compilers will accept source files without a newline, but
it does trigger the -Wnewline-eof warning.

Change-Id: I64a92b82f4d5724cd8b45821cfd59eb3de39514b
2021-01-07 22:56:55 +00:00
Evgenii Stepanov
e09fc24a94 Merge "Use ELF notes to set the desired memory tagging level." 2021-01-07 03:43:52 +00:00
Evgenii Stepanov
8564b8d9e6 Use ELF notes to set the desired memory tagging level.
Use a note in executables to specify
(none|sync|async) heap tagging level. To be extended with (heap x stack x
globals) in the future. A missing note disables all tagging.

Bug: b/135772972
Test: bionic-unit-tests (in a future change)

Change-Id: Iab145a922c7abe24cdce17323f9e0c1063cc1321
2021-01-06 16:08:18 -08:00
Evgenii Stepanov
286b3d4b8c Merge "(NFC) Symbolic names for Android ELF note types." 2021-01-06 19:23:08 +00:00
Evgenii Stepanov
dec48bdd9e (NFC) Symbolic names for Android ELF note types.
Bug: b/135772972
Test: none

Change-Id: Ia972200337d4e9a2adeba196edd06dd98348b6cd
2021-01-05 15:25:39 -08:00
Mitch Phillips
be77febd61 Merge "[Tagged Pointers] Point to SAC documentation in abort message." 2021-01-05 22:44:51 +00:00
Mitch Phillips
8540c54b49 [Tagged Pointers] Point to SAC documentation in abort message.
<EOM>

Test: atest CtsTaggingHostTestCases
Bug: 145604058
Change-Id: Ie3a77d4050e2ab99a03a119244ba75da974f251b
2021-01-05 13:10:21 -08:00
Treehugger Robot
5ec23f14b5 Merge "Changes to bionic/libc to demonstrate mixed builds." 2020-12-17 23:36:25 +00:00
Chris Parsons
8b768d3f1a Changes to bionic/libc to demonstrate mixed builds.
Test: source build/envsetup.sh && lunch 16 && source
build/soong/bazel/bazelenv.sh && m, then verify ninja
file was based on intermediates from bazel-out

Change-Id: I89f320dd58083710012ea1f8e3902e723602ea37
2020-12-17 11:05:01 -05:00
Treehugger Robot
742b1a648a Merge "Reland: Soft-enable MAC address restrictions with allowlist." 2020-12-17 09:26:40 +00:00
Bram Bonné
95ca52a7d6 Reland: Soft-enable MAC address restrictions with allowlist.
Soft-limits apps from calling bind() on NETLINK_ROUTE sockets, and
getting link info through getifaddrs(), while still allowing apps on the
allowlist to temporarily perform these actions.

This is different from existing behavior, where apps targeting an API
level < 30 were exempted from this restriction.

Actual enforcement will happen through SELinux (as is currently the
case for apps targeting API >= 30). This temporary change will then be
reverted.

If you arrived at this change due to an app showing unexpected behavior,
please file a bug at go/netlink-bug.

Bug: 170188668
Bug: 170214442
Test: Call bind() on NETLINK_ROUTE for an app on the allowlist.
Test: Call bind() on NETLINK_ROUTE for an app not on the allowlist.
Test: Call getifaddrs() for an app on the allowlist.
Test: Call getifaddrs() for an app not on the allowlist.
Test: Call bind() on a AF_UNIX socket with its protocol set to
NETLINK_ROUTE, confirm it can succeed.
Test: Verify that previously broken apps are no longer broken.

Change-Id: I8738f7912fdc816e0d30205557728ff9e84bf7e6
2020-12-15 16:52:58 +01:00
Christopher Ferris
32ff3f831c Update to v5.10 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-5.10

Test: Built cuttlefish and flame images. Ran bionic unit tests on both.
Change-Id: I37ffc850970adcce1febbe2269c202632fce763a
2020-12-14 22:37:59 -08:00
Bram Bonné
9e97280414 Revert "Soft-enable MAC address restrictions with allowlist."
Revert "Updates CTS tests for MAC address restrictions."

Revert submission 1518603-soft-restrict-mac

Reason for revert: Missing type check
Reverted Changes:
I0488932de:Soft-enable MAC address restrictions with allowlis...
Idb9d940e4:Updates CTS tests for MAC address restrictions.
I9461f287e:Return anonymized MAC for apps targeting SDK < 30

Change-Id: I7e8e593518088ff5c8f6083b34e6966852475b9b
2020-12-14 14:14:23 +01:00
Greg Kaiser
5c8d48ae78 Remove unused 'err' assignment
This was a little confusing because a quick glance suggested that
'err' was getting the value of getsockopt(), when actually it was
getting the result of the '<' operation.  Since 'err' wasn't
being used, we clarify by just removing it altogether.

Test: TreeHugger
Change-Id: I1ff80812b460973e9d512a558623e0c44c2ecf09
2020-12-11 06:54:54 -08:00
Bram Bonné
0ed9f70122 Merge "Soft-enable MAC address restrictions with allowlist." 2020-12-11 11:01:40 +00:00
Bram Bonné
0ba499896a Soft-enable MAC address restrictions with allowlist.
Soft-limits apps from calling bind() on NETLINK_ROUTE sockets, and
getting link info through getifaddrs(), while still allowing apps on the
allowlist to temporarily perform these actions.

This is different from existing behavior, where apps targeting an API
level < 30 were exempted from this restriction.

Actual enforcement will happen through SELinux (as is currently the
case for apps targeting API >= 30). This temporary change will then be
reverted.

If you arrived at this change due to an app showing unexpected behavior,
please file a bug at go/netlink-bug.

Bug: 170188668
Bug: 170214442
Test: Call bind() on NETLINK_ROUTE for an app on the allowlist.
Test: Call bind() on NETLINK_ROUTE for an app not on the allowlist.
Test: Call getifaddrs() for an app on the allowlist.
Test: Call getifaddrs() for an app not on the allowlist.
Change-Id: I0488932deea2a7211e55a24bc33bfa3cfb16fba2
2020-12-10 11:55:45 +01:00
Peter Collingbourne
713c692f78 Merge changes from topics "Ic7ea0f075751f8f077612617802775d2d0a799dc", "Iec02ae89f4a3d2ffe298817240f404e54b109a52" am: 1f2e000c80
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1520659

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I82b606f10035eae94aeb06f41070068ec1ec0ca3
2020-12-09 20:22:58 +00:00
Peter Collingbourne
1f2e000c80 Merge changes from topics "Ic7ea0f075751f8f077612617802775d2d0a799dc", "Iec02ae89f4a3d2ffe298817240f404e54b109a52"
* changes:
  Add a bionic-benchmarks-static target.
  Make our definition of std::nothrow weak.
2020-12-09 19:21:56 +00:00
Elliott Hughes
8b9c51af06 Merge "Simplify and improve tempnam() and tmpnam()." am: 12afdf0fa7
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1518224

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ie3703a300f3378804a30616a7238ecc1cdc20502
2020-12-09 18:41:30 +00:00
Elliott Hughes
12afdf0fa7 Merge "Simplify and improve tempnam() and tmpnam()." 2020-12-09 18:05:43 +00:00
Elliott Hughes
439ebbd349 Simplify and improve tempnam() and tmpnam().
They're both obsolescent in POSIX.1-2008, and you really shouldn't be
using them, but since we can't actually delete them...

This change makes them both obey $TMPDIR if set, and fall back to
/data/local/tmp otherwise. That's as good as we've managed for anything
else such as tmpfile(3).

Also add some tests.

Bug: http://b/174682340
Test: treehugger
Change-Id: Ieef99dcc2062f84b2b7cbae046787fdfe975e772
2020-12-08 22:26:06 -08:00
Peter Collingbourne
9397bdd13f Make our definition of std::nothrow weak.
We can sometimes fail to link a static executable because of
duplicate definitions of std::nothrow in bionic/libc/bionic/new.cpp
and external/libcxx/src/new.cpp. Fix it by making our definition
weak since it doesn't matter which one ends up being chosen.

Change-Id: Iec02ae89f4a3d2ffe298817240f404e54b109a52
2020-12-08 14:40:30 -08:00
Christopher Ferris
7d513540f4 Merge "Clean up header files from kernel directory." am: d911c669ae
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1517518

Change-Id: If261b2da448c79bd4efa14e8117e919ab94a5d59
2020-12-04 21:23:18 +00:00
Christopher Ferris
ccf17f0ec7 Clean up header files from kernel directory.
Add a make distclean for each supported arch before generating headers
and at the end so these files are not left hanging around in the
kernel directory.

Bug: 174795055

Test: Verified all generated files are deleted after running.
Test: Verified this generates the exact same files as before this change.
Change-Id: I0f66f580af2ea50c190eb532032017e782d7cae6
2020-12-03 18:18:52 -08:00
Xin Li
522094471e Merge "Merge rvc-qpr-dev-plus-aosp-without-vendor@6881855" into stage-aosp-master 2020-12-03 03:19:01 +00:00
Mitch Phillips
2210b8d542 [Tagged Pointers] Allow probing the current TP level w/ locking.
aosp/1484976 introduced a breaking change where
DisableMemoryMitigations() now indiscriminately turns tagged pointers
off. When android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) is called, the
correct behaviour is:
 - In SYNC/ASYNC MTE mode -> disable all tagged pointers.
 - If all tagged pointers are already disabled -> nop.
 - If we're in TBI mode -> nop (keep the TBI mode as-is).

In order to do that we have to allow probing of the current heap tagging
mode. In order to prevent TOCTOU between GetHeapTaggingLevel() and
SetHeapTaggingLevel(), we expose a global mutex that should be held when
calling these functions.

Bug: 174263432
Test: atest CtsTaggingHostTestCases on Flame
Change-Id: Ia96f7269d542c9041270458806aee36766d2fbbb
2020-11-30 10:49:03 -08:00
Xin Li
218b4e5a0b Merge rvc-qpr-dev-plus-aosp-without-vendor@6881855
Bug: 172690556
Merged-In: I25ee3022fb26e744eae9e3f14595ce52e76b337e
Change-Id: I7359621eca1148d6c3f3287fcaecdab8c03fa7f6
2020-11-28 19:22:49 -08:00
Bram Bonné
1e32ae2da2 Merge "Revert^2 "Soft-enables new MAC address restrictions."" 2020-11-25 09:59:25 +00:00
Mitch Phillips
742a003db6 [GWP-ASan] Remove include.
Unnecessary include, and the file was deleted with upstream changes.

Bug: N/A
Test: cd external/gwp_asan && atest
Change-Id: Id8facff0c5e382aa639ce158b7b5862ce157aa25
2020-11-19 16:01:14 -08:00
Peter Collingbourne
097846e25b Merge "Change the android_mallopt(M_SET_HEAP_TAGGING_LEVEL) API." 2020-11-18 20:57:36 +00:00
Peter Collingbourne
9eb85bf70c Change the android_mallopt(M_SET_HEAP_TAGGING_LEVEL) API.
- Make it apply to every thread, and thus remove the restriction
  that it must be called while the program is single threaded.
- Make it change TCF0 itself (on all threads), instead of requiring
  callers to do it themselves, which can be error prone.

And update all of the call sites.

Change the implementation of
android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) to call
android_mallopt(M_SET_HEAP_TAGGING_LEVEL) internally. This avoids
crashes during startup that were observed when the two mallopts
updated TCF0 unaware of each other.

I wouldn't expect there to be any out-of-tree callers at this point,
but it's worth noting that the new interface is backwards compatible
with the old one because it strictly expands the set of situations in
which the API can be used (i.e. situations where there are multiple
threads running or where TCF0 hadn't been updated beforehand).

Bug: 135772972
Change-Id: I7746707898ff31ef2e0af01c4f55ba90b72bef51
2020-11-18 10:24:29 -08:00
Bram Bonné
53211a98dc Revert^2 "Soft-enables new MAC address restrictions."
259776d8ff

The original change was reverted due to InterfaceParamsTest failing.
This test has now been fixed in r.android.com/1498525.
The original change message is below.

Updates getifaddrs() to behave as if RTM_GETLINK requests are not
allowed for non-system apps. This is different from previous behavior,
where apps targeting an API level < 30 were exempted from this
restriction.

Actual enforcement happens in SELinux. This change:
- Soft-enables the behavior until SELinux changes are in place
- Prevents logspam from SELinux denials after they are in place

Bug: 170188668
Test: atest bionic-unit-tests-static
Test: atest NetworkInterfaceTest
Test: Connect to Wi-Fi network
Test: Call getifaddrs() directly from within an app.
Test: Call NetworkInterface#getNetworkInterfaces() from within an app.

Change-Id: Ia9f61819f8fdf878c0e67e57de7e893fb3b1c233
2020-11-16 12:53:49 +00:00
Tej Singh
92b8588f17 Merge "Revert "Soft-enables new MAC address restrictions."" 2020-11-14 01:59:33 +00:00
Tej Singh
259776d8ff Revert "Soft-enables new MAC address restrictions."
Revert "Enforce RTM_GETLINK restrictions on all 3p apps"

Revert "Updates tests for untrusted app MAC address restrictions"

Revert submission 1450615-mac-address-restrictions

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

Reverted Changes:
I08c709b2b:Enforce RTM_GETLINK restrictions on all 3p apps
I95d124ae8:Soft-enables new MAC address restrictions.
I5392f8339:Updates tests for untrusted app MAC address restri...
I9d214c5d0:Return anonymized MAC for apps targeting SDK < 30

Change-Id: If09920b24370077d647d60cfda7fc0a110b77851
2020-11-13 22:27:15 +00:00
Bram Bonné
7433096f06 Merge "Soft-enables new MAC address restrictions." 2020-11-12 17:07:11 +00:00
Justin Yun
869a0faf21 Add "product_available" to product available modules
"vendor_available" modules were available to product modules.
However, not all "vendor_available" modules are required to be
available to product modules. Some modules want to be available only
to product modules but not vendor modules.

To cover the requirement, we separate "product_available" from
"vendor_available".
"vendor_available" will not provide product available module.

Bug: 150902910
Test: build
Change-Id: I13b8222e191333c6c2cb7794ef3344fdcc6ebe98
2020-11-11 15:29:47 +09:00
Peter Collingbourne
56f1c406a5 Merge "Clear PAC bits in android_unsafe_frame_pointer_chase()." 2020-11-04 01:32:49 +00:00
Matthew Maurer
de30635eb6 Put __*_ARRAY__ symbols before prioritized init/fini funcs
A constructor or destructor function with an integral priority is
placed in an .init_array or .fini_array section with the priority
suffixed to the section name:
 - __attribute__((constructor)) ==> .init_array
 - __attribute__((constructor(42))) ==> .init_array.42

The suffixed init/fini sections appear before the unsuffixed sections,
so the prioritized functions appeared before the __{INIT,FINI}_ARRAY__
symbols and were dropped when the symbols were used.

The (static) linker doesn't recognize priority suffixes on
.preinit_array.

This bug affected .init_array and .fini_array for static executables.
For dynamic executables, only .fini_array was affected, because
.init_array is handled by the dynamic loader instead, which uses
DT_INIT_ARRAY[SZ]. For DSOs, neither is affected, because the two
sections are only handled by the dynamic loader.

This patch also fixes a minor inconsistency where dynamic init/preinit
were passed argc/argv/envp, but static were not.

Bug: http://b/170983066
Test: bionic-unit-tests
Change-Id: I0fffa776e5d9bdb6f8af06b4c1af148236742fef
2020-11-02 17:28:41 -08:00
Peter Collingbourne
a5c4b17e13 Clear PAC bits in android_unsafe_frame_pointer_chase().
Bug: 172057932
Change-Id: Ie0eb4800a6699f2094070e97e5157d4e9c186097
2020-10-30 14:36:37 -07:00
Treehugger Robot
10c2875934 Merge "getgrnam, getgrgid, getpwnam, getpwuid for host" 2020-10-29 23:53:50 +00:00
Yifan Hong
02bee7182e Merge "Make vendor_ramdisk_available." 2020-10-29 17:17:29 +00:00
Jiyong Park
bf383283d9 getgrnam, getgrgid, getpwnam, getpwuid for host
The functions now read /etc/group and /etc/passwd on host machines.
Android-specific IDs are not recognized in the host.

getpwent and getgrent are still not working though. They require a
bigger refactoring to sequentially advance in the database files.

Bug: 171718702
Test: run assemble_cvd in aosp_cf_arm64_phone
Change-Id: Ie8da382a467bbd0bffac7b4b8592cd871db80181
2020-10-29 07:52:54 +09:00
Yifan Hong
b04490d7e5 Make vendor_ramdisk_available.
Test: pass
Bug: 156098440
Change-Id: I8fe2deb8fa3b24c227202be02d8af648629cffeb
2020-10-27 17:06:45 -07:00
Treehugger Robot
c3ecfb623f Merge "system(3) uses /bin/sh when built for host" 2020-10-26 19:28:27 +00:00
Jiyong Park
8dd649deac system(3) uses /bin/sh when built for host
/system/bin/sh exists only on Android. When Bionic is built for the
host, use the standard /bin/sh.

Bug: 159685774
Test: run aosp_cf_arm64_phone on rockpi4
Change-Id: Idf4028c134abc128f203fc4d3be591f06b8fe8ff
2020-10-26 22:02:53 +09:00
Colin Cross
c44b1d0676 Merge "Make the connection between implementation and llndk_library explicit" 2020-10-23 18:09:42 +00:00
Martin Stjernholm
d88c8eb6b0 Merge "Rename ART release APEX to com.android.art." 2020-10-23 10:03:24 +00:00
Christopher Ferris
9aa6b15d79 Merge "Update to v5.9 kernel headers." 2020-10-22 00:54:16 +00:00
Martin Stjernholm
81c260d34b Rename ART release APEX to com.android.art.
Test: See https://r.android.com/1457217
Bug: 169639321
Change-Id: I71c75987ebfb1196d63f452945c5d387f2976d86
Merged-In: I71c75987ebfb1196d63f452945c5d387f2976d86
2020-10-21 15:41:02 +01:00
Ryan Prichard
72b1aaf68e Merge "Fix __cxa_atexit run-time regression with many registrations" 2020-10-21 00:44:50 +00:00
Victor Chang
c0d50d4a37 Replace libandroidicu usage in bionic with the new libicu.so available in NDK
Bug: 160350521
Test: atest CtsBionicTestCases
Change-Id: Id5fa76872ec295674eb1bed3b66e037a04fe6bf8
2020-10-20 15:44:20 +01:00
Ryan Prichard
de523c02bb Fix __cxa_atexit run-time regression with many registrations
When an array element is added or removed, make only the relevant page
writable, rather than the entire array. The entire array is still made
writable during recompaction and expansion.

This change fixes most of a large regression in __cxa_atexit runtime
(blueline, taskset 10, performance governor, 100000 registrations,
times are in seconds)
 - Q: _Exit=0.292380, exit=0.626801
 - R: _Exit=28.435082, exit=95.785110
 - new: _Exit=0.352285, exit=0.713893

Test: bionic unit tests
Test: adb shell taskset 10 \
  /data/benchmarktest64/bionic-spawn-benchmarks/bionic-spawn-benchmarks \
  --benchmark_filter='atexit' \
  --benchmark_display_aggregates_only=true \
  --benchmark_repetitions=10
Bug: http://b/168043760
Change-Id: I88cc15c29c9890b422b7f621f29f98a03ca1f886
2020-10-20 01:10:33 -07:00
Christopher Ferris
25c18d45cf Update to v5.9 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-5.9

Test: Boots cuttlefish 64bit, passes 32 bit and 64 bit bionic unit tests.
Change-Id: Ib5503355b238ea75595538e63eb000c867d06ef7
2020-10-19 15:48:58 -07:00
Colin Cross
8393a8bc84 Make the connection between implementation and llndk_library explicit
Instead of assuming a module with the .llndk suffix exists, add an
llndk_stubs property to every cc_library module that has a
corresponding llndk_library.  Also rename the llndk_library to have
an explicit .llndk suffix.

Bug: 170784825
Test: no changes to build.ninja (excluding comments) or Android-${TARGET_PRODUCT}.mk
Change-Id: Ib5453472a09ebc64818ceb69bcbe1184720ce86a
2020-10-19 13:37:49 -07:00
Baligh Uddin
db0c6deed6 Fix visibility rules.
BUG: 163786882
Test: Local build + TH
Change-Id: I788af6cf17ebee1fa5001768389a2c8b855c3534
2020-10-16 15:46:59 +00:00
Lev Rumyantsev
cf878313b0 Merge "Make more functions weak for native bridge" 2020-10-15 23:58:14 +00:00
Treehugger Robot
ddbcea2c11 Merge "pthread_cond: only call futex_wake when there are waiters" 2020-10-15 20:11:00 +00:00
Tim Murray
9c08f4fecc pthread_cond: only call futex_wake when there are waiters
pthread_cond_pulse would unconditionally call futex, which meant that
a number of processes were spending a significant amount of time in
pthread_cond_broadcast and pthread_cond_signal when there were no
threads waiting on that pthread_cond_t.

This change adds a counter to the 64-bit pthread_cond_t struct and
only calls futex() in cases where there is a nonzero waiter count. The
32-bit pthread_cond_t is unchanged due to compatibility reasons.

Test: no pthread_cond_broadcast/signal stacks without try_to_wake_up
in SurfaceFlinger
bug: 168831708

Change-Id: I105e1345cd2a3a75f98cd0acf316e790ba1716f0
2020-10-15 16:16:07 +00:00
Vy Nguyen
19f84868f4 Fix bug in finding another thread's TCB.
Change-Id: I06c86ca0c077b464fc6c9fbdf5b89889a26da5fb
2020-10-15 10:28:19 -04:00
Lev Rumyantsev
814f38fc28 Make more functions weak for native bridge
Test: CtsNetTestCases android.net.cts.DnsTest#testDnsWorks
Bug: 170665833
Change-Id: I83242e336f6ee5a0115252a12eddf9def26db90f
2020-10-13 17:03:15 -07:00
Steven Moreland
dcbc8ec29a Merge changes from topic "I81ece86ace916eb6b435ab516cd431ec4b48a3bf"
* changes:
  Expose per-process memory init.
  Add an API for per-process disabling memory initialization.
2020-10-09 21:05:02 +00:00
Steven Moreland
0cdf132f84 Expose per-process memory init.
In order to disable memory initialization for a process, the following
command can be used:

    android_mallopt(M_DISABLE_MEMORY_MITIGATIONS, nullptr, 0);

Since this is needed in vendor processes, this is exposing this
functionality to llndk. For convenience (and adding standard logging),
a helper function is being added into libcutils in order to use this,
w/o having to get into so many details.

Bug: 166675194
Test: use function from libcutils
Change-Id: Ia816089a9f3469c50c70afaa7244abeac5a51dcd
2020-10-09 00:33:30 +00:00
Peter Collingbourne
5d3aa86cd1 Add an API for per-process disabling memory initialization.
Introduce an android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) API call
that may be used to disable zero- or pattern-init on non-MTE hardware,
or memory tagging on MTE hardware. The intent is that this function
may be called at any time, including when there are multiple threads
running.

Disabling zero- or pattern-init is quite trivial, we just need to set
a global variable to 0 via a Scudo API call (although there will be
some separate work required on the Scudo side to make this operation
thread-safe).

It is a bit more tricky to disable MTE across a process, because
the kernel does not provide an API for disabling tag checking in all
threads in a process, only per-thread. We need to send a signal to each
of the process's threads with a handler that issues the required prctl
call, and lock thread creation for the duration of the API call to
avoid races between thread enumeration and calls to pthread_create().

Bug: 135772972
Change-Id: I81ece86ace916eb6b435ab516cd431ec4b48a3bf
2020-10-08 14:02:36 -07:00
Bram Bonné
18286ed465 Soft-enables new MAC address restrictions.
Updates getifaddrs() to behave as if RTM_GETLINK requests are not
allowed for non-system apps. This is different from previous behavior,
where apps targeting an API level < 30 were exempted from this
restriction.

Actual enforcement happens in SELinux. This change:
- Soft-enables the behavior until SELinux changes are in place
- Prevents logspam from SELinux denials after they are in place

Bug: 170188668
Test: atest bionic-unit-tests-static
Test: atest NetworkInterfaceTest
Test: Connect to Wi-Fi network
Test: Call getifaddrs() directly from within an app.
Test: Call NetworkInterface#getNetworkInterfaces() from within an app.

Change-Id: I95d124ae81bcb26583db5ad01d95d441d52f973c
2020-10-06 13:42:19 +02:00
Evgeny Eltsin
b4215ff11d Merge "Mark __progname as weak for native_bridge" am: 08a43426a0 am: 90e8c9700c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1446695

Change-Id: I2fc31308d9f51438b3746d59f5617e469b1235e1
2020-10-03 08:31:36 +00:00
Evgeny Eltsin
08a43426a0 Merge "Mark __progname as weak for native_bridge" 2020-10-03 07:26:51 +00:00
Ryan Prichard
ec51368bb1 Merge "x86/x86_64: cleanup signal trampolines" am: 6351127c13 am: 10ca6d3804
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1439538

Change-Id: I7f001d1339e1f4f454db6be2f958f7c9b866737b
2020-10-03 00:36:57 +00:00
Ryan Prichard
6351127c13 Merge "x86/x86_64: cleanup signal trampolines" 2020-10-02 23:26:27 +00:00
Evgeny Eltsin
b752dd53fd Mark __progname as weak for native_bridge
Bug: 167968941
Test: m
Change-Id: I636fab0bbf8e5565fb017940e6128c4bed3bab30
2020-10-02 14:41:04 +02:00
Ryan Prichard
068735939a Merge "Enable arm64 .eh_frame terminator, align it to 4" am: 9494caa7e8 am: 14b209988b
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1439537

Change-Id: Icc4c2daac109451fc2550db5da3c7469229cdbc0
2020-10-01 07:51:38 +00:00
Ryan Prichard
9494caa7e8 Merge "Enable arm64 .eh_frame terminator, align it to 4" 2020-10-01 01:08:38 +00:00
Yi Kong
5800d6b561 Merge "No global ThinLTO for bionic" am: 897fd6ecb3 am: 833a61145c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1432874

Change-Id: I8bd5ddf66fc5c4cf4d947f8d6ec78d565ded930a
2020-09-30 02:38:24 +00:00
Yi Kong
15a05a77b4 No global ThinLTO for bionic
There are multiple build breakages with bionic when we enable ThinLTO
globally. Opt bionic out of ThinLTO for now.

#global-thinlto-opt-out

Test: TreeHugger
Bug: 169004486
Change-Id: I546a8074f9c3e0ddbd01d3b7cd730e215e3c0c49
2020-09-29 17:24:04 +00:00
Victor Khimenko
24c3dd690f Merge "Make __clone_for_fork pure native bridge mode abstraction" am: 07c85f1688 am: e157c11f68
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1441332

Change-Id: Ib364f706a95b9a87e5a5e88c2bffeff8097cfe85
2020-09-28 22:02:59 +00:00
Victor Khimenko
391368193d Merge "Stop marking symbols weak in native bionic build" am: d510f22732 am: 5a1564ee1c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1441331

Change-Id: I85a6b10f05afeaae53f39cd4d7c2ac1804290a05
2020-09-28 22:02:31 +00:00
Victor Khimenko
07c85f1688 Merge "Make __clone_for_fork pure native bridge mode abstraction" 2020-09-28 20:46:50 +00:00
Victor Khimenko
d510f22732 Merge "Stop marking symbols weak in native bionic build" 2020-09-28 20:46:38 +00:00
Christopher Ferris
56034a1004 Merge "alloc_debug: get load_bias error" am: 5aedb68499 am: c7e1b6bf4f
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1440524

Change-Id: I05c3fb2362b79bab35a5be466324adc7e591d802
2020-09-28 20:18:26 +00:00
Victor Khimenko
6427f39ba9 Make __clone_for_fork pure native bridge mode abstraction
In native build of libc it would be inlined and in native bridge mode
it's noinline, extern "C" and thus could be easily intercepted.

Test: m (without weak symbols in native bridge mode x86+arm build would be broken)

Change-Id: I67759858a5bc2174dce1db9732fdbd89ba7689cc
2020-09-28 20:36:39 +02:00
Victor Khimenko
b967e793a5 Stop marking symbols weak in native bionic build
Now, when we can detect native bridge mode is sources we can do that.

Test: m (without weak symbols in native bridge mode x86+arm build would be broken)

Change-Id: I360e7df8211d03636bbe716dc14655ee8d765493
2020-09-28 20:25:32 +02:00
Weiwei.Zhang
8d01fac300 alloc_debug: get load_bias error
malloc_debug can use libunwind and libunwindstck to unwind backtrace,
if libc.debug.malloc.options contains the string of "backtrace_full",
malloc_debug will use libunwindstck, and if libc.debug.malloc.options
contains the string of "backtrace=*", malloc_debug will use libunwind.

The result of libunwindstck is normal, but the result of libuniwnd
is abnormal, there is a offset between the rel_cp and the correct value,
so addr2line can't decode the right line number.

Libunwind and libunbiwndpack calculate load_bias is different, so malloc_debug
get load_bias alignment with libunwindstack.

Bug: 169539402
Change-Id: I640fb5db39af622a0bb52abf2c107984065a89d5
2020-09-28 07:15:32 +00:00
Ryan Prichard
fd8d687051 x86/x86_64: cleanup signal trampolines
Let the assembler handle the low-level details of generating .eh_frame,
and use .cfi_escape to output the DWARF3 DW_CFA_def_cfa_expression and
DW_CFA_expression instructions.

Explicitly output a nop instruction between the FDE start
(.cfi_startproc) and the trampoline symbol.

x86_64: remove the rsp instruction, which is redundant with the CFA
itself.

Bug: http://b/169383888
Test: compare `objdump -Wf` output before and after
Test: bionic-unit-tests
Change-Id: Ie2a6d111cb473596be8c9f4fd64534e91d88f2a1
2020-09-25 15:58:42 -07:00
Elliott Hughes
501f5e1783 Merge changes from topic "arm64_branch-protection" am: 73ed0c4525 am: d42324ece4
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1420068

Change-Id: Idab907493868dccffad555ea803dce7126484844
2020-09-25 17:16:52 +00:00
Tamas Petz
b8ab12127f Update crtbegin.c and crt*.S to support Armv8.5-A BTI am: 18621fb30c am: ee3ccc20bc
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1418557

Change-Id: Ibac80bf6dfac45d7bb100dd74d02561d08722640
2020-09-25 17:16:50 +00:00
Tamas Petz
e7e2457400 libc: Prepare support for Armv8.3-A PAuth and Armv8.5-A BTI in *.S am: 19d66e6f2d am: e20a8e46c3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1418553

Change-Id: Id1459ad80e7420cf747621567a87c18eaf354656
2020-09-25 17:16:46 +00:00
Elliott Hughes
dcf91e88e4 Merge "Enable BTI in bionic linker" am: 7241ac6c07 am: dc0dd76dfb
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1242754

Change-Id: I5c3182ee75ab371af884ec20e2f62f381c95cbf4
2020-09-25 17:16:44 +00:00
Tamas Petz
ee3ccc20bc Update crtbegin.c and crt*.S to support Armv8.5-A BTI am: 18621fb30c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1418557

Change-Id: I324540c4cc6e0268defa90b0d6b56b1bc1ab2bac
2020-09-25 17:03:57 +00:00
Tamas Petz
e20a8e46c3 libc: Prepare support for Armv8.3-A PAuth and Armv8.5-A BTI in *.S am: 19d66e6f2d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1418553

Change-Id: Iefa4c34373d931c8554da9a8666c3f6447ec4b0e
2020-09-25 17:03:49 +00:00
Elliott Hughes
73ed0c4525 Merge changes from topic "arm64_branch-protection"
* changes:
  libc: Add Armv8.3-A PAuth and Armv8.5-A BTI compatibility to *.S
  Update crtbegin.c and crt*.S to support Armv8.5-A BTI
  libm: Add Armv8.3-A PAuth and Armv8.5-A BTI support to assembly files
  libc: Prepare support for Armv8.3-A PAuth and Armv8.5-A BTI in *.S
2020-09-25 16:08:14 +00:00
Elliott Hughes
7241ac6c07 Merge "Enable BTI in bionic linker" 2020-09-25 16:08:14 +00:00
Treehugger Robot
ce280320ee Merge "Work around issues with aligned_alloc() and -O2." am: 5cd0172b52 am: 184d4ec341
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1438112

Change-Id: I14fa8239559e436f6327eb3f71f57f54751b87df
2020-09-25 05:45:52 +00:00
Ryan Prichard
bcef897b6d Enable arm64 .eh_frame terminator, align it to 4
Every architecture that uses .eh_frame needs a terminator at the end to
ensure that an unwinder library doesn't read past the end of the
section. This can happen when the unwinder looks up a PC that doesn't
have a matching FDE. Both LLVM libunwind and libgcc fall back to an
.eh_frame scan if the .eh_frame_hdr search table scan fails.

By convention, this terminator section is aligned to 4, even on 64-bit
targets. e.g. Both libgcc and compiler-rt have a crtend with 4-byte
.eh_frame alignment on arm64 and x86_64.

In practice, lld strips off the terminator from input object files and
adds one unconditionally to the output, but bfd/gold still require a
crtend with a terminator.

References:
 - https://reviews.llvm.org/D86256
 - https://reviews.llvm.org/D87750
 - https://sourceware.org/bugzilla/show_bug.cgi?id=2655

Test: examine crtend.o and crtend_so.o with `readelf -SW` and \
  `objdump -Wf`
Change-Id: Ib8478ee446ad806898aa7147a6208d384c7516d5
2020-09-24 22:01:32 -07:00
Treehugger Robot
5cd0172b52 Merge "Work around issues with aligned_alloc() and -O2." 2020-09-25 03:56:22 +00:00
Stephen Hines
1c33c4a263 Work around issues with aligned_alloc() and -O2.
The latest LLVM update to r399163 has exposed an issue with optimization
of `aligned_alloc()` at -O2. Invalid inputs are treated as valid, which
results in assertions being hit. This WAR is to make sure that the test
keeps running while we fix the issue upstream.

Bug: http://b/169206016
Bug: http://b/155835175
Test: atest malloc_hooks_system_tests:malloc_hooks_system_tests.MallocHooksTest#aligned_alloc_hook_error -- --abi x86
Change-Id: I74b290b73826481c62db3a99ac1a690c8a8a8db3
2020-09-24 17:17:57 -07:00
Dan Albert
90d0277de4 Merge "Avoid explicit use of "10000" in build files." am: bda85584d1 am: 97860da3a9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1399787

Change-Id: I3fa8a38d7b1fffbcb944e13bf8aae8f4935163b9
2020-09-24 23:48:57 +00:00
Peter Collingbourne
2c37b70ca5 Merge "Copy the M_THREAD_DISABLE_MEM_INIT constant value into malloc.h." am: 155901898d am: cb1bb4147e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1433459

Change-Id: I75325e19a4ea04d6d38a6507a3a80caaccb3e1f1
2020-09-24 23:48:41 +00:00
Dan Albert
bda85584d1 Merge "Avoid explicit use of "10000" in build files." 2020-09-24 21:02:12 +00:00
Peter Collingbourne
155901898d Merge "Copy the M_THREAD_DISABLE_MEM_INIT constant value into malloc.h." 2020-09-24 21:02:09 +00:00
Peter Collingbourne
978eb16cd4 Copy the M_THREAD_DISABLE_MEM_INIT constant value into malloc.h.
This will allow platform and application developers to use it.

Bug: 163630045
Change-Id: If9a361cb97aaf62d3fa124b60f64d51d609af48d
2020-09-24 17:01:54 +00:00
Tamas Petz
8d55d1872a Enable BTI in bionic linker
This patch adds support to load BTI-enabled objects.

According to the ABI, BTI is recorded in the .note.gnu.property section.
The new parser evaluates the property section, if exists.
It searches for .note section with NT_GNU_PROPERTY_TYPE_0.
Once found it tries to find GNU_PROPERTY_AARCH64_FEATURE_1_AND.
The results are cached.

The main change in linker is when protection of loaded ranges gets
applied. When BTI is requested and the platform also supports it
the prot flags have to be amended with PROT_BTI for executable ranges.
Failing to add PROT_BTI flag would disable BTI protection.
Moreover, adding the new PROT flag for shared objects without BTI
compatibility would break applications.

Kernel does not add PROT_BTI to a loaded ELF which has interpreter.
Linker handles this case too.

Test: 1. Flame boots
      2. Tested on FVP with BTI enabled

Change-Id: Iafdf223b74c6e75d9f17ca90500e6fe42c4c1218
2020-09-23 17:53:28 -07:00
Tom Cherry
e26aea945b Merge "Explicitly add the include path for android_filesystem_config.h" am: 6c19d67a73 am: e533c9684f
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1430129

Change-Id: I45a1bb39a6f44bf6a6076c79596028fb21b30546
2020-09-21 21:47:55 +00:00
Tom Cherry
379ed1ef62 Explicitly add the include path for android_filesystem_config.h
android_filesystem_config.h is found since system/core/include is on
the include path for all projects and contains a symlink to the real
android_filesystem_config.h.  This is fragile and the below bug seeks
to remove this symlink and have users correctly depend on
libcutils_headers.

In bionic, libcutils_headers header library cannot be used due to
cyclic dependencies, so it gets the actual include path instead, which
is less bad than depending on the build system injecting the for all
modules.

Bug: 165825252
Test: build
Change-Id: Id43bdea9553b1174ceb3efc2a3ed505888619c62
2020-09-21 10:09:25 -07:00
Peter Collingbourne
f6e51cbbc4 Merge "Dump the per-thread TAGGED_ADDR_CTRL value if available." am: cf69abc0f4 am: b38a5c05c1
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1427158

Change-Id: I0654372399831973721c2a70d36abae2591b7550
2020-09-19 06:19:38 +00:00
Peter Collingbourne
cf69abc0f4 Merge "Dump the per-thread TAGGED_ADDR_CTRL value if available." 2020-09-18 22:00:53 +00:00
Treehugger Robot
74f46dd739 Merge "Make it clearer that math.h isn't fdlibm." am: 60a39566f0 am: 8e5fb88a72
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1430135

Change-Id: I4d6dc3a9d073e538dce3158dd06c35d2f7d0d0a7
2020-09-18 02:42:07 +00:00
Elliott Hughes
fee514e714 Make it clearer that math.h isn't fdlibm.
It was originally based on fdlibm, but it's been through two different
projects since then, and `git blame` shows basically nothing remaining
from those days. Seems worth leaving something to explain the unusual
copyright header though!

Test: treehugger
Change-Id: I8e7252a755704b866e7f36c8e97adc021fa3cdad
2020-09-17 11:57:50 -07:00
Peter Collingbourne
98d79de51d Dump the per-thread TAGGED_ADDR_CTRL value if available.
This value indicates whether memory tagging is enabled on a thread,
the mode (sync or async) and the set of excluded tags. This information
can sometimes be important for understanding an MTE related crash,
so include it in the per-thread tombstone output.

Bug: 135772972
Change-Id: I25a16e10ac7fbb2b1ab2a961a5279f787039000b
2020-09-15 21:32:36 -07:00
Elliott Hughes
803ae885b2 Merge "Expose a function to reset the stack protector for the zygote." am: 1efa573832 am: 24509c663e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1424970

Change-Id: If9974850dc7e653079c60c30c36dfaf6d25af768
2020-09-11 21:17:18 +00:00
Elliott Hughes
a1e3f2c502 Expose a function to reset the stack protector for the zygote.
This is already covered by the existing test by virtue of being used for
all threads.

Bug: http://b/168258494
Test: treehugger
Change-Id: I5c872fd7f30a4c79de1d70e7702f4b12d4e94cd3
2020-09-11 08:56:58 -07:00
Peter Collingbourne
eaee6d3eb8 Merge "Implement a new mechanism to let Scudo access the TLS slot" am: bba9153c5c am: 691b23e2ff
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1423770

Change-Id: I327f3063839f21cf6976ddabf934bf476a9c5ac2
2020-09-11 02:31:19 +00:00
Peter Collingbourne
bba9153c5c Merge "Implement a new mechanism to let Scudo access the TLS slot" 2020-09-10 23:02:03 +00:00
Peter Collingbourne
38d290a11d Implement a new mechanism to let Scudo access the TLS slot
An upcoming change to Scudo will change how we use the TLS slot
in tsd_shared.h, which will be a little easier to deal with if
we can remove the code path that calls pthread_getspecific and
pthread_setspecific. The only known user of this code path is Fuchsia.

We can't eliminate this code path by making Fuchsia use ELF TLS
because although Fuchsia supports ELF TLS, it is not supported within
libc itself. To address this, Roland McGrath on the Fuchsia team has
proposed that Scudo will optionally call a platform-provided function
to access a TLS slot reserved for Scudo. Android also has a reserved
TLS slot, but the code that accesses the TLS slot lives in Scudo.

We can eliminate some complexity and duplicated code by having Android
implement the same mechanism that was proposed for Fuchsia, which is
what this change does. A separate change to Scudo will make use of it.

Bug: 163630045
Change-Id: I4678105c9c47a23feb5a5e80a314416de4556d9c
2020-09-10 13:55:24 -07:00
Elliott Hughes
facc5479da Merge "NGREG != ELF_NGREG." am: a5a9992671 am: ba4b40602a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1419433

Change-Id: Id9a17fbc319c956430fd37f96a699b3f16cb6c86
2020-09-09 20:33:13 +00:00
Elliott Hughes
8e5fc5b037 NGREG != ELF_NGREG.
Except they are the same on arm32/arm64, so we hadn't really noticed. x86
and x86-64 are quite different though, presumably by historical accident.

Fix the definitions and add some static asserts.

Bug: https://github.com/android/ndk/issues/1347
Test: treehugger
Change-Id: Ic27b172066cf3443749463b9b73c912d204f9516
2020-09-08 09:27:02 -07:00
Tamas Petz
f5bdee7fdf libc: Add Armv8.3-A PAuth and Armv8.5-A BTI compatibility to *.S
The most notable change is in sigsetjmp/siglongjmp. The former
stores LR signed with the current SP into jmp_buf. Calling siglongjmp
reads a signed LR and the corresponding SP from jmp_buf. This way not
only the checksum provides some means of integrity protection but
Pointer Authentication too.

Test: Tested on FVP with BTI enabled.

Change-Id: I9d720239775f8d2829a677901f546c4b14b5cbe5
2020-09-04 11:29:12 +02:00
Tamas Petz
18621fb30c Update crtbegin.c and crt*.S to support Armv8.5-A BTI
These files are linked to all ELF files therefore they must support BTI.

Test: Tested on FVP with BTI enabled using a patched clang.

Co-authored-by: Gabor Kertesz <gabor.kertesz@arm.com>
Co-authored-by: Daniel Kiss   <daniel.kiss@arm.com>
Co-authored-by: Tamas Petz    <tamas.petz@arm.com>

Change-Id: If5df0722e649bcdb8c4afb0531831dff42103c9c
2020-09-04 11:28:59 +02:00
Tamas Petz
19d66e6f2d libc: Prepare support for Armv8.3-A PAuth and Armv8.5-A BTI in *.S
The instruction "bti c" is added through ENTRY*() macro,
using __bionic_asm_custom_entry(f).

The .note.gnu.property section is added with the new macro
NOTE_GNU_PROPERTY(). BTI and PAuth features are automatically
selected based on the presence of __ARM_FEATURE_* macros.

Furthermore, gensyscalls.py got updated to append the new
macro to the generated syscalls-arm64.S.

Test: Tested on FVP with BTI enabled.

Change-Id: I40ffe294b8426421125fffd0a9758567d919a09d
2020-09-04 11:28:43 +02:00
Tom Cherry
eaecffe0eb Merge "Add benchmark for property mapping" am: 7e0816a0a4 am: 4473d90316
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1417669

Change-Id: If056081494312385e591be65fa04911bc5133a03
2020-09-02 19:16:48 +00:00
Tom Cherry
a5744e213f Add benchmark for property mapping
This benchmarks mapping property prefixes to property contexts with
two algorithms: the 'Legacy' method used before Android P and the
'Trie' used afterwards (the code in this directory).

It uses input mappings from both Oreo and the latest in AOSP ('S').
Note that there is nearly a 10x increase in the number of mappings in
S as there was in Oreo, which was predicted when the trie was
designed.

Results on cuttlefish:
-----------------------------------------------------------
Benchmark                 Time             CPU   Iterations
-----------------------------------------------------------
LegacyLookupOreo     683576 ns       673538 ns         1060
LegacyLookupS       5683109 ns      5596982 ns          124
TrieLookupOreo       299851 ns       295696 ns         2378
TrieLookupS          584831 ns       576801 ns         1204

The results show that the legacy look up uses 8.3x more CPU time to
handle the number of mappings added through S, whereas the Trie lookup
uses less than 2x more CPU time, showing that the trie scales better
with added mappings.

Test: run this benchmark
Change-Id: I35c3aa4429f049e327a891f9cbe1901d8855d7ba
2020-09-02 16:12:21 +00:00
Treehugger Robot
a3920cf767 Merge "Incorporate upstream's strptime %Z/%z support." am: 159bb3f86b am: 57af5a7c73
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1417572

Change-Id: I99d71533c73a721877bd43fa759912c7c5b60351
2020-09-02 16:11:24 +00:00
Elliott Hughes
d065c0489e Incorporate upstream's strptime %Z/%z support.
I made toybox use strptime %Z recently (so that it can parse the default
POSIX date(1) output), forgetting that bionic's strptime(3) doesn't
support %Z. Neither does glibc, for that matter; the toybox change works
on glibc effectively by accident --- glibc just ignores the next word
when parsing %Z and assumes that the current time zone ($TZ) is
appropriate. Which it is for the only obvious use case of "round trip
date(1) output".

The related %z is potentially quite a bit more useful in general (parsing
any valid RFC822 time zone), though sadly not useful for the toybox case
that prompted.

Every time I touch this file I promise that I'll actually get us back in
sync with upstream, and every time I fail to get round to it. Maybe
2020 or 2021 will finally be the year...

Also add corresponding tests.

Bug: https://b/167455975
Test: treehugger
Change-Id: I13a7fb7e3ad01ae855750b9314d2eec661fe034f
2020-09-01 19:11:28 -07:00
Ken Chen
e8fad600d5 Fix OOB read in DNS resolver am: 43264bc365 am: c5ea7569a8 am: 2c2546b158 am: cf6b3ecd4d
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/12329970

Change-Id: I333ae67e5f9e12228658a36f4cbdcf8716fb32a1
2020-08-30 06:02:04 +00:00
Ken Chen
cf6b3ecd4d Fix OOB read in DNS resolver am: 43264bc365 am: c5ea7569a8 am: 2c2546b158
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/12329970

Change-Id: I5e167b6717d7f90ba782e26ef553fb6d302b493a
2020-08-30 05:25:44 +00:00
Ken Chen
c5ea7569a8 Fix OOB read in DNS resolver am: 43264bc365
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/12329970

Change-Id: Ief989a779e7fea19a92fb90a863017ecdb1bc7a3
2020-08-30 04:49:07 +00:00
Bowgo Tsai
1e1c7845aa bionic_systrace: moving global static variables
Some global static variables are only used within a single function,
so moving them inside the function which requires them. This also
ensures those static variables of class types are initialized before
they are being used.

For example, this is needed for CachedProperty(), as some of the
member method, e.g., CachedProperty().Get(), might be invoked,
e.g., in __libc_preinit(), before the constructor is invoked.
This happens after we added property trace points in commit
Id2b93acb2ce02b308c0e4889f836159151af3b46.

For g_lock, we don't move them because it can be initialized by setting
its memory to 0. And it's used in two functions.
  https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/private/bionic_lock.h

Bug: 147275573
Test: atest CtsBionicTestCases
Test: adb shell perfetto -o /data/misc/perfetto-traces/test_trace -t 10s bionic sysprop
Change-Id: I99565ce2442d34f33830778915c737eed834f8b3
2020-08-25 02:26:30 +00:00
Josh Gao
1e0d28b9c2 Merge "async_safe: don't call libc's socket." 2020-08-21 23:34:20 +00:00
Josh Gao
d37113311c async_safe: don't call libc's socket.
Like with close, socket is no longer a simple syscall, so we can get
recursive calls that deadlock.

Bug: http://b/165206592
Test: bionic-unit-tests on cuttlefish
Test: treehugger
Change-Id: I2ba77d733d1ebf08a91afd6ca179e7ae6ae3866e
2020-08-21 14:23:57 -07:00
Bowgo Tsai
d0ecf0b30d Adding system property tracing
Introducing a new systrace tag, TRACE_TAG_SYSPROP, for use with
system property.

For property set, the tracing is added in __system_property_set() instead of
__system_property_update() / __system_property_add() so we can record
control properties like ctl.*, sys.powerctl.*, etc.., which won't be
updated via the latter two functions.

Bug: 147275573
Test: atest CtsBionicTestCases
Test: adb shell perfetto -o /data/misc/perfetto-traces/test_trace -t 10s bionic
Test: adb shell perfetto -o /data/misc/perfetto-traces/test_trace -t 10s sysprop
Test: adb shell /data/benchmarktest64/bionic-benchmarks/bionic-benchmarks \
      --benchmark_filter=BM_property --bionic_cpu=4, then compares the results
      of property benchmarks before and after the change, didn't see
      significant difference.

Change-Id: Id2b93acb2ce02b308c0e4889f836159151af3b46
Merged-In: Id2b93acb2ce02b308c0e4889f836159151af3b46
(cherry picked from commit 26970c3493)
2020-08-19 12:47:01 +08:00
Treehugger Robot
3936985e75 Merge "Disable HWASAN on ifunc resolvers." 2020-08-13 21:58:58 +00:00
Elliott Hughes
1c502d46b3 Merge "Various coverage improvements." 2020-08-13 21:27:09 +00:00
Dan Albert
48943b20c0 Avoid explicit use of "10000" in build files.
Test: treehugger
Bug: None
Change-Id: Iab713c5f4b53665f8224b3857beaa6a1d19f8d69
2020-08-13 13:35:17 -07:00
Peter Collingbourne
03d89a7068 Disable HWASAN on ifunc resolvers.
We can't have HWASAN enabled in these resolvers because they
may be called before HWASAN is initialized.

We were previously getting away with HWASAN being enabled on these
functions because ANDROID_EXPERIMENTAL_MTE was not defined, which
let the compiler simplify away any HWASAN instrumentation in the
resolvers. But with this build flag enabled (which is currently the
case in FVP, and eventually everywhere once the MTE kernel patches
land) the resolvers end up containing an HWASAN instrumented load of
the _hwcap2 field.

Bug: 135772972
Change-Id: Iac79d02ddc81630c955e107eb7f78389aeb33879
2020-08-13 13:01:44 -07:00
Vy Nguyen
d4d7efc1f8 Merge "Add a thread-properties API (Based on proposal at https://sourceware.org/glibc/wiki/ThreadPropertiesAPI)" 2020-08-13 19:58:03 +00:00
Elliott Hughes
7cebf835f3 Various coverage improvements.
Mostly from extra test cases, but also:

* Move the fgets size < 0 assertion into fgets.

* Use ELF aliases for strtoq/strtouq rather than duplicating code.

* Don't check uname() succeeded, since it can't fail.

Test: treehugger
Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
2020-08-12 15:52:14 -07:00
Elliott Hughes
aadcb07890 Merge "Cleanup for #inclusivefixit." 2020-08-12 22:13:11 +00:00
Treehugger Robot
d4da7b17a2 Merge "Create per-API versions of the CRT objects." 2020-08-12 22:01:27 +00:00
Dan Albert
dc503f65ec Create per-API versions of the CRT objects.
Test: treehugger
Bug: http://b/159925977
Change-Id: I3ad629f9370503b26f4a73787bccb3f669c41a0a
2020-08-11 14:14:31 -07:00
Dan Albert
d8f46916b6 Add api-level.h to dac, improve docs.
We don't list most of bionic on dac since it would be overwhelming for
the current layout, but this file in particular seems useful,
especially __ANDROID_API__. Unfortunately, c2devsite doesn't include
macro documentation. Until then, it's still useful to include the
functions defined in this header.

I've also elaborated a bit in the __ANDROID_API__ documentation, since
the existing phrasing led to confusion over whether it was closer to
minSdkVersion or compileSdkVersion. In practice these are identical
for the NDK, but if we switch to weakly-linked APIs via the
availability attribute that would change.

Test: built docs, looked at them
Bug: None
Change-Id: I5cf78a6143b5c15790c369bdf888611e4c1189db
2020-08-11 13:50:04 -07:00
Vy Nguyen
d500751443 Add a thread-properties API
(Based on proposal at https://sourceware.org/glibc/wiki/ThreadPropertiesAPI)

This includes API to:
 - locate static and dynamic TLS
 - register thread-exit and  dynamic TLS creation/destruction callbacks

Change-Id: Icd9d29a5b2f47495395645e19d3b2c96826f19c8
2020-08-11 16:51:43 +00:00
Elliott Hughes
f08e70a0d9 Merge "Reimplement our no-op utmp.h functions more simply." 2020-08-10 15:41:13 +00:00
Elliott Hughes
9a1d3976f1 Reimplement our no-op utmp.h functions more simply.
Now we're being marked down for our poor coverage, we may as well remove
more broken cruft. Despite the amount of effort that seems to have gone
into pututline(), it wasn't working with the other utmp.h functions (in
particular, utmpname()), and wasn't declared in the header file!

Test: treehugger
Change-Id: I1a583984189c751168c11c01431433f96f8c548b
2020-08-07 17:07:31 -07:00
Dan Albert
2dbea434d1 Make swab(3) inline prior to API 28.
Test: make checkbuild
Bug: https://stackoverflow.com/q/54392471/632035
Change-Id: Iaeb55231ea2395d7e1e31be63034f5db19025060
2020-08-07 13:10:51 -07:00
Elliott Hughes
422b2044ea Merge "Switch to musl memmem (via OpenBSD)." 2020-08-07 20:01:17 +00:00
Ken Chen
43264bc365 Fix OOB read in DNS resolver
The remote server specifies resplen, the length of the response it
intends to send. anssiz represents the size of the destination buffer.
If the reported resplen is larger than the anssiz, the code correctly
only reads up to anssiz bytes, but returns resplen. so later functions
will access far out of bounds.

The fix ensures that the length of send_vc return does not exceed the
buffer size.

Bug: 161362564
Test: build, flash, boot
Test: atest netd_integration_test
Merged-In: Id4b5df1be4652e4623847b0b0bad0af65b80fdd5
Change-Id: Id4b5df1be4652e4623847b0b0bad0af65b80fdd5
2020-08-07 20:19:43 +08:00
Treehugger Robot
cc8f1ea9e1 Merge "Allow native_bridge to intercept __get_thread()->stack_top" 2020-08-07 05:52:52 +00:00
Elliott Hughes
5633caa285 Switch to musl memmem (via OpenBSD).
Similar to the musl strstr. This patch also increases test coverage for
memmem, again similar to the strstr tests.

Test: treehugger
Change-Id: I7f4a2ab93a610cb692994d06d2512976e657ae9f
2020-08-06 14:33:48 -07:00
Christopher Ferris
eebb1ec687 Merge "Update to v5.8 kernel headers." 2020-08-06 16:31:03 +00:00
Treehugger Robot
e41012fe2e Merge "Enable coverage for libc." 2020-08-05 23:23:48 +00:00
Pirama Arumuga Nainar
8035caa311 Enable coverage for libc.
Bug: http://b/157081822

- Disable coverage for libtest_check_rtld_next_from_library to make
dlfcn.rtld_next_from_library to pass.
- The coverage runtime sets an environment variable to prevent
clobbering of the coverage data on disk.  Include that variable as well
when checking `printenv` output.  This is done at runtime by checking
for LLVM_PROFILE_FILE environment variable.
- dl.preinit_system_calls still fails after this change.

Test: bionic tests with libc coverage turned on.

Change-Id: I3ea2b0800886d8c0984969a4ee8bfb0da03c33b0
2020-08-05 14:58:40 -07:00
Christopher Ferris
8177cdf178 Update to v5.8 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-5.8

Test: NA
Change-Id: I2231c877589820fc09800a200cf4ac62ba74b04c
2020-08-04 13:50:49 -07:00
Steven Moreland
7591bb5ee1 Merge "SCUDO fill options only when USE_SCUDO" 2020-08-04 17:47:36 +00:00
Bowgo Tsai
a9208f3ac2 Moving bionic_systrace.cpp out of libc_bionic_ndk
We'll be enabling system tracing in libsystemproperties, which requires
using bionic_systrace.cpp from libc_bionic_ndk. However, libc_bionic_ndk
already depends on libsystemproperties.

Introducing a new library libc_bionic_systrace for bionic_systrace.cpp,
which can be used by both libc_bionic_ndk and libsystemproperties.

Bug: 147275573
Test: atest CtsBionicTestCases
Test: adb shell perfetto -o /data/misc/perfetto-traces/test_trace -t 10s bionic
Change-Id: I7306f922f212fa1c911583e1922e33612bfeada6
2020-08-04 11:08:05 +08:00
Evgeny Eltsin
61be80182c Fix __clone_for_fork attributes
Avoid name mangling and ensure no export.

Bug: 162625883
Test: bionic-unit-tests
Change-Id: If7700772e0a8c7a52be890d55ecdac33185f6b78
2020-08-01 13:33:01 +02:00
Evgeny Eltsin
f69030095d Allow native_bridge to intercept __get_thread()->stack_top
Bug: 158584334
Test: bionic-unit-tests --gtest_filter=android_unsafe_frame_pointer_chase*
Change-Id: Ib58372991027846eb35c7e393de321910fa92997
2020-08-01 13:29:03 +02:00
Elliott Hughes
907e0aebd2 Merge "Sync with upstream OpenBSD." 2020-07-31 23:47:05 +00:00
Treehugger Robot
0cfe54966b Merge "Sync with upstream NetBSD." 2020-07-31 21:14:34 +00:00
Elliott Hughes
26b06073f6 Sync with upstream OpenBSD.
Test: treehugger
Change-Id: I1fc649ba5d79a3d95242c6b2240dbb05c85d30e9
2020-07-31 13:01:38 -07:00
Elliott Hughes
79c91ae43b Sync with upstream NetBSD.
Test: treehugger
Change-Id: Ia88698f032c017fabc8d24bab12f33ed0b55e65e
2020-07-31 12:59:48 -07:00
Steven Moreland
fb65ee4c47 SCUDO fill options only when USE_SCUDO
For vanity reasons, this CL should be reverted after b/158870657, since
we want to make sure zero/pattern fill always happen when they are
requested.

Bug: 131355925
Bug: 158870657
Test: check build on normal devices hits USE_SCUDO branch with #error
Change-Id: I22d19dbc75004c8f7437e1247226bc3275cd4df5
2020-07-31 17:45:44 +00:00
Elliott Hughes
cf346532fc More cleanup for #inclusivefixit.
Found manually with grep, since the script seems to miss stuff.

Test: treehugger
Change-Id: I5933cbade9792801d4a0bec1ccb077efa6ad8fbc
2020-07-31 10:35:03 -07:00
Christopher Ferris
3025f128f3 Merge "Add support for new scudo mallopt options." 2020-07-29 16:38:06 +00:00
Christopher Ferris
8844879212 Add support for new scudo mallopt options.
Bug: 162092537

Test: Ran new unit tests.
Change-Id: I4b7d17a9e98166c03cd153eb9e9d847693914ea3
2020-07-28 18:20:32 -07:00
Treehugger Robot
72ac49dbd8 Merge "Remove pylintrc." 2020-07-29 01:12:56 +00:00
Elliott Hughes
fce3187088 Cleanup for #inclusivefixit.
This was initially just to try on "pty" and "tty" for size, while
discussing with other projects to try to align on vocabulary, but -- in
the implemention and tests at least -- but these work out so well that
I'm tempted to go with them anyway if we can't come to a concensus. We
can always come back and change them again later.

What I really like is that you pass the pty to functions like ptsname()
and grantpt() with a 'p' in the name, and the tty to functions like
ttyname() and tcsetattr() with just 't's.

The use of "parent" and "child" in forkpty() seems helpful too.

Also fix the documentation of forkpty(), which wasn't quite right.

Test: treehugger
Change-Id: Ic010c4b669f6528591c653e3701f4e41e0d0df9e
2020-07-28 12:12:20 -07:00
Tom Cherry
15786e407f Cleanup for #inclusivefixit.
Test: build
Change-Id: Ib2f264feae69fbbda5fe1e1c315b6116ecf520fa
2020-07-28 10:56:12 -07:00
Dan Albert
9dd11412a6 Remove pylintrc.
Considering none of the files in this directory are pylint clean I
don't think this is being used. They also seem to use a mix of styles
so we need to either unify or split things into subdirectories if we
want to use pylint here.

Test: None
Bug: http://b/161896447
Change-Id: I5bc298bd64d44cc10d3d28121666e7893222ea96
2020-07-27 13:40:28 -07:00
Elliott Hughes
3f3161093b Cleanup for #inclusivefixit.
Test: treehugger
Change-Id: Iec1af942b5dee37f08ad390afe9fbdb79c47c085
2020-07-23 13:43:23 -07:00
Bram Bonné
3a5a22d607 Resolve interface flags using SIOCGIFFLAGS ioctl
Normally, getifaddrs() gets its information about interface flags from
RTM_NEWLINK messages. With the ability for non-system apps to send
RTM_GETLINK messages going away, resolve these flags by performing a
SIOCGIFFLAGS ioctl call instead.

This fixes a bug where the flags were erroneously copied over from an
ifaddrmsg's ifa_flags.

Bug: 141455849
Bug: 161869825
Test: atest bionic-unit-tests-static
Test: Connect to wireless network.
Test: Call getifaddrs() from a non-system app targeting API R+, verify
that the interface flags are correct.

Change-Id: I552f3b9d21072f59ee6f0890f47cb1bdf3cfcf20
2020-07-23 08:40:25 -07:00
Elliott Hughes
6ba173a3f6 Merge "Changes for #inclusivefixit." 2020-07-22 19:26:37 +00:00
Neil Fuller
9b7338c6bb Merge "Track name changes in the tzdata format" 2020-07-22 09:50:10 +00:00
Elliott Hughes
68ae6ad12e Changes for #inclusivefixit.
Test: treehugger
Change-Id: I7ff0496c5c2792a41781e74634247f55b0548213
2020-07-21 16:34:58 -07:00
Bram Bonné
8e20ac4413 Resolve interface flags using SIOCGIFFLAGS ioctl
Normally, getifaddrs() gets its information about interface flags from
RTM_NEWLINK messages. With the ability for non-system apps to send
RTM_GETLINK messages going away, resolve these flags by performing a
SIOCGIFFLAGS ioctl call instead.

This fixes a bug where the flags were erroneously copied over from an
ifaddrmsg's ifa_flags.

Bug: 141455849
Test: atest bionic-unit-tests-static
Test: Connect to wireless network.
Test: Call getifaddrs() from a non-system app targeting API R+, verify
that the interface flags are correct.

Change-Id: I552f3b9d21072f59ee6f0890f47cb1bdf3cfcf20
2020-07-21 19:14:12 +02:00
Florian Mayer
c618960288 Improve diagram in malloc_heapprofd.
Include the functions that cause the state transitions.

Change-Id: I262e74c58e12316996451c418ab222f4512d005c
2020-06-26 14:27:58 +02:00
Treehugger Robot
b76e8e610c Merge "strings.h: undef ffs/ffsl/ffsll." 2020-06-25 19:11:08 +00:00
Elliott Hughes
c9889fdf15 strings.h: undef ffs/ffsl/ffsll.
Protect against software that #defines these, such as mesa3d.

Test: treehugger
Change-Id: I22e937423967676ea332956289419d48bb7c2cd3
2020-06-25 08:46:06 -07:00
Christopher Ferris
d381b26576 Merge "Remove references to libc_scudo." 2020-06-24 03:16:47 +00:00
Treehugger Robot
536b7ec5ac Merge "Revert "Disallow vmsplice(2) for all zygote-spawned processes."" 2020-06-23 19:44:54 +00:00
Elliott Hughes
b477ac74e7 Revert "Disallow vmsplice(2) for all zygote-spawned processes."
This reverts commit 3d1bd8efbe.

Reason for revert: http://b/159712722

The original test (`atest --test-mapping packages/providers/MediaProvider`) passed in AOSP, but there's a new use of vmsplice() in rvc-dev.

Bug: http://b/157591659
Bug: http://b/159712722
Change-Id: Icc9b752ca4fa21f7e18c409b55f3977b7460bfbe
Test: treehugger
2020-06-23 17:53:35 +00:00
Christopher Ferris
ef707f9056 Remove references to libc_scudo.
As scudo is now the default native allocator, there is no need to
keep this library around.

Test: Builds and walleye boots.
Change-Id: Id2918544651348854956d1348d2a634f6425b952
Merged-In: Id2918544651348854956d1348d2a634f6425b952
(cherry picked from commit 941ad56299)
2020-06-22 15:27:52 -07:00
Elliott Hughes
528e29d91c Simplify tzdata fallback logic.
It's a historical accident that we try all the other files even if a
higher-priority file doesn't contain the sought-for olson id. Stop
doing that.

Also remove a TODO that has never been warranted, and add one that it
will be many years before anyone can do anything about it, but by that
time the historical knowledge may have been lost.

Bug: http://b/159613340
Test: treehugger
Change-Id: I873579268753c84b0bb721ea56f71ba64506d45a
2020-06-22 12:55:12 -07:00
Elliott Hughes
3d1bd8efbe Disallow vmsplice(2) for all zygote-spawned processes.
Bug: http://b/157591659
Test: treehugger
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I6adfc6060f6382e70383f10fce4e65b09acd1dd0
2020-06-19 15:49:19 -07:00
Elliott Hughes
ad4b47c429 Merge "Don't look for licenses in .md files and pylintrc files." 2020-06-16 15:38:39 +00:00
Elliott Hughes
da45ea6687 Merge "Update libc/NOTICE." 2020-06-16 00:35:59 +00:00