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