priv_app.te 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. ###
  2. ### A domain for further sandboxing privileged apps.
  3. ###
  4. typeattribute priv_app coredomain;
  5. app_domain(priv_app)
  6. # Access the network.
  7. net_domain(priv_app)
  8. # Access bluetooth.
  9. bluetooth_domain(priv_app)
  10. # Allow the allocation and use of ptys
  11. # Used by: https://play.privileged.com/store/apps/details?id=jackpal.androidterm
  12. create_pty(priv_app)
  13. # webview crash handling depends on self ptrace (b/27697529, b/20150694, b/19277529#comment7)
  14. allow priv_app self:process ptrace;
  15. # Allow loading executable code from writable priv-app home
  16. # directories. This is a W^X violation, however, it needs
  17. # to be supported for now for the following reasons.
  18. # * /data/user_*/0/*/code_cache/* POSSIBLE uses (b/117841367)
  19. # 1) com.android.opengl.shaders_cache
  20. # 2) com.android.skia.shaders_cache
  21. # 3) com.android.renderscript.cache
  22. # * /data/user_de/0/com.google.android.gms/app_chimera
  23. # TODO: Tighten (b/112357170)
  24. allow priv_app privapp_data_file:file execute;
  25. allow priv_app privapp_data_file:lnk_file create_file_perms;
  26. # Priv apps can find services that expose both @SystemAPI and normal APIs.
  27. allow priv_app app_api_service:service_manager find;
  28. allow priv_app system_api_service:service_manager find;
  29. allow priv_app audioserver_service:service_manager find;
  30. allow priv_app cameraserver_service:service_manager find;
  31. allow priv_app drmserver_service:service_manager find;
  32. allow priv_app mediacodec_service:service_manager find;
  33. allow priv_app mediadrmserver_service:service_manager find;
  34. allow priv_app mediaextractor_service:service_manager find;
  35. allow priv_app mediametrics_service:service_manager find;
  36. allow priv_app mediaserver_service:service_manager find;
  37. allow priv_app network_watchlist_service:service_manager find;
  38. allow priv_app nfc_service:service_manager find;
  39. allow priv_app oem_lock_service:service_manager find;
  40. allow priv_app persistent_data_block_service:service_manager find;
  41. allow priv_app radio_service:service_manager find;
  42. allow priv_app recovery_service:service_manager find;
  43. allow priv_app stats_service:service_manager find;
  44. # Allow privileged apps to interact with gpuservice
  45. binder_call(priv_app, gpuservice)
  46. allow priv_app gpu_service:service_manager find;
  47. # Write to /cache.
  48. allow priv_app { cache_file cache_recovery_file }:dir create_dir_perms;
  49. allow priv_app { cache_file cache_recovery_file }:file create_file_perms;
  50. # /cache is a symlink to /data/cache on some devices. Allow reading the link.
  51. allow priv_app cache_file:lnk_file r_file_perms;
  52. # Write to /data/ota_package for OTA packages.
  53. allow priv_app ota_package_file:dir rw_dir_perms;
  54. allow priv_app ota_package_file:file create_file_perms;
  55. # Access to /data/media.
  56. allow priv_app media_rw_data_file:dir create_dir_perms;
  57. allow priv_app media_rw_data_file:file create_file_perms;
  58. # Used by Finsky / Android "Verify Apps" functionality when
  59. # running "adb install foo.apk".
  60. allow priv_app shell_data_file:file r_file_perms;
  61. allow priv_app shell_data_file:dir r_dir_perms;
  62. # Allow traceur to pass file descriptors through a content provider to betterbug
  63. allow priv_app trace_data_file:file { getattr read };
  64. # Allow verifier to access staged apks.
  65. allow priv_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms;
  66. allow priv_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms;
  67. # b/18504118: Allow reads from /data/anr/traces.txt
  68. allow priv_app anr_data_file:file r_file_perms;
  69. # Allow GMS core to access perfprofd output, which is stored
  70. # in /data/misc/perfprofd/. GMS core will need to list all
  71. # data stored in that directory to process them one by one.
  72. userdebug_or_eng(`
  73. allow priv_app perfprofd_data_file:file r_file_perms;
  74. allow priv_app perfprofd_data_file:dir r_dir_perms;
  75. ')
  76. # For AppFuse.
  77. allow priv_app vold:fd use;
  78. allow priv_app fuse_device:chr_file { read write };
  79. # /proc access
  80. allow priv_app {
  81. proc_vmstat
  82. }:file r_file_perms;
  83. allow priv_app sysfs_type:dir search;
  84. # Read access to /sys/class/net/wlan*/address
  85. r_dir_file(priv_app, sysfs_net)
  86. # Read access to /sys/block/zram*/mm_stat
  87. r_dir_file(priv_app, sysfs_zram)
  88. r_dir_file(priv_app, rootfs)
  89. # Allow GMS core to open kernel config for OTA matching through libvintf
  90. allow priv_app config_gz:file { open read getattr };
  91. # access the mac address
  92. allowxperm priv_app self:udp_socket ioctl SIOCGIFHWADDR;
  93. # Allow GMS core to communicate with update_engine for A/B update.
  94. binder_call(priv_app, update_engine)
  95. allow priv_app update_engine_service:service_manager find;
  96. # Allow GMS core to communicate with dumpsys storaged.
  97. binder_call(priv_app, storaged)
  98. allow priv_app storaged_service:service_manager find;
  99. # Allow GMS core to access system_update_service (e.g. to publish pending
  100. # system update info).
  101. allow priv_app system_update_service:service_manager find;
  102. # Allow GMS core to communicate with statsd.
  103. binder_call(priv_app, statsd)
  104. # Allow Phone to read/write cached ringtones (opened by system).
  105. allow priv_app ringtone_file:file { getattr read write };
  106. # Access to /data/preloads
  107. allow priv_app preloads_data_file:file r_file_perms;
  108. allow priv_app preloads_data_file:dir r_dir_perms;
  109. allow priv_app preloads_media_file:file r_file_perms;
  110. allow priv_app preloads_media_file:dir r_dir_perms;
  111. # Allow privileged apps (e.g. GMS core) to generate unique hardware IDs
  112. allow priv_app keystore:keystore_key gen_unique_id;
  113. # Allow GMS core to access /sys/fs/selinux/policyvers for compatibility check
  114. allow priv_app selinuxfs:file r_file_perms;
  115. read_runtime_log_tags(priv_app)
  116. # Write app-specific trace data to the Perfetto traced damon. This requires
  117. # connecting to its producer socket and obtaining a (per-process) tmpfs fd.
  118. allow priv_app traced:fd use;
  119. allow priv_app traced_tmpfs:file { read write getattr map };
  120. unix_socket_connect(priv_app, traced_producer, traced)
  121. # Allow priv_apps to request and collect incident reports.
  122. # (Also requires DUMP and PACKAGE_USAGE_STATS permissions)
  123. allow priv_app incident_service:service_manager find;
  124. binder_call(priv_app, incidentd)
  125. allow priv_app incidentd:fifo_file { read write };
  126. # Allow heap profiling if the app opts in by being marked
  127. # profileable/debuggable.
  128. can_profile_heap(priv_app)
  129. # Allow priv_apps to check whether Dynamic System Update is enabled
  130. get_prop(priv_app, dynamic_system_prop)
  131. # suppress denials for non-API accesses.
  132. dontaudit priv_app exec_type:file getattr;
  133. dontaudit priv_app device:dir read;
  134. dontaudit priv_app fs_bpf:dir search;
  135. dontaudit priv_app net_dns_prop:file read;
  136. dontaudit priv_app proc:file read;
  137. dontaudit priv_app proc_interrupts:file read;
  138. dontaudit priv_app proc_modules:file read;
  139. dontaudit priv_app proc_stat:file read;
  140. dontaudit priv_app proc_version:file read;
  141. dontaudit priv_app sysfs:dir read;
  142. dontaudit priv_app sysfs:file read;
  143. dontaudit priv_app sysfs_android_usb:file read;
  144. dontaudit priv_app wifi_prop:file read;
  145. dontaudit priv_app { wifi_prop exported_wifi_prop }:file read;
  146. # allow privileged apps to use UDP sockets provided by the system server but not
  147. # modify them other than to connect
  148. allow priv_app system_server:udp_socket {
  149. connect getattr read recvfrom sendto write getopt setopt };
  150. # Attempts to write to system_data_file is generally a sign
  151. # that apps are attempting to access encrypted storage before
  152. # the ACTION_USER_UNLOCKED intent is delivered. Suppress this
  153. # denial to prevent apps from spamming the logs.
  154. dontaudit priv_app system_data_file:dir write;
  155. ###
  156. ### neverallow rules
  157. ###
  158. # Receive or send uevent messages.
  159. neverallow priv_app domain:netlink_kobject_uevent_socket *;
  160. # Receive or send generic netlink messages
  161. neverallow priv_app domain:netlink_socket *;
  162. # Too much leaky information in debugfs. It's a security
  163. # best practice to ensure these files aren't readable.
  164. neverallow priv_app debugfs:file read;
  165. # Do not allow privileged apps to register services.
  166. # Only trusted components of Android should be registering
  167. # services.
  168. neverallow priv_app service_manager_type:service_manager add;
  169. # Do not allow privileged apps to connect to the property service
  170. # or set properties. b/10243159
  171. neverallow priv_app property_socket:sock_file write;
  172. neverallow priv_app init:unix_stream_socket connectto;
  173. neverallow priv_app property_type:property_service set;
  174. # Do not allow priv_app to be assigned mlstrustedsubject.
  175. # This would undermine the per-user isolation model being
  176. # enforced via levelFrom=user in seapp_contexts and the mls
  177. # constraints. As there is no direct way to specify a neverallow
  178. # on attribute assignment, this relies on the fact that fork
  179. # permission only makes sense within a domain (hence should
  180. # never be granted to any other domain within mlstrustedsubject)
  181. # and priv_app is allowed fork permission to itself.
  182. neverallow priv_app mlstrustedsubject:process fork;
  183. # Do not allow priv_app to hard link to any files.
  184. # In particular, if priv_app links to other app data
  185. # files, installd will not be able to guarantee the deletion
  186. # of the linked to file. Hard links also contribute to security
  187. # bugs, so we want to ensure priv_app never has this
  188. # capability.
  189. neverallow priv_app file_type:file link;
  190. # priv apps should not be able to open trace data files, they should depend
  191. # upon traceur to pass a file descriptor which they can then read
  192. neverallow priv_app trace_data_file:dir *;
  193. neverallow priv_app trace_data_file:file { no_w_file_perms open };
  194. # Do not allow priv_app access to cgroups.
  195. neverallow priv_app cgroup:file *;
  196. # Do not allow loading executable code from non-privileged
  197. # application home directories. Code loading across a security boundary
  198. # is dangerous and allows a full compromise of a privileged process
  199. # by an unprivileged process. b/112357170
  200. neverallow priv_app app_data_file:file no_x_file_perms;
  201. # Do not follow untrusted app provided symlinks
  202. neverallow priv_app app_data_file:lnk_file { open read getattr };