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