blob: 796095fd7e16b47db49ae5132585338cdb7ef187 [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 Tucci79d1dbb2019-01-23 20:42:16 +000027
28# Allow traceur to pass open file descriptors to traced, so traced can directly
29# write into the output file without doing roundtrips over IPC.
30allow traced traceur_app:fd use;
Stefan Andonianff413fd2024-01-24 22:04:52 +000031allow traced platform_app:fd use;
Carmen Jackson9678e072019-01-10 12:17:40 -080032allow traced trace_data_file:file { read write };
Primiano Tucci5d317322018-03-26 01:54:52 +010033
Collin Fijalkovich6f4cfe82020-12-11 14:51:32 -080034# Allow perfetto to access the proxy service for notifying Traceur.
35allow traced tracingproxy_service:service_manager find;
36binder_use(traced);
37binder_call(traced, system_server);
38
Ryan Savitski21f6ae62020-02-04 13:44:14 +000039# Allow traced to use shared memory supplied by producers. Typically, traced
40# (i.e. the tracing service) creates the shared memory used for data transfer
41# from the producer. This rule allows an alternative scheme, where the producer
42# creates the shared memory, that is then adopted by traced (after validating
43# that it is appropriately sealed).
44# This list has to replicate the tmpfs domains of all applicable domains that
45# have perfetto_producer() macro applied to them.
46# perfetto_tmpfs excluded as it should never need to use the producer-supplied
47# shared memory scheme.
48allow traced {
49 appdomain_tmpfs
50 heapprofd_tmpfs
51 surfaceflinger_tmpfs
52 traced_probes_tmpfs
53 userdebug_or_eng(`system_server_tmpfs')
54}:file { getattr map read write };
55
Nolan Scobie1f448fc2023-04-25 14:22:54 -040056# Allow setting debug properties which guard initialization of the Perfetto SDK
57# in SurfaceFlinger and HWUI's copy of Skia.
58# Required for the android.sdk_sysprop_guard data source.
59# TODO(b/281329340): remove this when no longer needed.
60set_prop(traced, debug_prop)
Primiano Tucci8da4e4f2019-02-01 22:52:02 +000061# Allow traced to notify Traceur when a trace ends by setting the
62# sys.trace.trace_end_signal property.
63set_prop(traced, system_trace_prop)
Florian Mayera769f0f2019-03-13 11:22:23 -070064# Allow to lazily start producers.
65set_prop(traced, traced_lazy_prop)
Ioannis Ilkos8d168e22023-02-10 17:52:19 +000066# Allow tracking the count of sessions intercepting Java OutOfMemoryError
67# If there are such tracing sessions and an OutOfMemoryError is thrown by ART,
68# the hprof plugin intercepts the error, lazily registers a data source to
69# traced and collects a heap dump.
70set_prop(traced, traced_oome_heap_session_count_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
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -080095 -system_data_file
Paul Crowleyaed0f762019-08-01 15:57:47 -070096 -system_data_root_file
Eric Biggers9a599232022-05-04 22:18:02 +000097 -media_userdir_file
98 -system_userdir_file
99 -vendor_userdir_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800100 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
101 # subsequent neverallow. Currently only getattr and search are allowed.
102 -vendor_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 Tucci5d317322018-03-26 01:54:52 +0100106neverallow traced {
107 data_file_type
Primiano Tucci5d317322018-03-26 01:54:52 +0100108 -perfetto_traces_data_file
Carmen Jackson9678e072019-01-10 12:17:40 -0800109 -trace_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700110 with_native_coverage(`-method_trace_data_file')
Primiano Tucci5d317322018-03-26 01:54:52 +0100111}:file ~write;
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100112
113# Only init is allowed to enter the traced domain via exec()
114neverallow { domain -init } traced:process transition;
115neverallow * traced:process dyntransition;
Carmen Jacksona60d7f22021-06-23 16:53:45 -0700116
117# Limit the processes that can access tracingproxy_service.
Lalit Magantib549e2d2021-12-10 21:50:44 +0000118neverallow {
119 domain
120 -traced
121 -dumpstate
122 -traceur_app
Stefan Andonianff413fd2024-01-24 22:04:52 +0000123 -platform_app
Lalit Magantib549e2d2021-12-10 21:50:44 +0000124 -shell
125 -system_server
126 -perfetto
127} tracingproxy_service:service_manager find;