1*e4a36f41SAndroid Build Coastguard Worker# Performance profiler, backed by perf_event_open(2). 2*e4a36f41SAndroid Build Coastguard Worker# See go/perfetto-perf-android. 3*e4a36f41SAndroid Build Coastguard Workertypeattribute traced_perf coredomain; 4*e4a36f41SAndroid Build Coastguard Workertypeattribute traced_perf mlstrustedsubject; 5*e4a36f41SAndroid Build Coastguard Worker 6*e4a36f41SAndroid Build Coastguard Workertype traced_perf_exec, system_file_type, exec_type, file_type; 7*e4a36f41SAndroid Build Coastguard Worker 8*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(traced_perf) 9*e4a36f41SAndroid Build Coastguard Workerperfetto_producer(traced_perf) 10*e4a36f41SAndroid Build Coastguard Worker 11*e4a36f41SAndroid Build Coastguard Worker# Allow traced_perf full use of perf_event_open(2). It will perform cpu-wide 12*e4a36f41SAndroid Build Coastguard Worker# profiling, but retain samples only for profileable processes. 13*e4a36f41SAndroid Build Coastguard Worker# Thread-specific profiling is still disallowed due to a PTRACE_MODE_ATTACH 14*e4a36f41SAndroid Build Coastguard Worker# check (which would require a process:attach SELinux allow-rule). 15*e4a36f41SAndroid Build Coastguard Workerallow traced_perf self:perf_event { open cpu kernel read write tracepoint }; 16*e4a36f41SAndroid Build Coastguard Worker 17*e4a36f41SAndroid Build Coastguard Worker# Allow CAP_KILL for delivery of dedicated signal to obtain proc-fds from a 18*e4a36f41SAndroid Build Coastguard Worker# process. Allow CAP_DAC_READ_SEARCH for stack unwinding and symbolization of 19*e4a36f41SAndroid Build Coastguard Worker# sampled stacks, which requires opening the backing libraries/executables (as 20*e4a36f41SAndroid Build Coastguard Worker# symbols are usually not mapped into the process space). Not all such files 21*e4a36f41SAndroid Build Coastguard Worker# are world-readable, e.g. odex files that included user profiles during 22*e4a36f41SAndroid Build Coastguard Worker# profile-guided optimization. 23*e4a36f41SAndroid Build Coastguard Workerallow traced_perf self:capability { kill dac_read_search }; 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Worker# Allow reading /system/data/packages.list. 26*e4a36f41SAndroid Build Coastguard Workerallow traced_perf packages_list_file:file r_file_perms; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# Allow reading files for stack unwinding and symbolization. 29*e4a36f41SAndroid Build Coastguard Workerr_dir_file(traced_perf, nativetest_data_file) 30*e4a36f41SAndroid Build Coastguard Workerr_dir_file(traced_perf, system_file_type) 31*e4a36f41SAndroid Build Coastguard Workerr_dir_file(traced_perf, apk_data_file) 32*e4a36f41SAndroid Build Coastguard Workerr_dir_file(traced_perf, dalvikcache_data_file) 33*e4a36f41SAndroid Build Coastguard Workerr_dir_file(traced_perf, vendor_file_type) 34*e4a36f41SAndroid Build Coastguard Worker# ART apex files and directory access to the containing /data/misc/apexdata. 35*e4a36f41SAndroid Build Coastguard Workerr_dir_file(traced_perf, apex_art_data_file) 36*e4a36f41SAndroid Build Coastguard Workerallow traced_perf apex_module_data_file:dir { getattr search }; 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker# Allow to temporarily lift the kptr_restrict setting and build a symbolization 39*e4a36f41SAndroid Build Coastguard Worker# map reading /proc/kallsyms. 40*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`set_prop(traced_perf, lower_kptr_restrict_prop)') 41*e4a36f41SAndroid Build Coastguard Workerallow traced_perf proc_kallsyms:file r_file_perms; 42*e4a36f41SAndroid Build Coastguard Worker 43*e4a36f41SAndroid Build Coastguard Worker# Allow reading tracefs files to get the format and numeric ids of tracepoints. 44*e4a36f41SAndroid Build Coastguard Workerallow traced_perf debugfs_tracing:dir r_dir_perms; 45*e4a36f41SAndroid Build Coastguard Workerallow traced_perf debugfs_tracing:file r_file_perms; 46*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 47*e4a36f41SAndroid Build Coastguard Worker allow traced_perf debugfs_tracing_debug:dir r_dir_perms; 48*e4a36f41SAndroid Build Coastguard Worker allow traced_perf debugfs_tracing_debug:file r_file_perms; 49*e4a36f41SAndroid Build Coastguard Worker') 50*e4a36f41SAndroid Build Coastguard Worker 51*e4a36f41SAndroid Build Coastguard Worker# Do not audit the cases where traced_perf attempts to access /proc/[pid] for 52*e4a36f41SAndroid Build Coastguard Worker# domains that it cannot read. 53*e4a36f41SAndroid Build Coastguard Workerdontaudit traced_perf domain:dir { search getattr open }; 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# Do not audit failures to signal a process, as there are cases when this is 56*e4a36f41SAndroid Build Coastguard Worker# expected (native processes on debug builds use the policy for enforcing which 57*e4a36f41SAndroid Build Coastguard Worker# processes are profileable). 58*e4a36f41SAndroid Build Coastguard Workerdontaudit traced_perf domain:process signal; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Worker# Never allow access to app data files 61*e4a36f41SAndroid Build Coastguard Workerneverallow traced_perf app_data_file_type:file *; 62*e4a36f41SAndroid Build Coastguard Worker 63*e4a36f41SAndroid Build Coastguard Worker# Never allow profiling privileged or otherwise incompatible domains. 64*e4a36f41SAndroid Build Coastguard Worker# Corresponding allow-rule is in private/domain.te. 65*e4a36f41SAndroid Build Coastguard Workernever_profile_perf(`{ 66*e4a36f41SAndroid Build Coastguard Worker apexd 67*e4a36f41SAndroid Build Coastguard Worker app_zygote 68*e4a36f41SAndroid Build Coastguard Worker bpfloader 69*e4a36f41SAndroid Build Coastguard Worker hal_configstore_server 70*e4a36f41SAndroid Build Coastguard Worker init 71*e4a36f41SAndroid Build Coastguard Worker kernel 72*e4a36f41SAndroid Build Coastguard Worker keystore 73*e4a36f41SAndroid Build Coastguard Worker llkd 74*e4a36f41SAndroid Build Coastguard Worker logd 75*e4a36f41SAndroid Build Coastguard Worker ueventd 76*e4a36f41SAndroid Build Coastguard Worker vendor_init 77*e4a36f41SAndroid Build Coastguard Worker vold 78*e4a36f41SAndroid Build Coastguard Worker webview_zygote 79*e4a36f41SAndroid Build Coastguard Worker zygote 80*e4a36f41SAndroid Build Coastguard Worker}') 81