1# Perfetto user-space tracing daemon (unprivileged) 2type traced_exec, system_file_type, exec_type, file_type; 3 4# Allow init to exec the daemon. 5init_daemon_domain(traced) 6tmpfs_domain(traced) 7 8# Allow apps in other MLS contexts (for multi-user) to access 9# share memory buffers created by traced. 10typeattribute traced_tmpfs mlstrustedobject; 11 12# Allow traced to start with a lower scheduling class and change 13# class accordingly to what defined in the config provided by 14# the privileged process that controls it. 15allow traced self:global_capability_class_set { sys_nice }; 16 17# Allow to pass a file descriptor for the output trace from "perfetto" (the 18# cmdline client) and other shell binaries to traced and let traced write 19# directly into that (rather than returning the trace contents over the socket). 20allow traced perfetto:fd use; 21allow traced shell:fd use; 22allow traced shell:fifo_file { read write }; 23 24# Allow the service to create new files within /data/misc/perfetto-traces. 25allow traced perfetto_traces_data_file:file create_file_perms; 26allow traced perfetto_traces_data_file:dir rw_dir_perms; 27 28# Allow traceur to pass open file descriptors to traced, so traced can directly 29# write into the output file without doing roundtrips over IPC. 30allow traced traceur_app:fd use; 31allow traced platform_app:fd use; 32allow traced trace_data_file:file { read write }; 33 34# Allow perfetto to access the proxy service for notifying Traceur. 35allow traced tracingproxy_service:service_manager find; 36binder_use(traced); 37binder_call(traced, system_server); 38 39# Allow traced to use shared memory supplied by producers. Typically, traced 40# (i.e. the tracing service) creates the shared memory used for data transfer 41# from the producer. This rule allows an alternative scheme, where the producer 42# creates the shared memory, that is then adopted by traced (after validating 43# that it is appropriately sealed). 44# This list has to replicate the tmpfs domains of all applicable domains that 45# have perfetto_producer() macro applied to them. 46# perfetto_tmpfs excluded as it should never need to use the producer-supplied 47# shared memory scheme. 48allow traced { 49 appdomain_tmpfs 50 heapprofd_tmpfs 51 surfaceflinger_tmpfs 52 traced_probes_tmpfs 53 userdebug_or_eng(`system_server_tmpfs') 54}:file { getattr map read write }; 55 56# Allow traced to detect if a process is frozen (b/381089063). 57allow traced cgroup_v2:file r_file_perms; 58 59# Allow traced/traced_relay to read the traced config properties. 60get_prop(traced, traced_config_prop) 61# Allow traced_relay to read the relay port being used 62get_prop(traced, traced_relay_relay_port_prop) 63 64# Allow setting debug properties which guard initialization of the Perfetto SDK 65# in SurfaceFlinger and HWUI's copy of Skia. 66# Required for the android.sdk_sysprop_guard data source. 67# TODO(b/281329340): remove this when no longer needed. 68set_prop(traced, debug_prop) 69# Allow traced to notify Traceur when a trace ends by setting the 70# sys.trace.trace_end_signal property. 71set_prop(traced, system_trace_prop) 72# Allow to lazily start producers. 73set_prop(traced, traced_lazy_prop) 74# Allow tracking the count of sessions intercepting Java OutOfMemoryError 75# If there are such tracing sessions and an OutOfMemoryError is thrown by ART, 76# the hprof plugin intercepts the error, lazily registers a data source to 77# traced and collects a heap dump. 78set_prop(traced, traced_oome_heap_session_count_prop) 79 80# Allow traced to talk to statsd for logging metrics. 81unix_socket_send(traced, statsdw, statsd) 82 83### 84### Neverallow rules 85### 86### traced should NEVER do any of this 87 88# Disallow mapping executable memory (execstack and exec are already disallowed 89# globally in domain.te). 90neverallow traced self:process execmem; 91 92# Block device access. 93neverallow traced dev_type:blk_file { read write }; 94 95# ptrace any other process 96neverallow traced domain:process ptrace; 97 98# Disallows access to /data files, still allowing to write to file descriptors 99# passed through the socket. 100neverallow traced { 101 data_file_type 102 -perfetto_traces_data_file 103 -system_data_file 104 -system_data_root_file 105 -media_userdir_file 106 -system_userdir_file 107 -vendor_userdir_file 108 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a 109 # subsequent neverallow. Currently only getattr and search are allowed. 110 -vendor_data_file 111 with_native_coverage(`-method_trace_data_file') 112}:dir *; 113neverallow traced { system_data_file }:dir ~{ getattr search }; 114neverallow traced { 115 data_file_type 116 -perfetto_traces_data_file 117 -trace_data_file 118 with_native_coverage(`-method_trace_data_file') 119}:file ~write; 120 121# Only init is allowed to enter the traced domain via exec() 122neverallow { domain -init } traced:process transition; 123neverallow * traced:process dyntransition; 124 125# Limit the processes that can access tracingproxy_service. 126neverallow { 127 domain 128 -traced 129 -dumpstate 130 -traceur_app 131 -platform_app 132 -shell 133 -system_server 134 -perfetto 135} tracingproxy_service:service_manager find; 136