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