Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 1 | # Perfetto user-space tracing daemon (unprivileged) |
Nick Kralevich | 5e37271 | 2018-09-27 10:21:37 -0700 | [diff] [blame] | 2 | type traced_exec, system_file_type, exec_type, file_type; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 3 | |
| 4 | # Allow init to exec the daemon. |
| 5 | init_daemon_domain(traced) |
Jeff Vander Stoep | 41a2abf | 2019-01-23 15:07:40 -0800 | [diff] [blame] | 6 | tmpfs_domain(traced) |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 7 | |
Primiano Tucci | 5ef6669 | 2018-02-21 13:44:39 +0000 | [diff] [blame] | 8 | # Allow apps in other MLS contexts (for multi-user) to access |
| 9 | # share memory buffers created by traced. |
| 10 | typeattribute traced_tmpfs mlstrustedobject; |
| 11 | |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 12 | # 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. |
| 15 | allow traced self:global_capability_class_set { sys_nice }; |
| 16 | |
Primiano Tucci | 5d31732 | 2018-03-26 01:54:52 +0100 | [diff] [blame] | 17 | # 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). |
| 20 | allow traced perfetto:fd use; |
| 21 | allow traced shell:fd use; |
Isabelle Taylor | 19f4998 | 2019-01-21 18:54:45 +0000 | [diff] [blame] | 22 | allow traced shell:fifo_file { read write }; |
Primiano Tucci | 386d95b | 2020-04-08 20:31:21 +0100 | [diff] [blame] | 23 | |
| 24 | # Allow the service to create new files within /data/misc/perfetto-traces. |
| 25 | allow traced perfetto_traces_data_file:file create_file_perms; |
| 26 | allow traced perfetto_traces_data_file:dir rw_dir_perms; |
Primiano Tucci | 79d1dbb | 2019-01-23 20:42:16 +0000 | [diff] [blame] | 27 | |
| 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. |
| 30 | allow traced traceur_app:fd use; |
Stefan Andonian | ff413fd | 2024-01-24 22:04:52 +0000 | [diff] [blame] | 31 | allow traced platform_app:fd use; |
Carmen Jackson | 9678e07 | 2019-01-10 12:17:40 -0800 | [diff] [blame] | 32 | allow traced trace_data_file:file { read write }; |
Primiano Tucci | 5d31732 | 2018-03-26 01:54:52 +0100 | [diff] [blame] | 33 | |
Collin Fijalkovich | 6f4cfe8 | 2020-12-11 14:51:32 -0800 | [diff] [blame] | 34 | # Allow perfetto to access the proxy service for notifying Traceur. |
| 35 | allow traced tracingproxy_service:service_manager find; |
| 36 | binder_use(traced); |
| 37 | binder_call(traced, system_server); |
| 38 | |
Ryan Savitski | 21f6ae6 | 2020-02-04 13:44:14 +0000 | [diff] [blame] | 39 | # 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. |
| 48 | allow 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 | |
Primiano Tucci | 93e601a | 2024-11-26 18:16:15 +0000 | [diff] [blame] | 56 | # Allow traced to detect if a process is frozen (b/381089063). |
| 57 | allow traced cgroup_v2:file r_file_perms; |
| 58 | |
Jahdiel Alvarez | 6729dcf | 2025-01-31 14:38:05 -0800 | [diff] [blame^] | 59 | # Allow traced/traced_relay to read the traced config properties. |
| 60 | get_prop(traced, traced_config_prop) |
Jahdiel Alvarez | 50d7312 | 2025-01-29 16:49:24 -0800 | [diff] [blame] | 61 | # Allow traced_relay to read the relay port being used |
| 62 | get_prop(traced, traced_relay_relay_port_prop) |
| 63 | |
Nolan Scobie | 1f448fc | 2023-04-25 14:22:54 -0400 | [diff] [blame] | 64 | # Allow setting debug properties which guard initialization of the Perfetto SDK |
| 65 | # in SurfaceFlinger and HWUI's copy of Skia. |
| 66 | # Required for the android.sdk_sysprop_guard data source. |
| 67 | # TODO(b/281329340): remove this when no longer needed. |
| 68 | set_prop(traced, debug_prop) |
Primiano Tucci | 8da4e4f | 2019-02-01 22:52:02 +0000 | [diff] [blame] | 69 | # Allow traced to notify Traceur when a trace ends by setting the |
| 70 | # sys.trace.trace_end_signal property. |
| 71 | set_prop(traced, system_trace_prop) |
Florian Mayer | a769f0f | 2019-03-13 11:22:23 -0700 | [diff] [blame] | 72 | # Allow to lazily start producers. |
| 73 | set_prop(traced, traced_lazy_prop) |
Ioannis Ilkos | 8d168e2 | 2023-02-10 17:52:19 +0000 | [diff] [blame] | 74 | # Allow tracking the count of sessions intercepting Java OutOfMemoryError |
| 75 | # If there are such tracing sessions and an OutOfMemoryError is thrown by ART, |
| 76 | # the hprof plugin intercepts the error, lazily registers a data source to |
| 77 | # traced and collects a heap dump. |
| 78 | set_prop(traced, traced_oome_heap_session_count_prop) |
Primiano Tucci | 8da4e4f | 2019-02-01 22:52:02 +0000 | [diff] [blame] | 79 | |
Lalit Maganti | 9165bf7 | 2020-12-16 18:45:31 +0000 | [diff] [blame] | 80 | # Allow traced to talk to statsd for logging metrics. |
| 81 | unix_socket_send(traced, statsdw, statsd) |
| 82 | |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 83 | ### |
| 84 | ### Neverallow rules |
| 85 | ### |
| 86 | ### traced should NEVER do any of this |
| 87 | |
| 88 | # Disallow mapping executable memory (execstack and exec are already disallowed |
| 89 | # globally in domain.te). |
| 90 | neverallow traced self:process execmem; |
| 91 | |
| 92 | # Block device access. |
| 93 | neverallow traced dev_type:blk_file { read write }; |
| 94 | |
| 95 | # ptrace any other process |
| 96 | neverallow traced domain:process ptrace; |
| 97 | |
| 98 | # Disallows access to /data files, still allowing to write to file descriptors |
| 99 | # passed through the socket. |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 100 | neverallow traced { |
| 101 | data_file_type |
Primiano Tucci | 386d95b | 2020-04-08 20:31:21 +0100 | [diff] [blame] | 102 | -perfetto_traces_data_file |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 103 | -system_data_file |
Paul Crowley | aed0f76 | 2019-08-01 15:57:47 -0700 | [diff] [blame] | 104 | -system_data_root_file |
Eric Biggers | 9a59923 | 2022-05-04 22:18:02 +0000 | [diff] [blame] | 105 | -media_userdir_file |
| 106 | -system_userdir_file |
| 107 | -vendor_userdir_file |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 108 | # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a |
| 109 | # subsequent neverallow. Currently only getattr and search are allowed. |
| 110 | -vendor_data_file |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 111 | with_native_coverage(`-method_trace_data_file') |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 112 | }:dir *; |
| 113 | neverallow traced { system_data_file }:dir ~{ getattr search }; |
Primiano Tucci | 5d31732 | 2018-03-26 01:54:52 +0100 | [diff] [blame] | 114 | neverallow traced { |
| 115 | data_file_type |
Primiano Tucci | 5d31732 | 2018-03-26 01:54:52 +0100 | [diff] [blame] | 116 | -perfetto_traces_data_file |
Carmen Jackson | 9678e07 | 2019-01-10 12:17:40 -0800 | [diff] [blame] | 117 | -trace_data_file |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 118 | with_native_coverage(`-method_trace_data_file') |
Primiano Tucci | 5d31732 | 2018-03-26 01:54:52 +0100 | [diff] [blame] | 119 | }:file ~write; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 120 | |
| 121 | # Only init is allowed to enter the traced domain via exec() |
| 122 | neverallow { domain -init } traced:process transition; |
| 123 | neverallow * traced:process dyntransition; |
Carmen Jackson | a60d7f2 | 2021-06-23 16:53:45 -0700 | [diff] [blame] | 124 | |
| 125 | # Limit the processes that can access tracingproxy_service. |
Lalit Maganti | b549e2d | 2021-12-10 21:50:44 +0000 | [diff] [blame] | 126 | neverallow { |
| 127 | domain |
| 128 | -traced |
| 129 | -dumpstate |
| 130 | -traceur_app |
Stefan Andonian | ff413fd | 2024-01-24 22:04:52 +0000 | [diff] [blame] | 131 | -platform_app |
Lalit Maganti | b549e2d | 2021-12-10 21:50:44 +0000 | [diff] [blame] | 132 | -shell |
| 133 | -system_server |
| 134 | -perfetto |
| 135 | } tracingproxy_service:service_manager find; |