platform_bionic/libc
Ryan Savitski d4aa14d9dd profiling: override dumpability while opening /proc/self/mem,maps
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
2022-02-11 16:31:24 +00:00
..
arch-arm [NFCI] Change Android's NT_TYPE to NT_ANDROID_TYPE. 2022-02-07 13:49:20 -08:00
arch-arm64 [NFCI] Change Android's NT_TYPE to NT_ANDROID_TYPE. 2022-02-07 13:49:20 -08:00
arch-common/bionic [NFCI] Change Android's NT_TYPE to NT_ANDROID_TYPE. 2022-02-07 13:49:20 -08:00
arch-x86 Clear the stack frame pointer in _start and __bionic_clone 2021-05-07 15:00:55 -07:00
arch-x86_64 setjmp/longjmp: avoid invalid values in the stack pointer. 2021-04-05 17:43:36 -07:00
async_safe bp2build: remove some bp2build_available props, use package_allowlist instead. 2021-03-19 02:06:27 -04:00
b64/include/bionic Export bionic's resolv base64 functions to musl 2022-02-03 16:25:26 -08:00
bionic profiling: override dumpability while opening /proc/self/mem,maps 2022-02-11 16:31:24 +00:00
dns Make res_init() work again. 2021-04-08 12:04:05 -07:00
execinfo/include Export bionic's execinfo functions to musl 2022-02-03 16:25:21 -08:00
fts/include Use the BSD license for our bogus fts.h. 2021-09-14 12:26:08 -07:00
include Annotate fortify functions with diagnose_as_builtin 2022-02-03 11:53:52 -08:00
kernel Update to v5.16 kernel headers. 2022-01-10 13:51:15 -08:00
malloc_debug Fix possible nullptr dereference. 2022-02-02 17:56:48 -08:00
malloc_hooks Silence -Wnon-power-of-two-alignment for a test 2022-01-28 13:27:07 -08:00
platform Disable pointer authentication in app processes. 2022-01-19 13:35:54 -08:00
private [MTE] Relax ELF note. 2022-02-08 13:17:18 -08:00
seccomp Use more inclusive language for seccomp filter 2020-06-15 10:12:17 -07:00
stdio Add the missing '--' to shell invocations. 2021-11-04 17:29:35 -07:00
system_properties Remove references to nonplat sepolicy 2021-11-05 09:30:25 +01:00
tools Merge "Ignore backup files left by emacs." 2021-04-20 01:24:49 +00:00
tzcode strftime: format small positive integers ourselves. 2021-12-06 14:55:00 -08:00
upstream-freebsd Fully disable clang format where needed. 2020-01-30 08:10:17 -08:00
upstream-netbsd Make res_init() work again. 2021-04-08 12:04:05 -07:00
upstream-openbsd Export fts as a static library for use with musl 2021-09-08 15:53:10 -07:00
versioner-dependencies Stop generating unused headers. 2020-02-03 17:56:06 -08:00
Android.bp Avoid duplicate genrule locations 2022-02-07 21:08:41 -08:00
fs_config_generator.py
libc.map.txt Fix incorrect API level for wcstombs and mbstowcs. 2021-11-09 23:29:33 +00:00
libstdc++.map.txt Remove dead code. 2020-02-13 22:25:02 -08:00
MODULE_LICENSE_BSD
NOTICE Export bionic's resolv base64 functions to musl 2022-02-03 16:25:26 -08:00
SECCOMP_ALLOWLIST_APP.TXT Use more inclusive language for seccomp filter 2020-06-15 10:12:17 -07:00
SECCOMP_ALLOWLIST_COMMON.TXT Add userfaultfd syscall in SECCOMP allowlist 2021-03-11 19:30:08 +00:00
SECCOMP_ALLOWLIST_SYSTEM.TXT Use more inclusive language for seccomp filter 2020-06-15 10:12:17 -07:00
SECCOMP_BLOCKLIST_APP.TXT Use more inclusive language for seccomp filter 2020-06-15 10:12:17 -07:00
SECCOMP_BLOCKLIST_COMMON.TXT Revert "Disallow vmsplice(2) for all zygote-spawned processes." 2020-06-23 17:53:35 +00:00
SECCOMP_PRIORITY.TXT Use more inclusive language for seccomp filter 2020-06-15 10:12:17 -07:00
SYSCALLS.TXT Allow bpf() syscall 2021-12-01 21:32:08 +00:00
version_script.txt