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