blob: cdcf0b96136cf3d5117c9c419de9c488b23d1433 [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
Kalesh Singhf3fb64a2024-08-28 16:53:37 +000085# Allow init to set 16kb app compatibility props
86set_prop(init, bionic_linker_16kb_app_compat_prop)
87
Akilesh Kailashdd8c0902024-11-11 15:49:46 -080088# Allow init to set/get prefetch boot prop to initiate record/replay
89set_prop(init, ctl_prefetch_prop);
90get_prop(init, prefetch_boot_prop);
91
Alexander Potapenko3d528172021-03-02 16:46:50 +010092# Allow accessing /sys/kernel/tracing/instances/bootreceiver to set up tracing.
93allow init debugfs_bootreceiver_tracing:file w_file_perms;
Andrew Walbrana995e842021-03-29 17:19:12 +000094
Pete Bentleye6da3b82022-09-16 15:31:39 +010095# PRNG seeder daemon socket is created and listened on by init before forking.
96allow init prng_seeder:unix_stream_socket { create bind listen };
97
Kalesh Singhfab8e1c2021-11-04 20:47:29 -070098# Devices with kernels where CONFIG_HIST_TRIGGERS isn't enabled will
99# attempt to write a non exisiting 'synthetic_events' file, when setting
100# up synthetic events. This is a no-op in tracefs.
101dontaudit init debugfs_tracing_debug:dir { write add_name };
102
Andrew Walbrana995e842021-03-29 17:19:12 +0000103# chown/chmod on devices.
104allow init {
105 dev_type
106 -hw_random_device
107 -keychord_device
Elliot Bermanae5869a2023-03-22 17:31:35 -0700108 -vm_manager_device_type
Andrew Walbrana995e842021-03-29 17:19:12 +0000109 -port_device
110}:chr_file setattr;
Inseob Kim75806ef2024-03-27 17:18:41 +0900111
112# /dev/__null__ node created by init.
113allow init tmpfs:chr_file { create setattr unlink rw_file_perms };
114
115#
116# init direct restorecon calls.
117#
118# /dev/kmsg
119allow init tmpfs:chr_file relabelfrom;
120allow init kmsg_device:chr_file { getattr write relabelto };
121# /dev/kmsg_debug
122userdebug_or_eng(`
123 allow init kmsg_debug_device:chr_file { open write relabelto };
124')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900125# /mnt/vm, also permissions to mkdir / mount / chmod / chown
126allow init vm_data_file:dir { add_name create search write getattr setattr relabelto mounton };
Inseob Kim75806ef2024-03-27 17:18:41 +0900127
128# allow init to mount and unmount debugfs in debug builds
129userdebug_or_eng(`
130 allow init debugfs:dir mounton;
131')
132
133# /dev/__properties__
134allow init properties_device:dir relabelto;
135allow init properties_serial:file { write relabelto };
136allow init property_type:file { append create getattr map open read relabelto rename setattr unlink write };
137# /dev/__properties__/property_info and /dev/__properties/appcompat_override/property_info
138allow init properties_device:file create_file_perms;
139allow init property_info:file relabelto;
140# /dev/event-log-tags
141allow init device:file relabelfrom;
142allow init runtime_event_log_tags_file:file { open write setattr relabelto create };
143# /dev/socket
144allow init { device socket_device dm_user_device }:dir relabelto;
145# allow init to establish connection and communicate with lmkd
146unix_socket_connect(init, lmkd, lmkd)
147# Relabel /dev nodes created in first stage init: /dev/console, /dev/null, /dev/ptmx, /dev/random
148# and /dev/urandom
149allow init { console_device null_device ptmx_device random_device } : chr_file relabelto;
150# /dev/device-mapper, /dev/block(/.*)?
151allow init tmpfs:{ chr_file blk_file } relabelfrom;
152allow init tmpfs:blk_file getattr;
153allow init block_device:{ dir blk_file lnk_file } relabelto;
154allow init dm_device:{ chr_file blk_file } relabelto;
155allow init dm_user_device:chr_file relabelto;
156allow init kernel:fd use;
157# restorecon for early mount device symlinks
158allow init tmpfs:lnk_file { getattr read relabelfrom };
159allow init {
160 metadata_block_device
161 misc_block_device
162 recovery_block_device
163 system_block_device
164 userdata_block_device
165}:{ blk_file lnk_file } relabelto;
166
167allow init dtbo_block_device:lnk_file relabelto;
168allow init super_block_device:lnk_file relabelto;
169
170# Create /mnt/sdcard -> /storage/self/primary symlink.
171allow init mnt_sdcard_file:lnk_file create;
172
173# setrlimit
174allow init self:global_capability_class_set sys_resource;
175
176# Remove /dev/.booting and load /debug_ramdisk/* files
177allow init tmpfs:file { getattr unlink };
178
179# Access pty created for fsck.
180allow init devpts:chr_file { read write open };
181
182# Create /dev/fscklogs files.
183allow init fscklogs:file create_file_perms;
184
185# Access /dev/__null__ node created prior to initial policy load.
186allow init tmpfs:chr_file write;
187
188# Access /dev/console.
189allow init console_device:chr_file rw_file_perms;
190
191# Access /dev/tty0.
192allow init tty_device:chr_file rw_file_perms;
193
194# Call mount(2).
195allow init self:global_capability_class_set sys_admin;
196
197# Call setns(2).
198allow init self:global_capability_class_set sys_chroot;
199
200# Create and mount on directories in /.
201allow init rootfs:dir create_dir_perms;
202allow init {
203 rootfs
204 cache_file
205 cgroup
206 linkerconfig_file
207 storage_file
208 mnt_user_file
209 system_data_file
210 system_data_root_file
211 system_dlkm_file
212 system_file
213 vendor_file
214 postinstall_mnt_dir
215 mirror_data_file
216 shell_data_file
217}:dir mounton;
218
219# Mount bpf fs on sys/fs/bpf
220allow init fs_bpf:dir mounton;
221
222# Mount on /dev/usb-ffs/adb.
223allow init device:dir mounton;
224
225# Mount tmpfs on /apex
226allow init apex_mnt_dir:dir mounton;
227
228# Bind-mount on /system/apex/com.android.art
229allow init art_apex_dir:dir mounton;
230
231# Create and remove symlinks in /.
232allow init rootfs:lnk_file { create unlink };
233
234# Mount debugfs on /sys/kernel/debug.
235allow init sysfs:dir mounton;
236
237# Create cgroups mount points in tmpfs and mount cgroups on them.
238allow init tmpfs:dir create_dir_perms;
239allow init tmpfs:dir mounton;
240allow init cgroup:dir create_dir_perms;
241allow init cgroup:file rw_file_perms;
242allow init cgroup_rc_file:file rw_file_perms;
243allow init cgroup_desc_file:file r_file_perms;
Inseob Kim75806ef2024-03-27 17:18:41 +0900244allow init vendor_cgroup_desc_file:file r_file_perms;
245allow init cgroup_v2:dir { mounton create_dir_perms};
246allow init cgroup_v2:file rw_file_perms;
247
248# /config
249allow init configfs:dir mounton;
250allow init configfs:dir create_dir_perms;
251allow init configfs:{ file lnk_file } create_file_perms;
252
253# /metadata
254allow init metadata_file:dir mounton;
255
256# Run restorecon on /dev
257allow init tmpfs:dir relabelfrom;
258
259# Create directories under /dev/cpuctl after chowning it to system.
260allow init self:global_capability_class_set { dac_override dac_read_search };
261
262# Set system clock.
263allow init self:global_capability_class_set sys_time;
264
265allow init self:global_capability_class_set { sys_rawio mknod };
266
267# Mounting filesystems from block devices.
268allow init dev_type:blk_file r_file_perms;
269allowxperm init dev_type:blk_file ioctl BLKROSET;
270allowxperm init system_data_root_file:dir ioctl F2FS_IOC_SHUTDOWN;
271
272# Mounting filesystems.
273# Only allow relabelto for types used in context= mount options,
274# which should all be assigned the contextmount_type attribute.
275# This can be done in device-specific policy via type or typeattribute
276# declarations.
277allow init {
278 fs_type
279 enforce_debugfs_restriction(`-debugfs_type')
280}:filesystem ~relabelto;
281
282# Allow init to mount/unmount debugfs in non-user builds.
283enforce_debugfs_restriction(`
284 userdebug_or_eng(`allow init debugfs_type:filesystem { mount unmount };')
285')
286
287# Allow init to mount tracefs in /sys/kernel/tracing
288allow init debugfs_tracing_debug:filesystem mount;
289
290allow init unlabeled:filesystem ~relabelto;
291allow init contextmount_type:filesystem relabelto;
292
293# Allow read-only access to context= mounted filesystems.
294allow init contextmount_type:dir r_dir_perms;
295allow init contextmount_type:notdevfile_class_set r_file_perms;
296
297# restorecon /adb_keys or any other rootfs files and directories to a more
298# specific type.
299allow init rootfs:{ dir file } relabelfrom;
300
301# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
302# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
303# system/core/init.rc requires at least cache_file and data_file_type.
304# init.<board>.rc files often include device-specific types, so
305# we just allow all file types except /system files here.
306allow init self:global_capability_class_set { chown fowner fsetid };
307
308allow init {
309 file_type
310 -app_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000311 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
312 -storage_area_dir
313 -storage_area_app_dir
314 -storage_area_content_file
315 ')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900316 -vm_data_file
Inseob Kim75806ef2024-03-27 17:18:41 +0900317 -bpffs_type
318 -exec_type
319 -misc_logd_file
320 -nativetest_data_file
321 -privapp_data_file
322 -system_app_data_file
323 -system_dlkm_file_type
324 -system_file_type
325 -vendor_file_type
326}:dir { create search getattr open read setattr ioctl };
327
328allow init {
329 file_type
330 -app_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000331 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
332 -storage_area_dir
333 -storage_area_app_dir
334 -storage_area_content_file
335 ')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900336 -vm_data_file
Inseob Kim75806ef2024-03-27 17:18:41 +0900337 -bpffs_type
338 -credstore_data_file
339 -exec_type
340 -keystore_data_file
341 -media_userdir_file
342 -misc_logd_file
343 -nativetest_data_file
344 -privapp_data_file
345 -shell_data_file
346 -system_app_data_file
347 -system_dlkm_file_type
348 -system_file_type
349 -system_userdir_file
350 -vendor_file_type
351 -vendor_userdir_file
352 -vold_data_file
353}:dir { write add_name remove_name rmdir relabelfrom };
354
355allow init {
356 file_type
357 -apex_info_file
358 -app_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000359 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
360 -storage_area_dir
361 -storage_area_app_dir
362 -storage_area_content_file
363 ')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900364 -vm_data_file
Inseob Kim75806ef2024-03-27 17:18:41 +0900365 -bpffs_type
366 -exec_type
367 -gsi_data_file
368 -credstore_data_file
369 -keystore_data_file
370 -misc_logd_file
371 -nativetest_data_file
372 -privapp_data_file
373 -runtime_event_log_tags_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 enforce_debugfs_restriction(`-debugfs_type')
381}:file { create getattr open read write setattr relabelfrom unlink map };
382
383allow init tracefs_type:file { create_file_perms relabelfrom };
384
385# Allow init to read /apex/apex-info-list.xml for preinstalled paths of APEXes to determine
386# subcontext for action/service defined in APEXes.
387allow init apex_info_file:file r_file_perms;
388
389allow init {
390 file_type
391 -app_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000392 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
393 -storage_area_dir
394 -storage_area_app_dir
395 -storage_area_content_file
396 ')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900397 -vm_data_file
Inseob Kim75806ef2024-03-27 17:18:41 +0900398 -bpffs_type
399 -exec_type
400 -gsi_data_file
401 -credstore_data_file
402 -keystore_data_file
403 -misc_logd_file
404 -nativetest_data_file
405 -privapp_data_file
406 -shell_data_file
407 -system_app_data_file
408 -system_dlkm_file_type
409 -system_file_type
410 -vendor_file_type
411 -vold_data_file
412}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
413
414allow init {
415 file_type
416 -apex_mnt_dir
417 -app_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000418 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
419 -storage_area_dir
420 -storage_area_app_dir
421 -storage_area_content_file
422 ')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900423 -vm_data_file
Inseob Kim75806ef2024-03-27 17:18:41 +0900424 -bpffs_type
425 -exec_type
426 -gsi_data_file
427 -credstore_data_file
428 -keystore_data_file
429 -misc_logd_file
430 -nativetest_data_file
431 -privapp_data_file
432 -shell_data_file
433 -system_app_data_file
434 -system_dlkm_file_type
435 -system_file_type
436 -vendor_file_type
437 -vold_data_file
438}:lnk_file { create getattr setattr relabelfrom unlink };
439
440allow init cache_file:lnk_file r_file_perms;
441
442allow init {
443 file_type
444 -bpffs_type
445 -system_dlkm_file_type
446 -system_file_type
447 -vendor_file_type
448 -exec_type
449 -app_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000450 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
451 -storage_area_dir
452 -storage_area_app_dir
453 -storage_area_content_file
454 ')
Inseob Kim0b9625d2024-07-31 17:42:23 +0900455 -vm_data_file
Inseob Kim75806ef2024-03-27 17:18:41 +0900456 -privapp_data_file
457}:dir_file_class_set relabelto;
458
459allow init { sysfs no_debugfs_restriction(`debugfs') debugfs_tracing debugfs_tracing_debug }:{ dir file lnk_file } { getattr relabelfrom };
460allow init { sysfs_type no_debugfs_restriction(`debugfs_type') tracefs_type }:{ dir file lnk_file } { relabelto getattr };
461allow init dev_type:dir create_dir_perms;
462allow init dev_type:lnk_file create;
463
464# Disable tracing by writing to /sys/kernel/debug/tracing/tracing_on
465allow init debugfs_tracing:file w_file_perms;
466
467# Setup and control wifi event tracing (see wifi-events.rc)
468allow init debugfs_tracing_instances:dir create_dir_perms;
469allow init debugfs_tracing_instances:file w_file_perms;
470allow init debugfs_wifi_tracing:file w_file_perms;
Nate Jiang3ea355c2024-06-06 00:29:46 +0000471allow init debugfs_wifi_tracing:dir create_dir_perms;
Inseob Kim75806ef2024-03-27 17:18:41 +0900472
473# chown/chmod on pseudo files.
474allow init {
475 fs_type
476 -bpffs_type
477 -contextmount_type
478 -keychord_device
479 -proc_type
480 -sdcard_type
481 -fusefs_type
482 -sysfs_type
483 -rootfs
484 enforce_debugfs_restriction(`-debugfs_type')
485}:file { open read setattr };
486allow init {
487 fs_type
488 -bpffs_type
489 -contextmount_type
490 -sdcard_type
491 -fusefs_type
492 -rootfs
493}:dir { open read setattr search };
494
495allow init {
496 binder_device
497 console_device
498 devpts
499 dm_device
500 hwbinder_device
501 input_device
502 kmsg_device
503 null_device
504 owntty_device
505 pmsg_device
506 ptmx_device
507 random_device
508 tty_device
509 zero_device
510}:chr_file { read open };
511
512# Unlabeled file access for upgrades from 4.2.
513allow init unlabeled:dir { create_dir_perms relabelfrom };
514allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
515
516# Any operation that can modify the kernel ring buffer, e.g. clear
517# or a read that consumes the messages that were read.
518allow init kernel:system syslog_mod;
519allow init self:global_capability2_class_set syslog;
520
521# init access to /proc.
522r_dir_file(init, proc_net_type)
523allow init proc_filesystems:file r_file_perms;
524
525userdebug_or_eng(`
526 # Overlayfs workdir write access check during mount to permit remount,rw
527 allow init overlayfs_file:dir { relabelfrom mounton write };
528 allow init overlayfs_file:file { append rename };
529 allow init overlayfs_file:chr_file unlink;
530 allow init system_block_device:blk_file { write };
531')
532
533allow init {
534 proc # b/67049235 processes /proc/<pid>/* files are mislabeled.
535 proc_bootconfig
536 proc_cmdline
537 proc_diskstats
538 proc_kmsg # Open /proc/kmsg for logd service.
539 proc_meminfo
540 proc_stat # Read /proc/stat for bootchart.
541 proc_uptime
542 proc_version
543}:file r_file_perms;
544
545allow init {
546 proc_abi
547 proc_cpu_alignment
548 proc_dirty
549 proc_hostname
550 proc_hung_task
551 proc_extra_free_kbytes
552 proc_net_type
553 proc_max_map_count
554 proc_min_free_order_shift
555 proc_overcommit_memory # /proc/sys/vm/overcommit_memory
556 proc_panic
557 proc_page_cluster
558 proc_perf
559 proc_sched
560 proc_sysrq
561 proc_watermark_boost_factor
562}:file w_file_perms;
563
564allow init {
565 proc_security
566}:file rw_file_perms;
567
568# init chmod/chown access to /proc files.
569allow init {
570 proc_cmdline
571 proc_bootconfig
572 proc_kmsg
573 proc_net
574 proc_pagetypeinfo
Bart Searsdbca6252024-08-04 23:06:24 +0000575 proc_qtaguid_stat
Inseob Kim75806ef2024-03-27 17:18:41 +0900576 proc_slabinfo
577 proc_sysrq
Bart Searsdbca6252024-08-04 23:06:24 +0000578 proc_qtaguid_ctrl
Inseob Kim75806ef2024-03-27 17:18:41 +0900579 proc_vmallocinfo
580}:file setattr;
581
582# init access to /sys files.
583allow init {
584 sysfs_android_usb
585 sysfs_dm_verity
586 sysfs_leds
587 sysfs_power
588 sysfs_fs_f2fs
589 sysfs_dm
590 sysfs_lru_gen_enabled
Kalesh Singh3a4c68d2024-04-09 16:24:48 -0700591 sysfs_pgsize_migration
Inseob Kim75806ef2024-03-27 17:18:41 +0900592}:file w_file_perms;
593
594allow init {
595 sysfs_dt_firmware_android
596 sysfs_fs_ext4_features
597}:file r_file_perms;
598
599allow init {
600 sysfs_zram
601}:file rw_file_perms;
602
603# allow init to create loop devices with /dev/loop-control
604allow init loop_control_device:chr_file rw_file_perms;
605allow init loop_device:blk_file rw_file_perms;
606allowxperm init loop_device:blk_file ioctl {
607 LOOP_SET_FD
608 LOOP_CLR_FD
609 LOOP_CTL_GET_FREE
610 LOOP_SET_BLOCK_SIZE
611 LOOP_SET_DIRECT_IO
612 LOOP_GET_STATUS
613 LOOP_SET_STATUS64
614};
615
616# Allow init to write to vibrator/trigger
617allow init sysfs_vibrator:file w_file_perms;
618
619# init chmod/chown access to /sys files.
620allow init {
621 sysfs_android_usb
622 sysfs_devices_system_cpu
Rob Barnesf0945b62024-10-30 22:24:21 +0000623 sysfs_firmware_acpi_tables
Inseob Kim75806ef2024-03-27 17:18:41 +0900624 sysfs_ipv4
625 sysfs_leds
626 sysfs_lowmemorykiller
627 sysfs_power
628 sysfs_vibrator
629 sysfs_wake_lock
630 sysfs_zram
631}:file setattr;
632
633# Set usermodehelpers.
634allow init { usermodehelper sysfs_usermodehelper }:file rw_file_perms;
635
636allow init self:global_capability_class_set net_admin;
637
638# Reboot.
639allow init self:global_capability_class_set sys_boot;
640
641# Init will create /data/misc/logd when the property persist.logd.logpersistd is "logcatd".
642# Init will also walk through the directory as part of a recursive restorecon.
643allow init misc_logd_file:dir { add_name open create read getattr setattr search write };
644allow init misc_logd_file:file { open create getattr setattr write };
645
646# Support "adb shell stop"
647allow init self:global_capability_class_set kill;
648allow init domain:process { getpgid sigkill signal };
649
650# Init creates credstore's directory on boot, and walks through
651# the directory as part of a recursive restorecon.
652allow init credstore_data_file:dir { open create read getattr setattr search };
653allow init credstore_data_file:file { getattr };
654
655# Init creates keystore's directory on boot, and walks through
656# the directory as part of a recursive restorecon.
657allow init keystore_data_file:dir { open create read getattr setattr search };
658allow init keystore_data_file:file { getattr };
659
660# Init creates vold's directory on boot, and walks through
661# the directory as part of a recursive restorecon.
662allow init vold_data_file:dir { open create read getattr setattr search };
663allow init vold_data_file:file { getattr };
664
665# Init creates /data/local/tmp at boot
666allow init shell_data_file:dir { open create read getattr setattr search };
667allow init shell_data_file:file { getattr };
668
669# Set UID, GID, and adjust capability bounding set for services.
670allow init self:global_capability_class_set { setuid setgid setpcap };
671
672# For bootchart to read the /proc/$pid/cmdline file of each process,
673# we need to have following line to allow init to have access
674# to different domains.
675r_dir_file(init, domain)
676
677# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
678# setexec is for services with seclabel options.
679# setfscreate is for labeling directories and socket files.
680# setsockcreate is for labeling local/unix domain sockets.
681allow init self:process { setexec setfscreate setsockcreate };
682
683# Get file context
684allow init file_contexts_file:file r_file_perms;
685
686# sepolicy access
687allow init sepolicy_file:file r_file_perms;
688
689# Perform SELinux access checks on setting properties.
690selinux_check_access(init)
691
692# Ask the kernel for the new context on services to label their sockets.
693allow init kernel:security compute_create;
694
695# Create sockets for the services.
696allow init domain:unix_stream_socket { create bind setopt };
697allow init domain:unix_dgram_socket { create bind setopt };
698
699# Create /data/property and files within it.
700allow init property_data_file:dir create_dir_perms;
701allow init property_data_file:file create_file_perms;
702
703# Set any property.
704allow init property_type:property_service set;
705
706# Send an SELinux userspace denial to the kernel audit subsystem,
707# so it can be picked up and processed by logd. These denials are
708# generated when an attempt to set a property is denied by policy.
ThiƩbaud Weksteen5bc9bb82024-09-20 16:45:52 +1000709allow init self:netlink_audit_socket create_socket_perms_no_ioctl;
710
711# For kernel < 6.13
712allow init self:netlink_audit_socket nlmsg_relay;
713# For kernel >= 6.13
714allow init self:netlink_audit_socket nlmsg;
715allowxperm init self:netlink_audit_socket nlmsg AUDIT_USER_AVC;
716
Inseob Kim75806ef2024-03-27 17:18:41 +0900717allow init self:global_capability_class_set audit_write;
718
719# Run "ifup lo" to bring up the localhost interface
720allow init self:udp_socket { create ioctl };
721# in addition to unpriv ioctls granted to all domains, init also needs:
722allowxperm init self:udp_socket ioctl SIOCSIFFLAGS;
723allow init self:global_capability_class_set net_raw;
724
725# Set scheduling info for psi monitor thread.
726# TODO: delete or revise this line b/131761776
727allow init kernel:process { getsched setsched };
728
729# swapon() needs write access to swap device
730# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
731allow init swap_block_device:blk_file rw_file_perms;
732
733# Create and access /dev files without a specific type,
734# e.g. /dev/.coldboot_done, /dev/.booting
735# TODO: Move these files into their own type unless they are
736# only ever accessed by init.
737allow init device:file create_file_perms;
738
739# keychord retrieval from /dev/input/ devices
740allow init input_device:dir r_dir_perms;
741allow init input_device:chr_file rw_file_perms;
742
743# Access device mapper for setting up dm-verity
744allow init dm_device:chr_file rw_file_perms;
745allow init dm_device:blk_file rw_file_perms;
746
747# Access dm-user for OTA boot
748allow init dm_user_device:chr_file rw_file_perms;
749
750# Access metadata block device for storing dm-verity state
751allow init metadata_block_device:blk_file rw_file_perms;
752
753# Read /sys/fs/pstore/console-ramoops to detect restarts caused
754# by dm-verity detecting corrupted blocks
755allow init pstorefs:dir search;
756allow init pstorefs:file r_file_perms;
757allow init kernel:system syslog_read;
758
759# linux keyring configuration
760allow init init:key { write search setattr };
761
762# Allow init to create /data/unencrypted
763allow init unencrypted_data_file:dir create_dir_perms;
764
765# Set encryption policy on dirs in /data
766allowxperm init { data_file_type unlabeled }:dir ioctl {
767 FS_IOC_GET_ENCRYPTION_POLICY
768 FS_IOC_SET_ENCRYPTION_POLICY
769};
770
771# Raw writes to misc block device
772allow init misc_block_device:blk_file w_file_perms;
773
774r_dir_file(init, system_file)
775r_dir_file(init, system_dlkm_file_type)
776r_dir_file(init, vendor_file_type)
777
778allow init system_data_file:file { getattr read };
779allow init system_data_file:lnk_file r_file_perms;
780
781# For init to be able to run shell scripts from vendor
782allow init vendor_shell_exec:file execute;
783
784# Metadata setup
785allow init vold_metadata_file:dir create_dir_perms;
786allow init vold_metadata_file:file getattr;
787allow init metadata_bootstat_file:dir create_dir_perms;
788allow init metadata_bootstat_file:file w_file_perms;
789allow init userspace_reboot_metadata_file:file w_file_perms;
790
791# Allow init to touch PSI monitors
792allow init proc_pressure_mem:file { rw_file_perms setattr };
793
794# init is using bootstrap bionic
795use_bootstrap_libs(init)
796
797# stat the root dir of fuse filesystems (for the mount handler)
798allow init fuse:dir { search getattr };
799
800# allow filesystem tuning
801allow init userdata_sysdev:file create_file_perms;
802
803# allow disk tuning
804allow init rootdisk_sysdev:file create_file_perms;
805
806###
807### neverallow rules
808###
809
810# The init domain is only entered via an exec based transition from the
811# kernel domain, never via setcon().
812neverallow domain init:process dyntransition;
813neverallow { domain -kernel } init:process transition;
814neverallow init { file_type fs_type -init_exec }:file entrypoint;
815
816# Never read/follow symlinks created by shell or untrusted apps.
817neverallow init shell_data_file:lnk_file read;
818neverallow init app_data_file_type:lnk_file read;
819
820# init should never execute a program without changing to another domain.
821neverallow init { file_type fs_type }:file execute_no_trans;
822
823# The use of sensitive environment variables, such as LD_PRELOAD, is disallowed
824# when init is executing other binaries. The use of LD_PRELOAD for init spawned
825# services is generally considered a no-no, as it injects libraries which the
826# binary was not expecting. This is especially problematic for APEXes. The use
827# of LD_PRELOAD via APEXes is a layering violation, and inappropriately loads
828# code into a process which wasn't expecting that code, with potentially
829# unexpected side effects. (b/140789528)
830neverallow init *:process noatsecure;
831
832# init can never add binder services
833neverallow init service_manager_type:service_manager { add find };
834# init can never list binder services
835neverallow init servicemanager:service_manager list;
836
837# Init should not be creating subdirectories in /data/local/tmp
838neverallow init shell_data_file:dir { write add_name remove_name };
839
840# Init should not access sysfs node that are not explicitly labeled.
841neverallow init sysfs:file { open write };
842
843# No domain should be allowed to ptrace init.
844neverallow * init:process ptrace;
845
846# init owns the root of /data
847# TODO(b/140259336) We want to remove vendor_init
848# TODO(b/141108496) We want to remove toolbox
849neverallow { domain -init -toolbox -vendor_init -vold } system_data_root_file:dir { write add_name remove_name };
850
851# Only init is allowed to set userspace reboot related properties.
852neverallow { domain -init } userspace_reboot_exported_prop:property_service set;
853
854neverallow init self:perf_event { kernel tracepoint read write };
855dontaudit init self:perf_event { kernel tracepoint read write };
856
857# Only init is allowed to set the sysprop indicating whether perf_event_open()
858# SELinux hooks were detected.
859neverallow { domain -init } init_perf_lsm_hooks_prop:property_service set;
860
861# Only init can write vts.native_server.on
862neverallow { domain -init } vts_status_prop:property_service set;
863
864# Only init can write normal ro.boot. properties
865neverallow { domain -init } bootloader_prop:property_service set;
866
867# Only init can write hal.instrumentation.enable
868neverallow { domain -init } hal_instrumentation_prop:property_service set;
869
870# Only init can write ro.property_service.version
871neverallow { domain -init } property_service_version_prop:property_service set;
872
873# Only init can set keystore.boot_level
874neverallow { domain -init } keystore_listen_prop:property_service set;