1*e4a36f41SAndroid Build Coastguard Worker# Perfetto command-line client. Can be used only from the domains that are 2*e4a36f41SAndroid Build Coastguard Worker# explicitly allowlisted with a domain_auto_trans(X, perfetto_exec, perfetto). 3*e4a36f41SAndroid Build Coastguard Worker# This command line client accesses the privileged socket of the traced 4*e4a36f41SAndroid Build Coastguard Worker# daemon. 5*e4a36f41SAndroid Build Coastguard Worker 6*e4a36f41SAndroid Build Coastguard Workertype perfetto_exec, system_file_type, exec_type, file_type; 7*e4a36f41SAndroid Build Coastguard Workertype perfetto_tmpfs, file_type; 8*e4a36f41SAndroid Build Coastguard Worker 9*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(perfetto); 10*e4a36f41SAndroid Build Coastguard Worker 11*e4a36f41SAndroid Build Coastguard Worker# Allow init to start a trace (for perfetto_boottrace). 12*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(perfetto) 13*e4a36f41SAndroid Build Coastguard Worker 14*e4a36f41SAndroid Build Coastguard Worker# Allow to access traced's privileged consumer socket. 15*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(perfetto, traced_consumer, traced) 16*e4a36f41SAndroid Build Coastguard Worker 17*e4a36f41SAndroid Build Coastguard Worker# Connect to the Perfetto traced daemon as a producer. This requires 18*e4a36f41SAndroid Build Coastguard Worker# connecting to its producer socket and obtaining a (per-process) tmpfs fd. 19*e4a36f41SAndroid Build Coastguard Workerperfetto_producer(perfetto) 20*e4a36f41SAndroid Build Coastguard Worker 21*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink traces into /data/misc/perfetto-traces. 22*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:dir rw_dir_perms; 23*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:file create_file_perms; 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink trace into /data/misc/perfetto-traces/bugreport* 26*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_bugreport_data_file:file create_file_perms; 27*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_bugreport_data_file:dir rw_dir_perms; 28*e4a36f41SAndroid Build Coastguard Worker 29*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink traces into /data/misc/perfetto-traces/profiling. 30*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_profiling_data_file:dir rw_dir_perms; 31*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_profiling_data_file:file create_file_perms; 32*e4a36f41SAndroid Build Coastguard Worker 33*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to access the proxy service for reporting traces. 34*e4a36f41SAndroid Build Coastguard Workerallow perfetto tracingproxy_service:service_manager find; 35*e4a36f41SAndroid Build Coastguard Workerbinder_use(perfetto) 36*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, system_server) 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from /data/misc/perfetto-configs. 39*e4a36f41SAndroid Build Coastguard Worker# shell and adb can write files into that directory. 40*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:dir r_dir_perms; 41*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:file r_file_perms; 42*e4a36f41SAndroid Build Coastguard Worker 43*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from /system/etc/perfetto. 44*e4a36f41SAndroid Build Coastguard Workerallow perfetto system_perfetto_config_file:dir r_dir_perms; 45*e4a36f41SAndroid Build Coastguard Workerallow perfetto system_perfetto_config_file:file r_file_perms; 46*e4a36f41SAndroid Build Coastguard Worker 47*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from statsd, mm_events and shell 48*e4a36f41SAndroid Build Coastguard Worker# (both root and non-root) on stdin and also to write the resulting trace to 49*e4a36f41SAndroid Build Coastguard Worker# stdout. 50*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su }:fd use; 51*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su system_server }:fifo_file { getattr read write ioctl }; 52*e4a36f41SAndroid Build Coastguard Worker 53*e4a36f41SAndroid Build Coastguard Worker# Allow to communicate use, read and write over the adb connection. 54*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:fd use; 55*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:unix_stream_socket { read write }; 56*e4a36f41SAndroid Build Coastguard Worker 57*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to reap perfetto. 58*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:process { sigchld }; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to write to statsd. 61*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(perfetto, statsdw, statsd) 62*e4a36f41SAndroid Build Coastguard Worker 63*e4a36f41SAndroid Build Coastguard Worker# Allow to access /dev/pts when launched in an adb shell. 64*e4a36f41SAndroid Build Coastguard Workerallow perfetto devpts:chr_file rw_file_perms; 65*e4a36f41SAndroid Build Coastguard Worker 66*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to ask incidentd to start a report. 67*e4a36f41SAndroid Build Coastguard Worker# TODO(lalitm): remove all incidentd rules when proxy service is stable. 68*e4a36f41SAndroid Build Coastguard Workerallow perfetto incident_service:service_manager find; 69*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, incidentd) 70*e4a36f41SAndroid Build Coastguard Worker 71*e4a36f41SAndroid Build Coastguard Worker# perfetto log formatter calls isatty() on its stderr. Denial when running 72*e4a36f41SAndroid Build Coastguard Worker# under adbd is harmless. Avoid generating denial logs. 73*e4a36f41SAndroid Build Coastguard Workerdontaudit perfetto adbd:unix_stream_socket getattr; 74*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto adbd:unix_stream_socket ioctl unpriv_tty_ioctls; 75*e4a36f41SAndroid Build Coastguard Worker# As above, when adbd is running in "su" domain (only the ioctl is denied in 76*e4a36f41SAndroid Build Coastguard Worker# practice). 77*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto su:unix_stream_socket ioctl unpriv_tty_ioctls; 78*e4a36f41SAndroid Build Coastguard Worker# Similarly, CTS tests end up hitting a denial on shell pipes. 79*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto shell:fifo_file ioctl unpriv_tty_ioctls; 80*e4a36f41SAndroid Build Coastguard Worker 81*e4a36f41SAndroid Build Coastguard Worker### 82*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 83*e4a36f41SAndroid Build Coastguard Worker### 84*e4a36f41SAndroid Build Coastguard Worker 85*e4a36f41SAndroid Build Coastguard Worker# Disallow anyone else from being able to handle traces except selected system 86*e4a36f41SAndroid Build Coastguard Worker# components. 87*e4a36f41SAndroid Build Coastguard Workerneverallow { 88*e4a36f41SAndroid Build Coastguard Worker domain 89*e4a36f41SAndroid Build Coastguard Worker -init # The creator of the folder. 90*e4a36f41SAndroid Build Coastguard Worker -perfetto # The owner of the folder. 91*e4a36f41SAndroid Build Coastguard Worker -adbd # For pulling traces. 92*e4a36f41SAndroid Build Coastguard Worker -shell # For devepment purposes. 93*e4a36f41SAndroid Build Coastguard Worker -traced # For write_into_file traces. 94*e4a36f41SAndroid Build Coastguard Worker -dumpstate # For attaching traces to bugreports. 95*e4a36f41SAndroid Build Coastguard Worker -incidentd # For receiving reported traces. TODO(lalitm): remove this. 96*e4a36f41SAndroid Build Coastguard Worker -priv_app # For stating traces for bug-report UI. 97*e4a36f41SAndroid Build Coastguard Worker -system_server # For accessing traces started by profiling apis. 98*e4a36f41SAndroid Build Coastguard Worker -trace_redactor # For accessing traces to be redacted. 99*e4a36f41SAndroid Build Coastguard Worker} perfetto_traces_data_file:dir *; 100*e4a36f41SAndroid Build Coastguard Workerneverallow { 101*e4a36f41SAndroid Build Coastguard Worker domain 102*e4a36f41SAndroid Build Coastguard Worker -init # The creator of the folder. 103*e4a36f41SAndroid Build Coastguard Worker -perfetto # The owner of the folder. 104*e4a36f41SAndroid Build Coastguard Worker -adbd # For pulling traces. 105*e4a36f41SAndroid Build Coastguard Worker -shell # For devepment purposes. 106*e4a36f41SAndroid Build Coastguard Worker -traced # For write_into_file traces. 107*e4a36f41SAndroid Build Coastguard Worker -incidentd # For receiving reported traces. TODO(lalitm): remove this. 108*e4a36f41SAndroid Build Coastguard Worker -trace_redactor # For redacting trace files. 109*e4a36f41SAndroid Build Coastguard Worker} perfetto_traces_data_file:file ~{ getattr read }; 110*e4a36f41SAndroid Build Coastguard Worker 111*e4a36f41SAndroid Build Coastguard Worker### perfetto should NEVER do any of the following 112*e4a36f41SAndroid Build Coastguard Worker 113*e4a36f41SAndroid Build Coastguard Worker# Disallow mapping executable memory (execstack and exec are already disallowed 114*e4a36f41SAndroid Build Coastguard Worker# globally in domain.te). 115*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto self:process execmem; 116*e4a36f41SAndroid Build Coastguard Worker 117*e4a36f41SAndroid Build Coastguard Worker# Block device access. 118*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto dev_type:blk_file { read write }; 119*e4a36f41SAndroid Build Coastguard Worker 120*e4a36f41SAndroid Build Coastguard Worker# ptrace any other process 121*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto domain:process ptrace; 122*e4a36f41SAndroid Build Coastguard Worker 123*e4a36f41SAndroid Build Coastguard Worker# Disallows access to other /data files. 124*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 125*e4a36f41SAndroid Build Coastguard Worker data_file_type 126*e4a36f41SAndroid Build Coastguard Worker -system_data_file 127*e4a36f41SAndroid Build Coastguard Worker -system_data_root_file 128*e4a36f41SAndroid Build Coastguard Worker -media_userdir_file 129*e4a36f41SAndroid Build Coastguard Worker -system_userdir_file 130*e4a36f41SAndroid Build Coastguard Worker -vendor_userdir_file 131*e4a36f41SAndroid Build Coastguard Worker # TODO(b/72998741) Remove exemption. Further restricted in a subsequent 132*e4a36f41SAndroid Build Coastguard Worker # neverallow. Currently only getattr and search are allowed. 133*e4a36f41SAndroid Build Coastguard Worker -vendor_data_file 134*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 135*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_bugreport_data_file 136*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_profiling_data_file 137*e4a36f41SAndroid Build Coastguard Worker -perfetto_configs_data_file 138*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 139*e4a36f41SAndroid Build Coastguard Worker}:dir *; 140*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 141*e4a36f41SAndroid Build Coastguard Worker system_data_file 142*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 143*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_profiling_data_file 144*e4a36f41SAndroid Build Coastguard Worker}:dir ~{ getattr search }; 145*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 146*e4a36f41SAndroid Build Coastguard Worker data_file_type 147*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 148*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_bugreport_data_file 149*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_profiling_data_file 150*e4a36f41SAndroid Build Coastguard Worker -perfetto_configs_data_file 151*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 152*e4a36f41SAndroid Build Coastguard Worker}:file ~write; 153