xref: /aosp_15_r20/system/sepolicy/prebuilts/api/34.0/private/traced.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
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 trace_data_file:file { read write };
32
33# Allow perfetto to access the proxy service for notifying Traceur.
34allow traced tracingproxy_service:service_manager find;
35binder_use(traced);
36binder_call(traced, system_server);
37
38# Allow traced to use shared memory supplied by producers. Typically, traced
39# (i.e. the tracing service) creates the shared memory used for data transfer
40# from the producer. This rule allows an alternative scheme, where the producer
41# creates the shared memory, that is then adopted by traced (after validating
42# that it is appropriately sealed).
43# This list has to replicate the tmpfs domains of all applicable domains that
44# have perfetto_producer() macro applied to them.
45# perfetto_tmpfs excluded as it should never need to use the producer-supplied
46# shared memory scheme.
47allow traced  {
48  appdomain_tmpfs
49  heapprofd_tmpfs
50  surfaceflinger_tmpfs
51  traced_probes_tmpfs
52  userdebug_or_eng(`system_server_tmpfs')
53}:file { getattr map read write };
54
55# Allow traced to notify Traceur when a trace ends by setting the
56# sys.trace.trace_end_signal property.
57set_prop(traced, system_trace_prop)
58# Allow to lazily start producers.
59set_prop(traced, traced_lazy_prop)
60# Allow tracking the count of sessions intercepting Java OutOfMemoryError
61# If there are such tracing sessions and an OutOfMemoryError is thrown by ART,
62# the hprof plugin intercepts the error, lazily registers a data source to
63# traced and collects a heap dump.
64set_prop(traced, traced_oome_heap_session_count_prop)
65
66# Allow traced to talk to statsd for logging metrics.
67unix_socket_send(traced, statsdw, statsd)
68
69###
70### Neverallow rules
71###
72### traced should NEVER do any of this
73
74# Disallow mapping executable memory (execstack and exec are already disallowed
75# globally in domain.te).
76neverallow traced self:process execmem;
77
78# Block device access.
79neverallow traced dev_type:blk_file { read write };
80
81# ptrace any other process
82neverallow traced domain:process ptrace;
83
84# Disallows access to /data files, still allowing to write to file descriptors
85# passed through the socket.
86neverallow traced {
87  data_file_type
88  -perfetto_traces_data_file
89  -system_data_file
90  -system_data_root_file
91  -media_userdir_file
92  -system_userdir_file
93  -vendor_userdir_file
94  # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
95  # subsequent neverallow. Currently only getattr and search are allowed.
96  -vendor_data_file
97  with_native_coverage(`-method_trace_data_file')
98}:dir *;
99neverallow traced { system_data_file }:dir ~{ getattr search };
100neverallow traced {
101  data_file_type
102  -perfetto_traces_data_file
103  -trace_data_file
104  with_native_coverage(`-method_trace_data_file')
105}:file ~write;
106
107# Only init is allowed to enter the traced domain via exec()
108neverallow { domain -init } traced:process transition;
109neverallow * traced:process dyntransition;
110
111# Limit the processes that can access tracingproxy_service.
112neverallow {
113  domain
114  -traced
115  -dumpstate
116  -traceur_app
117  -shell
118  -system_server
119  -perfetto
120} tracingproxy_service:service_manager find;
121