blob: 003e992c20869277c702e4a325e341288233e682 [file] [log] [blame]
Primiano Tuccic80f9e02017-12-21 03:51:15 +01001# Perfetto tracing probes, has tracefs access.
Nick Kralevich5e372712018-09-27 10:21:37 -07002type traced_probes_exec, system_file_type, exec_type, file_type;
Ryan Savitski21f6ae62020-02-04 13:44:14 +00003type traced_probes_tmpfs, file_type;
Primiano Tuccic80f9e02017-12-21 03:51:15 +01004
5# Allow init to exec the daemon.
6init_daemon_domain(traced_probes)
Ryan Savitski21f6ae62020-02-04 13:44:14 +00007tmpfs_domain(traced_probes)
Primiano Tuccic80f9e02017-12-21 03:51:15 +01008
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 Mayer5e522812019-10-08 16:15:14 +010011perfetto_producer(traced_probes)
Primiano Tuccic80f9e02017-12-21 03:51:15 +010012
13# Allow traced_probes to access tracefs.
Primiano Tuccic80f9e02017-12-21 03:51:15 +010014allow traced_probes debugfs_tracing:dir r_dir_perms;
15allow traced_probes debugfs_tracing:file rw_file_perms;
Primiano Tuccic80f9e02017-12-21 03:51:15 +010016allow traced_probes debugfs_trace_marker:file getattr;
Florian Mayer12376162020-11-05 12:54:52 +000017allow traced_probes debugfs_tracing_printk_formats:file r_file_perms;
Primiano Tuccib4b31f92018-02-09 11:15:22 +000018
Kalesh Singhaab7a732021-01-15 11:12:56 -050019# Allow traced_probes to access mm_events trace instance
20allow traced_probes debugfs_tracing_instances:dir search;
21allow traced_probes debugfs_mm_events_tracing:dir search;
22allow traced_probes debugfs_mm_events_tracing:file rw_file_perms;
23
Primiano Tuccib4b31f92018-02-09 11:15:22 +000024# TODO(primiano): temporarily I/O tracing categories are still
Jeff Sharkeya0e7a6d2020-07-31 12:28:11 -060025# userdebug only until we nail down the denylist/allowlist.
Primiano Tuccib4b31f92018-02-09 11:15:22 +000026userdebug_or_eng(`
Hector Dearman4802cbd2018-12-06 18:32:23 +000027allow traced_probes debugfs_tracing_debug:dir r_dir_perms;
Primiano Tuccib4b31f92018-02-09 11:15:22 +000028allow traced_probes debugfs_tracing_debug:file rw_file_perms;
Primiano Tuccic80f9e02017-12-21 03:51:15 +010029')
30
31# Allow traced_probes to start with a higher scheduling class and then downgrade
32# itself.
33allow traced_probes self:global_capability_class_set { sys_nice };
34
35# Allow procfs access
36r_dir_file(traced_probes, domain)
37
Primiano Tuccicd452302020-10-09 09:15:10 +010038# Allow to temporarily lift the kptr_restrict setting and build a symbolization
39# map reading /proc/kallsyms.
40userdebug_or_eng(`set_prop(traced_probes, lower_kptr_restrict_prop)')
41allow traced_probes proc_kallsyms:file r_file_perms;
42
Florian Mayerd04ffff2019-04-02 16:19:09 +010043# Allow to read packages.list file.
44allow traced_probes packages_list_file:file r_file_perms;
45
Andy Yu9e968492022-04-01 15:16:14 -070046# Allow to read game_mode_intervention.list file.
47allow traced_probes game_mode_intervention_list_file:file r_file_perms;
48
Primiano Tuccid807d582018-02-16 13:54:41 +000049# Allow to log to kernel dmesg when starting / stopping ftrace.
50allow traced_probes kmsg_device:chr_file write;
51
Florian Mayeref6358b2018-02-23 16:47:38 +000052# Allow traced_probes to list the system partition.
53allow traced_probes system_file:dir { open read };
54
Florian Mayer9fcf22b2018-03-02 10:52:56 +000055# Allow traced_probes to list some of the data partition.
Benjamin Gordon7ed266c2018-08-15 13:34:20 -060056allow traced_probes self:global_capability_class_set dac_read_search;
Florian Mayer9fcf22b2018-03-02 10:52:56 +000057
Florian Mayerff146962018-04-06 12:55:22 +010058allow traced_probes apk_data_file:dir { getattr open read search };
Orion Hodson8f75f762020-10-16 15:29:55 +010059allow traced_probes { apex_art_data_file apex_module_data_file }:dir { getattr open read search };
Florian Mayerff146962018-04-06 12:55:22 +010060allow traced_probes dalvikcache_data_file:dir { getattr open read search };
Florian Mayer9fcf22b2018-03-02 10:52:56 +000061userdebug_or_eng(`
Florian Mayerd04ffff2019-04-02 16:19:09 +010062# search and getattr are granted via domain and coredomain, respectively.
63allow traced_probes system_data_file:dir { open read };
Florian Mayer9fcf22b2018-03-02 10:52:56 +000064')
Florian Mayerff146962018-04-06 12:55:22 +010065allow traced_probes system_app_data_file:dir { getattr open read search };
66allow traced_probes backup_data_file:dir { getattr open read search };
67allow traced_probes bootstat_data_file:dir { getattr open read search };
68allow traced_probes update_engine_data_file:dir { getattr open read search };
69allow traced_probes update_engine_log_data_file:dir { getattr open read search };
Alan Stokes7aa40412020-12-04 14:07:52 +000070allow traced_probes { user_profile_root_file user_profile_data_file}:dir { getattr open read search };
Florian Mayer9fcf22b2018-03-02 10:52:56 +000071
Primiano Tuccifeaf22b2018-03-02 19:27:06 +000072# Allow traced_probes to run atrace. atrace pokes at system services to enable
73# their userspace TRACE macros.
74domain_auto_trans(traced_probes, atrace_exec, atrace);
75
Lalit Magantid6ae1a52018-11-16 12:17:24 +000076# Allow traced_probes to kill atrace on timeout.
77allow traced_probes atrace:process sigkill;
Primiano Tuccifeaf22b2018-03-02 19:27:06 +000078
Primiano Tucci51dc7cb2018-09-18 08:51:06 +010079# Allow traced_probes to access /proc files for system stats.
80# Note: trace data is NOT exposed to anything other than shell and privileged
81# system apps that have access to the traced consumer socket.
82allow traced_probes {
83 proc_meminfo
84 proc_vmstat
85 proc_stat
Derek Smithf5950292022-08-04 20:21:37 +000086 proc_buddyinfo
Jared Duke8db0b2b2023-12-11 22:37:32 +000087 proc_pressure_cpu
88 proc_pressure_io
89 proc_pressure_mem
Primiano Tucci51dc7cb2018-09-18 08:51:06 +010090}:file r_file_perms;
91
David Massoudc50fecd2021-04-16 20:02:06 +080092# Allow access to read /sys/class/devfreq/ and /$DEVICE/cur_freq files
93allow traced_probes sysfs_devfreq_dir:dir r_dir_perms;
94allow traced_probes sysfs_devfreq_cur:file r_file_perms;
95
Daeho Jeongbfa82132023-04-03 13:01:00 -070096# Allow access to read /proc/diskstats for I/O profiling.
97allow traced_probes proc_diskstats:file r_file_perms;
98
Ben Murdochf948ea52019-03-13 17:08:43 +000099# Allow access to the IHealth and IPowerStats HAL service for tracing battery counters.
Primiano Tucci353b93a2018-12-02 21:59:10 +0000100hal_client_domain(traced_probes, hal_health)
Ben Murdochf948ea52019-03-13 17:08:43 +0000101hal_client_domain(traced_probes, hal_power_stats)
Primiano Tucci353b93a2018-12-02 21:59:10 +0000102
Isabelle Taylore8c4ba82019-03-26 11:03:35 +0000103# Allow access to Atrace HAL for enabling vendor/device specific tracing categories.
104hal_client_domain(traced_probes, hal_atrace)
105
Primiano Tuccia64d5bb2019-01-10 20:07:51 +0000106# On debug builds allow to ingest system logs into the trace.
107userdebug_or_eng(`read_logd(traced_probes)')
108
Hector Dearman7ca04a72023-03-22 08:14:38 +0000109# Allow traced_probes to talk to statsd for logging metrics and recording atoms.
Lalit Maganti685205d2021-04-30 12:13:39 +0100110unix_socket_send(traced_probes, statsdw, statsd)
Hector Dearman7ca04a72023-03-22 08:14:38 +0000111binder_call(traced_probes, statsd)
112allow traced_probes stats_service:service_manager find;
Lalit Maganti685205d2021-04-30 12:13:39 +0100113
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100114###
115### Neverallow rules
116###
117### traced_probes should NEVER do any of this
118
119# Disallow mapping executable memory (execstack and exec are already disallowed
120# globally in domain.te).
121neverallow traced_probes self:process execmem;
122
123# Block device access.
124neverallow traced_probes dev_type:blk_file { read write };
125
126# ptrace any other app
127neverallow traced_probes domain:process ptrace;
128
129# Disallows access to /data files.
Primiano Tuccid807d582018-02-16 13:54:41 +0000130neverallow traced_probes {
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800131 data_file_type
Orion Hodson8f75f762020-10-16 15:29:55 +0100132 -apex_module_data_file
133 -apex_art_data_file
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000134 -apk_data_file
135 -dalvikcache_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800136 -system_data_file
Paul Crowleyaed0f762019-08-01 15:57:47 -0700137 -system_data_root_file
Eric Biggers9a599232022-05-04 22:18:02 +0000138 -media_userdir_file
139 -system_userdir_file
140 -vendor_userdir_file
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000141 -system_app_data_file
142 -backup_data_file
143 -bootstat_data_file
144 -update_engine_data_file
145 -update_engine_log_data_file
Alan Stokes7aa40412020-12-04 14:07:52 +0000146 -user_profile_root_file
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000147 -user_profile_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800148 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
149 # subsequent neverallow. Currently only getattr and search are allowed.
150 -vendor_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700151 with_native_coverage(`-method_trace_data_file')
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800152}:dir *;
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000153neverallow traced_probes system_data_file:dir ~{ getattr userdebug_or_eng(`open read') search };
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700154neverallow traced_probes {
155 data_file_type
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700156 -packages_list_file
157 with_native_coverage(`-method_trace_data_file')
Andy Yu9e968492022-04-01 15:16:14 -0700158 -game_mode_intervention_list_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700159}:file *;
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100160
161# Only init is allowed to enter the traced_probes domain via exec()
162neverallow { domain -init } traced_probes:process transition;
163neverallow * traced_probes:process dyntransition;
Kalesh Singhaab7a732021-01-15 11:12:56 -0500164