vendor_init.te 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. # vendor_init is its own domain.
  2. type vendor_init, domain, mlstrustedsubject;
  3. # Communication to the main init process
  4. allow vendor_init init:unix_stream_socket { read write };
  5. # Logging to kmsg
  6. allow vendor_init kmsg_device:chr_file { open getattr write };
  7. # Mount on /dev/usb-ffs/adb.
  8. allow vendor_init device:dir mounton;
  9. # Create and remove symlinks in /.
  10. allow vendor_init rootfs:lnk_file { create unlink };
  11. # Create cgroups mount points in tmpfs and mount cgroups on them.
  12. allow vendor_init cgroup:dir create_dir_perms;
  13. allow vendor_init cgroup:file w_file_perms;
  14. # /config
  15. allow vendor_init configfs:dir mounton;
  16. allow vendor_init configfs:dir create_dir_perms;
  17. allow vendor_init configfs:{ file lnk_file } create_file_perms;
  18. # Create directories under /dev/cpuctl after chowning it to system.
  19. allow vendor_init self:global_capability_class_set { dac_override dac_read_search };
  20. # mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
  21. # chown/chmod require open+read+setattr required for open()+fchown/fchmod().
  22. # system/core/init.rc requires at least cache_file and data_file_type.
  23. # init.<board>.rc files often include device-specific types, so
  24. # we just allow all file types except /system files here.
  25. allow vendor_init self:global_capability_class_set { chown fowner fsetid };
  26. # mkdir with FBE requires reading /data/unencrypted/{ref,mode}.
  27. allow vendor_init unencrypted_data_file:dir search;
  28. allow vendor_init unencrypted_data_file:file r_file_perms;
  29. # Set encryption policy on dirs in /data
  30. allowxperm vendor_init data_file_type:dir ioctl {
  31. FS_IOC_GET_ENCRYPTION_POLICY
  32. FS_IOC_SET_ENCRYPTION_POLICY
  33. };
  34. allow vendor_init system_data_file:dir getattr;
  35. allow vendor_init {
  36. file_type
  37. -core_data_file_type
  38. -exec_type
  39. -system_file_type
  40. -mnt_product_file
  41. -password_slot_metadata_file
  42. -unlabeled
  43. -vendor_file_type
  44. -vold_metadata_file
  45. -gsi_metadata_file
  46. -apex_metadata_file
  47. }:dir { create search getattr open read setattr ioctl write add_name remove_name rmdir relabelfrom };
  48. allow vendor_init unlabeled:{ dir notdevfile_class_set } { getattr relabelfrom };
  49. allow vendor_init {
  50. file_type
  51. -core_data_file_type
  52. -exec_type
  53. -password_slot_metadata_file
  54. -runtime_event_log_tags_file
  55. -system_file_type
  56. -unlabeled
  57. -vendor_file_type
  58. -vold_metadata_file
  59. -gsi_metadata_file
  60. -apex_metadata_file
  61. }:file { create getattr open read write setattr relabelfrom unlink map };
  62. allow vendor_init {
  63. file_type
  64. -core_data_file_type
  65. -exec_type
  66. -password_slot_metadata_file
  67. -system_file_type
  68. -unlabeled
  69. -vendor_file_type
  70. -vold_metadata_file
  71. -gsi_metadata_file
  72. -apex_metadata_file
  73. }:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
  74. allow vendor_init {
  75. file_type
  76. -apex_mnt_dir
  77. -core_data_file_type
  78. -exec_type
  79. -password_slot_metadata_file
  80. -system_file_type
  81. -unlabeled
  82. -vendor_file_type
  83. -vold_metadata_file
  84. -gsi_metadata_file
  85. -apex_metadata_file
  86. }:lnk_file { create getattr setattr relabelfrom unlink };
  87. allow vendor_init {
  88. file_type
  89. -core_data_file_type
  90. -exec_type
  91. -mnt_product_file
  92. -password_slot_metadata_file
  93. -system_file_type
  94. -vendor_file_type
  95. -vold_metadata_file
  96. -gsi_metadata_file
  97. -apex_metadata_file
  98. }:dir_file_class_set relabelto;
  99. allow vendor_init dev_type:dir create_dir_perms;
  100. allow vendor_init dev_type:lnk_file create;
  101. # Disable tracing by writing to /sys/kernel/debug/tracing/tracing_on
  102. allow vendor_init debugfs_tracing:file w_file_perms;
  103. # chown/chmod on pseudo files.
  104. allow vendor_init {
  105. fs_type
  106. -contextmount_type
  107. -keychord_device
  108. -sdcard_type
  109. -rootfs
  110. -proc_uid_time_in_state
  111. -proc_uid_concurrent_active_time
  112. -proc_uid_concurrent_policy_time
  113. }:file { open read setattr map };
  114. allow vendor_init {
  115. fs_type
  116. -contextmount_type
  117. -sdcard_type
  118. -rootfs
  119. -proc_uid_time_in_state
  120. -proc_uid_concurrent_active_time
  121. -proc_uid_concurrent_policy_time
  122. }:dir { open read setattr search };
  123. # chown/chmod on devices, e.g. /dev/ttyHS0
  124. allow vendor_init {
  125. dev_type
  126. -keychord_device
  127. -port_device
  128. -lowpan_device
  129. -hw_random_device
  130. }:chr_file setattr;
  131. allow vendor_init dev_type:blk_file getattr;
  132. # Write to /proc/sys/net/ping_group_range and other /proc/sys/net files.
  133. r_dir_file(vendor_init, proc_net_type)
  134. allow vendor_init proc_net_type:file w_file_perms;
  135. allow vendor_init self:global_capability_class_set net_admin;
  136. # Write to /proc/sys/vm/page-cluster
  137. allow vendor_init proc_page_cluster:file w_file_perms;
  138. # Write to sysfs nodes.
  139. allow vendor_init sysfs_type:dir r_dir_perms;
  140. allow vendor_init sysfs_type:lnk_file read;
  141. allow vendor_init { sysfs_type -sysfs_usermodehelper }:file rw_file_perms;
  142. # setfscreatecon() for labeling directories and socket files.
  143. allow vendor_init self:process { setfscreate };
  144. r_dir_file(vendor_init, vendor_file_type)
  145. # Vendor init can read properties
  146. allow vendor_init serialno_prop:file { getattr open read map };
  147. # Vendor init can perform operations on trusted and security Extended Attributes
  148. allow vendor_init self:global_capability_class_set sys_admin;
  149. # Raw writes to misc block device
  150. allow vendor_init misc_block_device:blk_file w_file_perms;
  151. # vendor_init is using bootstrap bionic
  152. allow vendor_init system_bootstrap_lib_file:dir r_dir_perms;
  153. allow vendor_init system_bootstrap_lib_file:file { execute read open getattr map };
  154. # Everything is labeled as rootfs in recovery mode. Vendor init has to execute
  155. # the dynamic linker and shared libraries.
  156. recovery_only(`
  157. allow vendor_init rootfs:file { r_file_perms execute };
  158. ')
  159. not_compatible_property(`
  160. set_prop(vendor_init, {
  161. property_type
  162. -device_config_activity_manager_native_boot_prop
  163. -device_config_boot_count_prop
  164. -device_config_reset_performed_prop
  165. -device_config_input_native_boot_prop
  166. -device_config_netd_native_prop
  167. -device_config_runtime_native_boot_prop
  168. -device_config_runtime_native_prop
  169. -device_config_media_native_prop
  170. -restorecon_prop
  171. -netd_stable_secret_prop
  172. -firstboot_prop
  173. -pm_prop
  174. -system_boot_reason_prop
  175. -bootloader_boot_reason_prop
  176. -last_boot_reason_prop
  177. -apexd_prop
  178. -gsid_prop
  179. -nnapi_ext_deny_product_prop
  180. })
  181. ')
  182. # Get file context
  183. allow vendor_init file_contexts_file:file r_file_perms;
  184. set_prop(vendor_init, bluetooth_a2dp_offload_prop)
  185. set_prop(vendor_init, bluetooth_audio_hal_prop)
  186. set_prop(vendor_init, cpu_variant_prop)
  187. set_prop(vendor_init, debug_prop)
  188. set_prop(vendor_init, exported_audio_prop)
  189. set_prop(vendor_init, exported_bluetooth_prop)
  190. set_prop(vendor_init, exported_config_prop)
  191. set_prop(vendor_init, exported_dalvik_prop)
  192. set_prop(vendor_init, exported_default_prop)
  193. set_prop(vendor_init, exported_ffs_prop)
  194. set_prop(vendor_init, exported_overlay_prop)
  195. set_prop(vendor_init, exported_pm_prop)
  196. set_prop(vendor_init, exported_radio_prop)
  197. set_prop(vendor_init, exported_system_radio_prop)
  198. set_prop(vendor_init, exported_wifi_prop)
  199. set_prop(vendor_init, exported2_config_prop)
  200. set_prop(vendor_init, exported2_system_prop)
  201. set_prop(vendor_init, exported2_vold_prop)
  202. set_prop(vendor_init, exported3_default_prop)
  203. set_prop(vendor_init, exported3_radio_prop)
  204. set_prop(vendor_init, logd_prop)
  205. set_prop(vendor_init, log_tag_prop)
  206. set_prop(vendor_init, log_prop)
  207. set_prop(vendor_init, serialno_prop)
  208. set_prop(vendor_init, vendor_default_prop)
  209. set_prop(vendor_init, vendor_security_patch_level_prop)
  210. set_prop(vendor_init, wifi_log_prop)
  211. get_prop(vendor_init, exported2_radio_prop)
  212. get_prop(vendor_init, exported3_system_prop)
  213. get_prop(vendor_init, theme_prop)
  214. ###
  215. ### neverallow rules
  216. ###
  217. # Vendor init shouldn't communicate with any vendor process, nor most system processes.
  218. neverallow_establish_socket_comms(vendor_init, { domain -init -logd -su -vendor_init });
  219. # The vendor_init domain is only entered via an exec based transition from the
  220. # init domain, never via setcon().
  221. neverallow domain vendor_init:process dyntransition;
  222. neverallow { domain -init } vendor_init:process transition;
  223. neverallow vendor_init { file_type fs_type -init_exec }:file entrypoint;
  224. # Never read/follow symlinks created by shell or untrusted apps.
  225. neverallow vendor_init { app_data_file privapp_data_file }:lnk_file read;
  226. neverallow vendor_init shell_data_file:lnk_file read;
  227. # Init should not be creating subdirectories in /data/local/tmp
  228. neverallow vendor_init shell_data_file:dir { write add_name remove_name };
  229. # init should never execute a program without changing to another domain.
  230. neverallow vendor_init { file_type fs_type }:file execute_no_trans;
  231. # Init never adds or uses services via service_manager.
  232. neverallow vendor_init service_manager_type:service_manager { add find };
  233. neverallow vendor_init servicemanager:service_manager list;
  234. # vendor_init should never be ptraced
  235. neverallow * vendor_init:process ptrace;