te_macros 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. #####################################
  2. # domain_trans(olddomain, type, newdomain)
  3. # Allow a transition from olddomain to newdomain
  4. # upon executing a file labeled with type.
  5. # This only allows the transition; it does not
  6. # cause it to occur automatically - use domain_auto_trans
  7. # if that is what you want.
  8. #
  9. define(`domain_trans', `
  10. # Old domain may exec the file and transition to the new domain.
  11. allow $1 $2:file { getattr open read execute map };
  12. allow $1 $3:process transition;
  13. # New domain is entered by executing the file.
  14. allow $3 $2:file { entrypoint open read execute getattr map };
  15. # New domain can send SIGCHLD to its caller.
  16. ifelse($1, `init', `', `allow $3 $1:process sigchld;')
  17. # Enable AT_SECURE, i.e. libc secure mode.
  18. dontaudit $1 $3:process noatsecure;
  19. # XXX dontaudit candidate but requires further study.
  20. allow $1 $3:process { siginh rlimitinh };
  21. ')
  22. #####################################
  23. # domain_auto_trans(olddomain, type, newdomain)
  24. # Automatically transition from olddomain to newdomain
  25. # upon executing a file labeled with type.
  26. #
  27. define(`domain_auto_trans', `
  28. # Allow the necessary permissions.
  29. domain_trans($1,$2,$3)
  30. # Make the transition occur by default.
  31. type_transition $1 $2:process $3;
  32. ')
  33. #####################################
  34. # file_type_trans(domain, dir_type, file_type)
  35. # Allow domain to create a file labeled file_type in a
  36. # directory labeled dir_type.
  37. # This only allows the transition; it does not
  38. # cause it to occur automatically - use file_type_auto_trans
  39. # if that is what you want.
  40. #
  41. define(`file_type_trans', `
  42. # Allow the domain to add entries to the directory.
  43. allow $1 $2:dir ra_dir_perms;
  44. # Allow the domain to create the file.
  45. allow $1 $3:notdevfile_class_set create_file_perms;
  46. allow $1 $3:dir create_dir_perms;
  47. ')
  48. #####################################
  49. # file_type_auto_trans(domain, dir_type, file_type)
  50. # Automatically label new files with file_type when
  51. # they are created by domain in directories labeled dir_type.
  52. #
  53. define(`file_type_auto_trans', `
  54. # Allow the necessary permissions.
  55. file_type_trans($1, $2, $3)
  56. # Make the transition occur by default.
  57. type_transition $1 $2:dir $3;
  58. type_transition $1 $2:notdevfile_class_set $3;
  59. ')
  60. #####################################
  61. # r_dir_file(domain, type)
  62. # Allow the specified domain to read directories, files
  63. # and symbolic links of the specified type.
  64. define(`r_dir_file', `
  65. allow $1 $2:dir r_dir_perms;
  66. allow $1 $2:{ file lnk_file } r_file_perms;
  67. ')
  68. #####################################
  69. # tmpfs_domain(domain)
  70. # Allow access to a unique type for this domain when creating tmpfs / ashmem files.
  71. define(`tmpfs_domain', `
  72. type_transition $1 tmpfs:file $1_tmpfs;
  73. allow $1 $1_tmpfs:file { read write getattr map };
  74. ')
  75. # pdx macros for IPC. pdx is a high-level name which contains transport-specific
  76. # rules from underlying transport (e.g. UDS-based implementation).
  77. #####################################
  78. # pdx_service_attributes(service)
  79. # Defines type attribute used to identify various service-related types.
  80. define(`pdx_service_attributes', `
  81. attribute pdx_$1_endpoint_dir_type;
  82. attribute pdx_$1_endpoint_socket_type;
  83. attribute pdx_$1_channel_socket_type;
  84. attribute pdx_$1_server_type;
  85. ')
  86. #####################################
  87. # pdx_service_socket_types(service, endpoint_dir_t)
  88. # Define types for endpoint and channel sockets.
  89. define(`pdx_service_socket_types', `
  90. typeattribute $2 pdx_$1_endpoint_dir_type;
  91. type pdx_$1_endpoint_socket, pdx_$1_endpoint_socket_type, pdx_endpoint_socket_type, file_type, coredomain_socket, mlstrustedobject, mlstrustedsubject;
  92. type pdx_$1_channel_socket, pdx_$1_channel_socket_type, pdx_channel_socket_type, coredomain_socket;
  93. userdebug_or_eng(`
  94. dontaudit su pdx_$1_endpoint_socket:unix_stream_socket *;
  95. dontaudit su pdx_$1_channel_socket:unix_stream_socket *;
  96. ')
  97. ')
  98. #####################################
  99. # pdx_server(server_domain, service)
  100. define(`pdx_server', `
  101. # Mark the server domain as a PDX server.
  102. typeattribute $1 pdx_$2_server_type;
  103. # Allow the init process to create the initial endpoint socket.
  104. allow init pdx_$2_endpoint_socket_type:unix_stream_socket { create bind };
  105. # Allow the server domain to use the endpoint socket and accept connections on it.
  106. # Not using macro like "rw_socket_perms_no_ioctl" because it provides more rights
  107. # than we need (e.g. we don"t need "bind" or "connect").
  108. allow $1 pdx_$2_endpoint_socket_type:unix_stream_socket { read getattr write setattr lock append getopt setopt shutdown listen accept };
  109. # Allow the server domain to apply security context label to the channel socket pair (allow process to use setsockcreatecon_raw()).
  110. allow $1 self:process setsockcreate;
  111. # Allow the server domain to create a client channel socket.
  112. allow $1 pdx_$2_channel_socket_type:unix_stream_socket create_stream_socket_perms;
  113. # Prevent other processes from claiming to be a server for the same service.
  114. neverallow {domain -$1} pdx_$2_endpoint_socket_type:unix_stream_socket { listen accept };
  115. ')
  116. #####################################
  117. # pdx_connect(client, service)
  118. define(`pdx_connect', `
  119. # Allow client to open the service endpoint file.
  120. allow $1 pdx_$2_endpoint_dir_type:dir r_dir_perms;
  121. allow $1 pdx_$2_endpoint_socket_type:sock_file rw_file_perms;
  122. # Allow the client to connect to endpoint socket.
  123. allow $1 pdx_$2_endpoint_socket_type:unix_stream_socket { connectto read write shutdown };
  124. ')
  125. #####################################
  126. # pdx_use(client, service)
  127. define(`pdx_use', `
  128. # Allow the client to use the PDX channel socket.
  129. # Not using macro like "rw_socket_perms_no_ioctl" because it provides more rights
  130. # than we need (e.g. we don"t need "bind" or "connect").
  131. allow $1 pdx_$2_channel_socket_type:unix_stream_socket { read getattr write setattr lock append getopt setopt shutdown };
  132. # Client needs to use an channel event fd from the server.
  133. allow $1 pdx_$2_server_type:fd use;
  134. # Servers may receive sync fences, gralloc buffers, etc, from clients.
  135. # This could be tightened on a per-server basis, but keeping track of service
  136. # clients is error prone.
  137. allow pdx_$2_server_type $1:fd use;
  138. ')
  139. #####################################
  140. # pdx_client(client, service)
  141. define(`pdx_client', `
  142. pdx_connect($1, $2)
  143. pdx_use($1, $2)
  144. ')
  145. #####################################
  146. # init_daemon_domain(domain)
  147. # Set up a transition from init to the daemon domain
  148. # upon executing its binary.
  149. define(`init_daemon_domain', `
  150. domain_auto_trans(init, $1_exec, $1)
  151. ')
  152. #####################################
  153. # app_domain(domain)
  154. # Allow a base set of permissions required for all apps.
  155. define(`app_domain', `
  156. typeattribute $1 appdomain;
  157. # Label tmpfs objects for all apps.
  158. type_transition $1 tmpfs:file appdomain_tmpfs;
  159. allow $1 appdomain_tmpfs:file { execute getattr map read write };
  160. neverallow { $1 -runas_app -shell } { domain -$1 }:file no_rw_file_perms;
  161. neverallow { appdomain -runas_app -shell -$1 } $1:file no_rw_file_perms;
  162. # The Android security model guarantees the confidentiality and integrity
  163. # of application data and execution state. Ptrace bypasses those
  164. # confidentiality guarantees. Disallow ptrace access from system components
  165. # to apps. Crash_dump is excluded, as it needs ptrace access to
  166. # produce stack traces. llkd is excluded, as it needs to inspect
  167. # the kernel stack for live lock conditions. runas_app is excluded, as it can
  168. # only access debuggable apps.
  169. neverallow { domain -$1 -crash_dump userdebug_or_eng(`-llkd') -runas_app } $1:process ptrace;
  170. ')
  171. #####################################
  172. # untrusted_app_domain(domain)
  173. # Allow a base set of permissions required for all untrusted apps.
  174. define(`untrusted_app_domain', `
  175. typeattribute $1 untrusted_app_all;
  176. ')
  177. #####################################
  178. # net_domain(domain)
  179. # Allow a base set of permissions required for network access.
  180. define(`net_domain', `
  181. typeattribute $1 netdomain;
  182. ')
  183. #####################################
  184. # bluetooth_domain(domain)
  185. # Allow a base set of permissions required for bluetooth access.
  186. define(`bluetooth_domain', `
  187. typeattribute $1 bluetoothdomain;
  188. ')
  189. #####################################
  190. # hal_attribute(hal_name)
  191. # Add an attribute for hal implementations along with necessary
  192. # restrictions.
  193. define(`hal_attribute', `
  194. attribute hal_$1;
  195. expandattribute hal_$1 true;
  196. attribute hal_$1_client;
  197. expandattribute hal_$1_client true;
  198. attribute hal_$1_server;
  199. expandattribute hal_$1_server false;
  200. neverallow { hal_$1_server -halserverdomain } domain:process fork;
  201. # hal_*_client and halclientdomain attributes are always expanded for
  202. # performance reasons. Neverallow rules targeting expanded attributes can not be
  203. # verified by CTS since these attributes are already expanded by that time.
  204. build_test_only(`
  205. neverallow { hal_$1_server -hal_$1 } domain:process fork;
  206. neverallow { hal_$1_client -halclientdomain } domain:process fork;
  207. ')
  208. ')
  209. #####################################
  210. # hal_server_domain(domain, hal_type)
  211. # Allow a base set of permissions required for a domain to offer a
  212. # HAL implementation of the specified type over HwBinder.
  213. #
  214. # For example, default implementation of Foo HAL:
  215. # type hal_foo_default, domain;
  216. # hal_server_domain(hal_foo_default, hal_foo)
  217. #
  218. define(`hal_server_domain', `
  219. typeattribute $1 halserverdomain;
  220. typeattribute $1 $2_server;
  221. typeattribute $1 $2;
  222. ')
  223. #####################################
  224. # hal_client_domain(domain, hal_type)
  225. # Allow a base set of permissions required for a domain to be a
  226. # client of a HAL of the specified type.
  227. #
  228. # For example, make some_domain a client of Foo HAL:
  229. # hal_client_domain(some_domain, hal_foo)
  230. #
  231. define(`hal_client_domain', `
  232. typeattribute $1 halclientdomain;
  233. typeattribute $1 $2_client;
  234. # TODO(b/34170079): Make the inclusion of the rules below conditional also on
  235. # non-Treble devices. For now, on non-Treble device, always grant clients of a
  236. # HAL sufficient access to run the HAL in passthrough mode (i.e., in-process).
  237. not_full_treble(`
  238. typeattribute $1 $2;
  239. # Find passthrough HAL implementations
  240. allow $2 system_file:dir r_dir_perms;
  241. allow $2 vendor_file:dir r_dir_perms;
  242. allow $2 vendor_file:file { read open getattr execute map };
  243. ')
  244. ')
  245. #####################################
  246. # passthrough_hal_client_domain(domain, hal_type)
  247. # Allow a base set of permissions required for a domain to be a
  248. # client of a passthrough HAL of the specified type.
  249. #
  250. # For example, make some_domain a client of passthrough Foo HAL:
  251. # passthrough_hal_client_domain(some_domain, hal_foo)
  252. #
  253. define(`passthrough_hal_client_domain', `
  254. typeattribute $1 halclientdomain;
  255. typeattribute $1 $2_client;
  256. typeattribute $1 $2;
  257. # Find passthrough HAL implementations
  258. allow $2 system_file:dir r_dir_perms;
  259. allow $2 vendor_file:dir r_dir_perms;
  260. allow $2 vendor_file:file { read open getattr execute map };
  261. ')
  262. #####################################
  263. # unix_socket_connect(clientdomain, socket, serverdomain)
  264. # Allow a local socket connection from clientdomain via
  265. # socket to serverdomain.
  266. #
  267. # Note: If you see denial records that distill to the
  268. # following allow rules:
  269. # allow clientdomain property_socket:sock_file write;
  270. # allow clientdomain init:unix_stream_socket connectto;
  271. # allow clientdomain something_prop:property_service set;
  272. #
  273. # This sequence is indicative of attempting to set a property.
  274. # use set_prop(sourcedomain, targetproperty)
  275. #
  276. define(`unix_socket_connect', `
  277. allow $1 $2_socket:sock_file write;
  278. allow $1 $3:unix_stream_socket connectto;
  279. ')
  280. #####################################
  281. # set_prop(sourcedomain, targetproperty)
  282. # Allows source domain to set the
  283. # targetproperty.
  284. #
  285. define(`set_prop', `
  286. unix_socket_connect($1, property, init)
  287. allow $1 $2:property_service set;
  288. get_prop($1, $2)
  289. ')
  290. #####################################
  291. # get_prop(sourcedomain, targetproperty)
  292. # Allows source domain to read the
  293. # targetproperty.
  294. #
  295. define(`get_prop', `
  296. allow $1 $2:file { getattr open read map };
  297. ')
  298. #####################################
  299. # unix_socket_send(clientdomain, socket, serverdomain)
  300. # Allow a local socket send from clientdomain via
  301. # socket to serverdomain.
  302. define(`unix_socket_send', `
  303. allow $1 $2_socket:sock_file write;
  304. allow $1 $3:unix_dgram_socket sendto;
  305. ')
  306. #####################################
  307. # binder_use(domain)
  308. # Allow domain to use Binder IPC.
  309. define(`binder_use', `
  310. # Call the servicemanager and transfer references to it.
  311. allow $1 servicemanager:binder { call transfer };
  312. # servicemanager performs getpidcon on clients.
  313. allow servicemanager $1:dir search;
  314. allow servicemanager $1:file { read open };
  315. allow servicemanager $1:process getattr;
  316. # rw access to /dev/binder and /dev/ashmem is presently granted to
  317. # all domains in domain.te.
  318. ')
  319. #####################################
  320. # hwbinder_use(domain)
  321. # Allow domain to use HwBinder IPC.
  322. define(`hwbinder_use', `
  323. # Call the hwservicemanager and transfer references to it.
  324. allow $1 hwservicemanager:binder { call transfer };
  325. # Allow hwservicemanager to send out callbacks
  326. allow hwservicemanager $1:binder { call transfer };
  327. # hwservicemanager performs getpidcon on clients.
  328. allow hwservicemanager $1:dir search;
  329. allow hwservicemanager $1:file { read open map };
  330. allow hwservicemanager $1:process getattr;
  331. # rw access to /dev/hwbinder and /dev/ashmem is presently granted to
  332. # all domains in domain.te.
  333. ')
  334. #####################################
  335. # vndbinder_use(domain)
  336. # Allow domain to use Binder IPC.
  337. define(`vndbinder_use', `
  338. # Talk to the vndbinder device node
  339. allow $1 vndbinder_device:chr_file rw_file_perms;
  340. # Call the vndservicemanager and transfer references to it.
  341. allow $1 vndservicemanager:binder { call transfer };
  342. # vndservicemanager performs getpidcon on clients.
  343. allow vndservicemanager $1:dir search;
  344. allow vndservicemanager $1:file { read open map };
  345. allow vndservicemanager $1:process getattr;
  346. ')
  347. #####################################
  348. # binder_call(clientdomain, serverdomain)
  349. # Allow clientdomain to perform binder IPC to serverdomain.
  350. define(`binder_call', `
  351. # Call the server domain and optionally transfer references to it.
  352. allow $1 $2:binder { call transfer };
  353. # Allow the serverdomain to transfer references to the client on the reply.
  354. allow $2 $1:binder transfer;
  355. # Receive and use open files from the server.
  356. allow $1 $2:fd use;
  357. ')
  358. #####################################
  359. # binder_service(domain)
  360. # Mark a domain as being a Binder service domain.
  361. # Used to allow binder IPC to the various system services.
  362. define(`binder_service', `
  363. typeattribute $1 binderservicedomain;
  364. ')
  365. #####################################
  366. # wakelock_use(domain)
  367. # Allow domain to manage wake locks
  368. define(`wakelock_use', `
  369. # TODO(b/115946999): Remove /sys/power/* permissions once CONFIG_PM_WAKELOCKS is
  370. # deprecated.
  371. # Access /sys/power/wake_lock and /sys/power/wake_unlock
  372. allow $1 sysfs_wake_lock:file rw_file_perms;
  373. # Accessing these files requires CAP_BLOCK_SUSPEND
  374. allow $1 self:global_capability2_class_set block_suspend;
  375. # system_suspend permissions
  376. binder_call($1, system_suspend_server)
  377. allow $1 system_suspend_hwservice:hwservice_manager find;
  378. # halclientdomain permissions
  379. hwbinder_use($1)
  380. get_prop($1, hwservicemanager_prop)
  381. allow $1 hidl_manager_hwservice:hwservice_manager find;
  382. ')
  383. #####################################
  384. # selinux_check_access(domain)
  385. # Allow domain to check SELinux permissions via selinuxfs.
  386. define(`selinux_check_access', `
  387. r_dir_file($1, selinuxfs)
  388. allow $1 selinuxfs:file w_file_perms;
  389. allow $1 kernel:security compute_av;
  390. allow $1 self:netlink_selinux_socket { read write create getattr setattr lock relabelfrom relabelto append bind connect listen accept getopt setopt shutdown recvfrom sendto name_bind };
  391. ')
  392. #####################################
  393. # selinux_check_context(domain)
  394. # Allow domain to check SELinux contexts via selinuxfs.
  395. define(`selinux_check_context', `
  396. r_dir_file($1, selinuxfs)
  397. allow $1 selinuxfs:file w_file_perms;
  398. allow $1 kernel:security check_context;
  399. ')
  400. #####################################
  401. # create_pty(domain)
  402. # Allow domain to create and use a pty, isolated from any other domain ptys.
  403. define(`create_pty', `
  404. # Each domain gets a unique devpts type.
  405. type $1_devpts, fs_type;
  406. # Label the pty with the unique type when created.
  407. type_transition $1 devpts:chr_file $1_devpts;
  408. # Allow use of the pty after creation.
  409. allow $1 $1_devpts:chr_file { open getattr read write ioctl };
  410. allowxperm $1 $1_devpts:chr_file ioctl unpriv_tty_ioctls;
  411. # TIOCSTI is only ever used for exploits. Block it.
  412. # b/33073072, b/7530569
  413. # http://www.openwall.com/lists/oss-security/2016/09/26/14
  414. neverallowxperm * $1_devpts:chr_file ioctl TIOCSTI;
  415. # Note: devpts:dir search and ptmx_device:chr_file rw_file_perms
  416. # allowed to everyone via domain.te.
  417. ')
  418. #####################################
  419. # Non system_app application set
  420. #
  421. define(`non_system_app_set', `{ appdomain -system_app }')
  422. #####################################
  423. # Recovery only
  424. # SELinux rules which apply only to recovery mode
  425. #
  426. define(`recovery_only', ifelse(target_recovery, `true', $1, ))
  427. #####################################
  428. # Full TREBLE only
  429. # SELinux rules which apply only to full TREBLE devices
  430. #
  431. define(`full_treble_only', ifelse(target_full_treble, `true', $1,
  432. ifelse(target_full_treble, `cts',
  433. # BEGIN_TREBLE_ONLY -- this marker is used by CTS -- do not modify
  434. $1
  435. # END_TREBLE_ONLY -- this marker is used by CTS -- do not modify
  436. , )))
  437. #####################################
  438. # Not full TREBLE
  439. # SELinux rules which apply only to devices which are not full TREBLE devices
  440. #
  441. define(`not_full_treble', ifelse(target_full_treble, `true', , $1))
  442. #####################################
  443. # Compatible property only
  444. # SELinux rules which apply only to devices with compatible property
  445. #
  446. define(`compatible_property_only', ifelse(target_compatible_property, `true', $1,
  447. ifelse(target_compatible_property, `cts',
  448. # BEGIN_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify
  449. $1
  450. # END_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify
  451. , )))
  452. #####################################
  453. # Not compatible property
  454. # SELinux rules which apply only to devices without compatible property
  455. #
  456. define(`not_compatible_property', ifelse(target_compatible_property, `true', , $1))
  457. #####################################
  458. # Userdebug or eng builds
  459. # SELinux rules which apply only to userdebug or eng builds
  460. #
  461. define(`userdebug_or_eng', ifelse(target_build_variant, `eng', $1, ifelse(target_build_variant, `userdebug', $1)))
  462. #####################################
  463. # asan builds
  464. # SELinux rules which apply only to asan builds
  465. #
  466. define(`with_asan', ifelse(target_with_asan, `true', userdebug_or_eng(`$1'), ))
  467. #####################################
  468. # native coverage builds
  469. # SELinux rules which apply only to builds with native coverage
  470. #
  471. define(`with_native_coverage', ifelse(target_with_native_coverage, `true', userdebug_or_eng(`$1'), ))
  472. #####################################
  473. # Build-time-only test
  474. # SELinux rules which are verified during build, but not as part of *TS testing.
  475. #
  476. define(`build_test_only', ifelse(target_exclude_build_test, `true', , $1))
  477. ####################################
  478. # Fallback crash handling for processes that can't exec crash_dump (e.g. because of seccomp).
  479. #
  480. define(`crash_dump_fallback', `
  481. userdebug_or_eng(`
  482. allow $1 su:fifo_file append;
  483. ')
  484. allow $1 anr_data_file:file append;
  485. allow $1 dumpstate:fd use;
  486. allow $1 incidentd:fd use;
  487. # TODO: Figure out why write is needed.
  488. allow $1 dumpstate:fifo_file { append write };
  489. allow $1 incidentd:fifo_file { append write };
  490. allow $1 system_server:fifo_file { append write };
  491. allow $1 tombstoned:unix_stream_socket connectto;
  492. allow $1 tombstoned:fd use;
  493. allow $1 tombstoned_crash_socket:sock_file write;
  494. allow $1 tombstone_data_file:file append;
  495. ')
  496. #####################################
  497. # WITH_DEXPREOPT builds
  498. # SELinux rules which apply only when pre-opting.
  499. #
  500. define(`with_dexpreopt', ifelse(target_with_dexpreopt, `true', $1))
  501. #####################################
  502. # write_logd(domain)
  503. # Ability to write to android log
  504. # daemon via sockets
  505. define(`write_logd', `
  506. unix_socket_send($1, logdw, logd)
  507. allow $1 pmsg_device:chr_file w_file_perms;
  508. ')
  509. #####################################
  510. # read_logd(domain)
  511. # Ability to run logcat and read from android
  512. # log daemon via sockets
  513. define(`read_logd', `
  514. allow $1 logcat_exec:file rx_file_perms;
  515. unix_socket_connect($1, logdr, logd)
  516. ')
  517. #####################################
  518. # read_runtime_log_tags(domain)
  519. # ability to directly map the runtime event log tags
  520. define(`read_runtime_log_tags', `
  521. allow $1 runtime_event_log_tags_file:file r_file_perms;
  522. ')
  523. #####################################
  524. # control_logd(domain)
  525. # Ability to control
  526. # android log daemon via sockets
  527. define(`control_logd', `
  528. # Group AID_LOG checked by filesystem & logd
  529. # to permit control commands
  530. unix_socket_connect($1, logd, logd)
  531. ')
  532. #####################################
  533. # use_keystore(domain)
  534. # Ability to use keystore.
  535. # Keystore is requires the following permissions
  536. # to call getpidcon.
  537. define(`use_keystore', `
  538. allow keystore $1:dir search;
  539. allow keystore $1:file { read open };
  540. allow keystore $1:process getattr;
  541. allow $1 keystore_service:service_manager find;
  542. binder_call($1, keystore)
  543. binder_call(keystore, $1)
  544. ')
  545. ###########################################
  546. # use_drmservice(domain)
  547. # Ability to use DrmService which requires
  548. # DrmService to call getpidcon.
  549. define(`use_drmservice', `
  550. allow drmserver $1:dir search;
  551. allow drmserver $1:file { read open };
  552. allow drmserver $1:process getattr;
  553. ')
  554. ###########################################
  555. # add_service(domain, service)
  556. # Ability for domain to add a service to service_manager
  557. # and find it. It also creates a neverallow preventing
  558. # others from adding it.
  559. define(`add_service', `
  560. allow $1 $2:service_manager { add find };
  561. neverallow { domain -$1 } $2:service_manager add;
  562. ')
  563. ###########################################
  564. # add_hwservice(domain, service)
  565. # Ability for domain to add a service to hwservice_manager
  566. # and find it. It also creates a neverallow preventing
  567. # others from adding it.
  568. define(`add_hwservice', `
  569. allow $1 $2:hwservice_manager { add find };
  570. allow $1 hidl_base_hwservice:hwservice_manager add;
  571. neverallow { domain -$1 } $2:hwservice_manager add;
  572. ')
  573. ###########################################
  574. # hal_attribute_hwservice(attribute, service)
  575. # Ability for domain to get a service to hwservice_manager
  576. # and find it. It also creates a neverallow preventing
  577. # others from adding it.
  578. #
  579. # Used to pair hal_foo_client with hal_foo_hwservice
  580. define(`hal_attribute_hwservice', `
  581. allow $1_client $2:hwservice_manager find;
  582. add_hwservice($1_server, $2)
  583. build_test_only(`
  584. neverallow { domain -$1_client -$1_server } $2:hwservice_manager find;
  585. ')
  586. ')
  587. ###################################
  588. # can_profile_heap(domain)
  589. # Allow processes within the domain to have their heap profiled by heapprofd.
  590. #
  591. # Note that profiling is performed differently between debug and user builds.
  592. # This macro covers both user and debug builds, but see
  593. # can_profile_heap_userdebug_or_eng for a variant that can be used when
  594. # allowing profiling for a domain only on debug builds, without granting
  595. # the exec permission. The exec permission is necessary for user builds, but
  596. # only a nice-to-have for development and testing purposes on debug builds.
  597. define(`can_profile_heap', `
  598. # Allow central daemon to send signal for client initialization.
  599. allow heapprofd $1:process signal;
  600. # Allow executing a private heapprofd process to handle profiling on
  601. # user builds (also debug builds for testing & development purposes).
  602. allow $1 heapprofd_exec:file rx_file_perms;
  603. # Allow directory & file read to the central heapprofd daemon, as it scans
  604. # /proc/[pid]/cmdline for by-process-name profiling configs.
  605. # Note that this excludes /proc/[pid]/mem, as it requires ptrace capabilities.
  606. allow heapprofd $1:file r_file_perms;
  607. allow heapprofd $1:dir r_dir_perms;
  608. # Profilability on user implies profilability on userdebug and eng.
  609. can_profile_heap_userdebug_or_eng($1)
  610. ')
  611. ###################################
  612. # can_profile_heap_userdebug_or_eng(domain)
  613. # Allow processes within the domain to have their heap profiled by heapprofd on
  614. # debug builds only.
  615. #
  616. # Only necessary when can_profile_heap cannot be applied, see its description
  617. # for rationale.
  618. define(`can_profile_heap_userdebug_or_eng', `
  619. userdebug_or_eng(`
  620. # Allow central daemon to send signal for client initialization.
  621. allow heapprofd $1:process signal;
  622. # Allow connecting to the daemon.
  623. unix_socket_connect($1, heapprofd, heapprofd)
  624. # Allow daemon to use the passed fds.
  625. allow heapprofd $1:fd use;
  626. # Allow to read and write to heapprofd shmem.
  627. # The client needs to read the read and write pointers in order to write.
  628. allow $1 heapprofd_tmpfs:file { read write getattr map };
  629. # Use shared memory received over the unix socket.
  630. allow $1 heapprofd:fd use;
  631. # To read from the received file descriptors.
  632. # /proc/[pid]/maps and /proc/[pid]/mem have the same SELinux label as the
  633. # process they relate to.
  634. allow heapprofd $1:file r_file_perms;
  635. # Allow searching the /proc/[pid] directory for cmdline.
  636. allow heapprofd $1:dir r_dir_perms;
  637. ')
  638. ')
  639. ###################################
  640. # never_profile_heap(domain)
  641. # Opt out of heap profiling by heapprofd.
  642. define(`never_profile_heap', `
  643. neverallow heapprofd $1:file read;
  644. neverallow heapprofd $1:process signal;
  645. ')