domain.te 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. # Rules for all domains.
  2. # Allow reaping by init.
  3. allow domain init:process sigchld;
  4. # Intra-domain accesses.
  5. allow domain self:process {
  6. fork
  7. sigchld
  8. sigkill
  9. sigstop
  10. signull
  11. signal
  12. getsched
  13. setsched
  14. getsession
  15. getpgid
  16. setpgid
  17. getcap
  18. setcap
  19. getattr
  20. setrlimit
  21. };
  22. allow domain self:fd use;
  23. allow domain proc:dir r_dir_perms;
  24. allow domain proc_net_type:dir search;
  25. r_dir_file(domain, self)
  26. allow domain self:{ fifo_file file } rw_file_perms;
  27. allow domain self:unix_dgram_socket { create_socket_perms sendto };
  28. allow domain self:unix_stream_socket { create_stream_socket_perms connectto };
  29. # Inherit or receive open files from others.
  30. allow domain init:fd use;
  31. userdebug_or_eng(`
  32. allow domain su:fd use;
  33. allow domain su:unix_stream_socket { connectto getattr getopt read write shutdown };
  34. allow domain su:unix_dgram_socket sendto;
  35. allow { domain -init } su:binder { call transfer };
  36. # Running something like "pm dump com.android.bluetooth" requires
  37. # fifo writes
  38. allow domain su:fifo_file { write getattr };
  39. # allow "gdbserver --attach" to work for su.
  40. allow domain su:process sigchld;
  41. # Allow writing coredumps to /cores/*
  42. allow domain coredump_file:file create_file_perms;
  43. allow domain coredump_file:dir ra_dir_perms;
  44. ')
  45. with_native_coverage(`
  46. # Allow writing coverage information to /data/misc/trace
  47. allow domain method_trace_data_file:dir create_dir_perms;
  48. allow domain method_trace_data_file:file create_file_perms;
  49. ')
  50. # Root fs.
  51. allow domain tmpfs:dir { getattr search };
  52. allow domain rootfs:dir search;
  53. allow domain rootfs:lnk_file { read getattr };
  54. # Device accesses.
  55. allow domain device:dir search;
  56. allow domain dev_type:lnk_file r_file_perms;
  57. allow domain devpts:dir search;
  58. allow domain socket_device:dir r_dir_perms;
  59. allow domain owntty_device:chr_file rw_file_perms;
  60. allow domain null_device:chr_file rw_file_perms;
  61. allow domain zero_device:chr_file rw_file_perms;
  62. allow {
  63. domain
  64. # TODO(b/113362644): route coredomain to ashmemd
  65. #-coredomain
  66. -mediaprovider
  67. -ephemeral_app
  68. -isolated_app
  69. -untrusted_app_all
  70. } ashmem_device:chr_file rw_file_perms;
  71. # Allow using fds to /dev/ashmem.
  72. allow domain ashmemd:fd use;
  73. # /dev/binder can be accessed by non-vendor domains and by apps
  74. allow {
  75. coredomain
  76. appdomain
  77. binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
  78. -hwservicemanager
  79. } binder_device:chr_file rw_file_perms;
  80. # Devices which are not full TREBLE have fewer restrictions on access to /dev/binder
  81. not_full_treble(`allow { domain -hwservicemanager -vndservicemanager } binder_device:chr_file rw_file_perms;')
  82. allow { domain -servicemanager -vndservicemanager -isolated_app } hwbinder_device:chr_file rw_file_perms;
  83. allow domain ptmx_device:chr_file rw_file_perms;
  84. allow domain random_device:chr_file rw_file_perms;
  85. allow domain proc_random:dir r_dir_perms;
  86. allow domain proc_random:file r_file_perms;
  87. allow domain properties_device:dir { search getattr };
  88. allow domain properties_serial:file r_file_perms;
  89. allow domain property_info:file r_file_perms;
  90. # Public readable properties
  91. get_prop(domain, debug_prop)
  92. get_prop(domain, exported_config_prop)
  93. get_prop(domain, exported_default_prop)
  94. get_prop(domain, exported_dumpstate_prop)
  95. get_prop(domain, exported_fingerprint_prop)
  96. get_prop(domain, exported_radio_prop)
  97. get_prop(domain, exported_secure_prop)
  98. get_prop(domain, exported_system_prop)
  99. get_prop(domain, exported_vold_prop)
  100. get_prop(domain, exported2_default_prop)
  101. get_prop(domain, logd_prop)
  102. # Let everyone read log properties, so that liblog can avoid sending unloggable
  103. # messages to logd.
  104. get_prop(domain, log_property_type)
  105. dontaudit domain property_type:file audit_access;
  106. allow domain property_contexts_file:file r_file_perms;
  107. allow domain init:key search;
  108. allow domain vold:key search;
  109. # logd access
  110. write_logd(domain)
  111. # Directory/link file access for path resolution.
  112. allow domain {
  113. system_file
  114. system_lib_file
  115. system_seccomp_policy_file
  116. system_security_cacerts_file
  117. }:dir r_dir_perms;
  118. allow domain system_file:lnk_file { getattr read };
  119. # Global access to /system/etc/security/cacerts/*, /system/etc/seccomp_policy/*, /system/lib[64]/*,
  120. # linker and its config.
  121. allow domain system_seccomp_policy_file:file r_file_perms;
  122. # cacerts are accessible from public Java API.
  123. allow domain system_security_cacerts_file:file r_file_perms;
  124. allow domain system_linker_exec:file { execute read open getattr map };
  125. allow domain system_linker_config_file:file r_file_perms;
  126. allow domain system_lib_file:file { execute read open getattr map };
  127. # To allow following symlinks at /system/bin/linker, /system/lib/libc.so, etc.
  128. allow domain system_linker_exec:lnk_file { read open getattr };
  129. allow domain system_lib_file:lnk_file { read open getattr };
  130. allow domain system_event_log_tags_file:file r_file_perms;
  131. allow { appdomain coredomain } system_file:file { execute read open getattr map };
  132. # Make sure system/vendor split doesn not affect non-treble
  133. # devices
  134. not_full_treble(`
  135. allow domain system_file:file { execute read open getattr map };
  136. allow domain vendor_file_type:dir { search getattr };
  137. allow domain vendor_file_type:file { execute read open getattr map };
  138. allow domain vendor_file_type:lnk_file { getattr read };
  139. ')
  140. # All domains are allowed to open and read directories
  141. # that contain HAL implementations (e.g. passthrough
  142. # HALs require clients to have these permissions)
  143. allow domain vendor_hal_file:dir r_dir_perms;
  144. # Everyone can read and execute all same process HALs
  145. allow domain same_process_hal_file:dir r_dir_perms;
  146. allow {
  147. domain
  148. -coredomain # access is explicitly granted to individual coredomains
  149. } same_process_hal_file:file { execute read open getattr map };
  150. # Any process can load vndk-sp libraries, which are system libraries
  151. # used by same process HALs
  152. allow domain vndk_sp_file:dir r_dir_perms;
  153. allow domain vndk_sp_file:file { execute read open getattr map };
  154. # All domains get access to /vendor/etc
  155. allow domain vendor_configs_file:dir r_dir_perms;
  156. allow domain vendor_configs_file:file { read open getattr map };
  157. full_treble_only(`
  158. # Allow all domains to be able to follow /system/vendor and/or
  159. # /vendor/odm symlinks.
  160. allow domain vendor_file_type:lnk_file { getattr open read };
  161. # This is required to be able to search & read /vendor/lib64
  162. # in order to lookup vendor libraries. The execute permission
  163. # for coredomains is granted *only* for same process HALs
  164. allow domain vendor_file:dir { getattr search };
  165. # Allow reading and executing out of /vendor to all vendor domains
  166. allow { domain -coredomain } vendor_file_type:dir r_dir_perms;
  167. allow { domain -coredomain } vendor_file_type:file { read open getattr execute map };
  168. allow { domain -coredomain } vendor_file_type:lnk_file { getattr read };
  169. ')
  170. # read and stat any sysfs symlinks
  171. allow domain sysfs:lnk_file { getattr read };
  172. # libc references /data/misc/zoneinfo and /system/usr/share/zoneinfo for
  173. # timezone related information.
  174. # This directory is considered to be a VNDK-stable
  175. allow domain { system_zoneinfo_file zoneinfo_data_file }:file r_file_perms;
  176. allow domain { system_zoneinfo_file zoneinfo_data_file }:dir r_dir_perms;
  177. # Lots of processes access current CPU information
  178. r_dir_file(domain, sysfs_devices_system_cpu)
  179. r_dir_file(domain, sysfs_usb);
  180. # If kernel CONFIG_TRANSPARENT_HUGEPAGE is enabled, libjemalloc5 (statically
  181. # included by libc) reads /sys/kernel/mm/transparent_hugepage/enabled.
  182. allow domain sysfs_transparent_hugepage:dir search;
  183. allow domain sysfs_transparent_hugepage:file r_file_perms;
  184. # files under /data.
  185. not_full_treble(`
  186. allow domain system_data_file:dir getattr;
  187. ')
  188. allow { coredomain appdomain } system_data_file:dir getattr;
  189. # /data has the label system_data_file. Vendor components need the search
  190. # permission on system_data_file for path traversal to /data/vendor.
  191. allow domain system_data_file:dir search;
  192. # TODO restrict this to non-coredomain
  193. allow domain vendor_data_file:dir { getattr search };
  194. # required by the dynamic linker
  195. allow domain proc:lnk_file { getattr read };
  196. # /proc/cpuinfo
  197. allow domain proc_cpuinfo:file r_file_perms;
  198. # /dev/cpu_variant:.*
  199. allow domain dev_cpu_variant:file r_file_perms;
  200. # jemalloc needs to read /proc/sys/vm/overcommit_memory
  201. allow domain proc_overcommit_memory:file r_file_perms;
  202. # profiling needs to read /proc/sys/kernel/perf_event_max_sample_rate
  203. allow domain proc_perf:file r_file_perms;
  204. # toybox loads libselinux which stats /sys/fs/selinux/
  205. allow domain selinuxfs:dir search;
  206. allow domain selinuxfs:file getattr;
  207. allow domain sysfs:dir search;
  208. allow domain selinuxfs:filesystem getattr;
  209. # Almost all processes log tracing information to
  210. # /sys/kernel/debug/tracing/trace_marker
  211. # The reason behind this is documented in b/6513400
  212. allow domain debugfs:dir search;
  213. allow domain debugfs_tracing:dir search;
  214. allow domain debugfs_tracing_debug:dir search;
  215. allow domain debugfs_trace_marker:file w_file_perms;
  216. # Filesystem access.
  217. allow domain fs_type:filesystem getattr;
  218. allow domain fs_type:dir getattr;
  219. # Restrict all domains to a whitelist for common socket types. Additional
  220. # ioctl commands may be added to individual domains, but this sets safe
  221. # defaults for all processes. Note that granting this whitelist to domain does
  222. # not grant the ioctl permission on these socket types. That must be granted
  223. # separately.
  224. allowxperm domain domain:{ icmp_socket rawip_socket tcp_socket udp_socket }
  225. ioctl { unpriv_sock_ioctls unpriv_tty_ioctls };
  226. # default whitelist for unix sockets.
  227. allowxperm domain { domain pdx_channel_socket_type }:{ unix_dgram_socket unix_stream_socket }
  228. ioctl unpriv_unix_sock_ioctls;
  229. # Restrict PTYs to only whitelisted ioctls.
  230. # Note that granting this whitelist to domain does
  231. # not grant the wider ioctl permission. That must be granted
  232. # separately.
  233. allowxperm domain devpts:chr_file ioctl unpriv_tty_ioctls;
  234. # All domains must clearly enumerate what ioctls they use
  235. # on filesystem objects (plain files, directories, symbolic links,
  236. # named pipes, and named sockets). We start off with a safe set.
  237. allowxperm domain { file_type fs_type domain dev_type }:{ dir notdevfile_class_set blk_file } ioctl { FIOCLEX FIONCLEX };
  238. # If a domain has ioctl access to tun_device, it must clearly enumerate the
  239. # ioctls used. Safe defaults are listed below.
  240. allowxperm domain tun_device:chr_file ioctl { FIOCLEX FIONCLEX };
  241. # Allow a process to make a determination whether a file descriptor
  242. # for a plain file or pipe (fifo_file) is a tty. Note that granting
  243. # this whitelist to domain does not grant the ioctl permission to
  244. # these files. That must be granted separately.
  245. allowxperm domain { file_type fs_type }:file ioctl { TCGETS };
  246. allowxperm domain domain:fifo_file ioctl { TCGETS };
  247. # If a domain has access to perform an ioctl on a block device, allow these
  248. # very common, benign ioctls
  249. allowxperm domain dev_type:blk_file ioctl { BLKGETSIZE64 BLKSSZGET };
  250. # Support sqlite F2FS specific optimizations
  251. # ioctl permission on the specific file type is still required
  252. # TODO: consider only compiling these rules if we know the
  253. # /data partition is F2FS
  254. allowxperm domain { file_type sdcard_type }:file ioctl {
  255. F2FS_IOC_ABORT_VOLATILE_WRITE
  256. F2FS_IOC_COMMIT_ATOMIC_WRITE
  257. F2FS_IOC_GET_FEATURES
  258. F2FS_IOC_GET_PIN_FILE
  259. F2FS_IOC_SET_PIN_FILE
  260. F2FS_IOC_START_ATOMIC_WRITE
  261. };
  262. # Workaround for policy compiler being too aggressive and removing hwservice_manager_type
  263. # when it's not explicitly used in allow rules
  264. allow { domain -domain } hwservice_manager_type:hwservice_manager { add find };
  265. # Workaround for policy compiler being too aggressive and removing vndservice_manager_type
  266. # when it's not explicitly used in allow rules
  267. allow { domain -domain } vndservice_manager_type:service_manager { add find };
  268. # Under ASAN, processes will try to read /data, as the sanitized libraries are there.
  269. with_asan(`allow domain system_data_file:dir getattr;')
  270. # Under ASAN, /system/asan.options needs to be globally accessible.
  271. with_asan(`allow domain system_asan_options_file:file r_file_perms;')
  272. # read APEX dir and stat any symlink pointing to APEXs.
  273. allow domain apex_mnt_dir:dir { getattr search };
  274. allow domain apex_mnt_dir:lnk_file r_file_perms;
  275. ###
  276. ### neverallow rules
  277. ###
  278. # All ioctls on file-like objects (except chr_file and blk_file) and
  279. # sockets must be restricted to a whitelist.
  280. neverallowxperm * *:{ dir notdevfile_class_set socket_class_set blk_file } ioctl { 0 };
  281. # b/68014825 and https://android-review.googlesource.com/516535
  282. # rfc6093 says that processes should not use the TCP urgent mechanism
  283. neverallowxperm domain domain:socket_class_set ioctl { SIOCATMARK };
  284. # TIOCSTI is only ever used for exploits. Block it.
  285. # b/33073072, b/7530569
  286. # http://www.openwall.com/lists/oss-security/2016/09/26/14
  287. neverallowxperm * devpts:chr_file ioctl TIOCSTI;
  288. # Do not allow any domain other than init to create unlabeled files.
  289. neverallow { domain -init -recovery } unlabeled:dir_file_class_set create;
  290. # Limit device node creation to these whitelisted domains.
  291. neverallow {
  292. domain
  293. -kernel
  294. -init
  295. -ueventd
  296. -vold
  297. } self:global_capability_class_set mknod;
  298. # No process can map low memory (< CONFIG_LSM_MMAP_MIN_ADDR).
  299. neverallow * self:memprotect mmap_zero;
  300. # No domain needs mac_override as it is unused by SELinux.
  301. neverallow * self:global_capability2_class_set mac_override;
  302. # Disallow attempts to set contexts not defined in current policy
  303. # This helps guarantee that unknown or dangerous contents will not ever
  304. # be set.
  305. neverallow * self:global_capability2_class_set mac_admin;
  306. # Once the policy has been loaded there shall be none to modify the policy.
  307. # It is sealed.
  308. neverallow * kernel:security load_policy;
  309. # Only init prior to switching context should be able to set enforcing mode.
  310. # init starts in kernel domain and switches to init domain via setcon in
  311. # the init.rc, so the setenforce occurs while still in kernel. After
  312. # switching domains, there is never any need to setenforce again by init.
  313. neverallow * kernel:security setenforce;
  314. neverallow { domain -kernel } kernel:security setcheckreqprot;
  315. # No booleans in AOSP policy, so no need to ever set them.
  316. neverallow * kernel:security setbool;
  317. # Adjusting the AVC cache threshold.
  318. # Not presently allowed to anything in policy, but possibly something
  319. # that could be set from init.rc.
  320. neverallow { domain -init } kernel:security setsecparam;
  321. # Only init, ueventd, shell and system_server should be able to access HW RNG
  322. neverallow {
  323. domain
  324. -init
  325. -shell # For CTS and is restricted to getattr in shell.te
  326. -system_server
  327. -ueventd
  328. } hw_random_device:chr_file *;
  329. # b/78174219 b/64114943
  330. neverallow {
  331. domain
  332. -shell # stat of /dev, getattr only
  333. -ueventd
  334. } keychord_device:chr_file *;
  335. # Ensure that all entrypoint executables are in exec_type or postinstall_file.
  336. neverallow * { file_type -exec_type -postinstall_file }:file entrypoint;
  337. # The dynamic linker always calls access(2) on the path. Don't generate SElinux
  338. # denials since the linker does not actually access the path in case the path
  339. # does not exist or isn't accessible for the process.
  340. dontaudit domain postinstall_mnt_dir:dir audit_access;
  341. #Ensure that nothing in userspace can access /dev/port
  342. neverallow {
  343. domain
  344. -shell # Shell user should not have any abilities outside of getattr
  345. -ueventd
  346. } port_device:chr_file *;
  347. neverallow * port_device:chr_file ~{ create relabelto unlink setattr getattr };
  348. # Only init should be able to configure kernel usermodehelpers or
  349. # security-sensitive proc settings.
  350. neverallow { domain -init } usermodehelper:file { append write };
  351. neverallow { domain -init -ueventd } sysfs_usermodehelper:file { append write };
  352. neverallow { domain -init -vendor_init } proc_security:file { append open read write };
  353. # Nobody is allowed to make binder calls into init.
  354. # Only servicemanager may transfer binder references to init
  355. # vendor_init shouldn't use binder at all.
  356. neverallow * init:binder ~{ transfer };
  357. neverallow { domain -servicemanager } init:binder { transfer };
  358. neverallow * vendor_init:binder *;
  359. # Don't allow raw read/write/open access to block_device
  360. # Rather force a relabel to a more specific type
  361. neverallow { domain -kernel -init -recovery } block_device:blk_file { open read write };
  362. # Do not allow renaming of block files or character files
  363. # Ability to do so can lead to possible use in an exploit chain
  364. # e.g. https://googleprojectzero.blogspot.com/2016/12/chrome-os-exploit-one-byte-overflow-and.html
  365. neverallow * *:{ blk_file chr_file } rename;
  366. # Don't allow raw read/write/open access to generic devices.
  367. # Rather force a relabel to a more specific type.
  368. neverallow domain device:chr_file { open read write };
  369. # Files from cache should never be executed
  370. neverallow domain { cache_file cache_backup_file cache_private_backup_file cache_recovery_file }:file execute;
  371. # Protect most domains from executing arbitrary content from /data.
  372. neverallow {
  373. domain
  374. -appdomain
  375. } {
  376. data_file_type
  377. -dalvikcache_data_file
  378. -system_data_file # shared libs in apks
  379. -apk_data_file
  380. }:file no_x_file_perms;
  381. # The test files and executables MUST not be accessible to any domain
  382. neverallow { domain userdebug_or_eng(`-kernel') } nativetest_data_file:file_class_set no_w_file_perms;
  383. neverallow domain nativetest_data_file:dir no_w_dir_perms;
  384. neverallow { domain userdebug_or_eng(`-shell') } nativetest_data_file:file no_x_file_perms;
  385. # Only the init property service should write to /data/property and /dev/__properties__
  386. neverallow { domain -init } property_data_file:dir no_w_dir_perms;
  387. neverallow { domain -init } property_data_file:file { no_w_file_perms no_x_file_perms };
  388. neverallow { domain -init } property_type:file { no_w_file_perms no_x_file_perms };
  389. neverallow { domain -init } properties_device:file { no_w_file_perms no_x_file_perms };
  390. neverallow { domain -init } properties_serial:file { no_w_file_perms no_x_file_perms };
  391. # Nobody should be doing writes to /system & /vendor
  392. # These partitions are intended to be read-only and must never be
  393. # modified. Doing so would violate important Android security guarantees
  394. # and invalidate dm-verity signatures.
  395. neverallow {
  396. domain
  397. with_asan(`-asan_extract')
  398. recovery_only(`userdebug_or_eng(`-fastbootd')')
  399. } {
  400. system_file_type
  401. vendor_file_type
  402. exec_type
  403. }:dir_file_class_set { create write setattr relabelfrom append unlink link rename };
  404. neverallow { domain -kernel with_asan(`-asan_extract') } { system_file_type vendor_file_type exec_type }:dir_file_class_set relabelto;
  405. # Don't allow mounting on top of /system files or directories
  406. neverallow * exec_type:dir_file_class_set mounton;
  407. neverallow { domain -init } { system_file_type vendor_file_type }:dir_file_class_set mounton;
  408. # Nothing should be writing to files in the rootfs.
  409. neverallow * rootfs:file { create write setattr relabelto append unlink link rename };
  410. # Restrict context mounts to specific types marked with
  411. # the contextmount_type attribute.
  412. neverallow * {fs_type -contextmount_type}:filesystem relabelto;
  413. # Ensure that context mount types are not writable, to ensure that
  414. # the write to /system restriction above is not bypassed via context=
  415. # mount to another type.
  416. neverallow * contextmount_type:dir_file_class_set
  417. { create setattr relabelfrom relabelto append link rename };
  418. neverallow { domain recovery_only(`userdebug_or_eng(`-fastbootd')') } contextmount_type:dir_file_class_set { write unlink };
  419. # Do not allow service_manager add for default service labels.
  420. # Instead domains should use a more specific type such as
  421. # system_app_service rather than the generic type.
  422. # New service_types are defined in {,hw,vnd}service.te and new mappings
  423. # from service name to service_type are defined in {,hw,vnd}service_contexts.
  424. neverallow * default_android_service:service_manager add;
  425. neverallow * default_android_vndservice:service_manager { add find };
  426. neverallow * default_android_hwservice:hwservice_manager { add find };
  427. # Looking up the base class/interface of all HwBinder services is a bad idea.
  428. # hwservicemanager currently offer such lookups only to make it so that security
  429. # decisions are expressed in SELinux policy. However, it's unclear whether this
  430. # lookup has security implications. If it doesn't, hwservicemanager should be
  431. # modified to not offer this lookup.
  432. # This rule can be removed if hwservicemanager is modified to not permit these
  433. # lookups.
  434. neverallow * hidl_base_hwservice:hwservice_manager find;
  435. # Require that domains explicitly label unknown properties, and do not allow
  436. # anyone but init to modify unknown properties.
  437. neverallow { domain -init -vendor_init } default_prop:property_service set;
  438. neverallow { domain -init -vendor_init } mmc_prop:property_service set;
  439. compatible_property_only(`
  440. neverallow { domain -init } default_prop:property_service set;
  441. neverallow { domain -init } mmc_prop:property_service set;
  442. neverallow { domain -init -vendor_init } exported_default_prop:property_service set;
  443. neverallow { domain -init } exported_secure_prop:property_service set;
  444. neverallow { domain -init } exported2_default_prop:property_service set;
  445. neverallow { domain -init -vendor_init } exported3_default_prop:property_service set;
  446. neverallow { domain -init -vendor_init } vendor_default_prop:property_service set;
  447. ')
  448. # Only core domains are allowed to access package_manager properties
  449. neverallow { domain -init -system_server } pm_prop:property_service set;
  450. neverallow { domain -coredomain } pm_prop:file no_rw_file_perms;
  451. compatible_property_only(`
  452. neverallow { domain -init -system_server -vendor_init } exported_pm_prop:property_service set;
  453. neverallow { domain -coredomain -vendor_init } exported_pm_prop:file no_rw_file_perms;
  454. ')
  455. # Do not allow reading device's serial number from system properties except form
  456. # a few whitelisted domains.
  457. neverallow {
  458. domain
  459. -adbd
  460. -dumpstate
  461. -fastbootd
  462. -hal_camera_server
  463. -hal_cas_server
  464. -hal_drm_server
  465. -init
  466. -mediadrmserver
  467. -recovery
  468. -shell
  469. -system_server
  470. -vendor_init
  471. } serialno_prop:file r_file_perms;
  472. # Do not allow reading the last boot timestamp from system properties
  473. neverallow { domain -init -system_server -dumpstate } firstboot_prop:file r_file_perms;
  474. neverallow {
  475. domain
  476. -init
  477. -recovery
  478. -system_server
  479. -shell # Shell is further restricted in shell.te
  480. -ueventd # Further restricted in ueventd.te
  481. } frp_block_device:blk_file no_rw_file_perms;
  482. # The metadata block device is set aside for device encryption and
  483. # verified boot metadata. It may be reset at will and should not
  484. # be used by other domains.
  485. neverallow {
  486. domain
  487. -init
  488. -recovery
  489. -vold
  490. -e2fs
  491. -fsck
  492. -fastbootd
  493. } metadata_block_device:blk_file { append link rename write open read ioctl lock };
  494. # No domain other than recovery, update_engine and fastbootd can write to system partition(s).
  495. neverallow {
  496. domain
  497. -fastbootd
  498. userdebug_or_eng(`-fsck')
  499. userdebug_or_eng(`-init')
  500. -recovery
  501. -update_engine
  502. } system_block_device:blk_file { write append };
  503. # No domains other than a select few can access the misc_block_device. This
  504. # block device is reserved for OTA use.
  505. # Do not assert this rule on userdebug/eng builds, due to some devices using
  506. # this partition for testing purposes.
  507. neverallow {
  508. domain
  509. userdebug_or_eng(`-domain') # exclude debuggable builds
  510. -fastbootd
  511. -hal_bootctl_server
  512. -init
  513. -uncrypt
  514. -update_engine
  515. -vendor_init
  516. -vendor_misc_writer
  517. -vold
  518. -recovery
  519. -ueventd
  520. } misc_block_device:blk_file { append link relabelfrom rename write open read ioctl lock };
  521. # Only (hw|vnd|)servicemanager should be able to register with binder as the context manager
  522. neverallow { domain -servicemanager -hwservicemanager -vndservicemanager } *:binder set_context_mgr;
  523. # The service managers are only allowed to access their own device node
  524. neverallow servicemanager hwbinder_device:chr_file no_rw_file_perms;
  525. neverallow servicemanager vndbinder_device:chr_file no_rw_file_perms;
  526. neverallow hwservicemanager binder_device:chr_file no_rw_file_perms;
  527. neverallow hwservicemanager vndbinder_device:chr_file no_rw_file_perms;
  528. neverallow vndservicemanager binder_device:chr_file no_rw_file_perms;
  529. neverallow vndservicemanager hwbinder_device:chr_file no_rw_file_perms;
  530. # On full TREBLE devices, only core components and apps can use Binder and servicemanager. Non-core
  531. # domain apps need this because Android framework offers many of its services to apps as Binder
  532. # services.
  533. full_treble_only(`
  534. neverallow {
  535. domain
  536. -coredomain
  537. -appdomain
  538. -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
  539. } binder_device:chr_file rw_file_perms;
  540. ')
  541. # libcutils can probe for /dev/binder permissions with access(). Ignore
  542. # generated denials. See b/129073672 for details.
  543. dontaudit domain binder_device:chr_file audit_access;
  544. full_treble_only(`
  545. neverallow {
  546. domain
  547. -coredomain
  548. -appdomain # restrictions for vendor apps are declared lower down
  549. -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
  550. } service_manager_type:service_manager find;
  551. ')
  552. full_treble_only(`
  553. # Vendor apps are permited to use only stable public services. If they were to use arbitrary
  554. # services which can change any time framework/core is updated, breakage is likely.
  555. neverallow {
  556. appdomain
  557. -coredomain
  558. } {
  559. service_manager_type
  560. -app_api_service
  561. -ephemeral_app_api_service
  562. -audioserver_service # TODO(b/36783122) remove exemptions below once app_api_service is fixed
  563. -cameraserver_service
  564. -drmserver_service
  565. -keystore_service
  566. -mediadrmserver_service
  567. -mediaextractor_service
  568. -mediametrics_service
  569. -mediaserver_service
  570. -nfc_service
  571. -radio_service
  572. -virtual_touchpad_service
  573. -vr_hwc_service
  574. -vr_manager_service
  575. }:service_manager find;
  576. ')
  577. full_treble_only(`
  578. neverallow {
  579. domain
  580. -coredomain
  581. -appdomain
  582. -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
  583. } servicemanager:binder { call transfer };
  584. ')
  585. # On full TREBLE devices, only vendor components, shell, and su can use VendorBinder.
  586. full_treble_only(`
  587. neverallow {
  588. coredomain
  589. -shell
  590. userdebug_or_eng(`-su')
  591. -ueventd # uevent is granted create for this device, but we still neverallow I/O below
  592. } vndbinder_device:chr_file rw_file_perms;
  593. ')
  594. full_treble_only(`
  595. neverallow ueventd vndbinder_device:chr_file { read write append ioctl };
  596. ')
  597. full_treble_only(`
  598. neverallow {
  599. coredomain
  600. -shell
  601. userdebug_or_eng(`-su')
  602. } vndservice_manager_type:service_manager *;
  603. ')
  604. full_treble_only(`
  605. neverallow {
  606. coredomain
  607. -shell
  608. userdebug_or_eng(`-su')
  609. } vndservicemanager:binder *;
  610. ')
  611. # On full TREBLE devices, socket communications between core components and vendor components are
  612. # not permitted.
  613. # Most general rules first, more specific rules below.
  614. # Core domains are not permitted to initiate communications to vendor domain sockets.
  615. # We are not restricting the use of already established sockets because it is fine for a process
  616. # to obtain an already established socket via some public/official/stable API and then exchange
  617. # data with its peer over that socket. The wire format in this scenario is dicatated by the API
  618. # and thus does not break the core-vendor separation.
  619. full_treble_only(`
  620. neverallow_establish_socket_comms({
  621. coredomain
  622. -init
  623. -adbd
  624. }, {
  625. domain
  626. -coredomain
  627. -socket_between_core_and_vendor_violators
  628. });
  629. ')
  630. # Vendor domains are not permitted to initiate communications to core domain sockets
  631. full_treble_only(`
  632. neverallow_establish_socket_comms({
  633. domain
  634. -coredomain
  635. -appdomain
  636. -socket_between_core_and_vendor_violators
  637. }, {
  638. coredomain
  639. -logd # Logging by writing to logd Unix domain socket is public API
  640. -netd # netdomain needs this
  641. -mdnsd # netdomain needs this
  642. userdebug_or_eng(`-su') # communications with su are permitted only on userdebug or eng builds
  643. -init
  644. -tombstoned # linker to tombstoned
  645. userdebug_or_eng('-heapprofd`)
  646. });
  647. ')
  648. # Vendor domains (except netdomain) are not permitted to initiate communications to netd sockets
  649. full_treble_only(`
  650. neverallow_establish_socket_comms({
  651. domain
  652. -coredomain
  653. -netdomain
  654. -socket_between_core_and_vendor_violators
  655. }, netd);
  656. ')
  657. # Vendor domains are not permitted to initiate create/open sockets owned by core domains
  658. full_treble_only(`
  659. neverallow {
  660. domain
  661. -coredomain
  662. -appdomain # appdomain restrictions below
  663. -data_between_core_and_vendor_violators # b/70393317
  664. -socket_between_core_and_vendor_violators
  665. -vendor_init
  666. } {
  667. coredomain_socket
  668. core_data_file_type
  669. unlabeled # used only by core domains
  670. }:sock_file ~{ append getattr ioctl read write };
  671. ')
  672. full_treble_only(`
  673. neverallow {
  674. appdomain
  675. -coredomain
  676. } {
  677. coredomain_socket
  678. unlabeled # used only by core domains
  679. core_data_file_type
  680. -app_data_file
  681. -privapp_data_file
  682. -pdx_endpoint_socket_type # used by VR layer
  683. -pdx_channel_socket_type # used by VR layer
  684. }:sock_file ~{ append getattr ioctl read write };
  685. ')
  686. # Core domains are not permitted to create/open sockets owned by vendor domains
  687. full_treble_only(`
  688. neverallow {
  689. coredomain
  690. -init
  691. -ueventd
  692. -socket_between_core_and_vendor_violators
  693. } {
  694. file_type
  695. dev_type
  696. -coredomain_socket
  697. -core_data_file_type
  698. -unlabeled
  699. }:sock_file ~{ append getattr ioctl read write };
  700. ')
  701. # On TREBLE devices, vendor and system components are only allowed to share
  702. # files by passing open FDs over hwbinder. Ban all directory access and all file
  703. # accesses other than what can be applied to an open FD such as
  704. # ioctl/stat/read/write/append. This is enforced by segregating /data.
  705. # Vendor domains may directly access file in /data/vendor by path, but may only
  706. # access files outside of /data/vendor via an open FD passed over hwbinder.
  707. # Likewise, core domains may only directly access files outside /data/vendor by
  708. # path and files in /data/vendor by open FD.
  709. full_treble_only(`
  710. # only coredomains may only access core_data_file_type, particularly not
  711. # /data/vendor
  712. neverallow {
  713. coredomain
  714. -appdomain # TODO(b/34980020) remove exemption for appdomain
  715. -data_between_core_and_vendor_violators
  716. -init
  717. -vold_prepare_subdirs
  718. } {
  719. data_file_type
  720. -core_data_file_type
  721. }:file_class_set ~{ append getattr ioctl read write map };
  722. ')
  723. full_treble_only(`
  724. neverallow {
  725. coredomain
  726. -appdomain # TODO(b/34980020) remove exemption for appdomain
  727. -data_between_core_and_vendor_violators
  728. -init
  729. -vold_prepare_subdirs
  730. } {
  731. data_file_type
  732. -core_data_file_type
  733. # TODO(b/72998741) Remove exemption. Further restricted in a subsequent
  734. # neverallow. Currently only getattr and search are allowed.
  735. -vendor_data_file
  736. }:dir *;
  737. ')
  738. full_treble_only(`
  739. # vendor domains may only access files in /data/vendor, never core_data_file_types
  740. neverallow {
  741. domain
  742. -appdomain # TODO(b/34980020) remove exemption for appdomain
  743. -coredomain
  744. -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
  745. -vendor_init
  746. } {
  747. core_data_file_type
  748. # libc includes functions like mktime and localtime which attempt to access
  749. # files in /data/misc/zoneinfo/tzdata and /system/usr/share/zoneinfo/tzdata.
  750. # These functions are considered vndk-stable and thus must be allowed for
  751. # all processes.
  752. -zoneinfo_data_file
  753. with_native_coverage(`-method_trace_data_file')
  754. }:file_class_set ~{ append getattr ioctl read write map };
  755. neverallow {
  756. vendor_init
  757. -data_between_core_and_vendor_violators
  758. } {
  759. core_data_file_type
  760. -unencrypted_data_file
  761. -zoneinfo_data_file
  762. with_native_coverage(`-method_trace_data_file')
  763. }:file_class_set ~{ append getattr ioctl read write map };
  764. # vendor init needs to be able to read unencrypted_data_file to create directories with FBE.
  765. # The vendor init binary lives on the system partition so there is not a concern with stability.
  766. neverallow vendor_init unencrypted_data_file:file ~r_file_perms;
  767. ')
  768. full_treble_only(`
  769. # vendor domains may only access dirs in /data/vendor, never core_data_file_types
  770. neverallow {
  771. domain
  772. -appdomain # TODO(b/34980020) remove exemption for appdomain
  773. -coredomain
  774. -data_between_core_and_vendor_violators
  775. -vendor_init
  776. } {
  777. core_data_file_type
  778. -system_data_file # default label for files on /data. Covered below...
  779. -vendor_data_file
  780. -zoneinfo_data_file
  781. with_native_coverage(`-method_trace_data_file')
  782. }:dir *;
  783. neverallow {
  784. vendor_init
  785. -data_between_core_and_vendor_violators
  786. } {
  787. core_data_file_type
  788. -unencrypted_data_file
  789. -system_data_file
  790. -vendor_data_file
  791. -zoneinfo_data_file
  792. with_native_coverage(`-method_trace_data_file')
  793. }:dir *;
  794. # vendor init needs to be able to read unencrypted_data_file to create directories with FBE.
  795. # The vendor init binary lives on the system partition so there is not a concern with stability.
  796. neverallow vendor_init unencrypted_data_file:dir ~search;
  797. ')
  798. full_treble_only(`
  799. # vendor domains may only access dirs in /data/vendor, never core_data_file_types
  800. neverallow {
  801. domain
  802. -appdomain # TODO(b/34980020) remove exemption for appdomain
  803. -coredomain
  804. -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
  805. } {
  806. system_data_file # default label for files on /data. Covered below
  807. }:dir ~{ getattr search };
  808. ')
  809. full_treble_only(`
  810. # coredomains may not access dirs in /data/vendor.
  811. neverallow {
  812. coredomain
  813. -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
  814. -init
  815. -vold # vold creates per-user storage for both system and vendor
  816. -vold_prepare_subdirs
  817. } {
  818. vendor_data_file # default label for files on /data. Covered below
  819. }:dir ~{ getattr search };
  820. ')
  821. full_treble_only(`
  822. # coredomains may not access dirs in /data/vendor.
  823. neverallow {
  824. coredomain
  825. -data_between_core_and_vendor_violators # TODO(b/34980020) Remove once all violators have been cleaned up
  826. -init
  827. } {
  828. vendor_data_file # default label for files on /data/vendor{,_ce,_de}.
  829. }:file_class_set ~{ append getattr ioctl read write map };
  830. ')
  831. full_treble_only(`
  832. # Non-vendor domains are not allowed to file execute shell
  833. # from vendor
  834. neverallow {
  835. coredomain
  836. -init
  837. -shell
  838. } vendor_shell_exec:file { execute execute_no_trans };
  839. ')
  840. full_treble_only(`
  841. # Do not allow vendor components to execute files from system
  842. # except for the ones whitelist here.
  843. neverallow {
  844. domain
  845. -coredomain
  846. -appdomain
  847. -vendor_executes_system_violators
  848. -vendor_init
  849. } {
  850. system_file_type
  851. -system_lib_file
  852. -system_linker_exec
  853. -crash_dump_exec
  854. -netutils_wrapper_exec
  855. userdebug_or_eng(`-tcpdump_exec')
  856. }:file { entrypoint execute execute_no_trans };
  857. ')
  858. full_treble_only(`
  859. # Do not allow system components to execute files from vendor
  860. # except for the ones whitelisted here.
  861. neverallow {
  862. coredomain
  863. -init
  864. -shell
  865. -system_executes_vendor_violators
  866. } {
  867. vendor_file_type
  868. -same_process_hal_file
  869. -vndk_sp_file
  870. -vendor_app_file
  871. -vendor_public_lib_file
  872. }:file execute;
  873. ')
  874. full_treble_only(`
  875. neverallow {
  876. coredomain
  877. -shell
  878. -system_executes_vendor_violators
  879. } {
  880. vendor_file_type
  881. -same_process_hal_file
  882. }:file execute_no_trans;
  883. ')
  884. full_treble_only(`
  885. # Do not allow system components access to /vendor files except for the
  886. # ones whitelisted here.
  887. neverallow {
  888. coredomain
  889. # TODO(b/37168747): clean up fwk access to /vendor
  890. -crash_dump
  891. -init # starts vendor executables
  892. -kernel # loads /vendor/firmware
  893. userdebug_or_eng(`-perfprofd')
  894. userdebug_or_eng(`-heapprofd')
  895. -shell
  896. -system_executes_vendor_violators
  897. -ueventd # reads /vendor/ueventd.rc
  898. } {
  899. vendor_file_type
  900. -same_process_hal_file
  901. -vendor_app_file
  902. -vendor_configs_file
  903. -vendor_framework_file
  904. -vendor_idc_file
  905. -vendor_keychars_file
  906. -vendor_keylayout_file
  907. -vendor_overlay_file
  908. -vendor_public_lib_file
  909. -vendor_task_profiles_file
  910. -vndk_sp_file
  911. }:file *;
  912. ')
  913. full_treble_only(`
  914. # Do not allow vendor components access to /system files except for the
  915. # ones whitelisted here.
  916. neverallow {
  917. domain
  918. -appdomain
  919. -coredomain
  920. -vendor_executes_system_violators
  921. # vendor_init needs access to init_exec for domain transition. vendor_init
  922. # neverallows are covered in public/vendor_init.te
  923. -vendor_init
  924. } {
  925. system_file_type
  926. -crash_dump_exec
  927. -file_contexts_file
  928. -netutils_wrapper_exec
  929. -property_contexts_file
  930. -system_event_log_tags_file
  931. -system_lib_file
  932. with_asan(`-system_asan_options_file')
  933. -system_linker_exec
  934. -system_linker_config_file
  935. -system_seccomp_policy_file
  936. -system_security_cacerts_file
  937. -system_zoneinfo_file
  938. -task_profiles_file
  939. userdebug_or_eng(`-tcpdump_exec')
  940. }:file *;
  941. ')
  942. # Only system_server should be able to send commands via the zygote socket
  943. neverallow { domain -zygote -system_server } zygote:unix_stream_socket connectto;
  944. neverallow { domain -system_server } zygote_socket:sock_file write;
  945. neverallow { domain -system_server -webview_zygote -app_zygote } webview_zygote:unix_stream_socket connectto;
  946. neverallow { domain -system_server } webview_zygote:sock_file write;
  947. neverallow { domain -system_server } app_zygote:sock_file write;
  948. neverallow {
  949. domain
  950. -tombstoned
  951. -crash_dump
  952. -dumpstate
  953. -incidentd
  954. -system_server
  955. # Processes that can't exec crash_dump
  956. -hal_codec2_server
  957. -hal_omx_server
  958. -mediaextractor
  959. } tombstoned_crash_socket:unix_stream_socket connectto;
  960. # Never allow anyone except dumpstate, incidentd, or the system server to connect or write to
  961. # the tombstoned intercept socket.
  962. neverallow { domain -dumpstate -incidentd -system_server } tombstoned_intercept_socket:sock_file write;
  963. neverallow { domain -dumpstate -incidentd -system_server } tombstoned_intercept_socket:unix_stream_socket connectto;
  964. # Android does not support System V IPCs.
  965. #
  966. # The reason for this is due to the fact that, by design, they lead to global
  967. # kernel resource leakage.
  968. #
  969. # For example, there is no way to automatically release a SysV semaphore
  970. # allocated in the kernel when:
  971. #
  972. # - a buggy or malicious process exits
  973. # - a non-buggy and non-malicious process crashes or is explicitly killed.
  974. #
  975. # Killing processes automatically to make room for new ones is an
  976. # important part of Android's application lifecycle implementation. This means
  977. # that, even assuming only non-buggy and non-malicious code, it is very likely
  978. # that over time, the kernel global tables used to implement SysV IPCs will fill
  979. # up.
  980. neverallow * *:{ shm sem msg msgq } *;
  981. # Do not mount on top of symlinks, fifos, or sockets.
  982. # Feature parity with Chromium LSM.
  983. neverallow * { file_type fs_type dev_type }:{ lnk_file fifo_file sock_file } mounton;
  984. # Nobody should be able to execute su on user builds.
  985. # On userdebug/eng builds, only dumpstate, shell, and
  986. # su itself execute su.
  987. neverallow { domain userdebug_or_eng(`-dumpstate -shell -su') } su_exec:file no_x_file_perms;
  988. # Do not allow the introduction of new execmod rules. Text relocations
  989. # and modification of executable pages are unsafe.
  990. # The only exceptions are for NDK text relocations associated with
  991. # https://code.google.com/p/android/issues/detail?id=23203
  992. # which, long term, need to go away.
  993. neverallow * {
  994. file_type
  995. -apk_data_file
  996. -app_data_file
  997. -asec_public_file
  998. }:file execmod;
  999. # Do not allow making the stack or heap executable.
  1000. # We would also like to minimize execmem but it seems to be
  1001. # required by some device-specific service domains.
  1002. neverallow * self:process { execstack execheap };
  1003. # Do not allow the introduction of new execmod rules. Text relocations
  1004. # and modification of executable pages are unsafe.
  1005. neverallow { domain -untrusted_app_25 -untrusted_app_27 } file_type:file execmod;
  1006. neverallow { domain -init } proc:{ file dir } mounton;
  1007. # Ensure that all types assigned to processes are included
  1008. # in the domain attribute, so that all allow and neverallow rules
  1009. # written on domain are applied to all processes.
  1010. # This is achieved by ensuring that it is impossible to transition
  1011. # from a domain to a non-domain type and vice versa.
  1012. # TODO - rework this: neverallow domain ~domain:process { transition dyntransition };
  1013. neverallow ~domain domain:process { transition dyntransition };
  1014. #
  1015. # Only system_app and system_server should be creating or writing
  1016. # their files. The proper way to share files is to setup
  1017. # type transitions to a more specific type or assigning a type
  1018. # to its parent directory via a file_contexts entry.
  1019. # Example type transition:
  1020. # mydomain.te:file_type_auto_trans(mydomain, system_data_file, new_file_type)
  1021. #
  1022. neverallow {
  1023. domain
  1024. -system_server
  1025. -system_app
  1026. -init
  1027. -toolbox # TODO(b/141108496) We want to remove toolbox
  1028. -installd # for relabelfrom and unlink, check for this in explicit neverallow
  1029. -vold_prepare_subdirs # For unlink
  1030. with_asan(`-asan_extract')
  1031. } system_data_file:file no_w_file_perms;
  1032. # do not grant anything greater than r_file_perms and relabelfrom unlink
  1033. # to installd
  1034. neverallow installd system_data_file:file ~{ r_file_perms relabelfrom unlink };
  1035. # respect system_app sandboxes
  1036. neverallow {
  1037. domain
  1038. -appdomain # finer-grained rules for appdomain are listed below
  1039. -system_server #populate com.android.providers.settings/databases/settings.db.
  1040. -installd # creation of app sandbox
  1041. -traced_probes # resolve inodes for i/o tracing.
  1042. # only needs open and read, the rest is neverallow in
  1043. # traced_probes.te.
  1044. } system_app_data_file:dir_file_class_set { create unlink open };
  1045. neverallow {
  1046. isolated_app
  1047. untrusted_app_all # finer-grained rules for appdomain are listed below
  1048. ephemeral_app
  1049. priv_app
  1050. } system_app_data_file:dir_file_class_set { create unlink open };
  1051. #
  1052. # Only these domains should transition to shell domain. This domain is
  1053. # permissible for the "shell user". If you need a process to exec a shell
  1054. # script with differing privilege, define a domain and set up a transition.
  1055. #
  1056. neverallow {
  1057. domain
  1058. -adbd
  1059. -init
  1060. -runas
  1061. -zygote
  1062. } shell:process { transition dyntransition };
  1063. # Only domains spawned from zygote, runas and simpleperf_app_runner may have the appdomain
  1064. # attribute.
  1065. neverallow { domain -simpleperf_app_runner -runas -app_zygote -webview_zygote -zygote } {
  1066. appdomain -shell userdebug_or_eng(`-su')
  1067. }:process { transition dyntransition };
  1068. # Minimize read access to shell- or app-writable symlinks.
  1069. # This is to prevent malicious symlink attacks.
  1070. neverallow {
  1071. domain
  1072. -appdomain
  1073. -installd
  1074. } { app_data_file privapp_data_file }:lnk_file read;
  1075. neverallow {
  1076. domain
  1077. -shell
  1078. userdebug_or_eng(`-uncrypt')
  1079. -installd
  1080. } shell_data_file:lnk_file read;
  1081. # In addition to the symlink reading restrictions above, restrict
  1082. # write access to shell owned directories. The /data/local/tmp
  1083. # directory is untrustworthy, and non-whitelisted domains should
  1084. # not be trusting any content in those directories.
  1085. neverallow {
  1086. domain
  1087. -adbd
  1088. -dumpstate
  1089. -installd
  1090. -init
  1091. -shell
  1092. -vold
  1093. } shell_data_file:dir no_w_dir_perms;
  1094. neverallow {
  1095. domain
  1096. -adbd
  1097. -appdomain
  1098. -dumpstate
  1099. -init
  1100. -installd
  1101. -simpleperf_app_runner
  1102. -system_server # why?
  1103. userdebug_or_eng(`-uncrypt')
  1104. } shell_data_file:dir { open search };
  1105. # Same as above for /data/local/tmp files. We allow shell files
  1106. # to be passed around by file descriptor, but not directly opened.
  1107. neverallow {
  1108. domain
  1109. -adbd
  1110. -appdomain
  1111. -dumpstate
  1112. -installd
  1113. userdebug_or_eng(`-uncrypt')
  1114. } shell_data_file:file open;
  1115. # servicemanager and vndservicemanager are the only processes which handle the
  1116. # service_manager list request
  1117. neverallow * ~{
  1118. servicemanager
  1119. vndservicemanager
  1120. }:service_manager list;
  1121. # hwservicemanager is the only process which handles hw list requests
  1122. neverallow * ~{
  1123. hwservicemanager
  1124. }:hwservice_manager list;
  1125. # only service_manager_types can be added to service_manager
  1126. # TODO - rework this: neverallow * ~service_manager_type:service_manager { add find };
  1127. # Prevent assigning non property types to properties
  1128. # TODO - rework this: neverallow * ~property_type:property_service set;
  1129. # Domain types should never be assigned to any files other
  1130. # than the /proc/pid files associated with a process. The
  1131. # executable file used to enter a domain should be labeled
  1132. # with its own _exec type, not with the domain type.
  1133. # Conventionally, this looks something like:
  1134. # $ cat mydaemon.te
  1135. # type mydaemon, domain;
  1136. # type mydaemon_exec, exec_type, file_type;
  1137. # init_daemon_domain(mydaemon)
  1138. # $ grep mydaemon file_contexts
  1139. # /system/bin/mydaemon -- u:object_r:mydaemon_exec:s0
  1140. neverallow * domain:file { execute execute_no_trans entrypoint };
  1141. # Do not allow access to the generic debugfs label. This is too broad.
  1142. # Instead, if access to part of debugfs is desired, it should have a
  1143. # more specific label.
  1144. # TODO: fix dumpstate
  1145. neverallow { domain -init -vendor_init -dumpstate } debugfs:{ file lnk_file } no_rw_file_perms;
  1146. # Do not allow executable files in debugfs.
  1147. neverallow domain debugfs_type:file { execute execute_no_trans };
  1148. # Profiles contain untrusted data and profman parses that. We should only run
  1149. # in from installd forked processes.
  1150. neverallow {
  1151. domain
  1152. -installd
  1153. -profman
  1154. } profman_exec:file no_x_file_perms;
  1155. # Enforce restrictions on kernel module origin.
  1156. # Do not allow kernel module loading except from system,
  1157. # vendor, and boot partitions.
  1158. neverallow * ~{ system_file vendor_file rootfs }:system module_load;
  1159. # Only allow filesystem caps to be set at build time. Runtime changes
  1160. # to filesystem capabilities are not permitted.
  1161. neverallow * self:global_capability_class_set setfcap;
  1162. # Enforce AT_SECURE for executing crash_dump.
  1163. neverallow domain crash_dump:process noatsecure;
  1164. # Do not permit non-core domains to register HwBinder services which are
  1165. # guaranteed to be provided by core domains only.
  1166. neverallow ~coredomain coredomain_hwservice:hwservice_manager add;
  1167. # Do not permit the registeration of HwBinder services which are guaranteed to
  1168. # be passthrough only (i.e., run in the process of their clients instead of a
  1169. # separate server process).
  1170. neverallow * same_process_hwservice:hwservice_manager add;
  1171. # On TREBLE devices, most coredomains should not access vendor_files.
  1172. # TODO(b/71553434): Remove exceptions here.
  1173. full_treble_only(`
  1174. neverallow {
  1175. coredomain
  1176. -appdomain
  1177. -bootanim
  1178. -crash_dump
  1179. -init
  1180. -kernel
  1181. -perfprofd
  1182. -heapprofd
  1183. -ueventd
  1184. } vendor_file:file { no_w_file_perms no_x_file_perms open };
  1185. ')
  1186. # If an already existing file is opened with O_CREAT, the kernel might generate
  1187. # a false report of a create denial. Silence these denials and make sure that
  1188. # inappropriate permissions are not granted.
  1189. # These filesystems don't allow files or directories to be created, so the permission
  1190. # to do so should never be granted.
  1191. neverallow domain {
  1192. proc_type
  1193. sysfs_type
  1194. }:dir { add_name create link remove_name rename reparent rmdir write };
  1195. # cgroupfs directories can be created, but not files within them.
  1196. neverallow domain cgroup:file create;
  1197. dontaudit domain proc_type:dir write;
  1198. dontaudit domain sysfs_type:dir write;
  1199. dontaudit domain cgroup:file create;
  1200. # These are only needed in permissive mode - in enforcing mode the
  1201. # directory write check fails and so these are never attempted.
  1202. userdebug_or_eng(`
  1203. dontaudit domain proc_type:dir add_name;
  1204. dontaudit domain sysfs_type:dir add_name;
  1205. dontaudit domain proc_type:file create;
  1206. dontaudit domain sysfs_type:file create;
  1207. ')
  1208. # Platform must not have access to /mnt/vendor.
  1209. neverallow {
  1210. coredomain
  1211. -init
  1212. -ueventd
  1213. -vold
  1214. -system_writes_mnt_vendor_violators
  1215. } mnt_vendor_file:dir *;
  1216. # Only apps are allowed access to vendor public libraries.
  1217. full_treble_only(`
  1218. neverallow {
  1219. coredomain
  1220. -appdomain
  1221. } vendor_public_lib_file:file { execute execute_no_trans };
  1222. ')
  1223. # Vendor domian must not have access to /mnt/product.
  1224. neverallow {
  1225. domain
  1226. -coredomain
  1227. } mnt_product_file:dir *;
  1228. # Platform must not have access to sysfs_batteryinfo, but should do it via health HAL and healthd
  1229. full_treble_only(`
  1230. neverallow {
  1231. coredomain
  1232. -healthd
  1233. -shell
  1234. # Generate uevents for health info
  1235. -ueventd
  1236. # Recovery uses health HAL passthrough implementation.
  1237. -recovery
  1238. # Charger uses health HAL passthrough implementation.
  1239. -charger
  1240. # TODO(b/110891300): remove this exception
  1241. -incidentd
  1242. } sysfs_batteryinfo:file { open read };
  1243. ')
  1244. neverallow {
  1245. domain
  1246. -hal_codec2_server
  1247. -hal_omx_server
  1248. } hal_codec2_hwservice:hwservice_manager add;