xref: /aosp_15_r20/system/sepolicy/prebuilts/api/33.0/private/domain.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# Transition to crash_dump when /system/bin/crash_dump* is executed.
2*e4a36f41SAndroid Build Coastguard Worker# This occurs when the process crashes.
3*e4a36f41SAndroid Build Coastguard Worker# We do not apply this to the su domain to avoid interfering with
4*e4a36f41SAndroid Build Coastguard Worker# tests (b/114136122)
5*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans({ domain userdebug_or_eng(`-su') }, crash_dump_exec, crash_dump);
6*e4a36f41SAndroid Build Coastguard Workerallow domain crash_dump:process sigchld;
7*e4a36f41SAndroid Build Coastguard Worker
8*e4a36f41SAndroid Build Coastguard Worker# Allow every process to check the heapprofd.enable properties to determine
9*e4a36f41SAndroid Build Coastguard Worker# whether to load the heap profiling library. This does not necessarily enable
10*e4a36f41SAndroid Build Coastguard Worker# heap profiling, as initialization will fail if it does not have the
11*e4a36f41SAndroid Build Coastguard Worker# necessary SELinux permissions.
12*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, heapprofd_prop);
13*e4a36f41SAndroid Build Coastguard Worker# Allow heap profiling on debug builds.
14*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`can_profile_heap({
15*e4a36f41SAndroid Build Coastguard Worker  domain
16*e4a36f41SAndroid Build Coastguard Worker  -bpfloader
17*e4a36f41SAndroid Build Coastguard Worker  -init
18*e4a36f41SAndroid Build Coastguard Worker  -kernel
19*e4a36f41SAndroid Build Coastguard Worker  -keystore
20*e4a36f41SAndroid Build Coastguard Worker  -llkd
21*e4a36f41SAndroid Build Coastguard Worker  -logd
22*e4a36f41SAndroid Build Coastguard Worker  -logpersist
23*e4a36f41SAndroid Build Coastguard Worker  -recovery
24*e4a36f41SAndroid Build Coastguard Worker  -recovery_persist
25*e4a36f41SAndroid Build Coastguard Worker  -recovery_refresh
26*e4a36f41SAndroid Build Coastguard Worker  -ueventd
27*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
28*e4a36f41SAndroid Build Coastguard Worker  -vold
29*e4a36f41SAndroid Build Coastguard Worker})')
30*e4a36f41SAndroid Build Coastguard Worker
31*e4a36f41SAndroid Build Coastguard Worker# As above, allow perf profiling most processes on debug builds.
32*e4a36f41SAndroid Build Coastguard Worker# zygote is excluded as system-wide profiling could end up with it
33*e4a36f41SAndroid Build Coastguard Worker# (unexpectedly) holding an open fd across a fork.
34*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`can_profile_perf({
35*e4a36f41SAndroid Build Coastguard Worker  domain
36*e4a36f41SAndroid Build Coastguard Worker  -bpfloader
37*e4a36f41SAndroid Build Coastguard Worker  -init
38*e4a36f41SAndroid Build Coastguard Worker  -kernel
39*e4a36f41SAndroid Build Coastguard Worker  -keystore
40*e4a36f41SAndroid Build Coastguard Worker  -llkd
41*e4a36f41SAndroid Build Coastguard Worker  -logd
42*e4a36f41SAndroid Build Coastguard Worker  -logpersist
43*e4a36f41SAndroid Build Coastguard Worker  -recovery
44*e4a36f41SAndroid Build Coastguard Worker  -recovery_persist
45*e4a36f41SAndroid Build Coastguard Worker  -recovery_refresh
46*e4a36f41SAndroid Build Coastguard Worker  -ueventd
47*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
48*e4a36f41SAndroid Build Coastguard Worker  -vold
49*e4a36f41SAndroid Build Coastguard Worker  -zygote
50*e4a36f41SAndroid Build Coastguard Worker})')
51*e4a36f41SAndroid Build Coastguard Worker
52*e4a36f41SAndroid Build Coastguard Worker# Everyone can access the IncFS list of features.
53*e4a36f41SAndroid Build Coastguard Workerr_dir_file(domain, sysfs_fs_incfs_features);
54*e4a36f41SAndroid Build Coastguard Worker
55*e4a36f41SAndroid Build Coastguard Worker# Path resolution access in cgroups.
56*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup:dir search;
57*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup:dir w_dir_perms;
58*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup:file w_file_perms;
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup_v2:dir search;
61*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup_v2:dir w_dir_perms;
62*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup_v2:file w_file_perms;
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup_rc_file:dir search;
65*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup_rc_file:file r_file_perms;
66*e4a36f41SAndroid Build Coastguard Workerallow domain task_profiles_file:file r_file_perms;
67*e4a36f41SAndroid Build Coastguard Workerallow domain task_profiles_api_file:file r_file_perms;
68*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_task_profiles_file:file r_file_perms;
69*e4a36f41SAndroid Build Coastguard Worker
70*e4a36f41SAndroid Build Coastguard Worker# Allow all domains to read sys.use_memfd to determine
71*e4a36f41SAndroid Build Coastguard Worker# if memfd support can be used if device supports it
72*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, use_memfd_prop);
73*e4a36f41SAndroid Build Coastguard Worker
74*e4a36f41SAndroid Build Coastguard Worker# Read access to sdkextensions props
75*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, module_sdkextensions_prop)
76*e4a36f41SAndroid Build Coastguard Worker
77*e4a36f41SAndroid Build Coastguard Worker# Read access to bq configuration values
78*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, bq_config_prop);
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# For now, everyone can access core property files
81*e4a36f41SAndroid Build Coastguard Worker# Device specific properties are not granted by default
82*e4a36f41SAndroid Build Coastguard Workernot_compatible_property(`
83*e4a36f41SAndroid Build Coastguard Worker    # DO NOT ADD ANY PROPERTIES HERE
84*e4a36f41SAndroid Build Coastguard Worker    get_prop(domain, core_property_type)
85*e4a36f41SAndroid Build Coastguard Worker    get_prop(domain, exported3_system_prop)
86*e4a36f41SAndroid Build Coastguard Worker    get_prop(domain, vendor_default_prop)
87*e4a36f41SAndroid Build Coastguard Worker')
88*e4a36f41SAndroid Build Coastguard Workercompatible_property_only(`
89*e4a36f41SAndroid Build Coastguard Worker    # DO NOT ADD ANY PROPERTIES HERE
90*e4a36f41SAndroid Build Coastguard Worker    get_prop({coredomain appdomain shell}, core_property_type)
91*e4a36f41SAndroid Build Coastguard Worker    get_prop({coredomain appdomain shell}, exported3_system_prop)
92*e4a36f41SAndroid Build Coastguard Worker    get_prop({coredomain appdomain shell}, exported_camera_prop)
93*e4a36f41SAndroid Build Coastguard Worker    get_prop({coredomain shell}, userspace_reboot_exported_prop)
94*e4a36f41SAndroid Build Coastguard Worker    get_prop({coredomain shell}, userspace_reboot_log_prop)
95*e4a36f41SAndroid Build Coastguard Worker    get_prop({coredomain shell}, userspace_reboot_test_prop)
96*e4a36f41SAndroid Build Coastguard Worker    get_prop({domain -coredomain -appdomain}, vendor_default_prop)
97*e4a36f41SAndroid Build Coastguard Worker')
98*e4a36f41SAndroid Build Coastguard Worker
99*e4a36f41SAndroid Build Coastguard Worker# Allow access to fsverity keyring.
100*e4a36f41SAndroid Build Coastguard Workerallow domain kernel:key search;
101*e4a36f41SAndroid Build Coastguard Worker# Allow access to keys in the fsverity keyring that were installed at boot.
102*e4a36f41SAndroid Build Coastguard Workerallow domain fsverity_init:key search;
103*e4a36f41SAndroid Build Coastguard Worker# For testing purposes, allow access to keys installed with su.
104*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
105*e4a36f41SAndroid Build Coastguard Worker  allow domain su:key search;
106*e4a36f41SAndroid Build Coastguard Worker')
107*e4a36f41SAndroid Build Coastguard Worker
108*e4a36f41SAndroid Build Coastguard Worker# Allow access to linkerconfig file
109*e4a36f41SAndroid Build Coastguard Workerallow domain linkerconfig_file:dir search;
110*e4a36f41SAndroid Build Coastguard Workerallow domain linkerconfig_file:file r_file_perms;
111*e4a36f41SAndroid Build Coastguard Worker
112*e4a36f41SAndroid Build Coastguard Worker# Allow all processes to check for the existence of the boringssl_self_test_marker files.
113*e4a36f41SAndroid Build Coastguard Workerallow domain boringssl_self_test_marker:dir search;
114*e4a36f41SAndroid Build Coastguard Worker
115*e4a36f41SAndroid Build Coastguard Worker# Allow all processes to connect to PRNG seeder daemon.
116*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(domain, prng_seeder, prng_seeder)
117*e4a36f41SAndroid Build Coastguard Worker
118*e4a36f41SAndroid Build Coastguard Worker# No domains other than a select few can access the misc_block_device. This
119*e4a36f41SAndroid Build Coastguard Worker# block device is reserved for OTA use.
120*e4a36f41SAndroid Build Coastguard Worker# Do not assert this rule on userdebug/eng builds, due to some devices using
121*e4a36f41SAndroid Build Coastguard Worker# this partition for testing purposes.
122*e4a36f41SAndroid Build Coastguard Workerneverallow {
123*e4a36f41SAndroid Build Coastguard Worker  domain
124*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-domain') # exclude debuggable builds
125*e4a36f41SAndroid Build Coastguard Worker  -fastbootd
126*e4a36f41SAndroid Build Coastguard Worker  -hal_bootctl_server
127*e4a36f41SAndroid Build Coastguard Worker  -init
128*e4a36f41SAndroid Build Coastguard Worker  -uncrypt
129*e4a36f41SAndroid Build Coastguard Worker  -update_engine
130*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
131*e4a36f41SAndroid Build Coastguard Worker  -vendor_misc_writer
132*e4a36f41SAndroid Build Coastguard Worker  -vold
133*e4a36f41SAndroid Build Coastguard Worker  -recovery
134*e4a36f41SAndroid Build Coastguard Worker  -ueventd
135*e4a36f41SAndroid Build Coastguard Worker  -mtectrl
136*e4a36f41SAndroid Build Coastguard Worker} misc_block_device:blk_file { append link relabelfrom rename write open read ioctl lock };
137*e4a36f41SAndroid Build Coastguard Worker
138*e4a36f41SAndroid Build Coastguard Worker# Limit ability to ptrace or read sensitive /proc/pid files of processes
139*e4a36f41SAndroid Build Coastguard Worker# with other UIDs to these allowlisted domains.
140*e4a36f41SAndroid Build Coastguard Workerneverallow {
141*e4a36f41SAndroid Build Coastguard Worker  domain
142*e4a36f41SAndroid Build Coastguard Worker  -vold
143*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-llkd')
144*e4a36f41SAndroid Build Coastguard Worker  -dumpstate
145*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-incidentd')
146*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-profcollectd')
147*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-simpleperf_boot')
148*e4a36f41SAndroid Build Coastguard Worker  -storaged
149*e4a36f41SAndroid Build Coastguard Worker  -system_server
150*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set sys_ptrace;
151*e4a36f41SAndroid Build Coastguard Worker
152*e4a36f41SAndroid Build Coastguard Worker# Limit ability to generate hardware unique device ID attestations to priv_apps
153*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -priv_app -gmscore_app } *:keystore_key gen_unique_id;
154*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -priv_app -gmscore_app } *:keystore2_key gen_unique_id;
155*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } *:keystore2_key use_dev_id;
156*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } keystore:keystore2 { clear_ns lock reset unlock };
157*e4a36f41SAndroid Build Coastguard Worker
158*e4a36f41SAndroid Build Coastguard Workerneverallow {
159*e4a36f41SAndroid Build Coastguard Worker  domain
160*e4a36f41SAndroid Build Coastguard Worker  -init
161*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
162*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-domain')
163*e4a36f41SAndroid Build Coastguard Worker} debugfs_tracing_debug:file no_rw_file_perms;
164*e4a36f41SAndroid Build Coastguard Worker
165*e4a36f41SAndroid Build Coastguard Worker# System_server owns dropbox data, and init creates/restorecons the directory
166*e4a36f41SAndroid Build Coastguard Worker# Disallow direct access by other processes.
167*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } dropbox_data_file:dir *;
168*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } dropbox_data_file:file ~{ getattr read };
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker###
171*e4a36f41SAndroid Build Coastguard Worker# Services should respect app sandboxes
172*e4a36f41SAndroid Build Coastguard Workerneverallow {
173*e4a36f41SAndroid Build Coastguard Worker  domain
174*e4a36f41SAndroid Build Coastguard Worker  -appdomain
175*e4a36f41SAndroid Build Coastguard Worker  -installd # creation of sandbox
176*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir_file_class_set { create unlink };
177*e4a36f41SAndroid Build Coastguard Worker
178*e4a36f41SAndroid Build Coastguard Worker# Only the following processes should be directly accessing private app
179*e4a36f41SAndroid Build Coastguard Worker# directories.
180*e4a36f41SAndroid Build Coastguard Workerneverallow {
181*e4a36f41SAndroid Build Coastguard Worker  domain
182*e4a36f41SAndroid Build Coastguard Worker  -adbd
183*e4a36f41SAndroid Build Coastguard Worker  -appdomain
184*e4a36f41SAndroid Build Coastguard Worker  -app_zygote
185*e4a36f41SAndroid Build Coastguard Worker  -dexoptanalyzer
186*e4a36f41SAndroid Build Coastguard Worker  -installd
187*e4a36f41SAndroid Build Coastguard Worker  -iorap_inode2filename
188*e4a36f41SAndroid Build Coastguard Worker  -iorap_prefetcherd
189*e4a36f41SAndroid Build Coastguard Worker  -profman
190*e4a36f41SAndroid Build Coastguard Worker  -rs # spawned by appdomain, so carryover the exception above
191*e4a36f41SAndroid Build Coastguard Worker  -runas
192*e4a36f41SAndroid Build Coastguard Worker  -system_server
193*e4a36f41SAndroid Build Coastguard Worker  -viewcompiler
194*e4a36f41SAndroid Build Coastguard Worker  -zygote
195*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir *;
196*e4a36f41SAndroid Build Coastguard Worker
197*e4a36f41SAndroid Build Coastguard Worker# Only apps should be modifying app data. installd is exempted for
198*e4a36f41SAndroid Build Coastguard Worker# restorecon and package install/uninstall.
199*e4a36f41SAndroid Build Coastguard Workerneverallow {
200*e4a36f41SAndroid Build Coastguard Worker  domain
201*e4a36f41SAndroid Build Coastguard Worker  -appdomain
202*e4a36f41SAndroid Build Coastguard Worker  -installd
203*e4a36f41SAndroid Build Coastguard Worker  -rs # spawned by appdomain, so carryover the exception above
204*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir ~r_dir_perms;
205*e4a36f41SAndroid Build Coastguard Worker
206*e4a36f41SAndroid Build Coastguard Workerneverallow {
207*e4a36f41SAndroid Build Coastguard Worker  domain
208*e4a36f41SAndroid Build Coastguard Worker  -appdomain
209*e4a36f41SAndroid Build Coastguard Worker  -app_zygote
210*e4a36f41SAndroid Build Coastguard Worker  -installd
211*e4a36f41SAndroid Build Coastguard Worker  -iorap_prefetcherd
212*e4a36f41SAndroid Build Coastguard Worker  -rs # spawned by appdomain, so carryover the exception above
213*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:file_class_set open;
214*e4a36f41SAndroid Build Coastguard Worker
215*e4a36f41SAndroid Build Coastguard Workerneverallow {
216*e4a36f41SAndroid Build Coastguard Worker  domain
217*e4a36f41SAndroid Build Coastguard Worker  -appdomain
218*e4a36f41SAndroid Build Coastguard Worker  -installd # creation of sandbox
219*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir_file_class_set { create unlink };
220*e4a36f41SAndroid Build Coastguard Worker
221*e4a36f41SAndroid Build Coastguard Workerneverallow {
222*e4a36f41SAndroid Build Coastguard Worker  domain
223*e4a36f41SAndroid Build Coastguard Worker  -installd
224*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir_file_class_set { relabelfrom relabelto };
225*e4a36f41SAndroid Build Coastguard Worker
226*e4a36f41SAndroid Build Coastguard Worker# The staging directory contains APEX and APK files. It is important to ensure
227*e4a36f41SAndroid Build Coastguard Worker# that these files cannot be accessed by other domains to ensure that the files
228*e4a36f41SAndroid Build Coastguard Worker# do not change between system_server staging the files and apexd processing
229*e4a36f41SAndroid Build Coastguard Worker# the files.
230*e4a36f41SAndroid Build Coastguard Workerneverallow {
231*e4a36f41SAndroid Build Coastguard Worker  domain
232*e4a36f41SAndroid Build Coastguard Worker  -init
233*e4a36f41SAndroid Build Coastguard Worker  -system_server
234*e4a36f41SAndroid Build Coastguard Worker  -apexd
235*e4a36f41SAndroid Build Coastguard Worker  -installd
236*e4a36f41SAndroid Build Coastguard Worker  -iorap_inode2filename
237*e4a36f41SAndroid Build Coastguard Worker  -priv_app
238*e4a36f41SAndroid Build Coastguard Worker  -virtualizationservice
239*e4a36f41SAndroid Build Coastguard Worker} staging_data_file:dir *;
240*e4a36f41SAndroid Build Coastguard Workerneverallow {
241*e4a36f41SAndroid Build Coastguard Worker  domain
242*e4a36f41SAndroid Build Coastguard Worker  -init
243*e4a36f41SAndroid Build Coastguard Worker  -system_app
244*e4a36f41SAndroid Build Coastguard Worker  -system_server
245*e4a36f41SAndroid Build Coastguard Worker  -apexd
246*e4a36f41SAndroid Build Coastguard Worker  -adbd
247*e4a36f41SAndroid Build Coastguard Worker  -kernel
248*e4a36f41SAndroid Build Coastguard Worker  -installd
249*e4a36f41SAndroid Build Coastguard Worker  -iorap_inode2filename
250*e4a36f41SAndroid Build Coastguard Worker  -priv_app
251*e4a36f41SAndroid Build Coastguard Worker  -shell
252*e4a36f41SAndroid Build Coastguard Worker  -virtualizationservice
253*e4a36f41SAndroid Build Coastguard Worker  -crosvm
254*e4a36f41SAndroid Build Coastguard Worker} staging_data_file:file *;
255*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -installd} staging_data_file:dir no_w_dir_perms;
256*e4a36f41SAndroid Build Coastguard Worker# apexd needs the link and unlink permissions, so list every `no_w_file_perms`
257*e4a36f41SAndroid Build Coastguard Worker# except for `link` and `unlink`.
258*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } staging_data_file:file
259*e4a36f41SAndroid Build Coastguard Worker  { append create relabelfrom rename setattr write no_x_file_perms };
260*e4a36f41SAndroid Build Coastguard Worker
261*e4a36f41SAndroid Build Coastguard Workerneverallow {
262*e4a36f41SAndroid Build Coastguard Worker    domain
263*e4a36f41SAndroid Build Coastguard Worker    -appdomain # for oemfs
264*e4a36f41SAndroid Build Coastguard Worker    -bootanim # for oemfs
265*e4a36f41SAndroid Build Coastguard Worker    -recovery # for /tmp/update_binary in tmpfs
266*e4a36f41SAndroid Build Coastguard Worker} { fs_type -rootfs }:file execute;
267*e4a36f41SAndroid Build Coastguard Worker
268*e4a36f41SAndroid Build Coastguard Worker#
269*e4a36f41SAndroid Build Coastguard Worker# Assert that, to the extent possible, we're not loading executable content from
270*e4a36f41SAndroid Build Coastguard Worker# outside the rootfs or /system partition except for a few allowlisted domains.
271*e4a36f41SAndroid Build Coastguard Worker# Executable files loaded from /data is a persistence vector
272*e4a36f41SAndroid Build Coastguard Worker# we want to avoid. See
273*e4a36f41SAndroid Build Coastguard Worker# https://bugs.chromium.org/p/project-zero/issues/detail?id=955 for example.
274*e4a36f41SAndroid Build Coastguard Worker#
275*e4a36f41SAndroid Build Coastguard Workerneverallow {
276*e4a36f41SAndroid Build Coastguard Worker    domain
277*e4a36f41SAndroid Build Coastguard Worker    -appdomain
278*e4a36f41SAndroid Build Coastguard Worker    with_asan(`-asan_extract')
279*e4a36f41SAndroid Build Coastguard Worker    -iorap_prefetcherd
280*e4a36f41SAndroid Build Coastguard Worker    -shell
281*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su')
282*e4a36f41SAndroid Build Coastguard Worker    -system_server_startup # for memfd backed executable regions
283*e4a36f41SAndroid Build Coastguard Worker    -app_zygote
284*e4a36f41SAndroid Build Coastguard Worker    -webview_zygote
285*e4a36f41SAndroid Build Coastguard Worker    -zygote
286*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-mediaextractor')
287*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-mediaswcodec')
288*e4a36f41SAndroid Build Coastguard Worker} {
289*e4a36f41SAndroid Build Coastguard Worker    file_type
290*e4a36f41SAndroid Build Coastguard Worker    -system_file_type
291*e4a36f41SAndroid Build Coastguard Worker    -system_lib_file
292*e4a36f41SAndroid Build Coastguard Worker    -system_linker_exec
293*e4a36f41SAndroid Build Coastguard Worker    -vendor_file_type
294*e4a36f41SAndroid Build Coastguard Worker    -exec_type
295*e4a36f41SAndroid Build Coastguard Worker    -postinstall_file
296*e4a36f41SAndroid Build Coastguard Worker}:file execute;
297*e4a36f41SAndroid Build Coastguard Worker
298*e4a36f41SAndroid Build Coastguard Worker# Only init is allowed to write cgroup.rc file
299*e4a36f41SAndroid Build Coastguard Workerneverallow {
300*e4a36f41SAndroid Build Coastguard Worker  domain
301*e4a36f41SAndroid Build Coastguard Worker  -init
302*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
303*e4a36f41SAndroid Build Coastguard Worker} cgroup_rc_file:file no_w_file_perms;
304*e4a36f41SAndroid Build Coastguard Worker
305*e4a36f41SAndroid Build Coastguard Worker# Only authorized processes should be writing to files in /data/dalvik-cache
306*e4a36f41SAndroid Build Coastguard Workerneverallow {
307*e4a36f41SAndroid Build Coastguard Worker  domain
308*e4a36f41SAndroid Build Coastguard Worker  -init # TODO: limit init to relabelfrom for files
309*e4a36f41SAndroid Build Coastguard Worker  -zygote
310*e4a36f41SAndroid Build Coastguard Worker  -installd
311*e4a36f41SAndroid Build Coastguard Worker  -postinstall_dexopt
312*e4a36f41SAndroid Build Coastguard Worker  -cppreopts
313*e4a36f41SAndroid Build Coastguard Worker  -dex2oat
314*e4a36f41SAndroid Build Coastguard Worker  -otapreopt_slot
315*e4a36f41SAndroid Build Coastguard Worker} dalvikcache_data_file:file no_w_file_perms;
316*e4a36f41SAndroid Build Coastguard Worker
317*e4a36f41SAndroid Build Coastguard Workerneverallow {
318*e4a36f41SAndroid Build Coastguard Worker  domain
319*e4a36f41SAndroid Build Coastguard Worker  -init
320*e4a36f41SAndroid Build Coastguard Worker  -installd
321*e4a36f41SAndroid Build Coastguard Worker  -postinstall_dexopt
322*e4a36f41SAndroid Build Coastguard Worker  -cppreopts
323*e4a36f41SAndroid Build Coastguard Worker  -dex2oat
324*e4a36f41SAndroid Build Coastguard Worker  -zygote
325*e4a36f41SAndroid Build Coastguard Worker  -otapreopt_slot
326*e4a36f41SAndroid Build Coastguard Worker} dalvikcache_data_file:dir no_w_dir_perms;
327*e4a36f41SAndroid Build Coastguard Worker
328*e4a36f41SAndroid Build Coastguard Worker# Only authorized processes should be writing to /data/misc/apexdata/com.android.art as it
329*e4a36f41SAndroid Build Coastguard Worker# contains boot class path and system server AOT artifacts following an ART APEX Mainline update.
330*e4a36f41SAndroid Build Coastguard Workerneverallow {
331*e4a36f41SAndroid Build Coastguard Worker  domain
332*e4a36f41SAndroid Build Coastguard Worker  # art-related processes
333*e4a36f41SAndroid Build Coastguard Worker  -composd
334*e4a36f41SAndroid Build Coastguard Worker  -compos_fd_server
335*e4a36f41SAndroid Build Coastguard Worker  -odrefresh
336*e4a36f41SAndroid Build Coastguard Worker  -odsign
337*e4a36f41SAndroid Build Coastguard Worker  # others
338*e4a36f41SAndroid Build Coastguard Worker  -apexd
339*e4a36f41SAndroid Build Coastguard Worker  -init
340*e4a36f41SAndroid Build Coastguard Worker  -vold_prepare_subdirs
341*e4a36f41SAndroid Build Coastguard Worker} apex_art_data_file:file no_w_file_perms;
342*e4a36f41SAndroid Build Coastguard Worker
343*e4a36f41SAndroid Build Coastguard Workerneverallow {
344*e4a36f41SAndroid Build Coastguard Worker  domain
345*e4a36f41SAndroid Build Coastguard Worker  # art-related processes
346*e4a36f41SAndroid Build Coastguard Worker  -composd
347*e4a36f41SAndroid Build Coastguard Worker  -compos_fd_server
348*e4a36f41SAndroid Build Coastguard Worker  -odrefresh
349*e4a36f41SAndroid Build Coastguard Worker  -odsign
350*e4a36f41SAndroid Build Coastguard Worker  # others
351*e4a36f41SAndroid Build Coastguard Worker  -apexd
352*e4a36f41SAndroid Build Coastguard Worker  -init
353*e4a36f41SAndroid Build Coastguard Worker  -vold_prepare_subdirs
354*e4a36f41SAndroid Build Coastguard Worker} apex_art_data_file:dir no_w_dir_perms;
355*e4a36f41SAndroid Build Coastguard Worker
356*e4a36f41SAndroid Build Coastguard Worker# Protect most domains from executing arbitrary content from /data.
357*e4a36f41SAndroid Build Coastguard Workerneverallow {
358*e4a36f41SAndroid Build Coastguard Worker  domain
359*e4a36f41SAndroid Build Coastguard Worker  -appdomain
360*e4a36f41SAndroid Build Coastguard Worker} {
361*e4a36f41SAndroid Build Coastguard Worker  data_file_type
362*e4a36f41SAndroid Build Coastguard Worker  -apex_art_data_file
363*e4a36f41SAndroid Build Coastguard Worker  -dalvikcache_data_file
364*e4a36f41SAndroid Build Coastguard Worker  -system_data_file # shared libs in apks
365*e4a36f41SAndroid Build Coastguard Worker  -apk_data_file
366*e4a36f41SAndroid Build Coastguard Worker}:file no_x_file_perms;
367*e4a36f41SAndroid Build Coastguard Worker
368*e4a36f41SAndroid Build Coastguard Worker# Minimize dac_override and dac_read_search.
369*e4a36f41SAndroid Build Coastguard Worker# Instead of granting them it is usually better to add the domain to
370*e4a36f41SAndroid Build Coastguard Worker# a Unix group or change the permissions of a file.
371*e4a36f41SAndroid Build Coastguard Workerdefine(`dac_override_allowed', `{
372*e4a36f41SAndroid Build Coastguard Worker  apexd
373*e4a36f41SAndroid Build Coastguard Worker  dnsmasq
374*e4a36f41SAndroid Build Coastguard Worker  dumpstate
375*e4a36f41SAndroid Build Coastguard Worker  init
376*e4a36f41SAndroid Build Coastguard Worker  installd
377*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`llkd')
378*e4a36f41SAndroid Build Coastguard Worker  lmkd
379*e4a36f41SAndroid Build Coastguard Worker  migrate_legacy_obb_data
380*e4a36f41SAndroid Build Coastguard Worker  netd
381*e4a36f41SAndroid Build Coastguard Worker  postinstall_dexopt
382*e4a36f41SAndroid Build Coastguard Worker  recovery
383*e4a36f41SAndroid Build Coastguard Worker  rss_hwm_reset
384*e4a36f41SAndroid Build Coastguard Worker  sdcardd
385*e4a36f41SAndroid Build Coastguard Worker  tee
386*e4a36f41SAndroid Build Coastguard Worker  ueventd
387*e4a36f41SAndroid Build Coastguard Worker  uncrypt
388*e4a36f41SAndroid Build Coastguard Worker  vendor_init
389*e4a36f41SAndroid Build Coastguard Worker  vold
390*e4a36f41SAndroid Build Coastguard Worker  vold_prepare_subdirs
391*e4a36f41SAndroid Build Coastguard Worker  zygote
392*e4a36f41SAndroid Build Coastguard Worker}')
393*e4a36f41SAndroid Build Coastguard Workerneverallow ~dac_override_allowed self:global_capability_class_set dac_override;
394*e4a36f41SAndroid Build Coastguard Worker# Since the kernel checks dac_read_search before dac_override, domains that
395*e4a36f41SAndroid Build Coastguard Worker# have dac_override should also have dac_read_search to eliminate spurious
396*e4a36f41SAndroid Build Coastguard Worker# denials.  Some domains have dac_read_search without having dac_override, so
397*e4a36f41SAndroid Build Coastguard Worker# this list should be a superset of the one above.
398*e4a36f41SAndroid Build Coastguard Workerneverallow ~{
399*e4a36f41SAndroid Build Coastguard Worker  dac_override_allowed
400*e4a36f41SAndroid Build Coastguard Worker  iorap_inode2filename
401*e4a36f41SAndroid Build Coastguard Worker  iorap_prefetcherd
402*e4a36f41SAndroid Build Coastguard Worker  traced_perf
403*e4a36f41SAndroid Build Coastguard Worker  traced_probes
404*e4a36f41SAndroid Build Coastguard Worker  heapprofd
405*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set dac_read_search;
406*e4a36f41SAndroid Build Coastguard Worker
407*e4a36f41SAndroid Build Coastguard Worker# Limit what domains can mount filesystems or change their mount flags.
408*e4a36f41SAndroid Build Coastguard Worker# sdcard_type (including vfat and exfat) and fusefs_type are exempt as a larger
409*e4a36f41SAndroid Build Coastguard Worker# set of domains need this capability, including device-specific domains.
410*e4a36f41SAndroid Build Coastguard Workerneverallow {
411*e4a36f41SAndroid Build Coastguard Worker    domain
412*e4a36f41SAndroid Build Coastguard Worker    -apexd
413*e4a36f41SAndroid Build Coastguard Worker    recovery_only(`-fastbootd')
414*e4a36f41SAndroid Build Coastguard Worker    -init
415*e4a36f41SAndroid Build Coastguard Worker    -kernel
416*e4a36f41SAndroid Build Coastguard Worker    -otapreopt_chroot
417*e4a36f41SAndroid Build Coastguard Worker    -recovery
418*e4a36f41SAndroid Build Coastguard Worker    -update_engine
419*e4a36f41SAndroid Build Coastguard Worker    -vold
420*e4a36f41SAndroid Build Coastguard Worker    -zygote
421*e4a36f41SAndroid Build Coastguard Worker} { fs_type
422*e4a36f41SAndroid Build Coastguard Worker    -sdcard_type
423*e4a36f41SAndroid Build Coastguard Worker    -fusefs_type
424*e4a36f41SAndroid Build Coastguard Worker}:filesystem { mount remount relabelfrom relabelto };
425*e4a36f41SAndroid Build Coastguard Worker
426*e4a36f41SAndroid Build Coastguard Workerenforce_debugfs_restriction(`
427*e4a36f41SAndroid Build Coastguard Worker  neverallow {
428*e4a36f41SAndroid Build Coastguard Worker    domain userdebug_or_eng(`-init')
429*e4a36f41SAndroid Build Coastguard Worker  } { debugfs_type -debugfs_tracing_debug }:filesystem { mount remount relabelfrom relabelto };
430*e4a36f41SAndroid Build Coastguard Worker')
431*e4a36f41SAndroid Build Coastguard Worker
432*e4a36f41SAndroid Build Coastguard Worker# Limit raw I/O to these allowlisted domains. Do not apply to debug builds.
433*e4a36f41SAndroid Build Coastguard Workerneverallow {
434*e4a36f41SAndroid Build Coastguard Worker  domain
435*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-domain')
436*e4a36f41SAndroid Build Coastguard Worker  -kernel
437*e4a36f41SAndroid Build Coastguard Worker  -gsid
438*e4a36f41SAndroid Build Coastguard Worker  -init
439*e4a36f41SAndroid Build Coastguard Worker  -recovery
440*e4a36f41SAndroid Build Coastguard Worker  -ueventd
441*e4a36f41SAndroid Build Coastguard Worker  -uncrypt
442*e4a36f41SAndroid Build Coastguard Worker  -tee
443*e4a36f41SAndroid Build Coastguard Worker  -hal_bootctl_server
444*e4a36f41SAndroid Build Coastguard Worker  -fastbootd
445*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set sys_rawio;
446*e4a36f41SAndroid Build Coastguard Worker
447*e4a36f41SAndroid Build Coastguard Worker# Limit directory operations that doesn't need to do app data isolation.
448*e4a36f41SAndroid Build Coastguard Workerneverallow {
449*e4a36f41SAndroid Build Coastguard Worker  domain
450*e4a36f41SAndroid Build Coastguard Worker  -fsck
451*e4a36f41SAndroid Build Coastguard Worker  -init
452*e4a36f41SAndroid Build Coastguard Worker  -installd
453*e4a36f41SAndroid Build Coastguard Worker  -zygote
454*e4a36f41SAndroid Build Coastguard Worker} mirror_data_file:dir *;
455*e4a36f41SAndroid Build Coastguard Worker
456*e4a36f41SAndroid Build Coastguard Worker# This property is being removed. Remove remaining access.
457*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -vendor_init } net_dns_prop:property_service set;
458*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -dumpstate -init -system_server -vendor_init } net_dns_prop:file read;
459*e4a36f41SAndroid Build Coastguard Worker
460*e4a36f41SAndroid Build Coastguard Worker# Only core domains are allowed to access package_manager properties
461*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } pm_prop:property_service set;
462*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -coredomain } pm_prop:file no_rw_file_perms;
463*e4a36f41SAndroid Build Coastguard Worker
464*e4a36f41SAndroid Build Coastguard Worker# Do not allow reading the last boot timestamp from system properties
465*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -dumpstate } firstboot_prop:file r_file_perms;
466*e4a36f41SAndroid Build Coastguard Worker
467*e4a36f41SAndroid Build Coastguard Worker# Kprobes should only be used by adb root
468*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -vendor_init } debugfs_kprobes:file *;
469*e4a36f41SAndroid Build Coastguard Worker
470*e4a36f41SAndroid Build Coastguard Worker# On TREBLE devices, most coredomains should not access vendor_files.
471*e4a36f41SAndroid Build Coastguard Worker# TODO(b/71553434): Remove exceptions here.
472*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
473*e4a36f41SAndroid Build Coastguard Worker  neverallow {
474*e4a36f41SAndroid Build Coastguard Worker    coredomain
475*e4a36f41SAndroid Build Coastguard Worker    -appdomain
476*e4a36f41SAndroid Build Coastguard Worker    -bootanim
477*e4a36f41SAndroid Build Coastguard Worker    -crash_dump
478*e4a36f41SAndroid Build Coastguard Worker    -heapprofd
479*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-profcollectd')
480*e4a36f41SAndroid Build Coastguard Worker    -init
481*e4a36f41SAndroid Build Coastguard Worker    -iorap_inode2filename
482*e4a36f41SAndroid Build Coastguard Worker    -iorap_prefetcherd
483*e4a36f41SAndroid Build Coastguard Worker    -kernel
484*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-simpleperf_boot')
485*e4a36f41SAndroid Build Coastguard Worker    -traced_perf
486*e4a36f41SAndroid Build Coastguard Worker    -ueventd
487*e4a36f41SAndroid Build Coastguard Worker  } vendor_file:file { no_w_file_perms no_x_file_perms open };
488*e4a36f41SAndroid Build Coastguard Worker')
489*e4a36f41SAndroid Build Coastguard Worker
490*e4a36f41SAndroid Build Coastguard Worker# Vendor domains are not permitted to initiate communications to core domain sockets
491*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
492*e4a36f41SAndroid Build Coastguard Worker  neverallow_establish_socket_comms({
493*e4a36f41SAndroid Build Coastguard Worker    domain
494*e4a36f41SAndroid Build Coastguard Worker    -coredomain
495*e4a36f41SAndroid Build Coastguard Worker    -appdomain
496*e4a36f41SAndroid Build Coastguard Worker    -socket_between_core_and_vendor_violators
497*e4a36f41SAndroid Build Coastguard Worker  }, {
498*e4a36f41SAndroid Build Coastguard Worker    coredomain
499*e4a36f41SAndroid Build Coastguard Worker    -logd # Logging by writing to logd Unix domain socket is public API
500*e4a36f41SAndroid Build Coastguard Worker    -netd # netdomain needs this
501*e4a36f41SAndroid Build Coastguard Worker    -mdnsd # netdomain needs this
502*e4a36f41SAndroid Build Coastguard Worker    -prng_seeder # Any process using libcrypto needs this
503*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-su') # communications with su are permitted only on userdebug or eng builds
504*e4a36f41SAndroid Build Coastguard Worker    -init
505*e4a36f41SAndroid Build Coastguard Worker    -tombstoned # linker to tombstoned
506*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-heapprofd')
507*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-traced')
508*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-traced_perf')
509*e4a36f41SAndroid Build Coastguard Worker  });
510*e4a36f41SAndroid Build Coastguard Worker')
511*e4a36f41SAndroid Build Coastguard Worker
512*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(`
513*e4a36f41SAndroid Build Coastguard Worker  # Do not allow system components access to /vendor files except for the
514*e4a36f41SAndroid Build Coastguard Worker  # ones allowed here.
515*e4a36f41SAndroid Build Coastguard Worker  neverallow {
516*e4a36f41SAndroid Build Coastguard Worker    coredomain
517*e4a36f41SAndroid Build Coastguard Worker    # TODO(b/37168747): clean up fwk access to /vendor
518*e4a36f41SAndroid Build Coastguard Worker    -crash_dump
519*e4a36f41SAndroid Build Coastguard Worker    -crosvm # loads vendor-specific disk images
520*e4a36f41SAndroid Build Coastguard Worker    -init # starts vendor executables
521*e4a36f41SAndroid Build Coastguard Worker    -iorap_inode2filename
522*e4a36f41SAndroid Build Coastguard Worker    -iorap_prefetcherd
523*e4a36f41SAndroid Build Coastguard Worker    -kernel # loads /vendor/firmware
524*e4a36f41SAndroid Build Coastguard Worker    -heapprofd
525*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-profcollectd')
526*e4a36f41SAndroid Build Coastguard Worker    -shell
527*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`-simpleperf_boot')
528*e4a36f41SAndroid Build Coastguard Worker    -system_executes_vendor_violators
529*e4a36f41SAndroid Build Coastguard Worker    -traced_perf # library/binary access for symbolization
530*e4a36f41SAndroid Build Coastguard Worker    -ueventd # reads /vendor/ueventd.rc
531*e4a36f41SAndroid Build Coastguard Worker    -vold # loads incremental fs driver
532*e4a36f41SAndroid Build Coastguard Worker  } {
533*e4a36f41SAndroid Build Coastguard Worker    vendor_file_type
534*e4a36f41SAndroid Build Coastguard Worker    -same_process_hal_file
535*e4a36f41SAndroid Build Coastguard Worker    -vendor_app_file
536*e4a36f41SAndroid Build Coastguard Worker    -vendor_apex_file
537*e4a36f41SAndroid Build Coastguard Worker    -vendor_configs_file
538*e4a36f41SAndroid Build Coastguard Worker    -vendor_service_contexts_file
539*e4a36f41SAndroid Build Coastguard Worker    -vendor_framework_file
540*e4a36f41SAndroid Build Coastguard Worker    -vendor_idc_file
541*e4a36f41SAndroid Build Coastguard Worker    -vendor_keychars_file
542*e4a36f41SAndroid Build Coastguard Worker    -vendor_keylayout_file
543*e4a36f41SAndroid Build Coastguard Worker    -vendor_overlay_file
544*e4a36f41SAndroid Build Coastguard Worker    -vendor_public_framework_file
545*e4a36f41SAndroid Build Coastguard Worker    -vendor_public_lib_file
546*e4a36f41SAndroid Build Coastguard Worker    -vendor_task_profiles_file
547*e4a36f41SAndroid Build Coastguard Worker    -vendor_uuid_mapping_config_file
548*e4a36f41SAndroid Build Coastguard Worker    -vndk_sp_file
549*e4a36f41SAndroid Build Coastguard Worker  }:file *;
550*e4a36f41SAndroid Build Coastguard Worker')
551*e4a36f41SAndroid Build Coastguard Worker
552*e4a36f41SAndroid Build Coastguard Worker# mlsvendorcompat is only for compatibility support for older vendor
553*e4a36f41SAndroid Build Coastguard Worker# images, and should not be granted to any domain in current policy.
554*e4a36f41SAndroid Build Coastguard Worker# (Every domain is allowed self:fork, so this will trigger if the
555*e4a36f41SAndroid Build Coastguard Worker# intsersection of domain & mlsvendorcompat is not empty.)
556*e4a36f41SAndroid Build Coastguard Workerneverallow domain mlsvendorcompat:process fork;
557*e4a36f41SAndroid Build Coastguard Worker
558*e4a36f41SAndroid Build Coastguard Worker# Only init and otapreopt_chroot should be mounting filesystems on locations
559*e4a36f41SAndroid Build Coastguard Worker# labeled system or vendor (/product and /vendor respectively).
560*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -otapreopt_chroot } { system_file_type vendor_file_type }:dir_file_class_set mounton;
561*e4a36f41SAndroid Build Coastguard Worker
562*e4a36f41SAndroid Build Coastguard Worker# Only allow init and vendor_init to read/write mm_events properties
563*e4a36f41SAndroid Build Coastguard Worker# NOTE: dumpstate is allowed to read any system property
564*e4a36f41SAndroid Build Coastguard Workerneverallow {
565*e4a36f41SAndroid Build Coastguard Worker  domain
566*e4a36f41SAndroid Build Coastguard Worker  -init
567*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
568*e4a36f41SAndroid Build Coastguard Worker  -dumpstate
569*e4a36f41SAndroid Build Coastguard Worker} mm_events_config_prop:file no_rw_file_perms;
570*e4a36f41SAndroid Build Coastguard Worker
571*e4a36f41SAndroid Build Coastguard Worker# Allow the tracing daemon and callstack sampler to use kallsyms to symbolize
572*e4a36f41SAndroid Build Coastguard Worker# kernel traces. Addresses are not disclosed, they are repalced with symbol
573*e4a36f41SAndroid Build Coastguard Worker# names (if available). Traces don't disclose KASLR.
574*e4a36f41SAndroid Build Coastguard Workerneverallow {
575*e4a36f41SAndroid Build Coastguard Worker  domain
576*e4a36f41SAndroid Build Coastguard Worker  -init
577*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-profcollectd')
578*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
579*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-simpleperf_boot')
580*e4a36f41SAndroid Build Coastguard Worker  -traced_probes
581*e4a36f41SAndroid Build Coastguard Worker  -traced_perf
582*e4a36f41SAndroid Build Coastguard Worker} proc_kallsyms:file { open read };
583*e4a36f41SAndroid Build Coastguard Worker
584*e4a36f41SAndroid Build Coastguard Worker# debugfs_kcov type is not included in this neverallow statement since the KCOV
585*e4a36f41SAndroid Build Coastguard Worker# tool uses it for kernel fuzzing.
586*e4a36f41SAndroid Build Coastguard Worker# vendor_modprobe is also exempted since the kernel modules it loads may create
587*e4a36f41SAndroid Build Coastguard Worker# debugfs files in its context.
588*e4a36f41SAndroid Build Coastguard Workerenforce_debugfs_restriction(`
589*e4a36f41SAndroid Build Coastguard Worker  neverallow {
590*e4a36f41SAndroid Build Coastguard Worker    domain
591*e4a36f41SAndroid Build Coastguard Worker    -vendor_modprobe
592*e4a36f41SAndroid Build Coastguard Worker    userdebug_or_eng(`
593*e4a36f41SAndroid Build Coastguard Worker      -init
594*e4a36f41SAndroid Build Coastguard Worker      -hal_dumpstate
595*e4a36f41SAndroid Build Coastguard Worker    ')
596*e4a36f41SAndroid Build Coastguard Worker  } { debugfs_type
597*e4a36f41SAndroid Build Coastguard Worker      userdebug_or_eng(`-debugfs_kcov')
598*e4a36f41SAndroid Build Coastguard Worker      -tracefs_type
599*e4a36f41SAndroid Build Coastguard Worker  }:file no_rw_file_perms;
600*e4a36f41SAndroid Build Coastguard Worker')
601*e4a36f41SAndroid Build Coastguard Worker
602*e4a36f41SAndroid Build Coastguard Worker# Restrict write access to etm sysfs interface.
603*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -ueventd -vendor_init } sysfs_devices_cs_etm:file no_w_file_perms;
604*e4a36f41SAndroid Build Coastguard Worker
605*e4a36f41SAndroid Build Coastguard Worker# Restrict write access to shell owned files. The /data/local/tmp directory is
606*e4a36f41SAndroid Build Coastguard Worker# untrustworthy, and non-allowed domains should not be trusting any content in
607*e4a36f41SAndroid Build Coastguard Worker# those directories. We allow shell files to be passed around by file
608*e4a36f41SAndroid Build Coastguard Worker# descriptor, but not directly opened.
609*e4a36f41SAndroid Build Coastguard Workerneverallow {
610*e4a36f41SAndroid Build Coastguard Worker  domain
611*e4a36f41SAndroid Build Coastguard Worker  -adbd
612*e4a36f41SAndroid Build Coastguard Worker  -appdomain
613*e4a36f41SAndroid Build Coastguard Worker  -dumpstate
614*e4a36f41SAndroid Build Coastguard Worker  -installd
615*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-uncrypt')
616*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-virtualizationservice')
617*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(`-crosvm')
618*e4a36f41SAndroid Build Coastguard Worker} shell_data_file:file open;
619*e4a36f41SAndroid Build Coastguard Worker
620*e4a36f41SAndroid Build Coastguard Worker# respect system_app sandboxes
621*e4a36f41SAndroid Build Coastguard Workerneverallow {
622*e4a36f41SAndroid Build Coastguard Worker  domain
623*e4a36f41SAndroid Build Coastguard Worker  -appdomain
624*e4a36f41SAndroid Build Coastguard Worker  -system_server #populate com.android.providers.settings/databases/settings.db.
625*e4a36f41SAndroid Build Coastguard Worker  -installd # creation of app sandbox
626*e4a36f41SAndroid Build Coastguard Worker  -iorap_inode2filename
627*e4a36f41SAndroid Build Coastguard Worker  -traced_probes # resolve inodes for i/o tracing.
628*e4a36f41SAndroid Build Coastguard Worker                 # only needs open and read, the rest is neverallow in
629*e4a36f41SAndroid Build Coastguard Worker                 # traced_probes.te.
630*e4a36f41SAndroid Build Coastguard Worker} system_app_data_file:dir_file_class_set { create unlink open };
631*e4a36f41SAndroid Build Coastguard Workerneverallow {
632*e4a36f41SAndroid Build Coastguard Worker  isolated_app
633*e4a36f41SAndroid Build Coastguard Worker  ephemeral_app
634*e4a36f41SAndroid Build Coastguard Worker  priv_app
635*e4a36f41SAndroid Build Coastguard Worker  sdk_sandbox
636*e4a36f41SAndroid Build Coastguard Worker  untrusted_app_all
637*e4a36f41SAndroid Build Coastguard Worker} system_app_data_file:dir_file_class_set { create unlink open };
638