blob: aa169662d4c3cd13f12e1884422808c18100d0d8 [file] [log] [blame]
Primiano Tuccic80f9e02017-12-21 03:51:15 +01001# Perfetto user-space tracing daemon (unprivileged)
Primiano Tucci79d1dbb2019-01-23 20:42:16 +00002
3# type traced is defined under /public (because iorapd rules
4# under public/ need to refer to it).
Nick Kralevich5e372712018-09-27 10:21:37 -07005type traced_exec, system_file_type, exec_type, file_type;
Jeff Vander Stoep41a2abf2019-01-23 15:07:40 -08006type traced_tmpfs, file_type;
Primiano Tuccic80f9e02017-12-21 03:51:15 +01007
8# Allow init to exec the daemon.
9init_daemon_domain(traced)
Jeff Vander Stoep41a2abf2019-01-23 15:07:40 -080010tmpfs_domain(traced)
Primiano Tuccic80f9e02017-12-21 03:51:15 +010011
Primiano Tucci5ef66692018-02-21 13:44:39 +000012# Allow apps in other MLS contexts (for multi-user) to access
13# share memory buffers created by traced.
14typeattribute traced_tmpfs mlstrustedobject;
15
Primiano Tuccic80f9e02017-12-21 03:51:15 +010016# 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
Primiano Tucci5d317322018-03-26 01:54:52 +010021# 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;
Isabelle Taylor19f49982019-01-21 18:54:45 +000026allow traced shell:fifo_file { read write };
Primiano Tucci386d95b2020-04-08 20:31:21 +010027
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;
Primiano Tucci2f998092021-01-07 17:12:21 +000031# ... and /data/misc/perfetto-traces/bugreport*
32allow traced perfetto_traces_bugreport_data_file:file create_file_perms;
33allow traced perfetto_traces_bugreport_data_file:dir rw_dir_perms;
Primiano Tucci79d1dbb2019-01-23 20:42:16 +000034
35# Allow traceur to pass open file descriptors to traced, so traced can directly
36# write into the output file without doing roundtrips over IPC.
37allow traced traceur_app:fd use;
Carmen Jackson9678e072019-01-10 12:17:40 -080038allow traced trace_data_file:file { read write };
Primiano Tucci5d317322018-03-26 01:54:52 +010039
Collin Fijalkovich6f4cfe82020-12-11 14:51:32 -080040# Allow perfetto to access the proxy service for notifying Traceur.
41allow traced tracingproxy_service:service_manager find;
42binder_use(traced);
43binder_call(traced, system_server);
44
Primiano Tucci79d1dbb2019-01-23 20:42:16 +000045# Allow iorapd to pass memfd descriptors to traced, so traced can directly
46# write into the shmem buffer file without doing roundtrips over IPC.
47allow traced iorapd:fd use;
48allow traced iorapd_tmpfs:file { read write };
49
Ryan Savitski21f6ae62020-02-04 13:44:14 +000050# Allow traced to use shared memory supplied by producers. Typically, traced
51# (i.e. the tracing service) creates the shared memory used for data transfer
52# from the producer. This rule allows an alternative scheme, where the producer
53# creates the shared memory, that is then adopted by traced (after validating
54# that it is appropriately sealed).
55# This list has to replicate the tmpfs domains of all applicable domains that
56# have perfetto_producer() macro applied to them.
57# perfetto_tmpfs excluded as it should never need to use the producer-supplied
58# shared memory scheme.
59allow traced {
60 appdomain_tmpfs
61 heapprofd_tmpfs
62 surfaceflinger_tmpfs
63 traced_probes_tmpfs
64 userdebug_or_eng(`system_server_tmpfs')
65}:file { getattr map read write };
66
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000067# Allow traced to notify Traceur when a trace ends by setting the
68# sys.trace.trace_end_signal property.
69set_prop(traced, system_trace_prop)
Florian Mayera769f0f2019-03-13 11:22:23 -070070# Allow to lazily start producers.
71set_prop(traced, traced_lazy_prop)
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000072
Lalit Maganti9165bf72020-12-16 18:45:31 +000073# Allow traced to talk to statsd for logging metrics.
74unix_socket_send(traced, statsdw, statsd)
75
Primiano Tuccic80f9e02017-12-21 03:51:15 +010076###
77### Neverallow rules
78###
79### traced should NEVER do any of this
80
81# Disallow mapping executable memory (execstack and exec are already disallowed
82# globally in domain.te).
83neverallow traced self:process execmem;
84
85# Block device access.
86neverallow traced dev_type:blk_file { read write };
87
88# ptrace any other process
89neverallow traced domain:process ptrace;
90
91# Disallows access to /data files, still allowing to write to file descriptors
92# passed through the socket.
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080093neverallow traced {
94 data_file_type
Primiano Tucci386d95b2020-04-08 20:31:21 +010095 -perfetto_traces_data_file
Primiano Tucci2f998092021-01-07 17:12:21 +000096 -perfetto_traces_bugreport_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080097 -system_data_file
Paul Crowleyaed0f762019-08-01 15:57:47 -070098 -system_data_root_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080099 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
100 # subsequent neverallow. Currently only getattr and search are allowed.
101 -vendor_data_file
102 -zoneinfo_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700103 with_native_coverage(`-method_trace_data_file')
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800104}:dir *;
105neverallow traced { system_data_file }:dir ~{ getattr search };
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100106neverallow traced zoneinfo_data_file:dir ~r_dir_perms;
107neverallow traced { data_file_type -zoneinfo_data_file }:lnk_file *;
Primiano Tucci5d317322018-03-26 01:54:52 +0100108neverallow traced {
109 data_file_type
110 -zoneinfo_data_file
111 -perfetto_traces_data_file
Primiano Tucci2f998092021-01-07 17:12:21 +0000112 -perfetto_traces_bugreport_data_file
Carmen Jackson9678e072019-01-10 12:17:40 -0800113 -trace_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700114 with_native_coverage(`-method_trace_data_file')
Primiano Tucci5d317322018-03-26 01:54:52 +0100115}:file ~write;
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100116
117# Only init is allowed to enter the traced domain via exec()
118neverallow { domain -init } traced:process transition;
119neverallow * traced:process dyntransition;