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 perfetto to access the proxy service for reporting traces. 30*e4a36f41SAndroid Build Coastguard Workerallow perfetto tracingproxy_service:service_manager find; 31*e4a36f41SAndroid Build Coastguard Workerbinder_use(perfetto) 32*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, system_server) 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from /data/misc/perfetto-configs. 35*e4a36f41SAndroid Build Coastguard Worker# shell and adb can write files into that directory. 36*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:dir r_dir_perms; 37*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:file r_file_perms; 38*e4a36f41SAndroid Build Coastguard Worker 39*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from statsd, mm_events and shell 40*e4a36f41SAndroid Build Coastguard Worker# (both root and non-root) on stdin and also to write the resulting trace to 41*e4a36f41SAndroid Build Coastguard Worker# stdout. 42*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su }:fd use; 43*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su }:fifo_file { getattr read write }; 44*e4a36f41SAndroid Build Coastguard Worker 45*e4a36f41SAndroid Build Coastguard Worker# Allow to communicate use, read and write over the adb connection. 46*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:fd use; 47*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:unix_stream_socket { read write }; 48*e4a36f41SAndroid Build Coastguard Worker 49*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to reap perfetto. 50*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:process { sigchld }; 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to write to statsd. 53*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(perfetto, statsdw, statsd) 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# Allow to access /dev/pts when launched in an adb shell. 56*e4a36f41SAndroid Build Coastguard Workerallow perfetto devpts:chr_file rw_file_perms; 57*e4a36f41SAndroid Build Coastguard Worker 58*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to ask incidentd to start a report. 59*e4a36f41SAndroid Build Coastguard Worker# TODO(lalitm): remove all incidentd rules when proxy service is stable. 60*e4a36f41SAndroid Build Coastguard Workerallow perfetto incident_service:service_manager find; 61*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, incidentd) 62*e4a36f41SAndroid Build Coastguard Worker 63*e4a36f41SAndroid Build Coastguard Worker# perfetto log formatter calls isatty() on its stderr. Denial when running 64*e4a36f41SAndroid Build Coastguard Worker# under adbd is harmless. Avoid generating denial logs. 65*e4a36f41SAndroid Build Coastguard Workerdontaudit perfetto adbd:unix_stream_socket getattr; 66*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto adbd:unix_stream_socket ioctl unpriv_tty_ioctls; 67*e4a36f41SAndroid Build Coastguard Worker# As above, when adbd is running in "su" domain (only the ioctl is denied in 68*e4a36f41SAndroid Build Coastguard Worker# practice). 69*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto su:unix_stream_socket ioctl unpriv_tty_ioctls; 70*e4a36f41SAndroid Build Coastguard Worker# Similarly, CTS tests end up hitting a denial on shell pipes. 71*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto shell:fifo_file ioctl unpriv_tty_ioctls; 72*e4a36f41SAndroid Build Coastguard Worker 73*e4a36f41SAndroid Build Coastguard Worker### 74*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 75*e4a36f41SAndroid Build Coastguard Worker### 76*e4a36f41SAndroid Build Coastguard Worker 77*e4a36f41SAndroid Build Coastguard Worker# Disallow anyone else from being able to handle traces except selected system 78*e4a36f41SAndroid Build Coastguard Worker# components. 79*e4a36f41SAndroid Build Coastguard Workerneverallow { 80*e4a36f41SAndroid Build Coastguard Worker domain 81*e4a36f41SAndroid Build Coastguard Worker -init # The creator of the folder. 82*e4a36f41SAndroid Build Coastguard Worker -perfetto # The owner of the folder. 83*e4a36f41SAndroid Build Coastguard Worker -adbd # For pulling traces. 84*e4a36f41SAndroid Build Coastguard Worker -shell # For devepment purposes. 85*e4a36f41SAndroid Build Coastguard Worker -traced # For write_into_file traces. 86*e4a36f41SAndroid Build Coastguard Worker -dumpstate # For attaching traces to bugreports. 87*e4a36f41SAndroid Build Coastguard Worker -incidentd # For receiving reported traces. TODO(lalitm): remove this. 88*e4a36f41SAndroid Build Coastguard Worker -priv_app # For stating traces for bug-report UI. 89*e4a36f41SAndroid Build Coastguard Worker} perfetto_traces_data_file:dir *; 90*e4a36f41SAndroid Build Coastguard Workerneverallow { 91*e4a36f41SAndroid Build Coastguard Worker domain 92*e4a36f41SAndroid Build Coastguard Worker -init # The creator of the folder. 93*e4a36f41SAndroid Build Coastguard Worker -perfetto # The owner of the folder. 94*e4a36f41SAndroid Build Coastguard Worker -adbd # For pulling traces. 95*e4a36f41SAndroid Build Coastguard Worker -shell # For devepment purposes. 96*e4a36f41SAndroid Build Coastguard Worker -traced # For write_into_file traces. 97*e4a36f41SAndroid Build Coastguard Worker -incidentd # For receiving reported traces. TODO(lalitm): remove this. 98*e4a36f41SAndroid Build Coastguard Worker} perfetto_traces_data_file:file ~{ getattr read }; 99*e4a36f41SAndroid Build Coastguard Worker 100*e4a36f41SAndroid Build Coastguard Worker### perfetto should NEVER do any of the following 101*e4a36f41SAndroid Build Coastguard Worker 102*e4a36f41SAndroid Build Coastguard Worker# Disallow mapping executable memory (execstack and exec are already disallowed 103*e4a36f41SAndroid Build Coastguard Worker# globally in domain.te). 104*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto self:process execmem; 105*e4a36f41SAndroid Build Coastguard Worker 106*e4a36f41SAndroid Build Coastguard Worker# Block device access. 107*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto dev_type:blk_file { read write }; 108*e4a36f41SAndroid Build Coastguard Worker 109*e4a36f41SAndroid Build Coastguard Worker# ptrace any other process 110*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto domain:process ptrace; 111*e4a36f41SAndroid Build Coastguard Worker 112*e4a36f41SAndroid Build Coastguard Worker# Disallows access to other /data files. 113*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 114*e4a36f41SAndroid Build Coastguard Worker data_file_type 115*e4a36f41SAndroid Build Coastguard Worker -system_data_file 116*e4a36f41SAndroid Build Coastguard Worker -system_data_root_file 117*e4a36f41SAndroid Build Coastguard Worker -media_userdir_file 118*e4a36f41SAndroid Build Coastguard Worker -system_userdir_file 119*e4a36f41SAndroid Build Coastguard Worker -vendor_userdir_file 120*e4a36f41SAndroid Build Coastguard Worker # TODO(b/72998741) Remove exemption. Further restricted in a subsequent 121*e4a36f41SAndroid Build Coastguard Worker # neverallow. Currently only getattr and search are allowed. 122*e4a36f41SAndroid Build Coastguard Worker -vendor_data_file 123*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 124*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_bugreport_data_file 125*e4a36f41SAndroid Build Coastguard Worker -perfetto_configs_data_file 126*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 127*e4a36f41SAndroid Build Coastguard Worker}:dir *; 128*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { system_data_file -perfetto_traces_data_file }:dir ~{ getattr search }; 129*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 130*e4a36f41SAndroid Build Coastguard Worker data_file_type 131*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 132*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_bugreport_data_file 133*e4a36f41SAndroid Build Coastguard Worker -perfetto_configs_data_file 134*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 135*e4a36f41SAndroid Build Coastguard Worker}:file ~write; 136