Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 1 | # Perfetto tracing probes, has tracefs access. |
Nick Kralevich | 5e37271 | 2018-09-27 10:21:37 -0700 | [diff] [blame] | 2 | type traced_probes_exec, system_file_type, exec_type, file_type; |
Ryan Savitski | 21f6ae6 | 2020-02-04 13:44:14 +0000 | [diff] [blame] | 3 | type traced_probes_tmpfs, file_type; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 4 | |
| 5 | # Allow init to exec the daemon. |
| 6 | init_daemon_domain(traced_probes) |
Ryan Savitski | 21f6ae6 | 2020-02-04 13:44:14 +0000 | [diff] [blame] | 7 | tmpfs_domain(traced_probes) |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 8 | |
| 9 | # Write trace data to the Perfetto traced damon. This requires connecting to its |
| 10 | # producer socket and obtaining a (per-process) tmpfs fd. |
Florian Mayer | 5e52281 | 2019-10-08 16:15:14 +0100 | [diff] [blame] | 11 | perfetto_producer(traced_probes) |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 12 | |
| 13 | # Allow traced_probes to access tracefs. |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 14 | allow traced_probes debugfs_tracing:dir r_dir_perms; |
| 15 | allow traced_probes debugfs_tracing:file rw_file_perms; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 16 | allow traced_probes debugfs_trace_marker:file getattr; |
Florian Mayer | 1237616 | 2020-11-05 12:54:52 +0000 | [diff] [blame] | 17 | allow traced_probes debugfs_tracing_printk_formats:file r_file_perms; |
Primiano Tucci | b4b31f9 | 2018-02-09 11:15:22 +0000 | [diff] [blame] | 18 | |
Kalesh Singh | aab7a73 | 2021-01-15 11:12:56 -0500 | [diff] [blame] | 19 | # Allow traced_probes to access mm_events trace instance |
| 20 | allow traced_probes debugfs_tracing_instances:dir search; |
| 21 | allow traced_probes debugfs_mm_events_tracing:dir search; |
| 22 | allow traced_probes debugfs_mm_events_tracing:file rw_file_perms; |
| 23 | |
Primiano Tucci | b4b31f9 | 2018-02-09 11:15:22 +0000 | [diff] [blame] | 24 | # TODO(primiano): temporarily I/O tracing categories are still |
Jeff Sharkey | a0e7a6d | 2020-07-31 12:28:11 -0600 | [diff] [blame] | 25 | # userdebug only until we nail down the denylist/allowlist. |
Primiano Tucci | b4b31f9 | 2018-02-09 11:15:22 +0000 | [diff] [blame] | 26 | userdebug_or_eng(` |
Hector Dearman | 4802cbd | 2018-12-06 18:32:23 +0000 | [diff] [blame] | 27 | allow traced_probes debugfs_tracing_debug:dir r_dir_perms; |
Primiano Tucci | b4b31f9 | 2018-02-09 11:15:22 +0000 | [diff] [blame] | 28 | allow traced_probes debugfs_tracing_debug:file rw_file_perms; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 29 | ') |
| 30 | |
| 31 | # Allow traced_probes to start with a higher scheduling class and then downgrade |
| 32 | # itself. |
| 33 | allow traced_probes self:global_capability_class_set { sys_nice }; |
| 34 | |
| 35 | # Allow procfs access |
| 36 | r_dir_file(traced_probes, domain) |
| 37 | |
Ryan Savitski | 4cd0994 | 2024-12-13 20:36:44 +0000 | [diff] [blame] | 38 | # For kernel address symbolisation. Allow reading from /proc/kallsyms inherited |
| 39 | # from init, as well as separately opening and locking the file for |
| 40 | # coordinating the use of that shared fd. |
| 41 | # On debuggable builds, allow using lower_kptr_restrict_prop to temporarily |
| 42 | # lift kptr_restrict systemwide. |
Primiano Tucci | cd45230 | 2020-10-09 09:15:10 +0100 | [diff] [blame] | 43 | userdebug_or_eng(`set_prop(traced_probes, lower_kptr_restrict_prop)') |
Ryan Savitski | 4cd0994 | 2024-12-13 20:36:44 +0000 | [diff] [blame] | 44 | allow traced_probes proc_kallsyms:file { open read lock }; |
Primiano Tucci | cd45230 | 2020-10-09 09:15:10 +0100 | [diff] [blame] | 45 | |
Florian Mayer | d04ffff | 2019-04-02 16:19:09 +0100 | [diff] [blame] | 46 | # Allow to read packages.list file. |
| 47 | allow traced_probes packages_list_file:file r_file_perms; |
| 48 | |
Andy Yu | 9e96849 | 2022-04-01 15:16:14 -0700 | [diff] [blame] | 49 | # Allow to read game_mode_intervention.list file. |
| 50 | allow traced_probes game_mode_intervention_list_file:file r_file_perms; |
| 51 | |
Primiano Tucci | d807d58 | 2018-02-16 13:54:41 +0000 | [diff] [blame] | 52 | # Allow to log to kernel dmesg when starting / stopping ftrace. |
| 53 | allow traced_probes kmsg_device:chr_file write; |
| 54 | |
Florian Mayer | ef6358b | 2018-02-23 16:47:38 +0000 | [diff] [blame] | 55 | # Allow traced_probes to list the system partition. |
| 56 | allow traced_probes system_file:dir { open read }; |
| 57 | |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 58 | # Allow traced_probes to list some of the data partition. |
Benjamin Gordon | 7ed266c | 2018-08-15 13:34:20 -0600 | [diff] [blame] | 59 | allow traced_probes self:global_capability_class_set dac_read_search; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 60 | |
Florian Mayer | ff14696 | 2018-04-06 12:55:22 +0100 | [diff] [blame] | 61 | allow traced_probes apk_data_file:dir { getattr open read search }; |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 62 | allow traced_probes { apex_art_data_file apex_module_data_file }:dir { getattr open read search }; |
Florian Mayer | ff14696 | 2018-04-06 12:55:22 +0100 | [diff] [blame] | 63 | allow traced_probes dalvikcache_data_file:dir { getattr open read search }; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 64 | userdebug_or_eng(` |
Florian Mayer | d04ffff | 2019-04-02 16:19:09 +0100 | [diff] [blame] | 65 | # search and getattr are granted via domain and coredomain, respectively. |
| 66 | allow traced_probes system_data_file:dir { open read }; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 67 | ') |
Florian Mayer | ff14696 | 2018-04-06 12:55:22 +0100 | [diff] [blame] | 68 | allow traced_probes system_app_data_file:dir { getattr open read search }; |
| 69 | allow traced_probes backup_data_file:dir { getattr open read search }; |
| 70 | allow traced_probes bootstat_data_file:dir { getattr open read search }; |
| 71 | allow traced_probes update_engine_data_file:dir { getattr open read search }; |
| 72 | allow traced_probes update_engine_log_data_file:dir { getattr open read search }; |
Alan Stokes | 7aa4041 | 2020-12-04 14:07:52 +0000 | [diff] [blame] | 73 | allow traced_probes { user_profile_root_file user_profile_data_file}:dir { getattr open read search }; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 74 | |
Primiano Tucci | feaf22b | 2018-03-02 19:27:06 +0000 | [diff] [blame] | 75 | # Allow traced_probes to run atrace. atrace pokes at system services to enable |
| 76 | # their userspace TRACE macros. |
| 77 | domain_auto_trans(traced_probes, atrace_exec, atrace); |
| 78 | |
Lalit Maganti | d6ae1a5 | 2018-11-16 12:17:24 +0000 | [diff] [blame] | 79 | # Allow traced_probes to kill atrace on timeout. |
| 80 | allow traced_probes atrace:process sigkill; |
Primiano Tucci | feaf22b | 2018-03-02 19:27:06 +0000 | [diff] [blame] | 81 | |
Primiano Tucci | 51dc7cb | 2018-09-18 08:51:06 +0100 | [diff] [blame] | 82 | # Allow traced_probes to access /proc files for system stats. |
| 83 | # Note: trace data is NOT exposed to anything other than shell and privileged |
| 84 | # system apps that have access to the traced consumer socket. |
| 85 | allow traced_probes { |
| 86 | proc_meminfo |
| 87 | proc_vmstat |
| 88 | proc_stat |
Derek Smith | f595029 | 2022-08-04 20:21:37 +0000 | [diff] [blame] | 89 | proc_buddyinfo |
Jared Duke | 8db0b2b | 2023-12-11 22:37:32 +0000 | [diff] [blame] | 90 | proc_pressure_cpu |
| 91 | proc_pressure_io |
| 92 | proc_pressure_mem |
Primiano Tucci | 51dc7cb | 2018-09-18 08:51:06 +0100 | [diff] [blame] | 93 | }:file r_file_perms; |
| 94 | |
David Massoud | c50fecd | 2021-04-16 20:02:06 +0800 | [diff] [blame] | 95 | # Allow access to read /sys/class/devfreq/ and /$DEVICE/cur_freq files |
| 96 | allow traced_probes sysfs_devfreq_dir:dir r_dir_perms; |
| 97 | allow traced_probes sysfs_devfreq_cur:file r_file_perms; |
| 98 | |
Daeho Jeong | bfa8213 | 2023-04-03 13:01:00 -0700 | [diff] [blame] | 99 | # Allow access to read /proc/diskstats for I/O profiling. |
| 100 | allow traced_probes proc_diskstats:file r_file_perms; |
| 101 | |
Ben Murdoch | f948ea5 | 2019-03-13 17:08:43 +0000 | [diff] [blame] | 102 | # Allow access to the IHealth and IPowerStats HAL service for tracing battery counters. |
Primiano Tucci | 353b93a | 2018-12-02 21:59:10 +0000 | [diff] [blame] | 103 | hal_client_domain(traced_probes, hal_health) |
Ben Murdoch | f948ea5 | 2019-03-13 17:08:43 +0000 | [diff] [blame] | 104 | hal_client_domain(traced_probes, hal_power_stats) |
Primiano Tucci | 353b93a | 2018-12-02 21:59:10 +0000 | [diff] [blame] | 105 | |
Isabelle Taylor | e8c4ba8 | 2019-03-26 11:03:35 +0000 | [diff] [blame] | 106 | # Allow access to Atrace HAL for enabling vendor/device specific tracing categories. |
| 107 | hal_client_domain(traced_probes, hal_atrace) |
| 108 | |
Primiano Tucci | a64d5bb | 2019-01-10 20:07:51 +0000 | [diff] [blame] | 109 | # On debug builds allow to ingest system logs into the trace. |
| 110 | userdebug_or_eng(`read_logd(traced_probes)') |
| 111 | |
Hector Dearman | 7ca04a7 | 2023-03-22 08:14:38 +0000 | [diff] [blame] | 112 | # Allow traced_probes to talk to statsd for logging metrics and recording atoms. |
Lalit Maganti | 685205d | 2021-04-30 12:13:39 +0100 | [diff] [blame] | 113 | unix_socket_send(traced_probes, statsdw, statsd) |
Hector Dearman | 7ca04a7 | 2023-03-22 08:14:38 +0000 | [diff] [blame] | 114 | binder_call(traced_probes, statsd) |
| 115 | allow traced_probes stats_service:service_manager find; |
Lalit Maganti | 685205d | 2021-04-30 12:13:39 +0100 | [diff] [blame] | 116 | |
Simon MacMullen | 53cba3e | 2025-01-10 17:07:04 +0000 | [diff] [blame] | 117 | # Allow traced_probes to talk to suspend control service to read details of kernel wakelocks. |
| 118 | allow traced_probes system_suspend_control_internal_service:service_manager find; |
| 119 | allow traced_probes system_suspend:binder call; |
| 120 | |
Ben Murdoch | d310497 | 2024-08-23 13:10:51 +0000 | [diff] [blame] | 121 | # Allow reading the system property representing number of desktop windows to |
| 122 | # set the initial value for the counter in traces. |
| 123 | get_prop(traced_probes, debug_tracing_desktop_mode_visible_tasks_prop) |
| 124 | |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 125 | ### |
| 126 | ### Neverallow rules |
| 127 | ### |
| 128 | ### traced_probes should NEVER do any of this |
| 129 | |
| 130 | # Disallow mapping executable memory (execstack and exec are already disallowed |
| 131 | # globally in domain.te). |
| 132 | neverallow traced_probes self:process execmem; |
| 133 | |
| 134 | # Block device access. |
| 135 | neverallow traced_probes dev_type:blk_file { read write }; |
| 136 | |
| 137 | # ptrace any other app |
| 138 | neverallow traced_probes domain:process ptrace; |
| 139 | |
| 140 | # Disallows access to /data files. |
Primiano Tucci | d807d58 | 2018-02-16 13:54:41 +0000 | [diff] [blame] | 141 | neverallow traced_probes { |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 142 | data_file_type |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 143 | -apex_module_data_file |
| 144 | -apex_art_data_file |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 145 | -apk_data_file |
| 146 | -dalvikcache_data_file |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 147 | -system_data_file |
Paul Crowley | aed0f76 | 2019-08-01 15:57:47 -0700 | [diff] [blame] | 148 | -system_data_root_file |
Eric Biggers | 9a59923 | 2022-05-04 22:18:02 +0000 | [diff] [blame] | 149 | -media_userdir_file |
| 150 | -system_userdir_file |
| 151 | -vendor_userdir_file |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 152 | -system_app_data_file |
| 153 | -backup_data_file |
| 154 | -bootstat_data_file |
| 155 | -update_engine_data_file |
| 156 | -update_engine_log_data_file |
Alan Stokes | 7aa4041 | 2020-12-04 14:07:52 +0000 | [diff] [blame] | 157 | -user_profile_root_file |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 158 | -user_profile_data_file |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 159 | # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a |
| 160 | # subsequent neverallow. Currently only getattr and search are allowed. |
| 161 | -vendor_data_file |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 162 | with_native_coverage(`-method_trace_data_file') |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 163 | }:dir *; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 164 | neverallow traced_probes system_data_file:dir ~{ getattr userdebug_or_eng(`open read') search }; |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 165 | neverallow traced_probes { |
| 166 | data_file_type |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 167 | -packages_list_file |
| 168 | with_native_coverage(`-method_trace_data_file') |
Andy Yu | 9e96849 | 2022-04-01 15:16:14 -0700 | [diff] [blame] | 169 | -game_mode_intervention_list_file |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 170 | }:file *; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 171 | |
| 172 | # Only init is allowed to enter the traced_probes domain via exec() |
| 173 | neverallow { domain -init } traced_probes:process transition; |
| 174 | neverallow * traced_probes:process dyntransition; |
Kalesh Singh | aab7a73 | 2021-01-15 11:12:56 -0500 | [diff] [blame] | 175 | |