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# 9define(`domain_trans', ` 10# Old domain may exec the file and transition to the new domain. 11allow $1 $2:file { getattr open read execute map }; 12allow $1 $3:process transition; 13# New domain is entered by executing the file. 14allow $3 $2:file { entrypoint open read execute getattr map }; 15# New domain can send SIGCHLD to its caller. 16ifelse($1, `init', `', `allow $3 $1:process sigchld;') 17# Enable AT_SECURE, i.e. libc secure mode. 18dontaudit $1 $3:process noatsecure; 19# XXX dontaudit candidate but requires further study. 20allow $1 $3:process { siginh rlimitinh }; 21') 22 23##################################### 24# domain_auto_trans(olddomain, type, newdomain) 25# Automatically transition from olddomain to newdomain 26# upon executing a file labeled with type. 27# 28define(`domain_auto_trans', ` 29# Allow the necessary permissions. 30domain_trans($1,$2,$3) 31# Make the transition occur by default. 32type_transition $1 $2:process $3; 33') 34 35##################################### 36# file_type_trans(domain, dir_type, file_type) 37# Allow domain to create a file labeled file_type in a 38# directory labeled dir_type. 39# This only allows the transition; it does not 40# cause it to occur automatically - use file_type_auto_trans 41# if that is what you want. 42# 43define(`file_type_trans', ` 44# Allow the domain to add entries to the directory. 45allow $1 $2:dir ra_dir_perms; 46# Allow the domain to create the file. 47allow $1 $3:notdevfile_class_set create_file_perms; 48allow $1 $3:dir create_dir_perms; 49') 50 51##################################### 52# file_type_auto_trans(domain, dir_type, file_type) 53# Automatically label new files with file_type when 54# they are created by domain in directories labeled dir_type. 55# 56define(`file_type_auto_trans', ` 57# Allow the necessary permissions. 58file_type_trans($1, $2, $3) 59# Make the transition occur by default. 60type_transition $1 $2:dir $3; 61type_transition $1 $2:notdevfile_class_set $3; 62') 63 64##################################### 65# r_dir_file(domain, type) 66# Allow the specified domain to read directories, files 67# and symbolic links of the specified type. 68define(`r_dir_file', ` 69allow $1 $2:dir r_dir_perms; 70allow $1 $2:{ file lnk_file } r_file_perms; 71') 72 73##################################### 74# tmpfs_domain(domain) 75# Allow access to a unique type for this domain when creating tmpfs / ashmem files. 76define(`tmpfs_domain', ` 77type_transition $1 tmpfs:file $1_tmpfs; 78allow $1 $1_tmpfs:file { read write getattr map }; 79') 80 81# pdx macros for IPC. pdx is a high-level name which contains transport-specific 82# rules from underlying transport (e.g. UDS-based implementation). 83 84##################################### 85# pdx_service_attributes(service) 86# Defines type attribute used to identify various service-related types. 87define(`pdx_service_attributes', ` 88attribute pdx_$1_endpoint_dir_type; 89attribute pdx_$1_endpoint_socket_type; 90attribute pdx_$1_channel_socket_type; 91attribute pdx_$1_server_type; 92') 93 94##################################### 95# pdx_service_socket_types(service, endpoint_dir_t) 96# Define types for endpoint and channel sockets. 97define(`pdx_service_socket_types', ` 98typeattribute $2 pdx_$1_endpoint_dir_type; 99type pdx_$1_endpoint_socket, pdx_$1_endpoint_socket_type, pdx_endpoint_socket_type, file_type, coredomain_socket, mlstrustedobject, mlstrustedsubject; 100type pdx_$1_channel_socket, pdx_$1_channel_socket_type, pdx_channel_socket_type, coredomain_socket; 101userdebug_or_eng(` 102dontaudit su pdx_$1_endpoint_socket:unix_stream_socket *; 103dontaudit su pdx_$1_channel_socket:unix_stream_socket *; 104') 105') 106 107##################################### 108# pdx_server(server_domain, service) 109define(`pdx_server', ` 110# Mark the server domain as a PDX server. 111typeattribute $1 pdx_$2_server_type; 112# Allow the init process to create the initial endpoint socket. 113allow init pdx_$2_endpoint_socket_type:unix_stream_socket { create bind }; 114# Allow the server domain to use the endpoint socket and accept connections on it. 115# Not using macro like "rw_socket_perms_no_ioctl" because it provides more rights 116# than we need (e.g. we don"t need "bind" or "connect"). 117allow $1 pdx_$2_endpoint_socket_type:unix_stream_socket { read getattr write setattr lock append getopt setopt shutdown listen accept }; 118# Allow the server domain to apply security context label to the channel socket pair (allow process to use setsockcreatecon_raw()). 119allow $1 self:process setsockcreate; 120# Allow the server domain to create a client channel socket. 121allow $1 pdx_$2_channel_socket_type:unix_stream_socket create_stream_socket_perms; 122# Prevent other processes from claiming to be a server for the same service. 123neverallow {domain -$1} pdx_$2_endpoint_socket_type:unix_stream_socket { listen accept }; 124') 125 126##################################### 127# pdx_connect(client, service) 128define(`pdx_connect', ` 129# Allow client to open the service endpoint file. 130allow $1 pdx_$2_endpoint_dir_type:dir r_dir_perms; 131allow $1 pdx_$2_endpoint_socket_type:sock_file rw_file_perms; 132# Allow the client to connect to endpoint socket. 133allow $1 pdx_$2_endpoint_socket_type:unix_stream_socket { connectto read write shutdown }; 134') 135 136##################################### 137# pdx_use(client, service) 138define(`pdx_use', ` 139# Allow the client to use the PDX channel socket. 140# Not using macro like "rw_socket_perms_no_ioctl" because it provides more rights 141# than we need (e.g. we don"t need "bind" or "connect"). 142allow $1 pdx_$2_channel_socket_type:unix_stream_socket { read getattr write setattr lock append getopt setopt shutdown }; 143# Client needs to use an channel event fd from the server. 144allow $1 pdx_$2_server_type:fd use; 145# Servers may receive sync fences, gralloc buffers, etc, from clients. 146# This could be tightened on a per-server basis, but keeping track of service 147# clients is error prone. 148allow pdx_$2_server_type $1:fd use; 149') 150 151##################################### 152# pdx_client(client, service) 153define(`pdx_client', ` 154pdx_connect($1, $2) 155pdx_use($1, $2) 156') 157 158##################################### 159# init_daemon_domain(domain) 160# Set up a transition from init to the daemon domain 161# upon executing its binary. 162define(`init_daemon_domain', ` 163domain_auto_trans(init, $1_exec, $1) 164') 165 166#################################### 167# userfaultfd_use(domain) 168# Allow domain to create/use userfaultfd. 169define(`userfaultfd_use', ` 170# Set up a type_transition to "userfaultfd" named anonymous inode object. 171type $1_userfaultfd; 172type_transition $1 $1:anon_inode $1_userfaultfd "[userfaultfd]"; 173# Allow domain to create/use userfaultfd anon_inode. 174allow $1 $1_userfaultfd:anon_inode { create ioctl read }; 175# Suppress errors generate during bugreport 176dontaudit su $1_userfaultfd:anon_inode *; 177# Other domains may not use userfaultfd anon_inodes created by this domain. 178neverallow { domain -$1 } $1_userfaultfd:anon_inode *; 179# This domain may not use userfaultfd anon_inodes created by other domains. 180neverallow $1 ~$1_userfaultfd:anon_inode *; 181') 182 183#################################### 184# virtualizationservice_use(domain) 185# Allow domain to create and communicate with a virtual machine using 186# virtualizationservice. 187define(`virtualizationservice_use', ` 188allow $1 virtualization_service:service_manager find; 189# Let the client call virtualizationservice. 190binder_call($1, virtualizationservice) 191# Let virtualizationservice call back to the client. 192binder_call(virtualizationservice, $1) 193# Let the client pass file descriptors to virtualizationservice and on 194# to crosvm 195allow { virtualizationservice crosvm } $1:fd use; 196# Allow piping console log to the client 197allow { virtualizationservice crosvm } $1:fifo_file write; 198# Allow client to read/write vsock created by virtualizationservice to 199# communicate with the VM that it created. Notice that we do not grant 200# permission to create a vsock; the client can only connect to VMs 201# that it owns. 202allow $1 virtualizationservice:vsock_socket { getattr read write }; 203# Allow client to inspect hypervisor capabilities 204get_prop($1, hypervisor_prop) 205') 206 207##################################### 208# app_domain(domain) 209# Allow a base set of permissions required for all apps. 210define(`app_domain', ` 211typeattribute $1 appdomain; 212# Label tmpfs objects for all apps. 213type_transition $1 tmpfs:file appdomain_tmpfs; 214userfaultfd_use($1) 215allow $1 appdomain_tmpfs:file { execute getattr map read write }; 216neverallow { $1 -runas_app -shell -simpleperf } { domain -$1 }:file no_rw_file_perms; 217neverallow { appdomain -runas_app -shell -simpleperf -$1 } $1:file no_rw_file_perms; 218# The Android security model guarantees the confidentiality and integrity 219# of application data and execution state. Ptrace bypasses those 220# confidentiality guarantees. Disallow ptrace access from system components to 221# apps. crash_dump is excluded, as it needs ptrace access to produce stack 222# traces. runas_app is excluded, as it operates only on debuggable apps. 223# simpleperf is excluded, as it operates only on debuggable or profileable 224# apps. llkd is excluded, as it needs ptrace access to inspect stack traces for 225# live lock conditions. 226neverallow { domain -$1 -crash_dump userdebug_or_eng(`-llkd') -runas_app -simpleperf } $1:process ptrace; 227') 228 229##################################### 230# untrusted_app_domain(domain) 231# Allow a base set of permissions required for all untrusted apps. 232define(`untrusted_app_domain', ` 233typeattribute $1 untrusted_app_all; 234') 235 236##################################### 237# net_domain(domain) 238# Allow a base set of permissions required for network access. 239define(`net_domain', ` 240typeattribute $1 netdomain; 241') 242 243##################################### 244# bluetooth_domain(domain) 245# Allow a base set of permissions required for bluetooth access. 246define(`bluetooth_domain', ` 247typeattribute $1 bluetoothdomain; 248') 249 250##################################### 251# hal_attribute(hal_name) 252# Add an attribute for hal implementations along with necessary 253# restrictions. 254define(`hal_attribute', ` 255attribute hal_$1; 256expandattribute hal_$1 true; 257attribute hal_$1_client; 258expandattribute hal_$1_client true; 259attribute hal_$1_server; 260expandattribute hal_$1_server false; 261 262neverallow { hal_$1_server -halserverdomain } domain:process fork; 263# hal_*_client and halclientdomain attributes are always expanded for 264# performance reasons. Neverallow rules targeting expanded attributes can not be 265# verified by CTS since these attributes are already expanded by that time. 266build_test_only(` 267neverallow { hal_$1_server -hal_$1 } domain:process fork; 268neverallow { hal_$1_client -halclientdomain } domain:process fork; 269') 270') 271 272##################################### 273# hal_server_domain(domain, hal_type) 274# Allow a base set of permissions required for a domain to offer a 275# HAL implementation of the specified type over HwBinder. 276# 277# For example, default implementation of Foo HAL: 278# type hal_foo_default, domain; 279# hal_server_domain(hal_foo_default, hal_foo) 280# 281define(`hal_server_domain', ` 282typeattribute $1 halserverdomain; 283typeattribute $1 $2_server; 284typeattribute $1 $2; 285') 286 287##################################### 288# hal_client_domain(domain, hal_type) 289# Allow a base set of permissions required for a domain to be a 290# client of a HAL of the specified type. 291# 292# For example, make some_domain a client of Foo HAL: 293# hal_client_domain(some_domain, hal_foo) 294# 295define(`hal_client_domain', ` 296typeattribute $1 halclientdomain; 297typeattribute $1 $2_client; 298 299# TODO(b/34170079): Make the inclusion of the rules below conditional also on 300# non-Treble devices. For now, on non-Treble device, always grant clients of a 301# HAL sufficient access to run the HAL in passthrough mode (i.e., in-process). 302not_full_treble(` 303typeattribute $1 $2; 304# Find passthrough HAL implementations 305allow $2 system_file:dir r_dir_perms; 306allow $2 vendor_file:dir r_dir_perms; 307allow $2 vendor_file:file { read open getattr execute map }; 308') 309') 310 311##################################### 312# passthrough_hal_client_domain(domain, hal_type) 313# Allow a base set of permissions required for a domain to be a 314# client of a passthrough HAL of the specified type. 315# 316# For example, make some_domain a client of passthrough Foo HAL: 317# passthrough_hal_client_domain(some_domain, hal_foo) 318# 319define(`passthrough_hal_client_domain', ` 320typeattribute $1 halclientdomain; 321typeattribute $1 $2_client; 322typeattribute $1 $2; 323# Find passthrough HAL implementations 324allow $2 system_file:dir r_dir_perms; 325allow $2 vendor_file:dir r_dir_perms; 326allow $2 vendor_file:file { read open getattr execute map }; 327') 328 329##################################### 330# unix_socket_connect(clientdomain, socket, serverdomain) 331# Allow a local socket connection from clientdomain via 332# socket to serverdomain. 333# 334# Note: If you see denial records that distill to the 335# following allow rules: 336# allow clientdomain property_socket:sock_file write; 337# allow clientdomain init:unix_stream_socket connectto; 338# allow clientdomain something_prop:property_service set; 339# 340# This sequence is indicative of attempting to set a property. 341# use set_prop(sourcedomain, targetproperty) 342# 343define(`unix_socket_connect', ` 344allow $1 $2_socket:sock_file write; 345allow $1 $3:unix_stream_socket connectto; 346') 347 348##################################### 349# set_prop(sourcedomain, targetproperty) 350# Allows source domain to set the 351# targetproperty. 352# 353define(`set_prop', ` 354unix_socket_connect($1, property, init) 355allow $1 $2:property_service set; 356get_prop($1, $2) 357') 358 359##################################### 360# get_prop(sourcedomain, targetproperty) 361# Allows source domain to read the 362# targetproperty. 363# 364define(`get_prop', ` 365allow $1 $2:file { getattr open read map }; 366') 367 368##################################### 369# unix_socket_send(clientdomain, socket, serverdomain) 370# Allow a local socket send from clientdomain via 371# socket to serverdomain. 372define(`unix_socket_send', ` 373allow $1 $2_socket:sock_file write; 374allow $1 $3:unix_dgram_socket sendto; 375') 376 377##################################### 378# binder_use(domain) 379# Allow domain to use Binder IPC. 380define(`binder_use', ` 381# Call the servicemanager and transfer references to it. 382allow $1 servicemanager:binder { call transfer }; 383# Allow servicemanager to send out callbacks 384allow servicemanager $1:binder { call transfer }; 385# servicemanager performs getpidcon on clients. 386allow servicemanager $1:dir search; 387allow servicemanager $1:file { read open }; 388allow servicemanager $1:process getattr; 389# rw access to /dev/binder and /dev/ashmem is presently granted to 390# all domains in domain.te. 391') 392 393##################################### 394# hwbinder_use(domain) 395# Allow domain to use HwBinder IPC. 396define(`hwbinder_use', ` 397# Call the hwservicemanager and transfer references to it. 398allow $1 hwservicemanager:binder { call transfer }; 399# Allow hwservicemanager to send out callbacks 400allow hwservicemanager $1:binder { call transfer }; 401# hwservicemanager performs getpidcon on clients. 402allow hwservicemanager $1:dir search; 403allow hwservicemanager $1:file { read open map }; 404allow hwservicemanager $1:process getattr; 405# rw access to /dev/hwbinder and /dev/ashmem is presently granted to 406# all domains in domain.te. 407') 408 409##################################### 410# vndbinder_use(domain) 411# Allow domain to use Binder IPC. 412define(`vndbinder_use', ` 413# Talk to the vndbinder device node 414allow $1 vndbinder_device:chr_file rw_file_perms; 415# Call the vndservicemanager and transfer references to it. 416allow $1 vndservicemanager:binder { call transfer }; 417# vndservicemanager performs getpidcon on clients. 418allow vndservicemanager $1:dir search; 419allow vndservicemanager $1:file { read open map }; 420allow vndservicemanager $1:process getattr; 421') 422 423##################################### 424# binder_call(clientdomain, serverdomain) 425# Allow clientdomain to perform binder IPC to serverdomain. 426define(`binder_call', ` 427# Call the server domain and optionally transfer references to it. 428allow $1 $2:binder { call transfer }; 429# Allow the serverdomain to transfer references to the client on the reply. 430allow $2 $1:binder transfer; 431# Receive and use open files from the server. 432allow $1 $2:fd use; 433') 434 435##################################### 436# binder_service(domain) 437# Mark a domain as being a Binder service domain. 438# Used to allow binder IPC to the various system services. 439define(`binder_service', ` 440typeattribute $1 binderservicedomain; 441') 442 443##################################### 444# wakelock_use(domain) 445# Allow domain to manage wake locks 446define(`wakelock_use', ` 447# TODO(b/115946999): Remove /sys/power/* permissions once CONFIG_PM_WAKELOCKS is 448# deprecated. 449# Access /sys/power/wake_lock and /sys/power/wake_unlock 450allow $1 sysfs_wake_lock:file rw_file_perms; 451# Accessing these files requires CAP_BLOCK_SUSPEND 452allow $1 self:global_capability2_class_set block_suspend; 453# system_suspend permissions 454binder_call($1, system_suspend_server) 455allow $1 system_suspend_hwservice:hwservice_manager find; 456# halclientdomain permissions 457hwbinder_use($1) 458get_prop($1, hwservicemanager_prop) 459allow $1 hidl_manager_hwservice:hwservice_manager find; 460# AIDL suspend hal permissions 461allow $1 hal_system_suspend_service:service_manager find; 462binder_use($1) 463') 464 465##################################### 466# selinux_check_access(domain) 467# Allow domain to check SELinux permissions via selinuxfs. 468define(`selinux_check_access', ` 469r_dir_file($1, selinuxfs) 470allow $1 selinuxfs:file w_file_perms; 471allow $1 kernel:security compute_av; 472allow $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 }; 473') 474 475##################################### 476# selinux_check_context(domain) 477# Allow domain to check SELinux contexts via selinuxfs. 478define(`selinux_check_context', ` 479r_dir_file($1, selinuxfs) 480allow $1 selinuxfs:file w_file_perms; 481allow $1 kernel:security check_context; 482') 483 484##################################### 485# create_pty(domain) 486# Allow domain to create and use a pty, isolated from any other domain ptys. 487define(`create_pty', ` 488# Each domain gets a unique devpts type. 489type $1_devpts, fs_type; 490# Label the pty with the unique type when created. 491type_transition $1 devpts:chr_file $1_devpts; 492# Allow use of the pty after creation. 493allow $1 $1_devpts:chr_file { open getattr read write ioctl }; 494allowxperm $1 $1_devpts:chr_file ioctl unpriv_tty_ioctls; 495# TIOCSTI is only ever used for exploits. Block it. 496# b/33073072, b/7530569 497# http://www.openwall.com/lists/oss-security/2016/09/26/14 498neverallowxperm * $1_devpts:chr_file ioctl TIOCSTI; 499# Note: devpts:dir search and ptmx_device:chr_file rw_file_perms 500# allowed to everyone via domain.te. 501') 502 503##################################### 504# Non system_app application set 505# 506define(`non_system_app_set', `{ appdomain -system_app }') 507 508##################################### 509# Recovery only 510# SELinux rules which apply only to recovery mode 511# 512define(`recovery_only', ifelse(target_recovery, `true', $1, )) 513 514##################################### 515# Not recovery 516# SELinux rules which apply only to non-recovery (normal) mode 517# 518define(`not_recovery', ifelse(target_recovery, `true', , $1)) 519 520##################################### 521# Full TREBLE only 522# SELinux rules which apply only to full TREBLE devices 523# 524define(`full_treble_only', ifelse(target_full_treble, `true', $1, 525ifelse(target_full_treble, `cts', 526# BEGIN_TREBLE_ONLY -- this marker is used by CTS -- do not modify 527$1 528# END_TREBLE_ONLY -- this marker is used by CTS -- do not modify 529, ))) 530 531##################################### 532# Not full TREBLE 533# SELinux rules which apply only to devices which are not full TREBLE devices 534# 535define(`not_full_treble', ifelse(target_full_treble, `true', , $1)) 536 537##################################### 538# enforce_debugfs_restriction 539# SELinux rules which apply to devices that enable debugfs restrictions. 540# The keyword "cts" is used to insert markers to only CTS test the neverallows 541# added by the macro for S-launch devices and newer. 542define(`enforce_debugfs_restriction', ifelse(target_enforce_debugfs_restriction, `true', $1, 543ifelse(target_enforce_debugfs_restriction, `cts', 544# BEGIN_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 545$1 546# END_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 547, ))) 548 549##################################### 550# no_debugfs_restriction 551# SELinux rules which apply to devices that do not have debugfs restrictions in non-user builds. 552define(`no_debugfs_restriction', ifelse(target_enforce_debugfs_restriction, `true', , $1)) 553 554##################################### 555# Compatible property only 556# SELinux rules which apply only to devices with compatible property 557# 558define(`compatible_property_only', ifelse(target_compatible_property, `true', $1, 559ifelse(target_compatible_property, `cts', 560# BEGIN_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify 561$1 562# END_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify 563, ))) 564 565##################################### 566# Not compatible property 567# SELinux rules which apply only to devices without compatible property 568# 569define(`not_compatible_property', ifelse(target_compatible_property, `true', , $1)) 570 571##################################### 572# Userdebug or eng builds 573# SELinux rules which apply only to userdebug or eng builds 574# 575define(`userdebug_or_eng', ifelse(target_build_variant, `eng', $1, ifelse(target_build_variant, `userdebug', $1))) 576 577##################################### 578# asan builds 579# SELinux rules which apply only to asan builds 580# 581define(`with_asan', ifelse(target_with_asan, `true', userdebug_or_eng(`$1'), )) 582 583##################################### 584# native coverage builds 585# SELinux rules which apply only to builds with native coverage 586# 587define(`with_native_coverage', ifelse(target_with_native_coverage, `true', userdebug_or_eng(`$1'), )) 588 589##################################### 590# Build-time-only test 591# SELinux rules which are verified during build, but not as part of *TS testing. 592# 593define(`build_test_only', ifelse(target_exclude_build_test, `true', , $1)) 594 595#################################### 596# Fallback crash handling for processes that can't exec crash_dump (e.g. because of seccomp). 597# 598define(`crash_dump_fallback', ` 599userdebug_or_eng(` 600 allow $1 su:fifo_file append; 601') 602allow $1 anr_data_file:file append; 603allow $1 dumpstate:fd use; 604allow $1 incidentd:fd use; 605# TODO: Figure out why write is needed. 606allow $1 dumpstate:fifo_file { append write }; 607allow $1 incidentd:fifo_file { append write }; 608allow $1 system_server:fifo_file { append write }; 609allow $1 tombstoned:unix_stream_socket connectto; 610allow $1 tombstoned:fd use; 611allow $1 tombstoned_crash_socket:sock_file write; 612allow $1 tombstone_data_file:file append; 613') 614 615##################################### 616# WITH_DEXPREOPT builds 617# SELinux rules which apply only when pre-opting. 618# 619define(`with_dexpreopt', ifelse(target_with_dexpreopt, `true', $1)) 620 621##################################### 622# write_logd(domain) 623# Ability to write to android log 624# daemon via sockets 625define(`write_logd', ` 626unix_socket_send($1, logdw, logd) 627allow $1 pmsg_device:chr_file w_file_perms; 628') 629 630##################################### 631# read_logd(domain) 632# Ability to run logcat and read from android 633# log daemon via sockets 634define(`read_logd', ` 635allow $1 logcat_exec:file rx_file_perms; 636unix_socket_connect($1, logdr, logd) 637') 638 639##################################### 640# read_runtime_log_tags(domain) 641# ability to directly map the runtime event log tags 642define(`read_runtime_log_tags', ` 643allow $1 runtime_event_log_tags_file:file r_file_perms; 644') 645 646##################################### 647# control_logd(domain) 648# Ability to control 649# android log daemon via sockets 650define(`control_logd', ` 651# Group AID_LOG checked by filesystem & logd 652# to permit control commands 653unix_socket_connect($1, logd, logd) 654') 655 656##################################### 657# use_keystore(domain) 658# Ability to use keystore. 659# Keystore is requires the following permissions 660# to call getpidcon. 661define(`use_keystore', ` 662 allow keystore $1:dir search; 663 allow keystore $1:file { read open }; 664 allow keystore $1:process getattr; 665 allow $1 apc_service:service_manager find; 666 allow $1 keystore_service:service_manager find; 667 allow $1 legacykeystore_service:service_manager find; 668 binder_call($1, keystore) 669 binder_call(keystore, $1) 670') 671 672##################################### 673# use_credstore(domain) 674# Ability to use credstore. 675define(`use_credstore', ` 676 allow credstore $1:dir search; 677 allow credstore $1:file { read open }; 678 allow credstore $1:process getattr; 679 allow $1 credstore_service:service_manager find; 680 binder_call($1, credstore) 681 binder_call(credstore, $1) 682') 683 684########################################### 685# use_drmservice(domain) 686# Ability to use DrmService which requires 687# DrmService to call getpidcon. 688define(`use_drmservice', ` 689 allow drmserver $1:dir search; 690 allow drmserver $1:file { read open }; 691 allow drmserver $1:process getattr; 692') 693 694########################################### 695# add_service(domain, service) 696# Ability for domain to add a service to service_manager 697# and find it. It also creates a neverallow preventing 698# others from adding it. 699define(`add_service', ` 700 allow $1 $2:service_manager { add find }; 701 neverallow { domain -$1 } $2:service_manager add; 702 703 # On debug builds with root, allow binder services to use binder over TCP. 704 # Not using rw_socket_perms_no_ioctl to avoid granting too many permissions. 705 userdebug_or_eng(` 706 allow $1 su:tcp_socket { accept getopt read write }; 707 ') 708') 709 710########################################### 711# add_hwservice(domain, service) 712# Ability for domain to add a service to hwservice_manager 713# and find it. It also creates a neverallow preventing 714# others from adding it. 715define(`add_hwservice', ` 716 allow $1 $2:hwservice_manager { add find }; 717 allow $1 hidl_base_hwservice:hwservice_manager add; 718 neverallow { domain -$1 } $2:hwservice_manager add; 719') 720 721########################################### 722# hal_attribute_hwservice(attribute, service) 723# Ability for domain to get a service to hwservice_manager 724# and find it. It also creates a neverallow preventing 725# others from adding it. 726# 727# Used to pair hal_foo_client with hal_foo_hwservice 728define(`hal_attribute_hwservice', ` 729 allow $1_client $2:hwservice_manager find; 730 add_hwservice($1_server, $2) 731 732 build_test_only(` 733 # if you are hitting this neverallow, try using: 734 # hal_client_domain(<your domain>, hal_<foo>) 735 # instead 736 neverallow { domain -$1_client -$1_server } $2:hwservice_manager find; 737 ') 738') 739 740########################################### 741# hal_attribute_service(attribute, service) 742# Ability for domain to get a service to service_manager 743# and find it. It also creates a neverallow preventing 744# others from adding it. 745# 746# Used to pair hal_foo_client with hal_foo_service 747define(`hal_attribute_service', ` 748 allow $1_client $2:service_manager find; 749 add_service($1_server, $2) 750 751 build_test_only(` 752 # if you are hitting this neverallow, try using: 753 # hal_client_domain(<your domain>, hal_<foo>) 754 # instead 755 neverallow { 756 domain 757 -$1_client 758 -$1_server 759 # some services are allowed to find all services 760 -atrace 761 -dumpstate 762 -shell 763 -system_app 764 -traceur_app 765 } $2:service_manager find; 766 ') 767') 768 769################################### 770# can_profile_heap(domain) 771# Allow processes within the domain to have their heap profiled by central 772# heapprofd. 773define(`can_profile_heap', ` 774 # Allow central daemon to send signal for client initialization. 775 allow heapprofd $1:process signal; 776 # Allow connecting to the daemon. 777 unix_socket_connect($1, heapprofd, heapprofd) 778 # Allow daemon to use the passed fds. 779 allow heapprofd $1:fd use; 780 # Allow to read and write to heapprofd shmem. 781 # The client needs to read the read and write pointers in order to write. 782 allow $1 heapprofd_tmpfs:file { read write getattr map }; 783 # Use shared memory received over the unix socket. 784 allow $1 heapprofd:fd use; 785 786 # To read and write from the received file descriptors. 787 # /proc/[pid]/maps and /proc/[pid]/mem have the same SELinux label as the 788 # process they relate to. 789 # We need to write to /proc/$PID/page_idle to find idle allocations. 790 # The client only opens /proc/self/page_idle with RDWR, everything else 791 # with RDONLY. 792 # heapprofd cannot open /proc/$PID/mem itself, as it does not have 793 # sys_ptrace. 794 allow heapprofd $1:file rw_file_perms; 795 # Allow searching the /proc/[pid] directory for cmdline. 796 allow heapprofd $1:dir r_dir_perms; 797') 798 799################################### 800# never_profile_heap(domain) 801# Opt out of heap profiling by heapprofd. 802define(`never_profile_heap', ` 803 neverallow heapprofd $1:file read; 804 neverallow heapprofd $1:process signal; 805') 806 807################################### 808# can_profile_perf(domain) 809# Allow processes within the domain to be profiled, and have their stacks 810# sampled, by traced_perf. 811define(`can_profile_perf', ` 812 # Allow directory & file read to traced_perf, as it stat(2)s /proc/[pid], and 813 # reads /proc/[pid]/cmdline. 814 allow traced_perf $1:file r_file_perms; 815 allow traced_perf $1:dir r_dir_perms; 816 817 # Allow central daemon to send signal to request /proc/[pid]/maps and 818 # /proc/[pid]/mem fds from this process. 819 allow traced_perf $1:process signal; 820 821 # Allow connecting to the daemon. 822 unix_socket_connect($1, traced_perf, traced_perf) 823 # Allow daemon to use the passed fds. 824 allow traced_perf $1:fd use; 825') 826 827################################### 828# never_profile_perf(domain) 829# Opt out of profiling by traced_perf. 830define(`never_profile_perf', ` 831 neverallow traced_perf $1:file read; 832 neverallow traced_perf $1:process signal; 833') 834 835################################### 836# perfetto_producer(domain) 837# Allow processes within the domain to write data to Perfetto. 838# When applying this macro, you might need to also allow traced to use the 839# producer tmpfs domain, if the producer will be the one creating the shared 840# memory. 841define(`perfetto_producer', ` 842 allow $1 traced:fd use; 843 allow $1 traced_tmpfs:file { read write getattr map }; 844 unix_socket_connect($1, traced_producer, traced) 845 846 # Also allow the service to use the producer file descriptors. This is 847 # necessary when the producer is creating the shared memory, as it will be 848 # passed to the service as a file descriptor (obtained from memfd_create). 849 allow traced $1:fd use; 850') 851 852########################################### 853# dump_hal(hal_type) 854# Ability to dump the hal debug info 855# 856define(`dump_hal', ` 857 hal_client_domain(dumpstate, $1); 858 allow $1_server dumpstate:fifo_file write; 859 allow $1_server dumpstate:fd use; 860') 861 862##################################### 863# treble_sysprop_neverallow(rules) 864# SELinux neverallow rules which enforces the accessibility of each property 865# outside the owner. 866# 867# For devices launching with R or later, exported properties must be explicitly marked as 868# "restricted" or "public", depending on the accessibility outside the owner. 869# For devices launching with Q or eariler, this neverallow rules can be relaxed with defining 870# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true on BoardConfig.mk. 871# See {partition}_{accessibility}_prop macros below. 872# 873# CTS uses these rules only for devices launching with R or later. 874# 875# TODO(b/131162102): deprecate BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW 876# 877define(`treble_sysprop_neverallow', ifelse(target_treble_sysprop_neverallow, `true', $1, 878ifelse(target_treble_sysprop_neverallow, `cts', 879# BEGIN_LAUNCHING_WITH_R_ONLY -- this marker is used by CTS -- do not modify 880$1 881# END_LAUNCHING_WITH_R_ONLY -- this marker is used by CTS -- do not modify 882, ))) 883 884##################################### 885# enforce_sysprop_owner(rules) 886# SELinux neverallow rules which enforces the owner of each property. 887# 888# For devices launching with S or later, all properties must be explicitly marked as one of: 889# system_property_type, vendor_property_type, or product_property_type. 890# For devices launching with R or eariler, this neverallow rules can be relaxed with defining 891# BUILD_BROKEN_ENFORCE_SYSPROP_OWNER := true on BoardConfig.mk. 892# See {partition}_{accessibility}_prop macros below. 893# 894# CTS uses these ules only for devices launching with S or later. 895# 896define(`enforce_sysprop_owner', ifelse(target_enforce_sysprop_owner, `true', $1, 897ifelse(target_enforce_sysprop_owner, `cts', 898# BEGIN_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 899$1 900# END_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 901, ))) 902 903########################################### 904# define_prop(name, owner, scope) 905# Define a property with given owner and scope 906# 907define(`define_prop', ` 908 type $1, property_type, $2_property_type, $2_$3_property_type; 909') 910 911########################################### 912# system_internal_prop(name) 913# Define a /system-owned property used only in /system 914# For devices launching with Q or eariler, this restriction can be relaxed with 915# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 916# 917define(`system_internal_prop', ` 918 define_prop($1, system, internal) 919 treble_sysprop_neverallow(` 920 neverallow { domain -coredomain } $1:file no_rw_file_perms; 921 ') 922') 923 924########################################### 925# system_restricted_prop(name) 926# Define a /system-owned property which can't be written outside /system 927# For devices launching with Q or eariler, this restriction can be relaxed with 928# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 929# 930define(`system_restricted_prop', ` 931 define_prop($1, system, restricted) 932 treble_sysprop_neverallow(` 933 neverallow { domain -coredomain } $1:property_service set; 934 ') 935') 936 937########################################### 938# system_public_prop(name) 939# Define a /system-owned property with no restrictions 940# 941define(`system_public_prop', `define_prop($1, system, public)') 942 943########################################### 944# system_vendor_config_prop(name) 945# Define a /system-owned property which can only be written by vendor_init 946# This is a macro for vendor-specific configuration properties which is meant 947# to be set once from vendor_init. 948# 949define(`system_vendor_config_prop', ` 950 system_public_prop($1) 951 set_prop(vendor_init, $1) 952 neverallow { domain -init -vendor_init } $1:property_service set; 953') 954 955########################################### 956# product_internal_prop(name) 957# Define a /product-owned property used only in /product 958# For devices launching with Q or eariler, this restriction can be relaxed with 959# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 960# 961define(`product_internal_prop', ` 962 define_prop($1, product, internal) 963 treble_sysprop_neverallow(` 964 neverallow { domain -coredomain } $1:file no_rw_file_perms; 965 ') 966') 967 968########################################### 969# product_restricted_prop(name) 970# Define a /product-owned property which can't be written outside /product 971# For devices launching with Q or eariler, this restriction can be relaxed with 972# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 973# 974define(`product_restricted_prop', ` 975 define_prop($1, product, restricted) 976 treble_sysprop_neverallow(` 977 neverallow { domain -coredomain } $1:property_service set; 978 ') 979') 980 981########################################### 982# product_public_prop(name) 983# Define a /product-owned property with no restrictions 984# 985define(`product_public_prop', `define_prop($1, product, public)') 986 987########################################### 988# vendor_internal_prop(name) 989# Define a /vendor-owned property used only in /vendor 990# For devices launching with Q or eariler, this restriction can be relaxed with 991# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 992# 993define(`vendor_internal_prop', ` 994 define_prop($1, vendor, internal) 995 treble_sysprop_neverallow(` 996# init and dumpstate are in coredomain, but should be able to read all props. 997 neverallow { coredomain -init -dumpstate } $1:file no_rw_file_perms; 998 ') 999') 1000 1001########################################### 1002# vendor_restricted_prop(name) 1003# Define a /vendor-owned property which can't be written outside /vendor 1004# For devices launching with Q or eariler, this restriction can be relaxed with 1005# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 1006# 1007define(`vendor_restricted_prop', ` 1008 define_prop($1, vendor, restricted) 1009 treble_sysprop_neverallow(` 1010# init is in coredomain, but should be able to write all props. 1011 neverallow { coredomain -init } $1:property_service set; 1012 ') 1013') 1014 1015########################################### 1016# vendor_public_prop(name) 1017# Define a /vendor-owned property with no restrictions 1018# 1019define(`vendor_public_prop', `define_prop($1, vendor, public)') 1020 1021##################################### 1022# read_fstab(domain) 1023# Ability to call ReadDefaultFstab() and ReadFstabFromFile(). 1024# 1025define(`read_fstab', ` 1026 allow $1 { metadata_file gsi_metadata_file_type }:dir search; 1027 allow $1 gsi_public_metadata_file:file r_file_perms; 1028 allow $1 { proc_bootconfig proc_cmdline }:file r_file_perms; 1029') 1030 1031###################################### 1032# use_bootstrap_libs(domain) 1033# Allow domain to use bootstrap bionic libraries in system/lib[64]/bootstrap 1034define(`use_bootstrap_libs', ` 1035 allow $1 system_bootstrap_lib_file:dir r_dir_perms; 1036 allow $1 system_bootstrap_lib_file:file { execute read open getattr map }; 1037') 1038