blob: 3029094f621c8d1a81aa500d9a38e4206ad6d548 [file] [log] [blame]
Primiano Tuccic80f9e02017-12-21 03:51:15 +01001# Perfetto user-space tracing daemon (unprivileged)
Nick Kralevich5e372712018-09-27 10:21:37 -07002type traced_exec, system_file_type, exec_type, file_type;
Primiano Tuccic80f9e02017-12-21 03:51:15 +01003
4# Allow init to exec the daemon.
5init_daemon_domain(traced)
Jeff Vander Stoep41a2abf2019-01-23 15:07:40 -08006tmpfs_domain(traced)
Primiano Tuccic80f9e02017-12-21 03:51:15 +01007
Primiano Tucci5ef66692018-02-21 13:44:39 +00008# Allow apps in other MLS contexts (for multi-user) to access
9# share memory buffers created by traced.
10typeattribute traced_tmpfs mlstrustedobject;
11
Primiano Tuccic80f9e02017-12-21 03:51:15 +010012# 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
Primiano Tucci5d317322018-03-26 01:54:52 +010017# 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;
Isabelle Taylor19f49982019-01-21 18:54:45 +000022allow traced shell:fifo_file { read write };
Primiano Tucci386d95b2020-04-08 20:31:21 +010023
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;
Primiano Tucci2f998092021-01-07 17:12:21 +000027# ... and /data/misc/perfetto-traces/bugreport*
28allow traced perfetto_traces_bugreport_data_file:file create_file_perms;
29allow traced perfetto_traces_bugreport_data_file:dir rw_dir_perms;
Primiano Tucci79d1dbb2019-01-23 20:42:16 +000030
31# Allow traceur to pass open file descriptors to traced, so traced can directly
32# write into the output file without doing roundtrips over IPC.
33allow traced traceur_app:fd use;
Carmen Jackson9678e072019-01-10 12:17:40 -080034allow traced trace_data_file:file { read write };
Primiano Tucci5d317322018-03-26 01:54:52 +010035
Collin Fijalkovich6f4cfe82020-12-11 14:51:32 -080036# Allow perfetto to access the proxy service for notifying Traceur.
37allow traced tracingproxy_service:service_manager find;
38binder_use(traced);
39binder_call(traced, system_server);
40
Ryan Savitski21f6ae62020-02-04 13:44:14 +000041# Allow traced to use shared memory supplied by producers. Typically, traced
42# (i.e. the tracing service) creates the shared memory used for data transfer
43# from the producer. This rule allows an alternative scheme, where the producer
44# creates the shared memory, that is then adopted by traced (after validating
45# that it is appropriately sealed).
46# This list has to replicate the tmpfs domains of all applicable domains that
47# have perfetto_producer() macro applied to them.
48# perfetto_tmpfs excluded as it should never need to use the producer-supplied
49# shared memory scheme.
50allow traced {
51 appdomain_tmpfs
52 heapprofd_tmpfs
53 surfaceflinger_tmpfs
54 traced_probes_tmpfs
55 userdebug_or_eng(`system_server_tmpfs')
56}:file { getattr map read write };
57
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000058# Allow traced to notify Traceur when a trace ends by setting the
59# sys.trace.trace_end_signal property.
60set_prop(traced, system_trace_prop)
Florian Mayera769f0f2019-03-13 11:22:23 -070061# Allow to lazily start producers.
62set_prop(traced, traced_lazy_prop)
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000063
Lalit Maganti9165bf72020-12-16 18:45:31 +000064# Allow traced to talk to statsd for logging metrics.
65unix_socket_send(traced, statsdw, statsd)
66
Primiano Tuccic80f9e02017-12-21 03:51:15 +010067###
68### Neverallow rules
69###
70### traced should NEVER do any of this
71
72# Disallow mapping executable memory (execstack and exec are already disallowed
73# globally in domain.te).
74neverallow traced self:process execmem;
75
76# Block device access.
77neverallow traced dev_type:blk_file { read write };
78
79# ptrace any other process
80neverallow traced domain:process ptrace;
81
82# Disallows access to /data files, still allowing to write to file descriptors
83# passed through the socket.
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080084neverallow traced {
85 data_file_type
Primiano Tucci386d95b2020-04-08 20:31:21 +010086 -perfetto_traces_data_file
Primiano Tucci2f998092021-01-07 17:12:21 +000087 -perfetto_traces_bugreport_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080088 -system_data_file
Paul Crowleyaed0f762019-08-01 15:57:47 -070089 -system_data_root_file
Eric Biggers9a599232022-05-04 22:18:02 +000090 -media_userdir_file
91 -system_userdir_file
92 -vendor_userdir_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080093 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
94 # subsequent neverallow. Currently only getattr and search are allowed.
95 -vendor_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -070096 with_native_coverage(`-method_trace_data_file')
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080097}:dir *;
98neverallow traced { system_data_file }:dir ~{ getattr search };
Primiano Tucci5d317322018-03-26 01:54:52 +010099neverallow traced {
100 data_file_type
Primiano Tucci5d317322018-03-26 01:54:52 +0100101 -perfetto_traces_data_file
Primiano Tucci2f998092021-01-07 17:12:21 +0000102 -perfetto_traces_bugreport_data_file
Carmen Jackson9678e072019-01-10 12:17:40 -0800103 -trace_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700104 with_native_coverage(`-method_trace_data_file')
Primiano Tucci5d317322018-03-26 01:54:52 +0100105}:file ~write;
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100106
107# Only init is allowed to enter the traced domain via exec()
108neverallow { domain -init } traced:process transition;
109neverallow * traced:process dyntransition;
Carmen Jacksona60d7f22021-06-23 16:53:45 -0700110
111# Limit the processes that can access tracingproxy_service.
Lalit Magantib549e2d2021-12-10 21:50:44 +0000112neverallow {
113 domain
114 -traced
115 -dumpstate
116 -traceur_app
117 -shell
118 -system_server
119 -perfetto
120} tracingproxy_service:service_manager find;