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