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 to access traced's privileged consumer socket. 12*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(perfetto, traced_consumer, traced) 13*e4a36f41SAndroid Build Coastguard Worker 14*e4a36f41SAndroid Build Coastguard Worker# Connect to the Perfetto traced daemon as a producer. This requires 15*e4a36f41SAndroid Build Coastguard Worker# connecting to its producer socket and obtaining a (per-process) tmpfs fd. 16*e4a36f41SAndroid Build Coastguard Workerperfetto_producer(perfetto) 17*e4a36f41SAndroid Build Coastguard Worker 18*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink traces into /data/misc/perfetto-traces. 19*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:dir rw_dir_perms; 20*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:file create_file_perms; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Allow to access binder to pass the traces to Dropbox. 23*e4a36f41SAndroid Build Coastguard Workerbinder_use(perfetto) 24*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, system_server) 25*e4a36f41SAndroid Build Coastguard Workerallow perfetto dropbox_service:service_manager find; 26*e4a36f41SAndroid Build Coastguard Worker 27*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from statsd and shell 28*e4a36f41SAndroid Build Coastguard Worker# (both root and non-root) on stdin and also to write the resulting trace to 29*e4a36f41SAndroid Build Coastguard Worker# stdout. 30*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd shell su }:fd use; 31*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd shell su }:fifo_file { getattr read write }; 32*e4a36f41SAndroid Build Coastguard Worker 33*e4a36f41SAndroid Build Coastguard Worker# Allow to communicate use, read and write over the adb connection. 34*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:fd use; 35*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:unix_stream_socket { read write }; 36*e4a36f41SAndroid Build Coastguard Worker 37*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to reap perfetto. 38*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:process { sigchld }; 39*e4a36f41SAndroid Build Coastguard Worker 40*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to write to statsd. 41*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(perfetto, statsdw, statsd) 42*e4a36f41SAndroid Build Coastguard Worker 43*e4a36f41SAndroid Build Coastguard Worker# Allow to access /dev/pts when launched in an adb shell. 44*e4a36f41SAndroid Build Coastguard Workerallow perfetto devpts:chr_file rw_file_perms; 45*e4a36f41SAndroid Build Coastguard Worker 46*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to ask incidentd to start a report. 47*e4a36f41SAndroid Build Coastguard Workerallow perfetto incident_service:service_manager find; 48*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, incidentd) 49*e4a36f41SAndroid Build Coastguard Worker 50*e4a36f41SAndroid Build Coastguard Worker# perfetto log formatter calls isatty() on its stderr. Denial when running 51*e4a36f41SAndroid Build Coastguard Worker# under adbd is harmless. Avoid generating denial logs. 52*e4a36f41SAndroid Build Coastguard Workerdontaudit perfetto adbd:unix_stream_socket getattr; 53*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto adbd:unix_stream_socket ioctl unpriv_tty_ioctls; 54*e4a36f41SAndroid Build Coastguard Worker# As above, when adbd is running in "su" domain (only the ioctl is denied in 55*e4a36f41SAndroid Build Coastguard Worker# practice). 56*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto su:unix_stream_socket ioctl unpriv_tty_ioctls; 57*e4a36f41SAndroid Build Coastguard Worker# Similarly, CTS tests end up hitting a denial on shell pipes. 58*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto shell:fifo_file ioctl unpriv_tty_ioctls; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Worker### 61*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 62*e4a36f41SAndroid Build Coastguard Worker### 63*e4a36f41SAndroid Build Coastguard Worker### perfetto should NEVER do any of this 64*e4a36f41SAndroid Build Coastguard Worker 65*e4a36f41SAndroid Build Coastguard Worker# Disallow mapping executable memory (execstack and exec are already disallowed 66*e4a36f41SAndroid Build Coastguard Worker# globally in domain.te). 67*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto self:process execmem; 68*e4a36f41SAndroid Build Coastguard Worker 69*e4a36f41SAndroid Build Coastguard Worker# Block device access. 70*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto dev_type:blk_file { read write }; 71*e4a36f41SAndroid Build Coastguard Worker 72*e4a36f41SAndroid Build Coastguard Worker# ptrace any other process 73*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto domain:process ptrace; 74*e4a36f41SAndroid Build Coastguard Worker 75*e4a36f41SAndroid Build Coastguard Worker# Disallows access to other /data files. 76*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 77*e4a36f41SAndroid Build Coastguard Worker data_file_type 78*e4a36f41SAndroid Build Coastguard Worker -system_data_file 79*e4a36f41SAndroid Build Coastguard Worker -system_data_root_file 80*e4a36f41SAndroid Build Coastguard Worker # TODO(b/72998741) Remove exemption. Further restricted in a subsequent 81*e4a36f41SAndroid Build Coastguard Worker # neverallow. Currently only getattr and search are allowed. 82*e4a36f41SAndroid Build Coastguard Worker -vendor_data_file 83*e4a36f41SAndroid Build Coastguard Worker -zoneinfo_data_file 84*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 85*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 86*e4a36f41SAndroid Build Coastguard Worker}:dir *; 87*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { system_data_file -perfetto_traces_data_file }:dir ~{ getattr search }; 88*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto zoneinfo_data_file:dir ~r_dir_perms; 89*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { data_file_type -zoneinfo_data_file -perfetto_traces_data_file }:lnk_file *; 90*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { 91*e4a36f41SAndroid Build Coastguard Worker data_file_type 92*e4a36f41SAndroid Build Coastguard Worker -zoneinfo_data_file 93*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 94*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 95*e4a36f41SAndroid Build Coastguard Worker}:file ~write; 96