xref: /aosp_15_r20/system/sepolicy/prebuilts/api/31.0/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 to access traced's privileged consumer socket.
12*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(perfetto, traced_consumer, traced)
13*e4a36f41SAndroid Build Coastguard Worker
14*e4a36f41SAndroid Build Coastguard Worker# Connect to the Perfetto traced daemon as a producer. This requires
15*e4a36f41SAndroid Build Coastguard Worker# connecting to its producer socket and obtaining a (per-process) tmpfs fd.
16*e4a36f41SAndroid Build Coastguard Workerperfetto_producer(perfetto)
17*e4a36f41SAndroid Build Coastguard Worker
18*e4a36f41SAndroid Build Coastguard Worker# Allow to write and unlink traces into /data/misc/perfetto-traces.
19*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:dir rw_dir_perms;
20*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_traces_data_file:file create_file_perms;
21*e4a36f41SAndroid Build Coastguard Worker
22*e4a36f41SAndroid Build Coastguard Worker# Allow to access binder to pass the traces to Dropbox.
23*e4a36f41SAndroid Build Coastguard Workerbinder_use(perfetto)
24*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, system_server)
25*e4a36f41SAndroid Build Coastguard Workerallow perfetto dropbox_service:service_manager find;
26*e4a36f41SAndroid Build Coastguard Worker
27*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from /data/misc/perfetto-configs.
28*e4a36f41SAndroid Build Coastguard Worker# shell and adb can write files into that directory.
29*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:dir r_dir_perms;
30*e4a36f41SAndroid Build Coastguard Workerallow perfetto perfetto_configs_data_file:file r_file_perms;
31*e4a36f41SAndroid Build Coastguard Worker
32*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to read the trace config from statsd, mm_events and shell
33*e4a36f41SAndroid Build Coastguard Worker# (both root and non-root) on stdin and also to write the resulting trace to
34*e4a36f41SAndroid Build Coastguard Worker# stdout.
35*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su }:fd use;
36*e4a36f41SAndroid Build Coastguard Workerallow perfetto { statsd mm_events shell su }:fifo_file { getattr read write };
37*e4a36f41SAndroid Build Coastguard Worker
38*e4a36f41SAndroid Build Coastguard Worker# Allow to communicate use, read and write over the adb connection.
39*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:fd use;
40*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:unix_stream_socket { read write };
41*e4a36f41SAndroid Build Coastguard Worker
42*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to reap perfetto.
43*e4a36f41SAndroid Build Coastguard Workerallow perfetto adbd:process { sigchld };
44*e4a36f41SAndroid Build Coastguard Worker
45*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to write to statsd.
46*e4a36f41SAndroid Build Coastguard Workerunix_socket_send(perfetto, statsdw, statsd)
47*e4a36f41SAndroid Build Coastguard Worker
48*e4a36f41SAndroid Build Coastguard Worker# Allow to access /dev/pts when launched in an adb shell.
49*e4a36f41SAndroid Build Coastguard Workerallow perfetto devpts:chr_file rw_file_perms;
50*e4a36f41SAndroid Build Coastguard Worker
51*e4a36f41SAndroid Build Coastguard Worker# Allow perfetto to ask incidentd to start a report.
52*e4a36f41SAndroid Build Coastguard Workerallow perfetto incident_service:service_manager find;
53*e4a36f41SAndroid Build Coastguard Workerbinder_call(perfetto, incidentd)
54*e4a36f41SAndroid Build Coastguard Worker
55*e4a36f41SAndroid Build Coastguard Worker# perfetto log formatter calls isatty() on its stderr. Denial when running
56*e4a36f41SAndroid Build Coastguard Worker# under adbd is harmless. Avoid generating denial logs.
57*e4a36f41SAndroid Build Coastguard Workerdontaudit perfetto adbd:unix_stream_socket getattr;
58*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto adbd:unix_stream_socket ioctl unpriv_tty_ioctls;
59*e4a36f41SAndroid Build Coastguard Worker# As above, when adbd is running in "su" domain (only the ioctl is denied in
60*e4a36f41SAndroid Build Coastguard Worker# practice).
61*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto su:unix_stream_socket ioctl unpriv_tty_ioctls;
62*e4a36f41SAndroid Build Coastguard Worker# Similarly, CTS tests end up hitting a denial on shell pipes.
63*e4a36f41SAndroid Build Coastguard Workerdontauditxperm perfetto shell:fifo_file ioctl unpriv_tty_ioctls;
64*e4a36f41SAndroid Build Coastguard Worker
65*e4a36f41SAndroid Build Coastguard Worker###
66*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules
67*e4a36f41SAndroid Build Coastguard Worker###
68*e4a36f41SAndroid Build Coastguard Worker### perfetto should NEVER do any of this
69*e4a36f41SAndroid Build Coastguard Worker
70*e4a36f41SAndroid Build Coastguard Worker# Disallow mapping executable memory (execstack and exec are already disallowed
71*e4a36f41SAndroid Build Coastguard Worker# globally in domain.te).
72*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto self:process execmem;
73*e4a36f41SAndroid Build Coastguard Worker
74*e4a36f41SAndroid Build Coastguard Worker# Block device access.
75*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto dev_type:blk_file { read write };
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Worker# ptrace any other process
78*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto domain:process ptrace;
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# Disallows access to other /data files.
81*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto {
82*e4a36f41SAndroid Build Coastguard Worker  data_file_type
83*e4a36f41SAndroid Build Coastguard Worker  -system_data_file
84*e4a36f41SAndroid Build Coastguard Worker  -system_data_root_file
85*e4a36f41SAndroid Build Coastguard Worker  # TODO(b/72998741) Remove exemption. Further restricted in a subsequent
86*e4a36f41SAndroid Build Coastguard Worker  # neverallow. Currently only getattr and search are allowed.
87*e4a36f41SAndroid Build Coastguard Worker  -vendor_data_file
88*e4a36f41SAndroid Build Coastguard Worker  -zoneinfo_data_file
89*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_data_file
90*e4a36f41SAndroid Build Coastguard Worker  -perfetto_configs_data_file
91*e4a36f41SAndroid Build Coastguard Worker  with_native_coverage(`-method_trace_data_file')
92*e4a36f41SAndroid Build Coastguard Worker}:dir *;
93*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { system_data_file -perfetto_traces_data_file }:dir ~{ getattr search };
94*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto zoneinfo_data_file:dir ~r_dir_perms;
95*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto { data_file_type -zoneinfo_data_file -perfetto_traces_data_file }:lnk_file *;
96*e4a36f41SAndroid Build Coastguard Workerneverallow perfetto {
97*e4a36f41SAndroid Build Coastguard Worker  data_file_type
98*e4a36f41SAndroid Build Coastguard Worker  -zoneinfo_data_file
99*e4a36f41SAndroid Build Coastguard Worker  -perfetto_traces_data_file
100*e4a36f41SAndroid Build Coastguard Worker  -perfetto_configs_data_file
101*e4a36f41SAndroid Build Coastguard Worker  with_native_coverage(`-method_trace_data_file')
102*e4a36f41SAndroid Build Coastguard Worker}:file ~write;
103