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