xref: /aosp_15_r20/system/sepolicy/prebuilts/api/202404/private/perfetto.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# Perfetto command-line client. Can be used only from the domains that are
2*e4a36f41SAndroid Build Coastguard Worker# explicitly allowlisted with a domain_auto_trans(X, perfetto_exec, perfetto).
3*e4a36f41SAndroid Build Coastguard Worker# This command line client accesses the privileged socket of the traced
4*e4a36f41SAndroid Build Coastguard Worker# daemon.
5*e4a36f41SAndroid Build Coastguard Worker
6*e4a36f41SAndroid Build Coastguard Workertype perfetto_exec, system_file_type, exec_type, file_type;
7*e4a36f41SAndroid Build Coastguard Workertype perfetto_tmpfs, file_type;
8*e4a36f41SAndroid Build Coastguard Worker
9*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(perfetto);
10*e4a36f41SAndroid Build Coastguard Worker
11*e4a36f41SAndroid Build Coastguard Worker# Allow init to start a trace (for perfetto_boottrace).
12*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(perfetto)
13*e4a36f41SAndroid Build Coastguard Worker
14*e4a36f41SAndroid Build Coastguard Worker# Allow to access traced's privileged consumer socket.
15*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(perfetto, traced_consumer, traced)
16*e4a36f41SAndroid Build Coastguard Worker
17*e4a36f41SAndroid Build Coastguard Worker# Connect to the Perfetto traced daemon as a producer. This requires
18*e4a36f41SAndroid Build Coastguard Worker# connecting to its producer socket and obtaining a (per-process) tmpfs fd.
19*e4a36f41SAndroid Build Coastguard Workerperfetto_producer(perfetto)
20*e4a36f41SAndroid Build Coastguard Worker
21*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink traces into /data/misc/perfetto-traces.
22*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:dir rw_dir_perms;
23*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:file create_file_perms;
24*e4a36f41SAndroid Build Coastguard Worker
25*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink trace into /data/misc/perfetto-traces/bugreport*
26*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_bugreport_data_file:file create_file_perms;
27*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_bugreport_data_file:dir rw_dir_perms;
28*e4a36f41SAndroid Build Coastguard Worker
29*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink traces into /data/misc/perfetto-traces/profiling.
30*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_profiling_data_file:dir rw_dir_perms;
31*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_profiling_data_file:file create_file_perms;
32*e4a36f41SAndroid Build Coastguard Worker
33*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to access the proxy service for reporting traces.
34*e4a36f41SAndroid Build Coastguard Workerallow perfetto tracingproxy_service:service_manager find;
35*e4a36f41SAndroid Build Coastguard Workerbinder_use(perfetto)
36*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, system_server)
37*e4a36f41SAndroid Build Coastguard Worker
38*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from /data/misc/perfetto-configs.
39*e4a36f41SAndroid Build Coastguard Worker# shell and adb can write files into that directory.
40*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:dir r_dir_perms;
41*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:file r_file_perms;
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from statsd, mm_events and shell
44*e4a36f41SAndroid Build Coastguard Worker# (both root and non-root) on stdin and also to write the resulting trace to
45*e4a36f41SAndroid Build Coastguard Worker# stdout.
46*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su }:fd use;
47*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su system_server }:fifo_file { getattr read write ioctl };
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker# Allow to communicate use, read and write over the adb connection.
50*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:fd use;
51*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:unix_stream_socket { read write };
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to reap perfetto.
54*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:process { sigchld };
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to write to statsd.
57*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(perfetto, statsdw, statsd)
58*e4a36f41SAndroid Build Coastguard Worker
59*e4a36f41SAndroid Build Coastguard Worker# Allow to access /dev/pts when launched in an adb shell.
60*e4a36f41SAndroid Build Coastguard Workerallow perfetto devpts:chr_file rw_file_perms;
61*e4a36f41SAndroid Build Coastguard Worker
62*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to ask incidentd to start a report.
63*e4a36f41SAndroid Build Coastguard Worker# TODO(lalitm): remove all incidentd rules when proxy service is stable.
64*e4a36f41SAndroid Build Coastguard Workerallow perfetto incident_service:service_manager find;
65*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, incidentd)
66*e4a36f41SAndroid Build Coastguard Worker
67*e4a36f41SAndroid Build Coastguard Worker# perfetto log formatter calls isatty() on its stderr. Denial when running
68*e4a36f41SAndroid Build Coastguard Worker# under adbd is harmless. Avoid generating denial logs.
69*e4a36f41SAndroid Build Coastguard Workerdontaudit perfetto adbd:unix_stream_socket getattr;
70*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto adbd:unix_stream_socket ioctl unpriv_tty_ioctls;
71*e4a36f41SAndroid Build Coastguard Worker# As above, when adbd is running in "su" domain (only the ioctl is denied in
72*e4a36f41SAndroid Build Coastguard Worker# practice).
73*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto su:unix_stream_socket ioctl unpriv_tty_ioctls;
74*e4a36f41SAndroid Build Coastguard Worker# Similarly, CTS tests end up hitting a denial on shell pipes.
75*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto shell:fifo_file ioctl unpriv_tty_ioctls;
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Worker###
78*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
79*e4a36f41SAndroid Build Coastguard Worker###
80*e4a36f41SAndroid Build Coastguard Worker
81*e4a36f41SAndroid Build Coastguard Worker# Disallow anyone else from being able to handle traces except selected system
82*e4a36f41SAndroid Build Coastguard Worker# components.
83*e4a36f41SAndroid Build Coastguard Workerneverallow {
84*e4a36f41SAndroid Build Coastguard Worker  domain
85*e4a36f41SAndroid Build Coastguard Worker  -init      # The creator of the folder.
86*e4a36f41SAndroid Build Coastguard Worker  -perfetto  # The owner of the folder.
87*e4a36f41SAndroid Build Coastguard Worker  -adbd      # For pulling traces.
88*e4a36f41SAndroid Build Coastguard Worker  -shell     # For devepment purposes.
89*e4a36f41SAndroid Build Coastguard Worker  -traced    # For write_into_file traces.
90*e4a36f41SAndroid Build Coastguard Worker  -dumpstate # For attaching traces to bugreports.
91*e4a36f41SAndroid Build Coastguard Worker  -incidentd # For receiving reported traces. TODO(lalitm): remove this.
92*e4a36f41SAndroid Build Coastguard Worker  -priv_app  # For stating traces for bug-report UI.
93*e4a36f41SAndroid Build Coastguard Worker  -system_server # For accessing traces started by profiling apis.
94*e4a36f41SAndroid Build Coastguard Worker} perfetto_traces_data_file:dir *;
95*e4a36f41SAndroid Build Coastguard Workerneverallow {
96*e4a36f41SAndroid Build Coastguard Worker  domain
97*e4a36f41SAndroid Build Coastguard Worker  -init      # The creator of the folder.
98*e4a36f41SAndroid Build Coastguard Worker  -perfetto  # The owner of the folder.
99*e4a36f41SAndroid Build Coastguard Worker  -adbd      # For pulling traces.
100*e4a36f41SAndroid Build Coastguard Worker  -shell     # For devepment purposes.
101*e4a36f41SAndroid Build Coastguard Worker  -traced    # For write_into_file traces.
102*e4a36f41SAndroid Build Coastguard Worker  -incidentd      # For receiving reported traces. TODO(lalitm): remove this.
103*e4a36f41SAndroid Build Coastguard Worker} perfetto_traces_data_file:file ~{ getattr read };
104*e4a36f41SAndroid Build Coastguard Worker
105*e4a36f41SAndroid Build Coastguard Worker### perfetto should NEVER do any of the following
106*e4a36f41SAndroid Build Coastguard Worker
107*e4a36f41SAndroid Build Coastguard Worker# Disallow mapping executable memory (execstack and exec are already disallowed
108*e4a36f41SAndroid Build Coastguard Worker# globally in domain.te).
109*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto self:process execmem;
110*e4a36f41SAndroid Build Coastguard Worker
111*e4a36f41SAndroid Build Coastguard Worker# Block device access.
112*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto dev_type:blk_file { read write };
113*e4a36f41SAndroid Build Coastguard Worker
114*e4a36f41SAndroid Build Coastguard Worker# ptrace any other process
115*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto domain:process ptrace;
116*e4a36f41SAndroid Build Coastguard Worker
117*e4a36f41SAndroid Build Coastguard Worker# Disallows access to other /data files.
118*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto {
119*e4a36f41SAndroid Build Coastguard Worker  data_file_type
120*e4a36f41SAndroid Build Coastguard Worker  -system_data_file
121*e4a36f41SAndroid Build Coastguard Worker  -system_data_root_file
122*e4a36f41SAndroid Build Coastguard Worker  -media_userdir_file
123*e4a36f41SAndroid Build Coastguard Worker  -system_userdir_file
124*e4a36f41SAndroid Build Coastguard Worker  -vendor_userdir_file
125*e4a36f41SAndroid Build Coastguard Worker  # TODO(b/72998741) Remove exemption. Further restricted in a subsequent
126*e4a36f41SAndroid Build Coastguard Worker  # neverallow. Currently only getattr and search are allowed.
127*e4a36f41SAndroid Build Coastguard Worker  -vendor_data_file
128*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_data_file
129*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_bugreport_data_file
130*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_profiling_data_file
131*e4a36f41SAndroid Build Coastguard Worker  -perfetto_configs_data_file
132*e4a36f41SAndroid Build Coastguard Worker  with_native_coverage(`-method_trace_data_file')
133*e4a36f41SAndroid Build Coastguard Worker}:dir *;
134*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto {
135*e4a36f41SAndroid Build Coastguard Worker  system_data_file
136*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_data_file
137*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_profiling_data_file
138*e4a36f41SAndroid Build Coastguard Worker}:dir ~{ getattr search };
139*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto {
140*e4a36f41SAndroid Build Coastguard Worker  data_file_type
141*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_data_file
142*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_bugreport_data_file
143*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_profiling_data_file
144*e4a36f41SAndroid Build Coastguard Worker  -perfetto_configs_data_file
145*e4a36f41SAndroid Build Coastguard Worker  with_native_coverage(`-method_trace_data_file')
146*e4a36f41SAndroid Build Coastguard Worker}:file ~write;
147