blob: ec3e4d0676909e035ed5692e162dcb320a32be04 [file] [log] [blame]
Ryan Savitskica0690e2019-01-16 16:29:43 +00001# Android heap profiling daemon. go/heapprofd.
2#
3# On user builds, this daemon is responsible for receiving the initial
4# profiling configuration, finding matching target processes (if profiling by
5# process name), and sending the activation signal to them (+ setting system
6# properties for new processes to start profiling from startup). When profiling
7# is triggered in a process, it spawns a private heapprofd subprocess (in its
8# own SELinux domain), which will exclusively handle profiling of its parent.
9#
10# On debug builds, this central daemon performs profiling for all target
11# processes (which talk directly to this daemon).
Florian Mayer4fde9ec2018-10-15 18:02:02 +010012type heapprofd_exec, exec_type, file_type, system_file_type;
Florian Mayer315d8bf2019-02-28 15:59:32 +000013type heapprofd_tmpfs, file_type;
Florian Mayer4fde9ec2018-10-15 18:02:02 +010014
15init_daemon_domain(heapprofd)
Florian Mayer315d8bf2019-02-28 15:59:32 +000016tmpfs_domain(heapprofd)
17
18# Allow apps in other MLS contexts (for multi-user) to access
Florian Mayer3b601a52019-03-04 16:43:37 +000019# shared memory buffers created by heapprofd.
Florian Mayer315d8bf2019-02-28 15:59:32 +000020typeattribute heapprofd_tmpfs mlstrustedobject;
Florian Mayer45f48472018-10-30 12:19:27 +000021
Florian Mayer0f3decf2018-11-08 13:58:13 +000022set_prop(heapprofd, heapprofd_prop);
23
Ryan Savitskica0690e2019-01-16 16:29:43 +000024# Necessary for /proc/[pid]/cmdline access & sending signals.
25typeattribute heapprofd mlstrustedsubject;
Florian Mayer45f48472018-10-30 12:19:27 +000026
Ryan Savitskica0690e2019-01-16 16:29:43 +000027# Allow sending signals to processes. This excludes SIGKILL, SIGSTOP and
28# SIGCHLD, which are controlled by separate permissions.
29allow heapprofd self:capability kill;
30
31# When scanning /proc/[pid]/cmdline to find matching processes for by-name
32# profiling, only whitelisted domains will be allowed by SELinux. Avoid
33# spamming logs with denials for entries that we can not access.
34dontaudit heapprofd domain:dir { search open };
35
36# Write trace data to the Perfetto traced daemon. This requires connecting to
37# its producer socket and obtaining a (per-process) tmpfs fd.
Florian Mayer5e522812019-10-08 16:15:14 +010038perfetto_producer(heapprofd)
Ryan Savitskica0690e2019-01-16 16:29:43 +000039
40# When handling profiling for all processes, heapprofd needs to read
41# executables/libraries/etc to do stack unwinding.
42userdebug_or_eng(`
Florian Mayer12f7e0e2019-03-27 10:59:28 +000043 r_dir_file(heapprofd, nativetest_data_file)
Florian Mayer3f8c2712018-12-03 11:02:07 +000044 r_dir_file(heapprofd, system_file_type)
45 r_dir_file(heapprofd, apk_data_file)
46 r_dir_file(heapprofd, dalvikcache_data_file)
47 r_dir_file(heapprofd, vendor_file_type)
Florian Mayere922aa32019-03-21 13:07:05 +000048 # Some dex files are not world-readable.
49 # We are still constrained by the SELinux rules above.
50 allow heapprofd self:global_capability_class_set dac_read_search;
Florian Mayer87b5e752019-05-16 19:47:04 +010051
52 allow heapprofd proc_kpageflags:file r_file_perms;
Florian Mayer45f48472018-10-30 12:19:27 +000053')
54
Florian Mayere922aa32019-03-21 13:07:05 +000055# This is going to happen on user but is benign because central heapprofd
56# does not actually need these permission.
57# If the dac_read_search capability check is rejected, the kernel then tries
58# to perform a dac_override capability check, so we need to dontaudit that
59# as well.
60dontaudit heapprofd self:global_capability_class_set { dac_read_search dac_override };
61
Florian Mayer45f48472018-10-30 12:19:27 +000062never_profile_heap(`{
63 bpfloader
64 init
65 kernel
66 keystore
67 llkd
68 logd
69 ueventd
70 vendor_init
71 vold
72}')
73
74full_treble_only(`
75 neverallow heapprofd vendor_file:file { no_w_file_perms no_x_file_perms };
76')