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') 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# Deprecated. Consider granting the exact permissions required by your service. 444define(`binder_service', ` 445typeattribute $1 binderservicedomain; 446') 447 448##################################### 449# wakelock_use(domain) 450# Allow domain to manage wake locks 451define(`wakelock_use', ` 452# TODO(b/115946999): Remove /sys/power/* permissions once CONFIG_PM_WAKELOCKS is 453# deprecated. 454# Access /sys/power/wake_lock and /sys/power/wake_unlock 455allow $1 sysfs_wake_lock:file rw_file_perms; 456# Accessing these files requires CAP_BLOCK_SUSPEND 457allow $1 self:global_capability2_class_set block_suspend; 458# system_suspend permissions 459binder_call($1, system_suspend_server) 460allow $1 system_suspend_hwservice:hwservice_manager find; 461# halclientdomain permissions 462hwbinder_use($1) 463get_prop($1, hwservicemanager_prop) 464allow $1 hidl_manager_hwservice:hwservice_manager find; 465# AIDL suspend hal permissions 466allow $1 hal_system_suspend_service:service_manager find; 467binder_use($1) 468') 469 470##################################### 471# selinux_check_access(domain) 472# Allow domain to check SELinux permissions via selinuxfs. 473define(`selinux_check_access', ` 474r_dir_file($1, selinuxfs) 475allow $1 selinuxfs:file w_file_perms; 476allow $1 kernel:security compute_av; 477allow $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 }; 478') 479 480##################################### 481# selinux_check_context(domain) 482# Allow domain to check SELinux contexts via selinuxfs. 483define(`selinux_check_context', ` 484r_dir_file($1, selinuxfs) 485allow $1 selinuxfs:file w_file_perms; 486allow $1 kernel:security check_context; 487') 488 489##################################### 490# create_pty(domain) 491# Allow domain to create and use a pty, isolated from any other domain ptys. 492define(`create_pty', ` 493# Each domain gets a unique devpts type. 494type $1_devpts, fs_type; 495# Label the pty with the unique type when created. 496type_transition $1 devpts:chr_file $1_devpts; 497# Allow use of the pty after creation. 498allow $1 $1_devpts:chr_file { open getattr read write ioctl }; 499allowxperm $1 $1_devpts:chr_file ioctl unpriv_tty_ioctls; 500# TIOCSTI is only ever used for exploits. Block it. 501# b/33073072, b/7530569 502# http://www.openwall.com/lists/oss-security/2016/09/26/14 503neverallowxperm * $1_devpts:chr_file ioctl TIOCSTI; 504# Note: devpts:dir search and ptmx_device:chr_file rw_file_perms 505# allowed to everyone via domain.te. 506') 507 508##################################### 509# Non system_app application set 510# 511define(`non_system_app_set', `{ appdomain -system_app }') 512 513##################################### 514# Recovery only 515# SELinux rules which apply only to recovery mode 516# 517define(`recovery_only', ifelse(target_recovery, `true', $1, )) 518 519##################################### 520# Not recovery 521# SELinux rules which apply only to non-recovery (normal) mode 522# 523define(`not_recovery', ifelse(target_recovery, `true', , $1)) 524 525##################################### 526# Full TREBLE only 527# SELinux rules which apply only to full TREBLE devices 528# 529define(`full_treble_only', ifelse(target_full_treble, `true', $1, 530ifelse(target_full_treble, `cts', 531# BEGIN_TREBLE_ONLY -- this marker is used by CTS -- do not modify 532$1 533# END_TREBLE_ONLY -- this marker is used by CTS -- do not modify 534, ))) 535 536##################################### 537# Not full TREBLE 538# SELinux rules which apply only to devices which are not full TREBLE devices 539# 540define(`not_full_treble', ifelse(target_full_treble, `true', , $1)) 541 542##################################### 543# enforce_debugfs_restriction 544# SELinux rules which apply to devices that enable debugfs restrictions. 545# The keyword "cts" is used to insert markers to only CTS test the neverallows 546# added by the macro for S-launch devices and newer. 547define(`enforce_debugfs_restriction', ifelse(target_enforce_debugfs_restriction, `true', $1, 548ifelse(target_enforce_debugfs_restriction, `cts', 549# BEGIN_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 550$1 551# END_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 552, ))) 553 554##################################### 555# no_debugfs_restriction 556# SELinux rules which apply to devices that do not have debugfs restrictions in non-user builds. 557define(`no_debugfs_restriction', ifelse(target_enforce_debugfs_restriction, `true', , $1)) 558 559##################################### 560# Compatible property only 561# SELinux rules which apply only to devices with compatible property 562# 563define(`compatible_property_only', ifelse(target_compatible_property, `true', $1, 564ifelse(target_compatible_property, `cts', 565# BEGIN_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify 566$1 567# END_COMPATIBLE_PROPERTY_ONLY -- this marker is used by CTS -- do not modify 568, ))) 569 570##################################### 571# Not compatible property 572# SELinux rules which apply only to devices without compatible property 573# 574define(`not_compatible_property', ifelse(target_compatible_property, `true', , $1)) 575 576##################################### 577# Userdebug or eng builds 578# SELinux rules which apply only to userdebug or eng builds 579# 580define(`userdebug_or_eng', ifelse(target_build_variant, `eng', $1, ifelse(target_build_variant, `userdebug', $1))) 581 582##################################### 583# asan builds 584# SELinux rules which apply only to asan builds 585# 586define(`with_asan', ifelse(target_with_asan, `true', userdebug_or_eng(`$1'), )) 587 588##################################### 589# native coverage builds 590# SELinux rules which apply only to builds with native coverage 591# 592define(`with_native_coverage', ifelse(target_with_native_coverage, `true', userdebug_or_eng(`$1'), )) 593 594##################################### 595# Build-time-only test 596# SELinux rules which are verified during build, but not as part of *TS testing. 597# 598define(`build_test_only', ifelse(target_exclude_build_test, `true', , $1)) 599 600#################################### 601# Fallback crash handling for processes that can't exec crash_dump (e.g. because of seccomp). 602# 603define(`crash_dump_fallback', ` 604userdebug_or_eng(` 605 allow $1 su:fifo_file append; 606') 607allow $1 anr_data_file:file append; 608allow $1 dumpstate:fd use; 609allow $1 incidentd:fd use; 610# TODO: Figure out why write is needed. 611allow $1 dumpstate:fifo_file { append write }; 612allow $1 incidentd:fifo_file { append write }; 613allow $1 system_server:fifo_file { append write }; 614allow $1 tombstoned:unix_stream_socket connectto; 615allow $1 tombstoned:fd use; 616allow $1 tombstoned_crash_socket:sock_file write; 617allow $1 tombstone_data_file:file append; 618') 619 620##################################### 621# WITH_DEXPREOPT builds 622# SELinux rules which apply only when pre-opting. 623# 624define(`with_dexpreopt', ifelse(target_with_dexpreopt, `true', $1)) 625 626##################################### 627# write_logd(domain) 628# Ability to write to android log 629# daemon via sockets 630define(`write_logd', ` 631unix_socket_send($1, logdw, logd) 632allow $1 pmsg_device:chr_file w_file_perms; 633') 634 635##################################### 636# read_logd(domain) 637# Ability to run logcat and read from android 638# log daemon via sockets 639define(`read_logd', ` 640allow $1 logcat_exec:file rx_file_perms; 641unix_socket_connect($1, logdr, logd) 642') 643 644##################################### 645# read_runtime_log_tags(domain) 646# ability to directly map the runtime event log tags 647define(`read_runtime_log_tags', ` 648allow $1 runtime_event_log_tags_file:file r_file_perms; 649') 650 651##################################### 652# control_logd(domain) 653# Ability to control 654# android log daemon via sockets 655define(`control_logd', ` 656# Group AID_LOG checked by filesystem & logd 657# to permit control commands 658unix_socket_connect($1, logd, logd) 659') 660 661##################################### 662# use_keystore(domain) 663# Ability to use keystore. 664# Keystore is requires the following permissions 665# to call getpidcon. 666define(`use_keystore', ` 667 allow keystore $1:dir search; 668 allow keystore $1:file { read open }; 669 allow keystore $1:process getattr; 670 allow $1 apc_service:service_manager find; 671 allow $1 keystore_service:service_manager find; 672 allow $1 legacykeystore_service:service_manager find; 673 binder_call($1, keystore) 674 binder_call(keystore, $1) 675') 676 677##################################### 678# use_credstore(domain) 679# Ability to use credstore. 680define(`use_credstore', ` 681 allow credstore $1:dir search; 682 allow credstore $1:file { read open }; 683 allow credstore $1:process getattr; 684 allow $1 credstore_service:service_manager find; 685 binder_call($1, credstore) 686 binder_call(credstore, $1) 687') 688 689########################################### 690# use_drmservice(domain) 691# Ability to use DrmService which requires 692# DrmService to call getpidcon. 693define(`use_drmservice', ` 694 allow drmserver $1:dir search; 695 allow drmserver $1:file { read open }; 696 allow drmserver $1:process getattr; 697') 698 699########################################### 700# add_service(domain, service) 701# Ability for domain to add a service to service_manager 702# and find it. It also creates a neverallow preventing 703# others from adding it. 704define(`add_service', ` 705 allow $1 $2:service_manager { add find }; 706 neverallow { domain -$1 } $2:service_manager add; 707 708 # On debug builds with root, allow binder services to use binder over TCP. 709 # Not using rw_socket_perms_no_ioctl to avoid granting too many permissions. 710 userdebug_or_eng(` 711 allow $1 su:tcp_socket { accept getopt read write }; 712 ') 713') 714 715########################################### 716# add_hwservice(domain, service) 717# Ability for domain to add a service to hwservice_manager 718# and find it. It also creates a neverallow preventing 719# others from adding it. 720define(`add_hwservice', ` 721 allow $1 $2:hwservice_manager { add find }; 722 allow $1 hidl_base_hwservice:hwservice_manager add; 723 neverallow { domain -$1 } $2:hwservice_manager add; 724') 725 726########################################### 727# hal_attribute_hwservice(attribute, service) 728# Ability for domain to get a service to hwservice_manager 729# and find it. It also creates a neverallow preventing 730# others from adding it. 731# 732# Used to pair hal_foo_client with hal_foo_hwservice 733define(`hal_attribute_hwservice', ` 734 allow $1_client $2:hwservice_manager find; 735 add_hwservice($1_server, $2) 736 737 build_test_only(` 738 # if you are hitting this neverallow, try using: 739 # hal_client_domain(<your domain>, hal_<foo>) 740 # instead 741 neverallow { domain -$1_client -$1_server } $2:hwservice_manager find; 742 ') 743') 744 745########################################### 746# hal_attribute_service(attribute, service) 747# Ability for domain to get a service to service_manager 748# and find it. It also creates a neverallow preventing 749# others from adding it. 750# 751# Used to pair hal_foo_client with hal_foo_service 752define(`hal_attribute_service', ` 753 allow $1_client $2:service_manager find; 754 add_service($1_server, $2) 755 756 build_test_only(` 757 # if you are hitting this neverallow, try using: 758 # hal_client_domain(<your domain>, hal_<foo>) 759 # instead 760 neverallow { 761 domain 762 -$1_client 763 -$1_server 764 # some services are allowed to find all services 765 -atrace 766 -shell 767 -system_app 768 -traceur_app 769 } $2:service_manager find; 770 ') 771') 772 773################################### 774# can_profile_heap(domain) 775# Allow processes within the domain to have their heap profiled by central 776# heapprofd. 777define(`can_profile_heap', ` 778 # Allow central daemon to send signal for client initialization. 779 allow heapprofd $1:process signal; 780 # Allow connecting to the daemon. 781 unix_socket_connect($1, heapprofd, heapprofd) 782 # Allow daemon to use the passed fds. 783 allow heapprofd $1:fd use; 784 # Allow to read and write to heapprofd shmem. 785 # The client needs to read the read and write pointers in order to write. 786 allow $1 heapprofd_tmpfs:file { read write getattr map }; 787 # Use shared memory received over the unix socket. 788 allow $1 heapprofd:fd use; 789 790 # To read and write from the received file descriptors. 791 # /proc/[pid]/maps and /proc/[pid]/mem have the same SELinux label as the 792 # process they relate to. 793 # We need to write to /proc/$PID/page_idle to find idle allocations. 794 # The client only opens /proc/self/page_idle with RDWR, everything else 795 # with RDONLY. 796 # heapprofd cannot open /proc/$PID/mem itself, as it does not have 797 # sys_ptrace. 798 allow heapprofd $1:file rw_file_perms; 799 # Allow searching the /proc/[pid] directory for cmdline. 800 allow heapprofd $1:dir r_dir_perms; 801') 802 803################################### 804# never_profile_heap(domain) 805# Opt out of heap profiling by heapprofd. 806define(`never_profile_heap', ` 807 neverallow heapprofd $1:file read; 808 neverallow heapprofd $1:process signal; 809') 810 811################################### 812# can_profile_perf(domain) 813# Allow processes within the domain to be profiled, and have their stacks 814# sampled, by traced_perf. 815define(`can_profile_perf', ` 816 # Allow directory & file read to traced_perf, as it stat(2)s /proc/[pid], and 817 # reads /proc/[pid]/cmdline. 818 allow traced_perf $1:file r_file_perms; 819 allow traced_perf $1:dir r_dir_perms; 820 821 # Allow central daemon to send signal to request /proc/[pid]/maps and 822 # /proc/[pid]/mem fds from this process. 823 allow traced_perf $1:process signal; 824 825 # Allow connecting to the daemon. 826 unix_socket_connect($1, traced_perf, traced_perf) 827 # Allow daemon to use the passed fds. 828 allow traced_perf $1:fd use; 829') 830 831################################### 832# never_profile_perf(domain) 833# Opt out of profiling by traced_perf. 834define(`never_profile_perf', ` 835 neverallow traced_perf $1:file read; 836 neverallow traced_perf $1:process signal; 837') 838 839################################### 840# perfetto_producer(domain) 841# Allow processes within the domain to write data to Perfetto. 842# When applying this macro, you might need to also allow traced to use the 843# producer tmpfs domain, if the producer will be the one creating the shared 844# memory. 845define(`perfetto_producer', ` 846 allow $1 traced:fd use; 847 allow $1 traced_tmpfs:file { read write getattr map }; 848 unix_socket_connect($1, traced_producer, traced) 849 850 # Also allow the service to use the producer file descriptors. This is 851 # necessary when the producer is creating the shared memory, as it will be 852 # passed to the service as a file descriptor (obtained from memfd_create). 853 allow traced $1:fd use; 854') 855 856########################################### 857# dump_hal(hal_type) 858# Ability to dump the hal debug info 859# 860define(`dump_hal', ` 861 hal_client_domain(dumpstate, $1); 862 allow $1_server dumpstate:fifo_file write; 863 allow $1_server dumpstate:fd use; 864') 865 866##################################### 867# treble_sysprop_neverallow(rules) 868# SELinux neverallow rules which enforces the accessibility of each property 869# outside the owner. 870# 871# For devices launching with R or later, exported properties must be explicitly marked as 872# "restricted" or "public", depending on the accessibility outside the owner. 873# For devices launching with Q or eariler, this neverallow rules can be relaxed with defining 874# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true on BoardConfig.mk. 875# See {partition}_{accessibility}_prop macros below. 876# 877# CTS uses these rules only for devices launching with R or later. 878# 879# TODO(b/131162102): deprecate BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW 880# 881define(`treble_sysprop_neverallow', ifelse(target_treble_sysprop_neverallow, `true', $1, 882ifelse(target_treble_sysprop_neverallow, `cts', 883# BEGIN_LAUNCHING_WITH_R_ONLY -- this marker is used by CTS -- do not modify 884$1 885# END_LAUNCHING_WITH_R_ONLY -- this marker is used by CTS -- do not modify 886, ))) 887 888##################################### 889# enforce_sysprop_owner(rules) 890# SELinux neverallow rules which enforces the owner of each property. 891# 892# For devices launching with S or later, all properties must be explicitly marked as one of: 893# system_property_type, vendor_property_type, or product_property_type. 894# For devices launching with R or eariler, this neverallow rules can be relaxed with defining 895# BUILD_BROKEN_ENFORCE_SYSPROP_OWNER := true on BoardConfig.mk. 896# See {partition}_{accessibility}_prop macros below. 897# 898# CTS uses these ules only for devices launching with S or later. 899# 900define(`enforce_sysprop_owner', ifelse(target_enforce_sysprop_owner, `true', $1, 901ifelse(target_enforce_sysprop_owner, `cts', 902# BEGIN_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 903$1 904# END_LAUNCHING_WITH_S_ONLY -- this marker is used by CTS -- do not modify 905, ))) 906 907########################################### 908# define_prop(name, owner, scope) 909# Define a property with given owner and scope 910# 911define(`define_prop', ` 912 type $1, property_type, $2_property_type, $2_$3_property_type; 913') 914 915########################################### 916# system_internal_prop(name) 917# Define a /system-owned property used only in /system 918# For devices launching with Q or eariler, this restriction can be relaxed with 919# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 920# 921define(`system_internal_prop', ` 922 define_prop($1, system, internal) 923 treble_sysprop_neverallow(` 924 neverallow { domain -coredomain } $1:file no_rw_file_perms; 925 ') 926') 927 928########################################### 929# system_restricted_prop(name) 930# Define a /system-owned property which can't be written outside /system 931# For devices launching with Q or eariler, this restriction can be relaxed with 932# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 933# 934define(`system_restricted_prop', ` 935 define_prop($1, system, restricted) 936 treble_sysprop_neverallow(` 937 neverallow { domain -coredomain } $1:property_service set; 938 ') 939') 940 941########################################### 942# system_public_prop(name) 943# Define a /system-owned property with no restrictions 944# 945define(`system_public_prop', `define_prop($1, system, public)') 946 947########################################### 948# system_vendor_config_prop(name) 949# Define a /system-owned property which can only be written by vendor_init 950# This is a macro for vendor-specific configuration properties which is meant 951# to be set once from vendor_init. 952# 953define(`system_vendor_config_prop', ` 954 system_public_prop($1) 955 set_prop(vendor_init, $1) 956 neverallow { domain -init -vendor_init } $1:property_service set; 957') 958 959########################################### 960# product_internal_prop(name) 961# Define a /product-owned property used only in /product 962# For devices launching with Q or eariler, this restriction can be relaxed with 963# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 964# 965define(`product_internal_prop', ` 966 define_prop($1, product, internal) 967 treble_sysprop_neverallow(` 968 neverallow { domain -coredomain } $1:file no_rw_file_perms; 969 ') 970') 971 972########################################### 973# product_restricted_prop(name) 974# Define a /product-owned property which can't be written outside /product 975# For devices launching with Q or eariler, this restriction can be relaxed with 976# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 977# 978define(`product_restricted_prop', ` 979 define_prop($1, product, restricted) 980 treble_sysprop_neverallow(` 981 neverallow { domain -coredomain } $1:property_service set; 982 ') 983') 984 985########################################### 986# product_public_prop(name) 987# Define a /product-owned property with no restrictions 988# 989define(`product_public_prop', `define_prop($1, product, public)') 990 991########################################### 992# vendor_internal_prop(name) 993# Define a /vendor-owned property used only in /vendor 994# For devices launching with Q or eariler, this restriction can be relaxed with 995# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 996# 997define(`vendor_internal_prop', ` 998 define_prop($1, vendor, internal) 999 treble_sysprop_neverallow(` 1000# init and dumpstate are in coredomain, but should be able to read all props. 1001 neverallow { coredomain -init -dumpstate } $1:file no_rw_file_perms; 1002 ') 1003') 1004 1005########################################### 1006# vendor_restricted_prop(name) 1007# Define a /vendor-owned property which can't be written outside /vendor 1008# For devices launching with Q or eariler, this restriction can be relaxed with 1009# BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW := true 1010# 1011define(`vendor_restricted_prop', ` 1012 define_prop($1, vendor, restricted) 1013 treble_sysprop_neverallow(` 1014# init is in coredomain, but should be able to write all props. 1015 neverallow { coredomain -init } $1:property_service set; 1016 ') 1017') 1018 1019########################################### 1020# vendor_public_prop(name) 1021# Define a /vendor-owned property with no restrictions 1022# 1023define(`vendor_public_prop', `define_prop($1, vendor, public)') 1024 1025##################################### 1026# read_fstab(domain) 1027# Ability to call ReadDefaultFstab() and ReadFstabFromFile(). 1028# 1029define(`read_fstab', ` 1030 allow $1 { metadata_file gsi_metadata_file_type }:dir search; 1031 allow $1 gsi_public_metadata_file:file r_file_perms; 1032 allow $1 { proc_bootconfig proc_cmdline }:file r_file_perms; 1033') 1034 1035###################################### 1036# use_bootstrap_libs(domain) 1037# Allow domain to use bootstrap bionic libraries in system/lib[64]/bootstrap 1038define(`use_bootstrap_libs', ` 1039 allow $1 system_bootstrap_lib_file:dir r_dir_perms; 1040 allow $1 system_bootstrap_lib_file:file { execute read open getattr map }; 1041') 1042 1043###################################### 1044# use_apex_info(domain) 1045# Allow access to apex information 1046define(`use_apex_info', ` 1047 allow $1 apex_mnt_dir:dir r_dir_perms; 1048 allow $1 apex_info_file:file r_file_perms; 1049 r_dir_file($1, vendor_apex_metadata_file) 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