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