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; |
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_probes) |
| 6 | |
| 7 | # Write trace data to the Perfetto traced damon. This requires connecting to its |
| 8 | # producer socket and obtaining a (per-process) tmpfs fd. |
Florian Mayer | 5e52281 | 2019-10-08 16:15:14 +0100 | [diff] [blame^] | 9 | perfetto_producer(traced_probes) |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 10 | |
| 11 | # Allow traced_probes to access tracefs. |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 12 | allow traced_probes debugfs_tracing:dir r_dir_perms; |
| 13 | allow traced_probes debugfs_tracing:file rw_file_perms; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 14 | allow traced_probes debugfs_trace_marker:file getattr; |
Primiano Tucci | b4b31f9 | 2018-02-09 11:15:22 +0000 | [diff] [blame] | 15 | |
| 16 | # TODO(primiano): temporarily I/O tracing categories are still |
| 17 | # userdebug only until we nail down the blacklist/whitelist. |
| 18 | userdebug_or_eng(` |
Hector Dearman | 4802cbd | 2018-12-06 18:32:23 +0000 | [diff] [blame] | 19 | allow traced_probes debugfs_tracing_debug:dir r_dir_perms; |
Primiano Tucci | b4b31f9 | 2018-02-09 11:15:22 +0000 | [diff] [blame] | 20 | allow traced_probes debugfs_tracing_debug:file rw_file_perms; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 21 | ') |
| 22 | |
| 23 | # Allow traced_probes to start with a higher scheduling class and then downgrade |
| 24 | # itself. |
| 25 | allow traced_probes self:global_capability_class_set { sys_nice }; |
| 26 | |
| 27 | # Allow procfs access |
| 28 | r_dir_file(traced_probes, domain) |
| 29 | |
Florian Mayer | d04ffff | 2019-04-02 16:19:09 +0100 | [diff] [blame] | 30 | # Allow to read packages.list file. |
| 31 | allow traced_probes packages_list_file:file r_file_perms; |
| 32 | |
Primiano Tucci | d807d58 | 2018-02-16 13:54:41 +0000 | [diff] [blame] | 33 | # Allow to log to kernel dmesg when starting / stopping ftrace. |
| 34 | allow traced_probes kmsg_device:chr_file write; |
| 35 | |
Florian Mayer | ef6358b | 2018-02-23 16:47:38 +0000 | [diff] [blame] | 36 | # Allow traced_probes to list the system partition. |
| 37 | allow traced_probes system_file:dir { open read }; |
| 38 | |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 39 | # Allow traced_probes to list some of the data partition. |
Benjamin Gordon | 7ed266c | 2018-08-15 13:34:20 -0600 | [diff] [blame] | 40 | allow traced_probes self:global_capability_class_set dac_read_search; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 41 | |
Florian Mayer | ff14696 | 2018-04-06 12:55:22 +0100 | [diff] [blame] | 42 | allow traced_probes apk_data_file:dir { getattr open read search }; |
| 43 | allow traced_probes dalvikcache_data_file:dir { getattr open read search }; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 44 | userdebug_or_eng(` |
Florian Mayer | d04ffff | 2019-04-02 16:19:09 +0100 | [diff] [blame] | 45 | # search and getattr are granted via domain and coredomain, respectively. |
| 46 | allow traced_probes system_data_file:dir { open read }; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 47 | ') |
Florian Mayer | ff14696 | 2018-04-06 12:55:22 +0100 | [diff] [blame] | 48 | allow traced_probes system_app_data_file:dir { getattr open read search }; |
| 49 | allow traced_probes backup_data_file:dir { getattr open read search }; |
| 50 | allow traced_probes bootstat_data_file:dir { getattr open read search }; |
| 51 | allow traced_probes update_engine_data_file:dir { getattr open read search }; |
| 52 | allow traced_probes update_engine_log_data_file:dir { getattr open read search }; |
| 53 | allow traced_probes user_profile_data_file:dir { getattr open read search }; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 54 | |
Primiano Tucci | feaf22b | 2018-03-02 19:27:06 +0000 | [diff] [blame] | 55 | # Allow traced_probes to run atrace. atrace pokes at system services to enable |
| 56 | # their userspace TRACE macros. |
| 57 | domain_auto_trans(traced_probes, atrace_exec, atrace); |
| 58 | |
Lalit Maganti | d6ae1a5 | 2018-11-16 12:17:24 +0000 | [diff] [blame] | 59 | # Allow traced_probes to kill atrace on timeout. |
| 60 | allow traced_probes atrace:process sigkill; |
Primiano Tucci | feaf22b | 2018-03-02 19:27:06 +0000 | [diff] [blame] | 61 | |
Primiano Tucci | 51dc7cb | 2018-09-18 08:51:06 +0100 | [diff] [blame] | 62 | # Allow traced_probes to access /proc files for system stats. |
| 63 | # Note: trace data is NOT exposed to anything other than shell and privileged |
| 64 | # system apps that have access to the traced consumer socket. |
| 65 | allow traced_probes { |
| 66 | proc_meminfo |
| 67 | proc_vmstat |
| 68 | proc_stat |
| 69 | }:file r_file_perms; |
| 70 | |
Ben Murdoch | f948ea5 | 2019-03-13 17:08:43 +0000 | [diff] [blame] | 71 | # 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] | 72 | hal_client_domain(traced_probes, hal_health) |
Ben Murdoch | f948ea5 | 2019-03-13 17:08:43 +0000 | [diff] [blame] | 73 | hal_client_domain(traced_probes, hal_power_stats) |
Primiano Tucci | 353b93a | 2018-12-02 21:59:10 +0000 | [diff] [blame] | 74 | |
Isabelle Taylor | e8c4ba8 | 2019-03-26 11:03:35 +0000 | [diff] [blame] | 75 | # Allow access to Atrace HAL for enabling vendor/device specific tracing categories. |
| 76 | hal_client_domain(traced_probes, hal_atrace) |
| 77 | |
Primiano Tucci | a64d5bb | 2019-01-10 20:07:51 +0000 | [diff] [blame] | 78 | # On debug builds allow to ingest system logs into the trace. |
| 79 | userdebug_or_eng(`read_logd(traced_probes)') |
| 80 | |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 81 | ### |
| 82 | ### Neverallow rules |
| 83 | ### |
| 84 | ### traced_probes should NEVER do any of this |
| 85 | |
| 86 | # Disallow mapping executable memory (execstack and exec are already disallowed |
| 87 | # globally in domain.te). |
| 88 | neverallow traced_probes self:process execmem; |
| 89 | |
| 90 | # Block device access. |
| 91 | neverallow traced_probes dev_type:blk_file { read write }; |
| 92 | |
| 93 | # ptrace any other app |
| 94 | neverallow traced_probes domain:process ptrace; |
| 95 | |
| 96 | # Disallows access to /data files. |
Primiano Tucci | d807d58 | 2018-02-16 13:54:41 +0000 | [diff] [blame] | 97 | neverallow traced_probes { |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 98 | data_file_type |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 99 | -apk_data_file |
| 100 | -dalvikcache_data_file |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 101 | -system_data_file |
Paul Crowley | aed0f76 | 2019-08-01 15:57:47 -0700 | [diff] [blame] | 102 | -system_data_root_file |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 103 | -system_app_data_file |
| 104 | -backup_data_file |
| 105 | -bootstat_data_file |
| 106 | -update_engine_data_file |
| 107 | -update_engine_log_data_file |
| 108 | -user_profile_data_file |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 109 | # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a |
| 110 | # subsequent neverallow. Currently only getattr and search are allowed. |
| 111 | -vendor_data_file |
| 112 | -zoneinfo_data_file |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 113 | with_native_coverage(`-method_trace_data_file') |
Jeff Vander Stoep | d25ccab | 2018-02-07 16:29:06 -0800 | [diff] [blame] | 114 | }:dir *; |
Florian Mayer | 9fcf22b | 2018-03-02 10:52:56 +0000 | [diff] [blame] | 115 | neverallow traced_probes system_data_file:dir ~{ getattr userdebug_or_eng(`open read') search }; |
Primiano Tucci | d807d58 | 2018-02-16 13:54:41 +0000 | [diff] [blame] | 116 | neverallow traced_probes zoneinfo_data_file:dir ~r_dir_perms; |
| 117 | neverallow traced_probes { data_file_type -zoneinfo_data_file }:lnk_file *; |
Pirama Arumuga Nainar | ce9c0c5 | 2019-06-13 15:05:15 -0700 | [diff] [blame] | 118 | neverallow traced_probes { |
| 119 | data_file_type |
| 120 | -zoneinfo_data_file |
| 121 | -packages_list_file |
| 122 | with_native_coverage(`-method_trace_data_file') |
| 123 | }:file *; |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 124 | |
| 125 | # Only init is allowed to enter the traced_probes domain via exec() |
| 126 | neverallow { domain -init } traced_probes:process transition; |
| 127 | neverallow * traced_probes:process dyntransition; |