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). 5type traced_exec, system_file_type, exec_type, file_type; 6 7# Allow init to exec the daemon. 8init_daemon_domain(traced) 9tmpfs_domain(traced) 10 11# Allow apps in other MLS contexts (for multi-user) to access 12# share memory buffers created by traced. 13typeattribute 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. 18allow 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). 23allow traced perfetto:fd use; 24allow traced shell:fd use; 25allow traced shell:fifo_file { read write }; 26 27# Allow the service to create new files within /data/misc/perfetto-traces. 28allow traced perfetto_traces_data_file:file create_file_perms; 29allow traced perfetto_traces_data_file:dir rw_dir_perms; 30# ... and /data/misc/perfetto-traces/bugreport* 31allow traced perfetto_traces_bugreport_data_file:file create_file_perms; 32allow 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. 36allow traced traceur_app:fd use; 37allow traced trace_data_file:file { read write }; 38 39# Allow perfetto to access the proxy service for notifying Traceur. 40allow traced tracingproxy_service:service_manager find; 41binder_use(traced); 42binder_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. 46allow traced iorapd:fd use; 47allow 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. 58allow 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. 68set_prop(traced, system_trace_prop) 69# Allow to lazily start producers. 70set_prop(traced, traced_lazy_prop) 71 72# Allow traced to talk to statsd for logging metrics. 73unix_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). 82neverallow traced self:process execmem; 83 84# Block device access. 85neverallow traced dev_type:blk_file { read write }; 86 87# ptrace any other process 88neverallow traced domain:process ptrace; 89 90# Disallows access to /data files, still allowing to write to file descriptors 91# passed through the socket. 92neverallow 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 *; 104neverallow traced { system_data_file }:dir ~{ getattr search }; 105neverallow traced zoneinfo_data_file:dir ~r_dir_perms; 106neverallow traced { data_file_type -zoneinfo_data_file }:lnk_file *; 107neverallow 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() 117neverallow { domain -init } traced:process transition; 118neverallow * traced:process dyntransition; 119 120# Limit the processes that can access tracingproxy_service. 121neverallow { domain -traced -dumpstate -traceur_app -shell -system_server } tracingproxy_service:service_manager find; 122