blob: 9d3a2c380f2e6526b17f0b03566a3c5a0bb535b1 [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
60# Only init is allowed to set userspace reboot related properties.
Nikita Ioffe7065e462019-11-14 12:59:15 +000061set_prop(init, userspace_reboot_exported_prop)
Nikita Ioffe7065e462019-11-14 12:59:15 +000062neverallow { domain -init } userspace_reboot_exported_prop:property_service set;
Ryan Savitski52b3d312020-01-14 18:20:06 +000063
64# Second-stage init performs a test for whether the kernel has SELinux hooks
65# for the perf_event_open() syscall. This is done by testing for the syscall
66# outcomes corresponding to this policy.
67# TODO(b/137092007): this can be removed once the platform stops supporting
68# kernels that precede the perf_event_open hooks (Android common kernels 4.4
69# and 4.9).
70allow init self:perf_event { open cpu };
Alistair Delva178f0ac2020-06-05 10:15:30 -070071allow init self:global_capability2_class_set perfmon;
Ryan Savitski52b3d312020-01-14 18:20:06 +000072neverallow init self:perf_event { kernel tracepoint read write };
73dontaudit init self:perf_event { kernel tracepoint read write };
74
David Anderson0c0c13a2020-10-30 00:12:22 -070075# Allow init to communicate with snapuserd to transition Virtual A/B devices
76# from the first-stage daemon to the second-stage.
77allow init snapuserd_socket:sock_file write;
78allow init snapuserd:unix_stream_socket connectto;
79# Allow for libsnapshot's use of flock() on /metadata/ota.
80allow init ota_metadata_file:dir lock;
81
Jooyung Hanb62be122021-04-12 21:44:43 +090082# Allow init to restore contexts of vd_device(/dev/block/vd[..]) when labeling
83# /dev/block.
84allow init vd_device:blk_file relabelto;
85
Ryan Savitski52b3d312020-01-14 18:20:06 +000086# Only init is allowed to set the sysprop indicating whether perf_event_open()
87# SELinux hooks were detected.
88set_prop(init, init_perf_lsm_hooks_prop)
89neverallow { domain -init } init_perf_lsm_hooks_prop:property_service set;
Inseob Kim212e2b62020-07-14 02:10:37 +090090
91# Only init can write vts.native_server.on
92set_prop(init, vts_status_prop)
Inseob Kim85acf6e2021-03-10 10:42:23 +090093neverallow { domain -init } vts_status_prop:property_service set;
Inseob Kim8c342472020-07-23 17:54:35 +090094
95# Only init can write normal ro.boot. properties
Inseob Kim85acf6e2021-03-10 10:42:23 +090096neverallow { domain -init } bootloader_prop:property_service set;
Inseob Kim40c67b22020-07-25 00:34:56 +090097
98# Only init can write hal.instrumentation.enable
Inseob Kim85acf6e2021-03-10 10:42:23 +090099neverallow { domain -init } hal_instrumentation_prop:property_service set;
Inseob Kim40c67b22020-07-25 00:34:56 +0900100
101# Only init can write ro.property_service.version
Inseob Kim85acf6e2021-03-10 10:42:23 +0900102neverallow { domain -init } property_service_version_prop:property_service set;
Paul Crowleyb0c55712021-02-23 08:40:05 -0800103
104# Only init can set keystore.boot_level
Inseob Kim85acf6e2021-03-10 10:42:23 +0900105neverallow { domain -init } keystore_listen_prop:property_service set;
Alexander Potapenko3d528172021-03-02 16:46:50 +0100106
107# Allow accessing /sys/kernel/tracing/instances/bootreceiver to set up tracing.
108allow init debugfs_bootreceiver_tracing:file w_file_perms;
Andrew Walbrana995e842021-03-29 17:19:12 +0000109
Pete Bentleye6da3b82022-09-16 15:31:39 +0100110# PRNG seeder daemon socket is created and listened on by init before forking.
111allow init prng_seeder:unix_stream_socket { create bind listen };
112
Kalesh Singhfab8e1c2021-11-04 20:47:29 -0700113# Devices with kernels where CONFIG_HIST_TRIGGERS isn't enabled will
114# attempt to write a non exisiting 'synthetic_events' file, when setting
115# up synthetic events. This is a no-op in tracefs.
116dontaudit init debugfs_tracing_debug:dir { write add_name };
117
Andrew Walbrana995e842021-03-29 17:19:12 +0000118# chown/chmod on devices.
119allow init {
120 dev_type
121 -hw_random_device
122 -keychord_device
Elliot Bermanae5869a2023-03-22 17:31:35 -0700123 -vm_manager_device_type
Andrew Walbrana995e842021-03-29 17:19:12 +0000124 -port_device
125}:chr_file setattr;