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