blob: a6e200e6220fcb79578c8460a7a143875d9cb787 [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;
Primiano Tuccic80f9e02017-12-21 03:51:15 +01006
7# Allow init to exec the daemon.
8init_daemon_domain(traced)
Jeff Vander Stoep41a2abf2019-01-23 15:07:40 -08009tmpfs_domain(traced)
Primiano Tuccic80f9e02017-12-21 03:51:15 +010010
Primiano Tucci5ef66692018-02-21 13:44:39 +000011# Allow apps in other MLS contexts (for multi-user) to access
12# share memory buffers created by traced.
13typeattribute traced_tmpfs mlstrustedobject;
14
Primiano Tuccic80f9e02017-12-21 03:51:15 +010015# Allow traced to start with a lower scheduling class and change
16# class accordingly to what defined in the config provided by
17# the privileged process that controls it.
18allow traced self:global_capability_class_set { sys_nice };
19
Primiano Tucci5d317322018-03-26 01:54:52 +010020# Allow to pass a file descriptor for the output trace from "perfetto" (the
21# cmdline client) and other shell binaries to traced and let traced write
22# directly into that (rather than returning the trace contents over the socket).
23allow traced perfetto:fd use;
24allow traced shell:fd use;
Isabelle Taylor19f49982019-01-21 18:54:45 +000025allow traced shell:fifo_file { read write };
Primiano Tucci386d95b2020-04-08 20:31:21 +010026
27# Allow the service to create new files within /data/misc/perfetto-traces.
28allow traced perfetto_traces_data_file:file create_file_perms;
29allow traced perfetto_traces_data_file:dir rw_dir_perms;
Primiano Tucci2f998092021-01-07 17:12:21 +000030# ... and /data/misc/perfetto-traces/bugreport*
31allow traced perfetto_traces_bugreport_data_file:file create_file_perms;
32allow traced perfetto_traces_bugreport_data_file:dir rw_dir_perms;
Primiano Tucci79d1dbb2019-01-23 20:42:16 +000033
34# Allow traceur to pass open file descriptors to traced, so traced can directly
35# write into the output file without doing roundtrips over IPC.
36allow traced traceur_app:fd use;
Carmen Jackson9678e072019-01-10 12:17:40 -080037allow traced trace_data_file:file { read write };
Primiano Tucci5d317322018-03-26 01:54:52 +010038
Collin Fijalkovich6f4cfe82020-12-11 14:51:32 -080039# Allow perfetto to access the proxy service for notifying Traceur.
40allow traced tracingproxy_service:service_manager find;
41binder_use(traced);
42binder_call(traced, system_server);
43
Primiano Tucci79d1dbb2019-01-23 20:42:16 +000044# Allow iorapd to pass memfd descriptors to traced, so traced can directly
45# write into the shmem buffer file without doing roundtrips over IPC.
46allow traced iorapd:fd use;
47allow traced iorapd_tmpfs:file { read write };
48
Ryan Savitski21f6ae62020-02-04 13:44:14 +000049# Allow traced to use shared memory supplied by producers. Typically, traced
50# (i.e. the tracing service) creates the shared memory used for data transfer
51# from the producer. This rule allows an alternative scheme, where the producer
52# creates the shared memory, that is then adopted by traced (after validating
53# that it is appropriately sealed).
54# This list has to replicate the tmpfs domains of all applicable domains that
55# have perfetto_producer() macro applied to them.
56# perfetto_tmpfs excluded as it should never need to use the producer-supplied
57# shared memory scheme.
58allow traced {
59 appdomain_tmpfs
60 heapprofd_tmpfs
61 surfaceflinger_tmpfs
62 traced_probes_tmpfs
63 userdebug_or_eng(`system_server_tmpfs')
64}:file { getattr map read write };
65
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000066# Allow traced to notify Traceur when a trace ends by setting the
67# sys.trace.trace_end_signal property.
68set_prop(traced, system_trace_prop)
Florian Mayera769f0f2019-03-13 11:22:23 -070069# Allow to lazily start producers.
70set_prop(traced, traced_lazy_prop)
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000071
Lalit Maganti9165bf72020-12-16 18:45:31 +000072# Allow traced to talk to statsd for logging metrics.
73unix_socket_send(traced, statsdw, statsd)
74
Primiano Tuccic80f9e02017-12-21 03:51:15 +010075###
76### Neverallow rules
77###
78### traced should NEVER do any of this
79
80# Disallow mapping executable memory (execstack and exec are already disallowed
81# globally in domain.te).
82neverallow traced self:process execmem;
83
84# Block device access.
85neverallow traced dev_type:blk_file { read write };
86
87# ptrace any other process
88neverallow traced domain:process ptrace;
89
90# Disallows access to /data files, still allowing to write to file descriptors
91# passed through the socket.
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080092neverallow traced {
93 data_file_type
Primiano Tucci386d95b2020-04-08 20:31:21 +010094 -perfetto_traces_data_file
Primiano Tucci2f998092021-01-07 17:12:21 +000095 -perfetto_traces_bugreport_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080096 -system_data_file
Paul Crowleyaed0f762019-08-01 15:57:47 -070097 -system_data_root_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080098 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
99 # subsequent neverallow. Currently only getattr and search are allowed.
100 -vendor_data_file
101 -zoneinfo_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700102 with_native_coverage(`-method_trace_data_file')
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800103}:dir *;
104neverallow traced { system_data_file }:dir ~{ getattr search };
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100105neverallow traced zoneinfo_data_file:dir ~r_dir_perms;
106neverallow traced { data_file_type -zoneinfo_data_file }:lnk_file *;
Primiano Tucci5d317322018-03-26 01:54:52 +0100107neverallow traced {
108 data_file_type
109 -zoneinfo_data_file
110 -perfetto_traces_data_file
Primiano Tucci2f998092021-01-07 17:12:21 +0000111 -perfetto_traces_bugreport_data_file
Carmen Jackson9678e072019-01-10 12:17:40 -0800112 -trace_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700113 with_native_coverage(`-method_trace_data_file')
Primiano Tucci5d317322018-03-26 01:54:52 +0100114}:file ~write;
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100115
116# Only init is allowed to enter the traced domain via exec()
117neverallow { domain -init } traced:process transition;
118neverallow * traced:process dyntransition;
Carmen Jacksona60d7f22021-06-23 16:53:45 -0700119
120# Limit the processes that can access tracingproxy_service.
Lalit Magantib549e2d2021-12-10 21:50:44 +0000121neverallow {
122 domain
123 -traced
124 -dumpstate
125 -traceur_app
126 -shell
127 -system_server
128 -perfetto
129} tracingproxy_service:service_manager find;