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