blob: a83e538e3e99eae79ecc6a2b578f0e3f3a794893 [file] [log] [blame]
Alex Klyubinf5446eb2017-03-23 14:27:32 -07001typeattribute init coredomain;
2
dcashmancc39f632016-07-22 13:13:11 -07003tmpfs_domain(init)
4
5# Transitions to seclabel processes in init.rc
dcashmancc39f632016-07-22 13:13:11 -07006domain_trans(init, rootfs, slideshow)
Tao Baoecc7e8c2018-09-07 15:05:33 -07007domain_auto_trans(init, charger_exec, charger)
Jin Qian4de505b2017-05-02 13:45:08 -07008domain_auto_trans(init, e2fs_exec, e2fs)
Joel Fernandes147cf642018-11-29 13:07:40 -08009domain_auto_trans(init, bpfloader_exec, bpfloader)
10
dcashmancc39f632016-07-22 13:13:11 -070011recovery_only(`
Tao Baoecc7e8c2018-09-07 15:05:33 -070012 # Files in recovery image are labeled as rootfs.
Bowgo Tsai5846c792017-07-31 18:38:28 +080013 domain_trans(init, rootfs, adbd)
Kelvin Zhang19a57852022-08-30 00:12:26 +000014 domain_trans(init, rootfs, hal_bootctl_server)
Tao Baoecc7e8c2018-09-07 15:05:33 -070015 domain_trans(init, rootfs, charger)
Jerry Zhang1d85efa2018-05-29 10:54:16 -070016 domain_trans(init, rootfs, fastbootd)
Sandeep Dhavalef0ea9532022-11-08 23:57:09 +000017 domain_trans(init, rootfs, hal_fastboot_server)
Yifan Hong705db2b2021-11-15 18:56:22 -080018 domain_trans(init, rootfs, hal_health_server)
dcashmancc39f632016-07-22 13:13:11 -070019 domain_trans(init, rootfs, recovery)
Kiyoung Kim2c271aa2019-12-09 14:57:46 +090020 domain_trans(init, rootfs, linkerconfig)
Yifan Hongd6b29012021-11-13 00:22:01 -080021 domain_trans(init, rootfs, servicemanager)
David Andersond84b67e2021-02-04 12:30:09 -080022 domain_trans(init, rootfs, snapuserd)
dcashmancc39f632016-07-22 13:13:11 -070023')
24domain_trans(init, shell_exec, shell)
25domain_trans(init, init_exec, ueventd)
Tom Cherry621c24c2017-09-28 14:34:36 -070026domain_trans(init, init_exec, vendor_init)
Sandeep Patile41af202017-06-02 16:09:26 -070027domain_trans(init, { rootfs toolbox_exec }, modprobe)
dcashmancc39f632016-07-22 13:13:11 -070028userdebug_or_eng(`
Tom Cherry938ab052018-08-03 10:49:20 -070029 # case where logpersistd is actually logcat -f in logd context (nee: logcatd)
Mark Salyzynda62cb42016-08-10 11:10:02 -070030 domain_auto_trans(init, logcat_exec, logpersist)
Tom Cherry938ab052018-08-03 10:49:20 -070031
32 # allow init to execute services marked with seclabel u:r:su:s0 in userdebug/eng
33 allow init su:process transition;
34 dontaudit init su:process noatsecure;
35 allow init su:process { siginh rlimitinh };
dcashmancc39f632016-07-22 13:13:11 -070036')
Branden Archerd36b1d52018-11-27 15:47:12 -080037
Nikita Ioffe23ba9762019-12-09 21:21:55 +000038# Allow init to figure out name of dm-device from it's /dev/block/dm-XX path.
39# This is useful in case of remounting ext4 userdata into checkpointing mode,
40# since it potentially requires tearing down dm-devices (e.g. dm-bow, dm-crypto)
41# that userdata is mounted onto.
42allow init sysfs_dm:file read;
43
Bart Van Assche9059e212021-07-29 14:53:51 -070044# Allow init to modify the properties of loop devices.
45allow init sysfs_loop:dir r_dir_perms;
46allow init sysfs_loop:file rw_file_perms;
47
Bart Van Assche60b7d9a2021-10-13 16:21:54 +000048# Allow init to examine the properties of block devices.
Bart Van Assche398b0af2021-10-13 10:56:57 -070049allow init sysfs_type:file { getattr read };
50# Allow init get the attributes of block devices in /dev/block.
51allow init dev_type:dir r_dir_perms;
52allow init dev_type:blk_file getattr;
Bart Van Assche60b7d9a2021-10-13 16:21:54 +000053
Michael Rosenfeld3ccbebb2021-02-10 18:45:35 -080054# Allow init to write to the drop_caches file.
55allow init proc_drop_caches:file rw_file_perms;
56
Branden Archerd36b1d52018-11-27 15:47:12 -080057# Allow the BoringSSL self test to request a reboot upon failure
58set_prop(init, powerctl_prop)
Nikita Ioffe7065e462019-11-14 12:59:15 +000059
Nikita Ioffe7065e462019-11-14 12:59:15 +000060set_prop(init, userspace_reboot_exported_prop)
Ryan Savitski52b3d312020-01-14 18:20:06 +000061
62# Second-stage init performs a test for whether the kernel has SELinux hooks
63# for the perf_event_open() syscall. This is done by testing for the syscall
64# outcomes corresponding to this policy.
65# TODO(b/137092007): this can be removed once the platform stops supporting
66# kernels that precede the perf_event_open hooks (Android common kernels 4.4
67# and 4.9).
68allow init self:perf_event { open cpu };
Alistair Delva178f0ac2020-06-05 10:15:30 -070069allow init self:global_capability2_class_set perfmon;
Ryan Savitski52b3d312020-01-14 18:20:06 +000070
David Anderson0c0c13a2020-10-30 00:12:22 -070071# Allow init to communicate with snapuserd to transition Virtual A/B devices
72# from the first-stage daemon to the second-stage.
73allow init snapuserd_socket:sock_file write;
74allow init snapuserd:unix_stream_socket connectto;
75# Allow for libsnapshot's use of flock() on /metadata/ota.
76allow init ota_metadata_file:dir lock;
77
Jooyung Hanb62be122021-04-12 21:44:43 +090078# Allow init to restore contexts of vd_device(/dev/block/vd[..]) when labeling
79# /dev/block.
80allow init vd_device:blk_file relabelto;
81
Ryan Savitski52b3d312020-01-14 18:20:06 +000082set_prop(init, init_perf_lsm_hooks_prop)
Inseob Kim212e2b62020-07-14 02:10:37 +090083set_prop(init, vts_status_prop)
Alexander Potapenko3d528172021-03-02 16:46:50 +010084
85# Allow accessing /sys/kernel/tracing/instances/bootreceiver to set up tracing.
86allow init debugfs_bootreceiver_tracing:file w_file_perms;
Andrew Walbrana995e842021-03-29 17:19:12 +000087
Pete Bentleye6da3b82022-09-16 15:31:39 +010088# PRNG seeder daemon socket is created and listened on by init before forking.
89allow init prng_seeder:unix_stream_socket { create bind listen };
90
Kalesh Singhfab8e1c2021-11-04 20:47:29 -070091# Devices with kernels where CONFIG_HIST_TRIGGERS isn't enabled will
92# attempt to write a non exisiting 'synthetic_events' file, when setting
93# up synthetic events. This is a no-op in tracefs.
94dontaudit init debugfs_tracing_debug:dir { write add_name };
95
Andrew Walbrana995e842021-03-29 17:19:12 +000096# chown/chmod on devices.
97allow init {
98 dev_type
99 -hw_random_device
100 -keychord_device
Elliot Bermanae5869a2023-03-22 17:31:35 -0700101 -vm_manager_device_type
Andrew Walbrana995e842021-03-29 17:19:12 +0000102 -port_device
103}:chr_file setattr;
Inseob Kim75806ef2024-03-27 17:18:41 +0900104
105# /dev/__null__ node created by init.
106allow init tmpfs:chr_file { create setattr unlink rw_file_perms };
107
108#
109# init direct restorecon calls.
110#
111# /dev/kmsg
112allow init tmpfs:chr_file relabelfrom;
113allow init kmsg_device:chr_file { getattr write relabelto };
114# /dev/kmsg_debug
115userdebug_or_eng(`
116 allow init kmsg_debug_device:chr_file { open write relabelto };
117')
118
119# allow init to mount and unmount debugfs in debug builds
120userdebug_or_eng(`
121 allow init debugfs:dir mounton;
122')
123
124# /dev/__properties__
125allow init properties_device:dir relabelto;
126allow init properties_serial:file { write relabelto };
127allow init property_type:file { append create getattr map open read relabelto rename setattr unlink write };
128# /dev/__properties__/property_info and /dev/__properties/appcompat_override/property_info
129allow init properties_device:file create_file_perms;
130allow init property_info:file relabelto;
131# /dev/event-log-tags
132allow init device:file relabelfrom;
133allow init runtime_event_log_tags_file:file { open write setattr relabelto create };
134# /dev/socket
135allow init { device socket_device dm_user_device }:dir relabelto;
136# allow init to establish connection and communicate with lmkd
137unix_socket_connect(init, lmkd, lmkd)
138# Relabel /dev nodes created in first stage init: /dev/console, /dev/null, /dev/ptmx, /dev/random
139# and /dev/urandom
140allow init { console_device null_device ptmx_device random_device } : chr_file relabelto;
141# /dev/device-mapper, /dev/block(/.*)?
142allow init tmpfs:{ chr_file blk_file } relabelfrom;
143allow init tmpfs:blk_file getattr;
144allow init block_device:{ dir blk_file lnk_file } relabelto;
145allow init dm_device:{ chr_file blk_file } relabelto;
146allow init dm_user_device:chr_file relabelto;
147allow init kernel:fd use;
148# restorecon for early mount device symlinks
149allow init tmpfs:lnk_file { getattr read relabelfrom };
150allow init {
151 metadata_block_device
152 misc_block_device
153 recovery_block_device
154 system_block_device
155 userdata_block_device
156}:{ blk_file lnk_file } relabelto;
157
158allow init dtbo_block_device:lnk_file relabelto;
159allow init super_block_device:lnk_file relabelto;
160
161# Create /mnt/sdcard -> /storage/self/primary symlink.
162allow init mnt_sdcard_file:lnk_file create;
163
164# setrlimit
165allow init self:global_capability_class_set sys_resource;
166
167# Remove /dev/.booting and load /debug_ramdisk/* files
168allow init tmpfs:file { getattr unlink };
169
170# Access pty created for fsck.
171allow init devpts:chr_file { read write open };
172
173# Create /dev/fscklogs files.
174allow init fscklogs:file create_file_perms;
175
176# Access /dev/__null__ node created prior to initial policy load.
177allow init tmpfs:chr_file write;
178
179# Access /dev/console.
180allow init console_device:chr_file rw_file_perms;
181
182# Access /dev/tty0.
183allow init tty_device:chr_file rw_file_perms;
184
185# Call mount(2).
186allow init self:global_capability_class_set sys_admin;
187
188# Call setns(2).
189allow init self:global_capability_class_set sys_chroot;
190
191# Create and mount on directories in /.
192allow init rootfs:dir create_dir_perms;
193allow init {
194 rootfs
195 cache_file
196 cgroup
197 linkerconfig_file
198 storage_file
199 mnt_user_file
200 system_data_file
201 system_data_root_file
202 system_dlkm_file
203 system_file
204 vendor_file
205 postinstall_mnt_dir
206 mirror_data_file
207 shell_data_file
208}:dir mounton;
209
210# Mount bpf fs on sys/fs/bpf
211allow init fs_bpf:dir mounton;
212
213# Mount on /dev/usb-ffs/adb.
214allow init device:dir mounton;
215
216# Mount tmpfs on /apex
217allow init apex_mnt_dir:dir mounton;
218
219# Bind-mount on /system/apex/com.android.art
220allow init art_apex_dir:dir mounton;
221
222# Create and remove symlinks in /.
223allow init rootfs:lnk_file { create unlink };
224
225# Mount debugfs on /sys/kernel/debug.
226allow init sysfs:dir mounton;
227
228# Create cgroups mount points in tmpfs and mount cgroups on them.
229allow init tmpfs:dir create_dir_perms;
230allow init tmpfs:dir mounton;
231allow init cgroup:dir create_dir_perms;
232allow init cgroup:file rw_file_perms;
233allow init cgroup_rc_file:file rw_file_perms;
234allow init cgroup_desc_file:file r_file_perms;
235allow init cgroup_desc_api_file:file r_file_perms;
236allow init vendor_cgroup_desc_file:file r_file_perms;
237allow init cgroup_v2:dir { mounton create_dir_perms};
238allow init cgroup_v2:file rw_file_perms;
239
240# /config
241allow init configfs:dir mounton;
242allow init configfs:dir create_dir_perms;
243allow init configfs:{ file lnk_file } create_file_perms;
244
245# /metadata
246allow init metadata_file:dir mounton;
247
248# Run restorecon on /dev
249allow init tmpfs:dir relabelfrom;
250
251# Create directories under /dev/cpuctl after chowning it to system.
252allow init self:global_capability_class_set { dac_override dac_read_search };
253
254# Set system clock.
255allow init self:global_capability_class_set sys_time;
256
257allow init self:global_capability_class_set { sys_rawio mknod };
258
259# Mounting filesystems from block devices.
260allow init dev_type:blk_file r_file_perms;
261allowxperm init dev_type:blk_file ioctl BLKROSET;
262allowxperm init system_data_root_file:dir ioctl F2FS_IOC_SHUTDOWN;
263
264# Mounting filesystems.
265# Only allow relabelto for types used in context= mount options,
266# which should all be assigned the contextmount_type attribute.
267# This can be done in device-specific policy via type or typeattribute
268# declarations.
269allow init {
270 fs_type
271 enforce_debugfs_restriction(`-debugfs_type')
272}:filesystem ~relabelto;
273
274# Allow init to mount/unmount debugfs in non-user builds.
275enforce_debugfs_restriction(`
276 userdebug_or_eng(`allow init debugfs_type:filesystem { mount unmount };')
277')
278
279# Allow init to mount tracefs in /sys/kernel/tracing
280allow init debugfs_tracing_debug:filesystem mount;
281
282allow init unlabeled:filesystem ~relabelto;
283allow init contextmount_type:filesystem relabelto;
284
285# Allow read-only access to context= mounted filesystems.
286allow init contextmount_type:dir r_dir_perms;
287allow init contextmount_type:notdevfile_class_set r_file_perms;
288
289# restorecon /adb_keys or any other rootfs files and directories to a more
290# specific type.
291allow init rootfs:{ dir file } relabelfrom;
292
293# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
294# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
295# system/core/init.rc requires at least cache_file and data_file_type.
296# init.<board>.rc files often include device-specific types, so
297# we just allow all file types except /system files here.
298allow init self:global_capability_class_set { chown fowner fsetid };
299
300allow init {
301 file_type
302 -app_data_file
303 -bpffs_type
304 -exec_type
305 -misc_logd_file
306 -nativetest_data_file
307 -privapp_data_file
308 -system_app_data_file
309 -system_dlkm_file_type
310 -system_file_type
311 -vendor_file_type
312}:dir { create search getattr open read setattr ioctl };
313
314allow init {
315 file_type
316 -app_data_file
317 -bpffs_type
318 -credstore_data_file
319 -exec_type
320 -keystore_data_file
321 -media_userdir_file
322 -misc_logd_file
323 -nativetest_data_file
324 -privapp_data_file
325 -shell_data_file
326 -system_app_data_file
327 -system_dlkm_file_type
328 -system_file_type
329 -system_userdir_file
330 -vendor_file_type
331 -vendor_userdir_file
332 -vold_data_file
333}:dir { write add_name remove_name rmdir relabelfrom };
334
335allow init {
336 file_type
337 -apex_info_file
338 -app_data_file
339 -bpffs_type
340 -exec_type
341 -gsi_data_file
342 -credstore_data_file
343 -keystore_data_file
344 -misc_logd_file
345 -nativetest_data_file
346 -privapp_data_file
347 -runtime_event_log_tags_file
348 -shell_data_file
349 -system_app_data_file
350 -system_dlkm_file_type
351 -system_file_type
352 -vendor_file_type
353 -vold_data_file
354 enforce_debugfs_restriction(`-debugfs_type')
355}:file { create getattr open read write setattr relabelfrom unlink map };
356
357allow init tracefs_type:file { create_file_perms relabelfrom };
358
359# Allow init to read /apex/apex-info-list.xml for preinstalled paths of APEXes to determine
360# subcontext for action/service defined in APEXes.
361allow init apex_info_file:file r_file_perms;
362
363allow init {
364 file_type
365 -app_data_file
366 -bpffs_type
367 -exec_type
368 -gsi_data_file
369 -credstore_data_file
370 -keystore_data_file
371 -misc_logd_file
372 -nativetest_data_file
373 -privapp_data_file
374 -shell_data_file
375 -system_app_data_file
376 -system_dlkm_file_type
377 -system_file_type
378 -vendor_file_type
379 -vold_data_file
380}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
381
382allow init {
383 file_type
384 -apex_mnt_dir
385 -app_data_file
386 -bpffs_type
387 -exec_type
388 -gsi_data_file
389 -credstore_data_file
390 -keystore_data_file
391 -misc_logd_file
392 -nativetest_data_file
393 -privapp_data_file
394 -shell_data_file
395 -system_app_data_file
396 -system_dlkm_file_type
397 -system_file_type
398 -vendor_file_type
399 -vold_data_file
400}:lnk_file { create getattr setattr relabelfrom unlink };
401
402allow init cache_file:lnk_file r_file_perms;
403
404allow init {
405 file_type
406 -bpffs_type
407 -system_dlkm_file_type
408 -system_file_type
409 -vendor_file_type
410 -exec_type
411 -app_data_file
412 -privapp_data_file
413}:dir_file_class_set relabelto;
414
415allow init { sysfs no_debugfs_restriction(`debugfs') debugfs_tracing debugfs_tracing_debug }:{ dir file lnk_file } { getattr relabelfrom };
416allow init { sysfs_type no_debugfs_restriction(`debugfs_type') tracefs_type }:{ dir file lnk_file } { relabelto getattr };
417allow init dev_type:dir create_dir_perms;
418allow init dev_type:lnk_file create;
419
420# Disable tracing by writing to /sys/kernel/debug/tracing/tracing_on
421allow init debugfs_tracing:file w_file_perms;
422
423# Setup and control wifi event tracing (see wifi-events.rc)
424allow init debugfs_tracing_instances:dir create_dir_perms;
425allow init debugfs_tracing_instances:file w_file_perms;
426allow init debugfs_wifi_tracing:file w_file_perms;
427
428# chown/chmod on pseudo files.
429allow init {
430 fs_type
431 -bpffs_type
432 -contextmount_type
433 -keychord_device
434 -proc_type
435 -sdcard_type
436 -fusefs_type
437 -sysfs_type
438 -rootfs
439 enforce_debugfs_restriction(`-debugfs_type')
440}:file { open read setattr };
441allow init {
442 fs_type
443 -bpffs_type
444 -contextmount_type
445 -sdcard_type
446 -fusefs_type
447 -rootfs
448}:dir { open read setattr search };
449
450allow init {
451 binder_device
452 console_device
453 devpts
454 dm_device
455 hwbinder_device
456 input_device
457 kmsg_device
458 null_device
459 owntty_device
460 pmsg_device
461 ptmx_device
462 random_device
463 tty_device
464 zero_device
465}:chr_file { read open };
466
467# Unlabeled file access for upgrades from 4.2.
468allow init unlabeled:dir { create_dir_perms relabelfrom };
469allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
470
471# Any operation that can modify the kernel ring buffer, e.g. clear
472# or a read that consumes the messages that were read.
473allow init kernel:system syslog_mod;
474allow init self:global_capability2_class_set syslog;
475
476# init access to /proc.
477r_dir_file(init, proc_net_type)
478allow init proc_filesystems:file r_file_perms;
479
480userdebug_or_eng(`
481 # Overlayfs workdir write access check during mount to permit remount,rw
482 allow init overlayfs_file:dir { relabelfrom mounton write };
483 allow init overlayfs_file:file { append rename };
484 allow init overlayfs_file:chr_file unlink;
485 allow init system_block_device:blk_file { write };
486')
487
488allow init {
489 proc # b/67049235 processes /proc/<pid>/* files are mislabeled.
490 proc_bootconfig
491 proc_cmdline
492 proc_diskstats
493 proc_kmsg # Open /proc/kmsg for logd service.
494 proc_meminfo
495 proc_stat # Read /proc/stat for bootchart.
496 proc_uptime
497 proc_version
498}:file r_file_perms;
499
500allow init {
501 proc_abi
502 proc_cpu_alignment
503 proc_dirty
504 proc_hostname
505 proc_hung_task
506 proc_extra_free_kbytes
507 proc_net_type
508 proc_max_map_count
509 proc_min_free_order_shift
510 proc_overcommit_memory # /proc/sys/vm/overcommit_memory
511 proc_panic
512 proc_page_cluster
513 proc_perf
514 proc_sched
515 proc_sysrq
516 proc_watermark_boost_factor
517}:file w_file_perms;
518
519allow init {
520 proc_security
521}:file rw_file_perms;
522
523# init chmod/chown access to /proc files.
524allow init {
525 proc_cmdline
526 proc_bootconfig
527 proc_kmsg
528 proc_net
529 proc_pagetypeinfo
530 proc_qtaguid_stat
531 proc_slabinfo
532 proc_sysrq
533 proc_qtaguid_ctrl
534 proc_vmallocinfo
535}:file setattr;
536
537# init access to /sys files.
538allow init {
539 sysfs_android_usb
540 sysfs_dm_verity
541 sysfs_leds
542 sysfs_power
543 sysfs_fs_f2fs
544 sysfs_dm
545 sysfs_lru_gen_enabled
546}:file w_file_perms;
547
548allow init {
549 sysfs_dt_firmware_android
550 sysfs_fs_ext4_features
551}:file r_file_perms;
552
553allow init {
554 sysfs_zram
555}:file rw_file_perms;
556
557# allow init to create loop devices with /dev/loop-control
558allow init loop_control_device:chr_file rw_file_perms;
559allow init loop_device:blk_file rw_file_perms;
560allowxperm init loop_device:blk_file ioctl {
561 LOOP_SET_FD
562 LOOP_CLR_FD
563 LOOP_CTL_GET_FREE
564 LOOP_SET_BLOCK_SIZE
565 LOOP_SET_DIRECT_IO
566 LOOP_GET_STATUS
567 LOOP_SET_STATUS64
568};
569
570# Allow init to write to vibrator/trigger
571allow init sysfs_vibrator:file w_file_perms;
572
573# init chmod/chown access to /sys files.
574allow init {
575 sysfs_android_usb
576 sysfs_devices_system_cpu
577 sysfs_ipv4
578 sysfs_leds
579 sysfs_lowmemorykiller
580 sysfs_power
581 sysfs_vibrator
582 sysfs_wake_lock
583 sysfs_zram
584}:file setattr;
585
586# Set usermodehelpers.
587allow init { usermodehelper sysfs_usermodehelper }:file rw_file_perms;
588
589allow init self:global_capability_class_set net_admin;
590
591# Reboot.
592allow init self:global_capability_class_set sys_boot;
593
594# Init will create /data/misc/logd when the property persist.logd.logpersistd is "logcatd".
595# Init will also walk through the directory as part of a recursive restorecon.
596allow init misc_logd_file:dir { add_name open create read getattr setattr search write };
597allow init misc_logd_file:file { open create getattr setattr write };
598
599# Support "adb shell stop"
600allow init self:global_capability_class_set kill;
601allow init domain:process { getpgid sigkill signal };
602
603# Init creates credstore's directory on boot, and walks through
604# the directory as part of a recursive restorecon.
605allow init credstore_data_file:dir { open create read getattr setattr search };
606allow init credstore_data_file:file { getattr };
607
608# Init creates keystore's directory on boot, and walks through
609# the directory as part of a recursive restorecon.
610allow init keystore_data_file:dir { open create read getattr setattr search };
611allow init keystore_data_file:file { getattr };
612
613# Init creates vold's directory on boot, and walks through
614# the directory as part of a recursive restorecon.
615allow init vold_data_file:dir { open create read getattr setattr search };
616allow init vold_data_file:file { getattr };
617
618# Init creates /data/local/tmp at boot
619allow init shell_data_file:dir { open create read getattr setattr search };
620allow init shell_data_file:file { getattr };
621
622# Set UID, GID, and adjust capability bounding set for services.
623allow init self:global_capability_class_set { setuid setgid setpcap };
624
625# For bootchart to read the /proc/$pid/cmdline file of each process,
626# we need to have following line to allow init to have access
627# to different domains.
628r_dir_file(init, domain)
629
630# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
631# setexec is for services with seclabel options.
632# setfscreate is for labeling directories and socket files.
633# setsockcreate is for labeling local/unix domain sockets.
634allow init self:process { setexec setfscreate setsockcreate };
635
636# Get file context
637allow init file_contexts_file:file r_file_perms;
638
639# sepolicy access
640allow init sepolicy_file:file r_file_perms;
641
642# Perform SELinux access checks on setting properties.
643selinux_check_access(init)
644
645# Ask the kernel for the new context on services to label their sockets.
646allow init kernel:security compute_create;
647
648# Create sockets for the services.
649allow init domain:unix_stream_socket { create bind setopt };
650allow init domain:unix_dgram_socket { create bind setopt };
651
652# Create /data/property and files within it.
653allow init property_data_file:dir create_dir_perms;
654allow init property_data_file:file create_file_perms;
655
656# Set any property.
657allow init property_type:property_service set;
658
659# Send an SELinux userspace denial to the kernel audit subsystem,
660# so it can be picked up and processed by logd. These denials are
661# generated when an attempt to set a property is denied by policy.
662allow init self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_relay };
663allow init self:global_capability_class_set audit_write;
664
665# Run "ifup lo" to bring up the localhost interface
666allow init self:udp_socket { create ioctl };
667# in addition to unpriv ioctls granted to all domains, init also needs:
668allowxperm init self:udp_socket ioctl SIOCSIFFLAGS;
669allow init self:global_capability_class_set net_raw;
670
671# Set scheduling info for psi monitor thread.
672# TODO: delete or revise this line b/131761776
673allow init kernel:process { getsched setsched };
674
675# swapon() needs write access to swap device
676# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
677allow init swap_block_device:blk_file rw_file_perms;
678
679# Create and access /dev files without a specific type,
680# e.g. /dev/.coldboot_done, /dev/.booting
681# TODO: Move these files into their own type unless they are
682# only ever accessed by init.
683allow init device:file create_file_perms;
684
685# keychord retrieval from /dev/input/ devices
686allow init input_device:dir r_dir_perms;
687allow init input_device:chr_file rw_file_perms;
688
689# Access device mapper for setting up dm-verity
690allow init dm_device:chr_file rw_file_perms;
691allow init dm_device:blk_file rw_file_perms;
692
693# Access dm-user for OTA boot
694allow init dm_user_device:chr_file rw_file_perms;
695
696# Access metadata block device for storing dm-verity state
697allow init metadata_block_device:blk_file rw_file_perms;
698
699# Read /sys/fs/pstore/console-ramoops to detect restarts caused
700# by dm-verity detecting corrupted blocks
701allow init pstorefs:dir search;
702allow init pstorefs:file r_file_perms;
703allow init kernel:system syslog_read;
704
705# linux keyring configuration
706allow init init:key { write search setattr };
707
708# Allow init to create /data/unencrypted
709allow init unencrypted_data_file:dir create_dir_perms;
710
711# Set encryption policy on dirs in /data
712allowxperm init { data_file_type unlabeled }:dir ioctl {
713 FS_IOC_GET_ENCRYPTION_POLICY
714 FS_IOC_SET_ENCRYPTION_POLICY
715};
716
717# Raw writes to misc block device
718allow init misc_block_device:blk_file w_file_perms;
719
720r_dir_file(init, system_file)
721r_dir_file(init, system_dlkm_file_type)
722r_dir_file(init, vendor_file_type)
723
724allow init system_data_file:file { getattr read };
725allow init system_data_file:lnk_file r_file_perms;
726
727# For init to be able to run shell scripts from vendor
728allow init vendor_shell_exec:file execute;
729
730# Metadata setup
731allow init vold_metadata_file:dir create_dir_perms;
732allow init vold_metadata_file:file getattr;
733allow init metadata_bootstat_file:dir create_dir_perms;
734allow init metadata_bootstat_file:file w_file_perms;
735allow init userspace_reboot_metadata_file:file w_file_perms;
736
737# Allow init to touch PSI monitors
738allow init proc_pressure_mem:file { rw_file_perms setattr };
739
740# init is using bootstrap bionic
741use_bootstrap_libs(init)
742
743# stat the root dir of fuse filesystems (for the mount handler)
744allow init fuse:dir { search getattr };
745
746# allow filesystem tuning
747allow init userdata_sysdev:file create_file_perms;
748
749# allow disk tuning
750allow init rootdisk_sysdev:file create_file_perms;
751
752###
753### neverallow rules
754###
755
756# The init domain is only entered via an exec based transition from the
757# kernel domain, never via setcon().
758neverallow domain init:process dyntransition;
759neverallow { domain -kernel } init:process transition;
760neverallow init { file_type fs_type -init_exec }:file entrypoint;
761
762# Never read/follow symlinks created by shell or untrusted apps.
763neverallow init shell_data_file:lnk_file read;
764neverallow init app_data_file_type:lnk_file read;
765
766# init should never execute a program without changing to another domain.
767neverallow init { file_type fs_type }:file execute_no_trans;
768
769# The use of sensitive environment variables, such as LD_PRELOAD, is disallowed
770# when init is executing other binaries. The use of LD_PRELOAD for init spawned
771# services is generally considered a no-no, as it injects libraries which the
772# binary was not expecting. This is especially problematic for APEXes. The use
773# of LD_PRELOAD via APEXes is a layering violation, and inappropriately loads
774# code into a process which wasn't expecting that code, with potentially
775# unexpected side effects. (b/140789528)
776neverallow init *:process noatsecure;
777
778# init can never add binder services
779neverallow init service_manager_type:service_manager { add find };
780# init can never list binder services
781neverallow init servicemanager:service_manager list;
782
783# Init should not be creating subdirectories in /data/local/tmp
784neverallow init shell_data_file:dir { write add_name remove_name };
785
786# Init should not access sysfs node that are not explicitly labeled.
787neverallow init sysfs:file { open write };
788
789# No domain should be allowed to ptrace init.
790neverallow * init:process ptrace;
791
792# init owns the root of /data
793# TODO(b/140259336) We want to remove vendor_init
794# TODO(b/141108496) We want to remove toolbox
795neverallow { domain -init -toolbox -vendor_init -vold } system_data_root_file:dir { write add_name remove_name };
796
797# Only init is allowed to set userspace reboot related properties.
798neverallow { domain -init } userspace_reboot_exported_prop:property_service set;
799
800neverallow init self:perf_event { kernel tracepoint read write };
801dontaudit init self:perf_event { kernel tracepoint read write };
802
803# Only init is allowed to set the sysprop indicating whether perf_event_open()
804# SELinux hooks were detected.
805neverallow { domain -init } init_perf_lsm_hooks_prop:property_service set;
806
807# Only init can write vts.native_server.on
808neverallow { domain -init } vts_status_prop:property_service set;
809
810# Only init can write normal ro.boot. properties
811neverallow { domain -init } bootloader_prop:property_service set;
812
813# Only init can write hal.instrumentation.enable
814neverallow { domain -init } hal_instrumentation_prop:property_service set;
815
816# Only init can write ro.property_service.version
817neverallow { domain -init } property_service_version_prop:property_service set;
818
819# Only init can set keystore.boot_level
820neverallow { domain -init } keystore_listen_prop:property_service set;