1*e4a36f41SAndroid Build Coastguard Worker# Domain used when running /system/bin/simpleperf to profile a specific app. 2*e4a36f41SAndroid Build Coastguard Worker# Entered either by the app itself exec-ing the binary, or through 3*e4a36f41SAndroid Build Coastguard Worker# simpleperf_app_runner (with shell as its origin). Certain other domains 4*e4a36f41SAndroid Build Coastguard Worker# (runas_app, shell) can also exec this binary without a domain transition. 5*e4a36f41SAndroid Build Coastguard Workertypeattribute simpleperf coredomain; 6*e4a36f41SAndroid Build Coastguard Workertype simpleperf_exec, system_file_type, exec_type, file_type; 7*e4a36f41SAndroid Build Coastguard Worker 8*e4a36f41SAndroid Build Coastguard Worker# Define apps that can be marked debuggable/profileable and be profiled by simpleperf. 9*e4a36f41SAndroid Build Coastguard Workerdefine(`simpleperf_profileable_apps', `{ 10*e4a36f41SAndroid Build Coastguard Worker ephemeral_app 11*e4a36f41SAndroid Build Coastguard Worker isolated_app 12*e4a36f41SAndroid Build Coastguard Worker platform_app 13*e4a36f41SAndroid Build Coastguard Worker priv_app 14*e4a36f41SAndroid Build Coastguard Worker untrusted_app_all 15*e4a36f41SAndroid Build Coastguard Worker}') 16*e4a36f41SAndroid Build Coastguard Worker 17*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans({ simpleperf_profileable_apps -runas_app }, simpleperf_exec, simpleperf) 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker# When running in this domain, simpleperf is scoped to profiling an individual 20*e4a36f41SAndroid Build Coastguard Worker# app. The necessary MAC permissions for profiling are more maintainable and 21*e4a36f41SAndroid Build Coastguard Worker# consistent if simpleperf is marked as an app domain as well (as, for example, 22*e4a36f41SAndroid Build Coastguard Worker# it will then see the same set of system libraries as the app). 23*e4a36f41SAndroid Build Coastguard Workerapp_domain(simpleperf) 24*e4a36f41SAndroid Build Coastguard Workeruntrusted_app_domain(simpleperf) 25*e4a36f41SAndroid Build Coastguard Worker 26*e4a36f41SAndroid Build Coastguard Worker# Allow ptrace attach to the target app, for reading JIT debug info (using 27*e4a36f41SAndroid Build Coastguard Worker# process_vm_readv) during unwinding and symbolization. 28*e4a36f41SAndroid Build Coastguard Workerallow simpleperf simpleperf_profileable_apps:process ptrace; 29*e4a36f41SAndroid Build Coastguard Worker 30*e4a36f41SAndroid Build Coastguard Worker# Allow using perf_event_open syscall for profiling the target app. 31*e4a36f41SAndroid Build Coastguard Workerallow simpleperf self:perf_event { open read write kernel }; 32*e4a36f41SAndroid Build Coastguard Worker 33*e4a36f41SAndroid Build Coastguard Worker# Allow /proc/<pid> access for the target app (for example, when trying to 34*e4a36f41SAndroid Build Coastguard Worker# discover it by cmdline). 35*e4a36f41SAndroid Build Coastguard Workerr_dir_file(simpleperf, simpleperf_profileable_apps) 36*e4a36f41SAndroid Build Coastguard Worker 37*e4a36f41SAndroid Build Coastguard Worker# Allow apps signalling simpleperf domain, which is the domain that the simpleperf 38*e4a36f41SAndroid Build Coastguard Worker# profiler runs as when executed by the app. The signals are used to control 39*e4a36f41SAndroid Build Coastguard Worker# the profiler (which would be profiling the app that is sending the signal). 40*e4a36f41SAndroid Build Coastguard Workerallow simpleperf_profileable_apps simpleperf:process signal; 41*e4a36f41SAndroid Build Coastguard Worker 42*e4a36f41SAndroid Build Coastguard Worker# Suppress denial logspam when simpleperf is trying to find a matching process 43*e4a36f41SAndroid Build Coastguard Worker# by scanning /proc/<pid>/cmdline files. The /proc/<pid> directories are within 44*e4a36f41SAndroid Build Coastguard Worker# the same domain as their respective processes, most of which this domain is 45*e4a36f41SAndroid Build Coastguard Worker# not allowed to see. 46*e4a36f41SAndroid Build Coastguard Workerdontaudit simpleperf domain:dir search; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# Neverallows: 49*e4a36f41SAndroid Build Coastguard Worker 50*e4a36f41SAndroid Build Coastguard Worker# Profiling must be confined to the scope of an individual app. 51*e4a36f41SAndroid Build Coastguard Workerneverallow simpleperf self:perf_event ~{ open read write kernel }; 52