aboutsummaryrefslogtreecommitdiff
path: root/libc/bionic
Commit message (Collapse)AuthorAgeFilesLines
* Add persistent GWP-ASan sysprops.Mitch Phillips2022-06-302-13/+30
| | | | | | | | | | | | | | Adds persistent sysprops for test infra usage, and adds the tests for the sysprops. The test does some fancy flocking in order to restore any existing GWP-ASan sysprop usage in the test cleanup. Bug: 236738714 Test: atest bionic-unit-tests Ignore-AOSP-First: cherry-pick to internal branch Change-Id: I8956296d39c98ce8c7dd0a703b240530d8ad48db Merged-In: I8956296d39c98ce8c7dd0a703b240530d8ad48db
* allowlist new Linux close_range() system call, use it in posix_spawn()Maciej Żenczykowski2022-04-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | Linux kernel's close_range() system call (currently) allows: close() unshare() fcntl(F_SETFD, FD_CLOEXEC) to be performed on ranges of fds. All 3 of these are already allowed by seccomp bpf: as such this doesn't allow you to do anything you can't already do. We can't add close_range() properly to bionic because we'd need to fiddle about with ltp and it's too late to add new T API anyway, so let's just make the direct syscall() call. We'll add proper support in U. See also: https://man7.org/linux/man-pages/man2/close_range.2.html Test: TreeHugger Bug: 229913920 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I85586d544fc23bed6aee59f00bdb79ee7a8150d1 Merged-In: I85586d544fc23bed6aee59f00bdb79ee7a8150d1
* posix_spawn - implement support for POSIX_SPAWN_CLOEXEC_DEFAULTMaciej Żenczykowski2022-04-271-1/+25
| | | | | | | | | | | | | | | | This new posix_spawn attribute flag marks all file descriptors (except stdin/out/err) as close-on-exec before executing any user registered file actions (posix_spawn_file_actions_addopen/adddup2). Test: TreeHugger Bug: 229913920 Original change: https://android-review.googlesource.com/c/platform/bionic/+/1955269 Merged-In: If458100d6a253a9b0348d4e93a9a610225f89615 Change-Id: If458100d6a253a9b0348d4e93a9a610225f89615 Signed-off-by: Maciej Żenczykowski <maze@google.com> (cherry picked from commit fb66c0c345f17d740b6a2ef7755f768dd5bd96ee)
* Merge "[GWP-ASan] Provide runtime configuration through an env var + sysprop."Mitch Phillips2022-04-217-137/+353
|\
| * [GWP-ASan] Provide runtime configuration through an env var + sysprop.Mitch Phillips2022-04-207-137/+353
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces GWP-ASan system properties and environment variables to control the internal sampling rates of GWP-ASan. This can be used for: 1. "Torture testing" the system, i.e. running it under an extremely high sampling rate under GWP-ASan. 2. Increasing sampling remotely to allow further crash report collection of rare issues. There are three sets of system properites: 1. libc.debug.gwp_asan.*.system_default: Default values for native executables and system apps. 2. libc.debug.gwp_asan.*.app_default: Default values for non-system apps, and 3. libc.debug.gwp_asan.*.<basename/app_name>: Default values for an individual app or native process. There are three variables that can be changed: 1. The allocation sampling rate (default: 2500) - using the environment variable GWP_ASAN_SAMPLE_RATE or the libc.debug.gwp_asan.sample_rate.* system property. 2. The process sampling rate (default: 128 for system apps/processes, 1 for opted-in apps) - using the environment variable GWP_ASAN_PROCESS_SAMPLING or the libc.debug.gwp_asan.process_sampling.* system property, 3. The number of slots available (default: 32) - using the environment variable GWP_ASAN_MAX_ALLOCS or the libc.debug.gwp_asan.max_allocs.* system property. If not specified, #3 will be calculated as a ratio of the default |2500 SampleRate : 32 slots|. So, a sample rate of "1250" (i.e. twice as frequent sampling) will result in a doubling of the max_allocs to "64". Bug: 219651032 Test: atest bionic-unit-tests Change-Id: Idb40a2a4d074e01ce3c4e635ad639a91a32d570f
* | Merge "In android_set_abort_message, check for nullptr."Christopher Ferris2022-04-121-0/+4
|\ \
| * | In android_set_abort_message, check for nullptr.Christopher Ferris2022-04-121-0/+4
| |/ | | | | | | | | | | | | | | | | | | | | | | | | If a process is failing due to out of memory, some code calls android_set_abort_message with a nullptr. Specifically, the libc++ library std::terminate can call do this. In this case, put a null in the abort message. Test: Call with nullptr and verify the code does not crash. Test: Modified crasher to set an abort message and set a null abort Test: message. Ran both, verified the abort message displays in Test: first case, and doesn't display in the second case. Change-Id: Ia9250f47e4537853ce93bbb20b35915a78caa502
* / [GWP-ASan] Fix bugs in realloc().Mitch Phillips2022-04-111-2/+13
|/ | | | | | | | | | | | Two edge cases were found in aosp/2038947: 1. realloc(p, 0) == free() and returns nullptr. Previously, we just returned a new pointer. 2. If the malloc() part of realloc() fails (e.g. when the size of the allocation is 1 << 56), then the old memory shouldn't be destroyed. Bug: N/A Test: Covered using atest bionic-unit-tests using aosp/2038947. Change-Id: Ibafc752787129922a1e0323ffa14221d6a14f108
* Merge "Revert "Disable pointer authentication in app processes.""Elliott Hughes2022-03-141-2/+3
|\
| * Revert "Disable pointer authentication in app processes."Elliott Hughes2022-03-101-2/+3
| | | | | | | | | | | | | | | | | | | | | | Revert submission 1954983-master-I3030c47be9d02a27505bd4775c1982a20755758c Reason for revert: PAC has shipped with S, and we're going with app compat outreach rather than regressing security. Reverted Changes: I3030c47be:Disable pointer authentication in app processes. I3030c47be:Disable pointer authentication in app processes. Change-Id: I8761f08ddbd9077ff98b1a9a0c323de968792778
* | posix_spawn: always clear O_CLOEXEC for dup'ed fds.Elliott Hughes2022-02-161-1/+11
| | | | | | | | | | | | | | | | | | | | dup2(2) is a no-op if the new and old fds are equal, but it's pretty clear that any useful caller in the posix_spawn(3) context wants us to clear O_CLOEXEC even if we don't actually "move" the fd. Bug: https://www.austingroupbugs.net/view.php?id=411 Test: treehugger Change-Id: I5ce1a1f9216df5afd295cc9e35b84527873e9541
* | profiling: override dumpability while opening /proc/self/mem,mapsRyan Savitski2022-02-111-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For the perf profiling signal handler to succeed in opening /proc/self/mem, the process needs to be marked as dumpable in posix terms. This patch addresses a scenario since Android S where the process is considered profileable, but is not dumpable on "user" builds. The solution is to mark the process as dumpable while opening the procfs descriptors, restoring the original value afterwards. This is the same approach as the heapprofd heap profiler, which performs the override within the loaded client library [1]. The particular scenario being addressed is: * user build * app does not explicitly opt into being profiled by shell * app does not explicitly opt out of all profiling In this case, the app is considered profileable by the platform (but NOT shell). Therefore ActivityThread marks the process as profileable [2], but the zygote keeps the process as undumpable as it considers the profileability from the shell domain [3]. We could change the logic in the zygote to leave such processes in the dumpable state, but the override within the signal handler is considered to be more contained as the dumpability is only needed temporarily. This override would also apply for any non-dumpable native services that are signalled for profiling, which is also desireable for profiling coverage. This change does not elide any of the existing profileability checks by the signal handler's preamble and the profiler itself. [1] https://cs.android.com/android/platform/superproject/+/master:external/perfetto/src/profiling/memory/client.cc;l=184;drc=78cd82ba31233ce810618e07d349fd34efdb861d [2] https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/app/ActivityThread.java;l=6610;drc=de9cf3392d7872c2bee69b65a614e77bb166b26e [3] https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/jni/com_android_internal_os_Zygote.cpp;l=1680;drc=master Tested: clock app on barbet-user succeeds in opening the procfs descriptors within the signal handler. Tested: systemwide profiling on sargo-userdebug works as before. Bug: 196810669 BYPASS_INCLUSIVE_LANGUAGE_REASON=referencing the name of a cmdline utility Change-Id: Id621d4312418ff0736c97065e9ee577ff67f40da
* | [MTE] Relax ELF note.Mitch Phillips2022-02-081-12/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the ELF note parsing in the loader is not permissive. This patch relaxes the restrictions on the bits of the ELF note that could be extended in the future. This may allow more MTE options in apexes. If we add some extra metadata bit (say, in bit 5) in the future, and then build MTE into every apex, we don't want it to crash on Android 13 devices (we'd much rather it just be a no-op). Remove the (unused anywhere) NT_MEMTAG_DEFAULT and call it NT_MEMTAG_NONE. And finally, make the tests work on bionic-unit-tests-static. We previously didn't deploy the test binaries, so add them as a data dependency. Bug: N/A Test: atest bionic-unit-tests-static Change-Id: I13530faad55c719c6eb848297f8ce378e18afbfc
* | Merge "[MTE] add sysprop to set mte state globally"Treehugger Robot2022-02-081-2/+4
|\ \
| * | [MTE] add sysprop to set mte state globallyFlorian Mayer2022-02-071-2/+4
| | | | | | | | | | | | | | | | | | this can be used to run CTS w/ maximum MTE coverage on normal builds. Change-Id: I527b8549f30fd4bd9511d94ca142ea08b72d1a78
* | | [NFCI] Change Android's NT_TYPE to NT_ANDROID_TYPE.Mitch Phillips2022-02-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Normally, platform-specific note types in the toolchain are prefixed with the platform name. Because we're exposing the NT_TYPE_MEMTAG and synthesizing the note in the toolchain in an upcoming patch (https://reviews.llvm.org/D118948), it's been requested that we change the name to include the platform prefix. While NT_TYPE_IDENT and NT_TYPE_KUSER aren't known about or synthesized by the toolchain, update those references as well for consistency. Bug: N/A Test: Build Android Change-Id: I7742e4917ae275d59d7984991664ea48028053a1
* | | Fix HWASan crashes in heapprofd initialization.Florian Mayer2022-02-011-7/+9
| | | | | | | | | | | | | | | | | | | | | Test: atest perfetto_integrationtests on HWASan build Bug: 210588740 Change-Id: Iddaa4a7d0dedee541f97bbf0a13958de023bdf59
* | | Merge "Fix recursive deadlock inside bionic_systrace"Daniele Di Proietto2022-01-261-2/+34
|\ \ \ | |/ / |/| |
| * | Fix recursive deadlock inside bionic_systraceDaniele Di Proietto2022-01-251-2/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The first time should_trace() returns true, bionic_trace_begin() calls open() on trace_marker. The problem is that open() can call bionic_trace_begin(). We've observed this happening, for example when: * fdtrack is enabled. dlopen("libfdtrack.so") can be used to enable fdtrack on a process. * ThreadA is busy unwinding inside fdtrack and is holding an fdtrack internal mutex. * ThreadB calls bionic_trace_begin() for the first time since the property "debug.atrace.tags.enableflags" contains ATRACE_TAG_BIONIC. * ThreadB calls open("/sys/kernel/tracing/trace_marker"). Since fdtrack is enabled, ThreadB tries to do unwinding as well. * ThreadB, inside fdtrack's unwinding tries to grab the same mutex that ThreadA is holding. * Mutex contention is reported using bionic_systrace, therefore bionic_trace_begin() is called again on ThreadB. * ThreadB tries to grab g_lock in bionin_systrace.cpp, but that's already held by ThreadB itself, earlier on the stack. Therefore ThreadB is stuck. I managed to reproduce the above scenario by manually pausing ThreadA inside unwinding with a debugger and letting ThreadB hitting bionic_trace_begin() for the first time. We could avoid using g_lock while calling open() (either by releasing g_lock and reacquiring it later, or by using atomics), but bionic_trace_begin() would try to call open() again. In my tests, open() does not call bionic_trace_begin() a third time, because fdtrack has reentrancy protection, but there might be another code path inside open that calls bionic_trace_begin again (it could be racy or only happen in certain configurations). This commit fixes the problem by implementing reentrancy protection in bionic_systrace. Sample callstack from ThreadA deadlocked before the fix: ``` * frame #0: 0x0000007436db077c libc.so`syscall at syscall.S:41 frame #1: 0x0000007436db0ba0 libc.so`bionic_trace_begin(char const*) [inlined] __futex(ftx=0x000000743737a548, op=<unavailable>, value=2, timeout=0x0000000000000000, bitset=-1) at bionic_futex.h:45:16 frame #2: 0x0000007436db0b8c libc.so`bionic_trace_begin(char const*) [inlined] __futex_wait_ex(ftx=0x000000743737a548, value=2) at bionic_futex.h:66:10 frame #3: 0x0000007436db0b78 libc.so`bionic_trace_begin(char const*) [inlined] Lock::lock(this=0x000000743737a548) at bionic_lock.h:67:7 frame #4: 0x0000007436db0b74 libc.so`bionic_trace_begin(char const*) [inlined] should_trace() at bionic_systrace.cpp:38:10 frame #5: 0x0000007436db0b74 libc.so`bionic_trace_begin(message="Contending for pthread mutex") at bionic_systrace.cpp:59:8 frame #6: 0x0000007436e193e4 libc.so`NonPI::MutexLockWithTimeout(pthread_mutex_internal_t*, bool, timespec const*) [inlined] NonPI::NormalMutexLock(mutex=0x0000007296cae9f0, shared=0, use_realtime_clock=false, abs_timeout_or_null=0x0000000000000000) at pthread_mutex.cpp:592:17 frame #7: 0x0000007436e193c8 libc.so`NonPI::MutexLockWithTimeout(mutex=0x0000007296cae9f0, use_realtime_clock=false, abs_timeout_or_null=0x0000000000000000) at pthread_mutex.cpp:719:16 frame #8: 0x0000007436e1912c libc.so`::pthread_mutex_lock(mutex_interface=<unavailable>) at pthread_mutex.cpp:839:12 [artificial] frame #9: 0x00000071a4e5b290 libfdtrack.so`std::__1::mutex::lock() [inlined] std::__1::__libcpp_mutex_lock(__m=<unavailable>) at __threading_support:256:10 frame #10: 0x00000071a4e5b28c libfdtrack.so`std::__1::mutex::lock(this=<unavailable>) at mutex.cpp:31:14 frame #11: 0x00000071a4e32634 libfdtrack.so`unwindstack::Elf::Step(unsigned long, unwindstack::Regs*, unwindstack::Memory*, bool*, bool*) [inlined] std::__1::lock_guard<std::__1::mutex>::lock_guard(__m=0x0000007296cae9f0) at __mutex_base:104:27 frame #12: 0x00000071a4e32618 libfdtrack.so`unwindstack::Elf::Step(this=0x0000007296cae9c0, rel_pc=66116, regs=0x0000007266ca0470, process_memory=0x0000007246caa130, finished=0x0000007ff910efb4, is_signal_frame=0x0000007ff910efb0) at Elf.cpp:206:31 frame #13: 0x00000071a4e2b3b0 libfdtrack.so`unwindstack::LocalUnwinder::Unwind(this=0x00000071a4ea1528, frame_info=<unavailable>, max_frames=34) at LocalUnwinder.cpp:102:22 frame #14: 0x00000071a4e2a3ec libfdtrack.so`fd_hook(event=<unavailable>) at fdtrack.cpp:119:18 frame #15: 0x0000007436dbf684 libc.so`::__open_2(pathname=<unavailable>, flags=<unavailable>) at open.cpp:72:10 frame #16: 0x0000007436db0a04 libc.so`bionic_trace_begin(char const*) [inlined] open(pathname=<unavailable>, flags=524289) at fcntl.h:63:12 frame #17: 0x0000007436db09f0 libc.so`bionic_trace_begin(char const*) [inlined] get_trace_marker_fd() at bionic_systrace.cpp:49:25 frame #18: 0x0000007436db09c0 libc.so`bionic_trace_begin(message="pthread_create") at bionic_systrace.cpp:63:25 ``` Bug: 213642769 Change-Id: I10d331859045cb4a8609b007f5c6cf2577ff44df
* | | Merge "Disable pointer authentication in app processes."Peter Collingbourne2022-01-241-3/+2
|\ \ \ | |/ / |/| / | |/
| * Disable pointer authentication in app processes.Peter Collingbourne2022-01-191-3/+2
| | | | | | | | | | | | | | | | | | | | Unfortunately we have discovered that some applications in the wild are using PAC instructions incorrectly. To keep those applications working on PAC enabled devices, disable PAC in application processes for now. Bug: 212660282 Change-Id: I3030c47be9d02a27505bd4775c1982a20755758c
* | c32rtomb/mbrtoc32: remove dead code.Elliott Hughes2021-12-152-9/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | When we added the fast path for the common case of ASCII, we forgot to remove the now-dead code that handled the 1-byte case later in these functions. This was obvious from the code coverage data. Note that the 16-bit variants are unaffected because they're implemented as calls to the 32-bit variants with extra range checks/surrogate handling surrounding the call. Test: treehugger Change-Id: Ibd40f823519acb9aae8037bdeb3f9c5e36b9d9a6
* | mbrtoc16: explain the line that has no test coverage.Elliott Hughes2021-11-181-3/+6
| | | | | | | | | | | | | | | | | | We could remove this line, but it seems reasonable to leave it in for clarification/safety, especially if it's moved after the common success case? Test: treehugger Change-Id: I5f7e0da8397f80018e6d55321b26371790087f5c
* | Merge "Optimize the mbs fast path slightly."Elliott Hughes2021-11-164-6/+6
|\ \ | |/ |/|
| * Optimize the mbs fast path slightly.Elliott Hughes2021-11-164-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From a logcat profile: ``` |--95.06%-- convertPrintable(char*, char const*, unsigned long) | |--13.95%-- [hit in function] | | | |--35.96%-- mbrtoc32 | | |--82.72%-- [hit in function] | | | | | |--11.07%-- mbsinit | | | | | |--5.96%-- @plt ``` I think we'd assumed that mbsinit() would be inlined, but since these functions aren't all in wchar.cpp it wasn't being. This change moves the implementation into a (more clearly named) inline function so we can trivially reclaim that 11%+6%. Benchmarks before: ``` ------------------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------------------- BM_stdlib_mbrtowc_1 8.03 ns 7.95 ns 87144997 BM_stdlib_mbrtowc_2 22.0 ns 21.8 ns 32002437 BM_stdlib_mbrtowc_3 30.0 ns 29.7 ns 23517699 BM_stdlib_mbrtowc_4 37.4 ns 37.1 ns 18895204 BM_stdlib_mbstowcs_ascii 792373 ns 782484 ns 890 bytes_per_second=609.389M/s BM_stdlib_mbstowcs_wide 15836785 ns 15678316 ns 44 bytes_per_second=30.4138M/s ``` Benchmarks after: ``` ------------------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------------------- BM_stdlib_mbrtowc_1 5.76 ns 5.72 ns 121863813 BM_stdlib_mbrtowc_2 17.1 ns 16.9 ns 41487260 BM_stdlib_mbrtowc_3 24.2 ns 24.0 ns 29141629 BM_stdlib_mbrtowc_4 30.3 ns 30.1 ns 23229291 BM_stdlib_mbstowcs_ascii 783506 ns 775389 ns 903 bytes_per_second=614.965M/s BM_stdlib_mbstowcs_wide 12787003 ns 12672642 ns 55 bytes_per_second=37.6273M/s ``` Bug: http://b/206523398 Test: treehugger Change-Id: If8c6c39880096ddd2cbd323c68dca82e9849ace6
* | Add the missing '--' to shell invocations.Elliott Hughes2021-11-041-1/+1
|/ | | | | | | | | | | | | | | This came up with POSIX recently. Doesn't seem like it matters since everyone's had this wrong for 40 years, but "meh" --- it's a trivial fix, and it's strictly correct even if nobody needs this, so let's just do it... (Geoff Clare pointed out that my app compat concern "what if someone's relying on this bug to pass flags to the shell?" isn't relevant because while you can indeed do that, you then can't pass a command!) Bug: https://austingroupbugs.net/view.php?id=1440 Test: treehugger Change-Id: I64f6440da55e2dc29d0136ee62007197d2f00d46
* Don't open /dev/null until we need to.Elliott Hughes2021-10-281-40/+15
| | | | | | | | | | This saves a couple of syscalls in the common case, and also lets static binaries run in a chroot without /dev/null as long as stdin/stdout/stderr are actually connected to something (which the toybox maintainer tried to do). Test: manual with strace Change-Id: Ic9a28896a07304a3bd428acfd9ddca9d22015f6e
* Add execinfo functionality.Christopher Ferris2021-10-201-0/+187
| | | | | | | Bug: 27877410 Test: Add new unit tests. Change-Id: Id5d7eb27a23f50e99a04f5ee1ab64047ba269bab
* Add preadv2/pwritev2 wrappers.Elliott Hughes2021-10-182-19/+91
| | | | | | | | | | They're in glibc, though not in musl. Also add basic doc comments to the whole of <sys/uio.h>. Bug: http://b/203002492 Test: treehugger Change-Id: Ic607f7f349e5b7c9bf66c25b7bd68f827da530d6
* malloc_heapprofd: Avoid a spurious error logDaniele Di Proietto2021-10-071-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the following scenario: * Heapprofd wants to profile a process. * The process receives the heapprofd signal, so it sets up the ephemeral hooks. * The process does not perform any allocation, so the proper heapprofd hook is never installed. * Heapprofd terminates. * Now heapprofd wants to start a new profiling session. * The process receives the heapprofd signal (again). In the signal handler, no action is needed at this point. The ephemeral hooks are already setup, so, at the next malloc, the proper heapprofd hooks will be installed. Before this commit, the code logged an error message, but still worked correctly. This commit basically just skips the error_log below. Example of the error message that is now suppressed: ``` process: heapprofd: failed to transition kInitialState -> kInstallingEphemeralHook. current state (possible race): 2 ``` Tested by: * Running a process that calls malloc on input from stdin. * (Optional, tested both cases) Enable GWP-Asan by calling `android_mallopt(M_INITIALIZE_GWP_ASAN, ...`. The call will return success. * Attaching heapprofd: ``` external/perfetto/tools/heap_profile -i 1 -p `adb shell pidof <...>` ``` * Detaching heapprofd (CTRL-C). The trace will be empty. * (If not enabled before) Enabling GWP-Asan. The call will fail (because GWP-Asan detects heapprofd hooks). * Reattaching heapprofd. * Triggering some malloc()s in the process. The error log from above will not appear in `adb logcat`. * Detaching heapprofd (CTRL-C). The trace will NOT be empty. Bug: 192258849 Change-Id: I01699b10ecd19e52e1e77f83fcca955ebd885942
* Merge "Treat static binaries "the same" for the profiling signals."Treehugger Robot2021-09-302-2/+11
|\
| * Treat static binaries "the same" for the profiling signals.Elliott Hughes2021-09-292-2/+11
| | | | | | | | | | | | | | | | | | | | Strictly this still isn't quite the same, because they won't actually be profiled, but at least they won't *crash* now if they're sent a profiling signal. Bug: http://b/201497662 Test: treehugger Change-Id: I0728492eed77584cd850d28897056996387e6671
* | Merge "bionic: fix broken end atrace events"Lalit Maganti2021-09-301-1/+15
|\ \
| * | bionic: fix broken end atrace eventsLalit Maganti2021-09-291-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When calling write on an FD for trace_marker, it is expected that the pointer passed will be paged into memory. If this isn't the case, the kernel will ignore the string passed and instead write "<faulted>" to the ring buffer. For end events, we were passing a constant string which resides in the rodata section of the ELF file. If this section is paged out, we end up not closing atrace stacks correctly leading to very broken traces. For even more context, see the associated bug. Fix this issue by reading the constant string to the stack first which should mean the string is always paged in. Bug: 197620214 Change-Id: I6a444ac6fe83a6a9fb696c5621e392eca7e9437a
* | | Fix broken return code of M_INITIALIZE_GWP_ASAN.Christopher Ferris2021-09-204-6/+18
| |/ |/| | | | | | | | | | | | | | | | | When calling android_mallopt using M_INITIALIZE_GWP_ASAN, nothing was being returned. Fix this, add a test, and also refactor the code a bit so dynamic and static share the same code. Test: Unit tests pass in dynamic and static versions. Test: Passed using both jemalloc and scudo. Change-Id: Ibe54b6ccabdbd44d2378892e793df393978bc02b
* | Export fts as a static library for use with muslColin Cross2021-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | musl libc doesn't provide fts, but elfutils and libabigail need it. Export bionic's fts as a staic library that can be linked into elfutils and libabigail when compiling against musl. fts uses recallocarray, which musl doesn't provide, so also include recallocarray.c in libfts.a. Requires minor tweaks to fts.c and a wrapper around fts.h to make them compatible with musl, primarily by providing local definitions of macros provided in bionic's sys/cdefs.h. Bug: 190084016 Test: m libfts Change-Id: Ifac9a59e7504c0c1f5f8a3a5bd3c19a13980b83c
* | Compile fts.c in libc_openbsd_ndkColin Cross2021-09-081-5/+0
|/ | | | | | | | | fts.c is from openbsd and has compatibility macros to make it compile as part of bionic. Move it into libc_openbsd_ndk where it will get the workarounds from -include openbsd-compat.h instead. Test: m libc Change-Id: I213d423af8f010e39460b611e902acbf3561ae7a
* Merge "Reland "Fix GWP hooks not being restored, leading to crashes.""Florian Mayer2021-08-031-29/+46
|\
| * Reland "Fix GWP hooks not being restored, leading to crashes."Florian Mayer2021-07-301-29/+46
| | | | | | | | | | | | | | | | | | | | | | | | If the DispatchReset fails, the subsequent iteration has the wrong idea of what the "original" table is, and if a subsequent DispatchReset succeeds it unhooks them. Repro in https://r.android.com/1767868. Bug: 193012939 Bug: 189776979 Change-Id: I30445c053fcb785669f75d9c83056926d850edce
* | POSIX strerror_r returns an error number, not -1Colin Cross2021-07-301-2/+1
| | | | | | | | | | | | | | | | The posix spec says strerror_r returns a positive error number, not -1 and set errno. Test: bionic-unit-tests-static Change-Id: I6a12d50d046f9caac299bf3bff63e6c9496c1b6f
* | Revert "Adding system property tracing"Bowgo Tsai2021-07-212-32/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Revert submission 1403568-sysprop_trace Reason for revert: makes property get/set non-reentrant Reverted Changes: I6f85f3f52:Add systrace tag for system property Id2b93acb2:Adding system property tracing Id78992d23:Add systrace tag for system property I1ba9fc7bd:Add systrace tag for system property Bug: 193050299 Test: build and boot a device Change-Id: Ic7a83fb01a39113d408ed0c95d27f694d5a2649c Merged-In: Ic7a83fb01a39113d408ed0c95d27f694d5a2649c (cherry picked from commit 61a5a8380d6417e9b85bb2f6a4a694ef4222031f)
* | Revert "bionic_systrace: moving global static variables"Bowgo Tsai2021-07-211-11/+15
|/ | | | | | | | | | | | This reverts commit 1e1c7845aab0542306f61d8e8c880aca096ea336. Reason for revert: makes property get/set non-reentrant Bug: 193050299 Test: build and boot a device Change-Id: If59e3dc25684a3c2b1d3ff74f995311afe6c6e89 Merged-In: If59e3dc25684a3c2b1d3ff74f995311afe6c6e89 (cherry picked from commit 3ec21f527acbaefb5f7a114125bc7a93baa780c7)
* Merge "Allow the kernel to upgrade ASYNC mode processes to SYNC mode."Treehugger Robot2021-07-022-2/+11
|\
| * Allow the kernel to upgrade ASYNC mode processes to SYNC mode.Peter Collingbourne2021-07-012-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On devices where the performance of ASYNC mode is similar to SYNC mode on certain CPUs, OEMs may choose to configure the kernel to prefer SYNC mode on those CPUs by writing the value "sync" to the sysfs node: /sys/devices/system/cpu/cpu<N>/mte_tcf_preferred The kernel will only respect the per-CPU preference if the user program allows this by specifying the preferred mode as a member of a set of allowed modes. Since only kernels with r.android.com/1754670 support specifying multiple modes, fall back to trying to specify a single mode if that doesn't work. Bug: 189966263 Change-Id: Ie7ada3b073178b7967f0819cbdadc2d8e3a2c648
* | Document more clearly that we don't plan on using faccessat2(2).Elliott Hughes2021-06-251-4/+4
| | | | | | | | | | Test: treehugger Change-Id: Idea76ab97865bf26c1f6b16200ba2c7d1fe50ee8
* | Merge "Disable return PAC in __pthread_start."Peter Collingbourne2021-06-091-0/+5
|\ \
| * | Disable return PAC in __pthread_start.Peter Collingbourne2021-06-081-0/+5
| |/ | | | | | | | | | | | | | | | | This function doesn't return, but it does appear in stack traces. Avoid using return PAC in this function because we may end up resetting IA, which may confuse unwinders due to mismatching keys. Bug: 189808795 Change-Id: I953da9078acd1d43eb7a47fb11f75caa0099fa12
* / Fix dangling pointer in heapprofd API.Florian Mayer2021-06-021-7/+3
|/ | | | | | | | | | | We would dlopen heapprofd_client.so, which has a static initializer [1] that passes a pointer to of its functions to heapprofd_client_api.so. If we dlclose heapprofd_client.so, this pointer is dangling. [1]: https://cs.android.com/android/platform/superproject/+/master:external/perfetto/src/profiling/memory/malloc_interceptor_bionic_hooks.cc?q=symbol:g_heap_id Bug: 189332777 Change-Id: Ia4a9d9dd7c89eceec86c6fac5f4b66de85d7604e
* Enable RTM_GETLINK restrictions on all appsBram Bonné2021-04-301-5/+2
| | | | | | | | | | | | | | | | | | | | | Extend existing restrictions targeting only apps with API level >= 30 to all apps. Actual enforcement happens in SELinux. This change just prevents logspam. To be merged when automerge to sc-dev ends. Bug: 170188668 Test: atest bionic-unit-tests-static Test: atest NetworkInterfaceTest Test: Connect to Wi-Fi network Test: atest CtsSelinuxTargetSdk27TestCases Test: atest CtsSelinuxTargetSdk28TestCasesTest: atest CtsSelinuxTargetSdk29TestCases Test: atest CtsSelinuxTargetSdkCurrentTestCases Change-Id: If1761354216b23a1e55e6b9606de452899afff0c
* Avoid prctl(PR_PAC_RESET_KEYS) on devices without PAC support.Peter Collingbourne2021-04-221-1/+6
| | | | | | | | | | Processes loaded from vendor partitions may have their own sandboxes that would reject the prctl. Because no devices launched with PAC enabled before S, we can avoid issues on upgrading devices by checking for PAC support before issuing the prctl. Bug: 186117046 Change-Id: I9905b963df01c9007d9fb4527273062ea87a5075