Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 1 | # Perfetto user-space tracing daemon (unprivileged) |
| 2 | |
| 3 | # type traced is defined under /public (because iorapd rules |
| 4 | # under public/ need to refer to it). |
| 5 | type traced_exec, system_file_type, exec_type, file_type; |
| 6 | |
| 7 | # Allow init to exec the daemon. |
| 8 | init_daemon_domain(traced) |
| 9 | tmpfs_domain(traced) |
| 10 | |
| 11 | # Allow apps in other MLS contexts (for multi-user) to access |
| 12 | # share memory buffers created by traced. |
| 13 | typeattribute traced_tmpfs mlstrustedobject; |
| 14 | |
| 15 | # Allow traced to start with a lower scheduling class and change |
| 16 | # class accordingly to what defined in the config provided by |
| 17 | # the privileged process that controls it. |
| 18 | allow traced self:global_capability_class_set { sys_nice }; |
| 19 | |
| 20 | # Allow to pass a file descriptor for the output trace from "perfetto" (the |
| 21 | # cmdline client) and other shell binaries to traced and let traced write |
| 22 | # directly into that (rather than returning the trace contents over the socket). |
| 23 | allow traced perfetto:fd use; |
| 24 | allow traced shell:fd use; |
| 25 | allow traced shell:fifo_file { read write }; |
| 26 | |
| 27 | # Allow the service to create new files within /data/misc/perfetto-traces. |
| 28 | allow traced perfetto_traces_data_file:file create_file_perms; |
| 29 | allow traced perfetto_traces_data_file:dir rw_dir_perms; |
| 30 | # ... and /data/misc/perfetto-traces/bugreport* |
| 31 | allow traced perfetto_traces_bugreport_data_file:file create_file_perms; |
| 32 | allow traced perfetto_traces_bugreport_data_file:dir rw_dir_perms; |
| 33 | |
| 34 | # Allow traceur to pass open file descriptors to traced, so traced can directly |
| 35 | # write into the output file without doing roundtrips over IPC. |
| 36 | allow traced traceur_app:fd use; |
| 37 | allow traced trace_data_file:file { read write }; |
| 38 | |
| 39 | # Allow perfetto to access the proxy service for notifying Traceur. |
| 40 | allow traced tracingproxy_service:service_manager find; |
| 41 | binder_use(traced); |
| 42 | binder_call(traced, system_server); |
| 43 | |
| 44 | # Allow iorapd to pass memfd descriptors to traced, so traced can directly |
| 45 | # write into the shmem buffer file without doing roundtrips over IPC. |
| 46 | allow traced iorapd:fd use; |
| 47 | allow traced iorapd_tmpfs:file { read write }; |
| 48 | |
| 49 | # Allow traced to use shared memory supplied by producers. Typically, traced |
| 50 | # (i.e. the tracing service) creates the shared memory used for data transfer |
| 51 | # from the producer. This rule allows an alternative scheme, where the producer |
| 52 | # creates the shared memory, that is then adopted by traced (after validating |
| 53 | # that it is appropriately sealed). |
| 54 | # This list has to replicate the tmpfs domains of all applicable domains that |
| 55 | # have perfetto_producer() macro applied to them. |
| 56 | # perfetto_tmpfs excluded as it should never need to use the producer-supplied |
| 57 | # shared memory scheme. |
| 58 | allow traced { |
| 59 | appdomain_tmpfs |
| 60 | heapprofd_tmpfs |
| 61 | surfaceflinger_tmpfs |
| 62 | traced_probes_tmpfs |
| 63 | userdebug_or_eng(`system_server_tmpfs') |
| 64 | }:file { getattr map read write }; |
| 65 | |
| 66 | # Allow traced to notify Traceur when a trace ends by setting the |
| 67 | # sys.trace.trace_end_signal property. |
| 68 | set_prop(traced, system_trace_prop) |
| 69 | # Allow to lazily start producers. |
| 70 | set_prop(traced, traced_lazy_prop) |
| 71 | |
| 72 | # Allow traced to talk to statsd for logging metrics. |
| 73 | unix_socket_send(traced, statsdw, statsd) |
| 74 | |
| 75 | ### |
| 76 | ### Neverallow rules |
| 77 | ### |
| 78 | ### traced should NEVER do any of this |
| 79 | |
| 80 | # Disallow mapping executable memory (execstack and exec are already disallowed |
| 81 | # globally in domain.te). |
| 82 | neverallow traced self:process execmem; |
| 83 | |
| 84 | # Block device access. |
| 85 | neverallow traced dev_type:blk_file { read write }; |
| 86 | |
| 87 | # ptrace any other process |
| 88 | neverallow traced domain:process ptrace; |
| 89 | |
| 90 | # Disallows access to /data files, still allowing to write to file descriptors |
| 91 | # passed through the socket. |
| 92 | neverallow traced { |
| 93 | data_file_type |
| 94 | -perfetto_traces_data_file |
| 95 | -perfetto_traces_bugreport_data_file |
| 96 | -system_data_file |
| 97 | -system_data_root_file |
| 98 | # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a |
| 99 | # subsequent neverallow. Currently only getattr and search are allowed. |
| 100 | -vendor_data_file |
| 101 | -zoneinfo_data_file |
| 102 | with_native_coverage(`-method_trace_data_file') |
| 103 | }:dir *; |
| 104 | neverallow traced { system_data_file }:dir ~{ getattr search }; |
| 105 | neverallow traced zoneinfo_data_file:dir ~r_dir_perms; |
| 106 | neverallow traced { data_file_type -zoneinfo_data_file }:lnk_file *; |
| 107 | neverallow traced { |
| 108 | data_file_type |
| 109 | -zoneinfo_data_file |
| 110 | -perfetto_traces_data_file |
| 111 | -perfetto_traces_bugreport_data_file |
| 112 | -trace_data_file |
| 113 | with_native_coverage(`-method_trace_data_file') |
| 114 | }:file ~write; |
| 115 | |
| 116 | # Only init is allowed to enter the traced domain via exec() |
| 117 | neverallow { domain -init } traced:process transition; |
| 118 | neverallow * traced:process dyntransition; |