blob: 9da4d94c19f31f60227eef70508bf622838ee85c [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
19# TODO(primiano): temporarily I/O tracing categories are still
Jeff Sharkeya0e7a6d2020-07-31 12:28:11 -060020# userdebug only until we nail down the denylist/allowlist.
Primiano Tuccib4b31f92018-02-09 11:15:22 +000021userdebug_or_eng(`
Hector Dearman4802cbd2018-12-06 18:32:23 +000022allow traced_probes debugfs_tracing_debug:dir r_dir_perms;
Primiano Tuccib4b31f92018-02-09 11:15:22 +000023allow traced_probes debugfs_tracing_debug:file rw_file_perms;
Primiano Tuccic80f9e02017-12-21 03:51:15 +010024')
25
26# Allow traced_probes to start with a higher scheduling class and then downgrade
27# itself.
28allow traced_probes self:global_capability_class_set { sys_nice };
29
30# Allow procfs access
31r_dir_file(traced_probes, domain)
32
Primiano Tuccicd452302020-10-09 09:15:10 +010033# Allow to temporarily lift the kptr_restrict setting and build a symbolization
34# map reading /proc/kallsyms.
35userdebug_or_eng(`set_prop(traced_probes, lower_kptr_restrict_prop)')
36allow traced_probes proc_kallsyms:file r_file_perms;
37
Florian Mayerd04ffff2019-04-02 16:19:09 +010038# Allow to read packages.list file.
39allow traced_probes packages_list_file:file r_file_perms;
40
Primiano Tuccid807d582018-02-16 13:54:41 +000041# Allow to log to kernel dmesg when starting / stopping ftrace.
42allow traced_probes kmsg_device:chr_file write;
43
Florian Mayeref6358b2018-02-23 16:47:38 +000044# Allow traced_probes to list the system partition.
45allow traced_probes system_file:dir { open read };
46
Florian Mayer9fcf22b2018-03-02 10:52:56 +000047# Allow traced_probes to list some of the data partition.
Benjamin Gordon7ed266c2018-08-15 13:34:20 -060048allow traced_probes self:global_capability_class_set dac_read_search;
Florian Mayer9fcf22b2018-03-02 10:52:56 +000049
Florian Mayerff146962018-04-06 12:55:22 +010050allow traced_probes apk_data_file:dir { getattr open read search };
51allow traced_probes dalvikcache_data_file:dir { getattr open read search };
Florian Mayer9fcf22b2018-03-02 10:52:56 +000052userdebug_or_eng(`
Florian Mayerd04ffff2019-04-02 16:19:09 +010053# search and getattr are granted via domain and coredomain, respectively.
54allow traced_probes system_data_file:dir { open read };
Florian Mayer9fcf22b2018-03-02 10:52:56 +000055')
Florian Mayerff146962018-04-06 12:55:22 +010056allow traced_probes system_app_data_file:dir { getattr open read search };
57allow traced_probes backup_data_file:dir { getattr open read search };
58allow traced_probes bootstat_data_file:dir { getattr open read search };
59allow traced_probes update_engine_data_file:dir { getattr open read search };
60allow traced_probes update_engine_log_data_file:dir { getattr open read search };
Alan Stokes7aa40412020-12-04 14:07:52 +000061allow traced_probes { user_profile_root_file user_profile_data_file}:dir { getattr open read search };
Florian Mayer9fcf22b2018-03-02 10:52:56 +000062
Primiano Tuccifeaf22b2018-03-02 19:27:06 +000063# Allow traced_probes to run atrace. atrace pokes at system services to enable
64# their userspace TRACE macros.
65domain_auto_trans(traced_probes, atrace_exec, atrace);
66
Lalit Magantid6ae1a52018-11-16 12:17:24 +000067# Allow traced_probes to kill atrace on timeout.
68allow traced_probes atrace:process sigkill;
Primiano Tuccifeaf22b2018-03-02 19:27:06 +000069
Primiano Tucci51dc7cb2018-09-18 08:51:06 +010070# Allow traced_probes to access /proc files for system stats.
71# Note: trace data is NOT exposed to anything other than shell and privileged
72# system apps that have access to the traced consumer socket.
73allow traced_probes {
74 proc_meminfo
75 proc_vmstat
76 proc_stat
77}:file r_file_perms;
78
Ben Murdochf948ea52019-03-13 17:08:43 +000079# Allow access to the IHealth and IPowerStats HAL service for tracing battery counters.
Primiano Tucci353b93a2018-12-02 21:59:10 +000080hal_client_domain(traced_probes, hal_health)
Ben Murdochf948ea52019-03-13 17:08:43 +000081hal_client_domain(traced_probes, hal_power_stats)
Primiano Tucci353b93a2018-12-02 21:59:10 +000082
Isabelle Taylore8c4ba82019-03-26 11:03:35 +000083# Allow access to Atrace HAL for enabling vendor/device specific tracing categories.
84hal_client_domain(traced_probes, hal_atrace)
85
Primiano Tuccia64d5bb2019-01-10 20:07:51 +000086# On debug builds allow to ingest system logs into the trace.
87userdebug_or_eng(`read_logd(traced_probes)')
88
Primiano Tuccic80f9e02017-12-21 03:51:15 +010089###
90### Neverallow rules
91###
92### traced_probes should NEVER do any of this
93
94# Disallow mapping executable memory (execstack and exec are already disallowed
95# globally in domain.te).
96neverallow traced_probes self:process execmem;
97
98# Block device access.
99neverallow traced_probes dev_type:blk_file { read write };
100
101# ptrace any other app
102neverallow traced_probes domain:process ptrace;
103
104# Disallows access to /data files.
Primiano Tuccid807d582018-02-16 13:54:41 +0000105neverallow traced_probes {
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800106 data_file_type
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000107 -apk_data_file
108 -dalvikcache_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800109 -system_data_file
Paul Crowleyaed0f762019-08-01 15:57:47 -0700110 -system_data_root_file
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000111 -system_app_data_file
112 -backup_data_file
113 -bootstat_data_file
114 -update_engine_data_file
115 -update_engine_log_data_file
Alan Stokes7aa40412020-12-04 14:07:52 +0000116 -user_profile_root_file
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000117 -user_profile_data_file
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800118 # TODO(b/72998741) Remove vendor_data_file exemption. Further restricted in a
119 # subsequent neverallow. Currently only getattr and search are allowed.
120 -vendor_data_file
121 -zoneinfo_data_file
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700122 with_native_coverage(`-method_trace_data_file')
Jeff Vander Stoepd25ccab2018-02-07 16:29:06 -0800123}:dir *;
Florian Mayer9fcf22b2018-03-02 10:52:56 +0000124neverallow traced_probes system_data_file:dir ~{ getattr userdebug_or_eng(`open read') search };
Primiano Tuccid807d582018-02-16 13:54:41 +0000125neverallow traced_probes zoneinfo_data_file:dir ~r_dir_perms;
126neverallow traced_probes { data_file_type -zoneinfo_data_file }:lnk_file *;
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700127neverallow traced_probes {
128 data_file_type
129 -zoneinfo_data_file
130 -packages_list_file
131 with_native_coverage(`-method_trace_data_file')
132}:file *;
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100133
134# Only init is allowed to enter the traced_probes domain via exec()
135neverallow { domain -init } traced_probes:process transition;
136neverallow * traced_probes:process dyntransition;