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