1# vendor_init is its own domain. 2type vendor_init, domain, mlstrustedsubject; 3 4# Communication to the main init process 5allow vendor_init init:unix_stream_socket { read write }; 6 7# Logging to kmsg 8allow vendor_init kmsg_device:chr_file { open getattr write }; 9 10# Mount on /dev/usb-ffs/adb. 11allow vendor_init device:dir mounton; 12 13# Create and remove symlinks in /. 14allow vendor_init rootfs:lnk_file { create unlink }; 15 16# Create cgroups mount points in tmpfs and mount cgroups on them. 17allow vendor_init cgroup:dir create_dir_perms; 18allow vendor_init cgroup:file w_file_perms; 19allow vendor_init cgroup_v2:dir create_dir_perms; 20allow vendor_init cgroup_v2:file w_file_perms; 21 22# /config 23allow vendor_init configfs:dir mounton; 24allow vendor_init configfs:dir create_dir_perms; 25allow vendor_init configfs:{ file lnk_file } create_file_perms; 26 27# Create directories under /dev/cpuctl after chowning it to system. 28allow vendor_init self:global_capability_class_set { dac_override dac_read_search }; 29 30# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files. 31# chown/chmod require open+read+setattr required for open()+fchown/fchmod(). 32# system/core/init.rc requires at least cache_file and data_file_type. 33# init.<board>.rc files often include device-specific types, so 34# we just allow all file types except /system files here. 35allow vendor_init self:global_capability_class_set { chown fowner fsetid }; 36 37# mkdir with FBE requires reading /data/unencrypted/{ref,mode}. 38allow vendor_init unencrypted_data_file:dir search; 39allow vendor_init unencrypted_data_file:file r_file_perms; 40 41# Set encryption policy on dirs in /data 42allowxperm vendor_init data_file_type:dir ioctl { 43 FS_IOC_GET_ENCRYPTION_POLICY 44 FS_IOC_SET_ENCRYPTION_POLICY 45}; 46 47allow vendor_init system_data_file:dir getattr; 48 49allow vendor_init { 50 file_type 51 -core_data_file_type 52 -exec_type 53 -system_file_type 54 -mnt_product_file 55 -password_slot_metadata_file 56 -ota_metadata_file 57 -unlabeled 58 -vendor_file_type 59 -vold_metadata_file 60 -gsi_metadata_file_type 61 -apex_metadata_file 62 -userspace_reboot_metadata_file 63}:dir { create search getattr open read setattr ioctl write add_name remove_name rmdir relabelfrom }; 64 65allow vendor_init unlabeled:{ dir notdevfile_class_set } { getattr relabelfrom }; 66 67allow vendor_init { 68 file_type 69 -core_data_file_type 70 -exec_type 71 -password_slot_metadata_file 72 -ota_metadata_file 73 -runtime_event_log_tags_file 74 -system_file_type 75 -unlabeled 76 -vendor_file_type 77 -vold_metadata_file 78 -gsi_metadata_file_type 79 -apex_metadata_file 80 -apex_info_file 81 -userspace_reboot_metadata_file 82 enforce_debugfs_restriction(`-debugfs_type') 83}:file { create getattr open read write setattr relabelfrom unlink map }; 84 85allow vendor_init { 86 file_type 87 -core_data_file_type 88 -exec_type 89 -password_slot_metadata_file 90 -ota_metadata_file 91 -system_file_type 92 -unlabeled 93 -vendor_file_type 94 -vold_metadata_file 95 -gsi_metadata_file_type 96 -apex_metadata_file 97 -userspace_reboot_metadata_file 98}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink }; 99 100allow vendor_init { 101 file_type 102 -apex_mnt_dir 103 -core_data_file_type 104 -exec_type 105 -password_slot_metadata_file 106 -ota_metadata_file 107 -system_file_type 108 -unlabeled 109 -vendor_file_type 110 -vold_metadata_file 111 -gsi_metadata_file_type 112 -apex_metadata_file 113 -userspace_reboot_metadata_file 114}:lnk_file { create getattr setattr relabelfrom unlink }; 115 116allow vendor_init { 117 file_type 118 -core_data_file_type 119 -exec_type 120 -mnt_product_file 121 -password_slot_metadata_file 122 -ota_metadata_file 123 -system_file_type 124 -vendor_file_type 125 -vold_metadata_file 126 -gsi_metadata_file_type 127 -apex_metadata_file 128 -userspace_reboot_metadata_file 129}:dir_file_class_set relabelto; 130 131allow vendor_init dev_type:dir create_dir_perms; 132allow vendor_init dev_type:lnk_file create; 133 134# Disable tracing by writing to /sys/kernel/debug/tracing/tracing_on 135allow vendor_init debugfs_tracing:file w_file_perms; 136 137# chown/chmod on pseudo files. 138allow vendor_init { 139 fs_type 140 -contextmount_type 141 -keychord_device 142 -sdcard_type 143 -rootfs 144 -proc_uid_time_in_state 145 -proc_uid_concurrent_active_time 146 -proc_uid_concurrent_policy_time 147 enforce_debugfs_restriction(`-debugfs_type') 148}:file { open read setattr map }; 149 150allow vendor_init tracefs_type:file { open read setattr map }; 151 152allow vendor_init { 153 fs_type 154 -contextmount_type 155 -sdcard_type 156 -rootfs 157 -proc_uid_time_in_state 158 -proc_uid_concurrent_active_time 159 -proc_uid_concurrent_policy_time 160}:dir { open read setattr search }; 161 162allow vendor_init dev_type:blk_file getattr; 163 164# Write to /proc/sys/net/ping_group_range and other /proc/sys/net files. 165r_dir_file(vendor_init, proc_net_type) 166allow vendor_init proc_net_type:file w_file_perms; 167allow vendor_init self:global_capability_class_set net_admin; 168 169# Write to /proc/sys/vm/page-cluster 170allow vendor_init proc_page_cluster:file w_file_perms; 171 172# Write to sysfs nodes. 173allow vendor_init sysfs_type:dir r_dir_perms; 174allow vendor_init sysfs_type:lnk_file read; 175allow vendor_init { sysfs_type -sysfs_usermodehelper }:file rw_file_perms; 176 177# setfscreatecon() for labeling directories and socket files. 178allow vendor_init self:process { setfscreate }; 179 180r_dir_file(vendor_init, vendor_file_type) 181 182# Vendor init can read properties 183allow vendor_init serialno_prop:file { getattr open read map }; 184 185# Vendor init can perform operations on trusted and security Extended Attributes 186allow vendor_init self:global_capability_class_set sys_admin; 187 188# Raw writes to misc block device 189allow vendor_init misc_block_device:blk_file w_file_perms; 190 191# vendor_init is using bootstrap bionic 192allow vendor_init system_bootstrap_lib_file:dir r_dir_perms; 193allow vendor_init system_bootstrap_lib_file:file { execute read open getattr map }; 194 195# allow filesystem tuning 196allow vendor_init userdata_sysdev:file create_file_perms; 197 198# Everything is labeled as rootfs in recovery mode. Vendor init has to execute 199# the dynamic linker and shared libraries. 200recovery_only(` 201 allow vendor_init rootfs:file { r_file_perms execute }; 202') 203 204not_compatible_property(` 205 set_prop(vendor_init, { 206 property_type 207 -system_internal_property_type 208 -system_restricted_property_type 209 }) 210') 211 212# Get file context 213allow vendor_init file_contexts_file:file r_file_perms; 214 215# Allow vendor_init to (re)set nice 216allow vendor_init self:capability sys_nice; 217 218set_prop(vendor_init, apk_verity_prop) 219set_prop(vendor_init, bluetooth_a2dp_offload_prop) 220set_prop(vendor_init, bluetooth_audio_hal_prop) 221set_prop(vendor_init, camera2_extensions_prop) 222set_prop(vendor_init, camerax_extensions_prop) 223set_prop(vendor_init, cpu_variant_prop) 224set_prop(vendor_init, dalvik_runtime_prop) 225set_prop(vendor_init, debug_prop) 226set_prop(vendor_init, exported_bluetooth_prop) 227set_prop(vendor_init, exported_camera_prop) 228set_prop(vendor_init, exported_config_prop) 229set_prop(vendor_init, exported_default_prop) 230set_prop(vendor_init, exported_overlay_prop) 231set_prop(vendor_init, exported_pm_prop) 232set_prop(vendor_init, ffs_control_prop) 233set_prop(vendor_init, hw_timeout_multiplier_prop) 234set_prop(vendor_init, incremental_prop) 235set_prop(vendor_init, lmkd_prop) 236set_prop(vendor_init, logd_prop) 237set_prop(vendor_init, log_tag_prop) 238set_prop(vendor_init, log_prop) 239set_prop(vendor_init, qemu_hw_prop) 240set_prop(vendor_init, radio_control_prop) 241set_prop(vendor_init, rebootescrow_hal_prop) 242set_prop(vendor_init, serialno_prop) 243set_prop(vendor_init, soc_prop) 244set_prop(vendor_init, surfaceflinger_color_prop) 245set_prop(vendor_init, usb_control_prop) 246set_prop(vendor_init, userspace_reboot_config_prop) 247set_prop(vendor_init, vehicle_hal_prop) 248set_prop(vendor_init, vendor_default_prop) 249set_prop(vendor_init, vendor_security_patch_level_prop) 250set_prop(vendor_init, vndk_prop) 251set_prop(vendor_init, virtual_ab_prop) 252set_prop(vendor_init, vold_post_fs_data_prop) 253set_prop(vendor_init, wifi_hal_prop) 254set_prop(vendor_init, wifi_log_prop) 255set_prop(vendor_init, zram_control_prop) 256 257get_prop(vendor_init, boot_status_prop) 258get_prop(vendor_init, exported3_system_prop) 259get_prop(vendor_init, ota_prop) 260get_prop(vendor_init, power_debug_prop) 261get_prop(vendor_init, provisioned_prop) 262get_prop(vendor_init, retaildemo_prop) 263get_prop(vendor_init, surfaceflinger_display_prop) 264get_prop(vendor_init, test_harness_prop) 265get_prop(vendor_init, theme_prop) 266set_prop(vendor_init, dck_prop) 267 268 269### 270### neverallow rules 271### 272 273# Vendor init shouldn't communicate with any vendor process, nor most system processes. 274neverallow_establish_socket_comms(vendor_init, { domain -init -logd -su -vendor_init }); 275 276# The vendor_init domain is only entered via an exec based transition from the 277# init domain, never via setcon(). 278neverallow domain vendor_init:process dyntransition; 279neverallow { domain -init } vendor_init:process transition; 280neverallow vendor_init { file_type fs_type -init_exec }:file entrypoint; 281 282# Never read/follow symlinks created by shell or untrusted apps. 283neverallow vendor_init { app_data_file privapp_data_file }:lnk_file read; 284neverallow vendor_init shell_data_file:lnk_file read; 285# Init should not be creating subdirectories in /data/local/tmp 286neverallow vendor_init shell_data_file:dir { write add_name remove_name }; 287 288# init should never execute a program without changing to another domain. 289neverallow vendor_init { file_type fs_type }:file execute_no_trans; 290 291# Init never adds or uses services via service_manager. 292neverallow vendor_init service_manager_type:service_manager { add find }; 293neverallow vendor_init servicemanager:service_manager list; 294 295# vendor_init should never be ptraced 296neverallow * vendor_init:process ptrace; 297