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 Workerallow traced perfetto_traces_data_file:file { read write }; 28*e4a36f41SAndroid Build Coastguard Worker 29*e4a36f41SAndroid Build Coastguard Worker# Allow traceur to pass open file descriptors to traced, so traced can directly 30*e4a36f41SAndroid Build Coastguard Worker# write into the output file without doing roundtrips over IPC. 31*e4a36f41SAndroid Build Coastguard Workerallow traced traceur_app:fd use; 32*e4a36f41SAndroid Build Coastguard Workerallow traced trace_data_file:file { read write }; 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Worker# Allow iorapd to pass memfd descriptors to traced, so traced can directly 35*e4a36f41SAndroid Build Coastguard Worker# write into the shmem buffer file without doing roundtrips over IPC. 36*e4a36f41SAndroid Build Coastguard Workerallow traced iorapd:fd use; 37*e4a36f41SAndroid Build Coastguard Workerallow traced iorapd_tmpfs:file { read write }; 38*e4a36f41SAndroid Build Coastguard Worker 39*e4a36f41SAndroid Build Coastguard Worker# Allow traced to notify Traceur when a trace ends by setting the 40*e4a36f41SAndroid Build Coastguard Worker# sys.trace.trace_end_signal property. 41*e4a36f41SAndroid Build Coastguard Workerset_prop(traced, system_trace_prop) 42*e4a36f41SAndroid Build Coastguard Worker# Allow to lazily start producers. 43*e4a36f41SAndroid Build Coastguard Workerset_prop(traced, traced_lazy_prop) 44*e4a36f41SAndroid Build Coastguard Worker 45*e4a36f41SAndroid Build Coastguard Worker### 46*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 47*e4a36f41SAndroid Build Coastguard Worker### 48*e4a36f41SAndroid Build Coastguard Worker### traced should NEVER do any of this 49*e4a36f41SAndroid Build Coastguard Worker 50*e4a36f41SAndroid Build Coastguard Worker# Disallow mapping executable memory (execstack and exec are already disallowed 51*e4a36f41SAndroid Build Coastguard Worker# globally in domain.te). 52*e4a36f41SAndroid Build Coastguard Workerneverallow traced self:process execmem; 53*e4a36f41SAndroid Build Coastguard Worker 54*e4a36f41SAndroid Build Coastguard Worker# Block device access. 55*e4a36f41SAndroid Build Coastguard Workerneverallow traced dev_type:blk_file { read write }; 56*e4a36f41SAndroid Build Coastguard Worker 57*e4a36f41SAndroid Build Coastguard Worker# ptrace any other process 58*e4a36f41SAndroid Build Coastguard Workerneverallow traced domain:process ptrace; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Worker# Disallows access to /data files, still allowing to write to file descriptors 61*e4a36f41SAndroid Build Coastguard Worker# passed through the socket. 62*e4a36f41SAndroid Build Coastguard Workerneverallow traced { 63*e4a36f41SAndroid Build Coastguard Worker data_file_type 64*e4a36f41SAndroid Build Coastguard Worker -system_data_file 65*e4a36f41SAndroid Build Coastguard Worker # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a 66*e4a36f41SAndroid Build Coastguard Worker # subsequent neverallow. Currently only getattr and search are allowed. 67*e4a36f41SAndroid Build Coastguard Worker -vendor_data_file 68*e4a36f41SAndroid Build Coastguard Worker -zoneinfo_data_file 69*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 70*e4a36f41SAndroid Build Coastguard Worker}:dir *; 71*e4a36f41SAndroid Build Coastguard Workerneverallow traced { system_data_file }:dir ~{ getattr search }; 72*e4a36f41SAndroid Build Coastguard Workerneverallow traced zoneinfo_data_file:dir ~r_dir_perms; 73*e4a36f41SAndroid Build Coastguard Workerneverallow traced { data_file_type -zoneinfo_data_file }:lnk_file *; 74*e4a36f41SAndroid Build Coastguard Workerneverallow traced { 75*e4a36f41SAndroid Build Coastguard Worker data_file_type 76*e4a36f41SAndroid Build Coastguard Worker -zoneinfo_data_file 77*e4a36f41SAndroid Build Coastguard Worker -perfetto_traces_data_file 78*e4a36f41SAndroid Build Coastguard Worker -trace_data_file 79*e4a36f41SAndroid Build Coastguard Worker with_native_coverage(`-method_trace_data_file') 80*e4a36f41SAndroid Build Coastguard Worker}:file ~write; 81*e4a36f41SAndroid Build Coastguard Worker 82*e4a36f41SAndroid Build Coastguard Worker# Only init is allowed to enter the traced domain via exec() 83*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } traced:process transition; 84*e4a36f41SAndroid Build Coastguard Workerneverallow * traced:process dyntransition; 85