1# 2# System Server aka system_server spawned by zygote. 3# Most of the framework services run in this process. 4# 5type system_server, domain, domain_deprecated, mlstrustedsubject; 6 7# Define a type for tmpfs-backed ashmem regions. 8tmpfs_domain(system_server) 9 10# For art. 11allow system_server dalvikcache_data_file:file execute; 12allow system_server dalvikcache_data_file:dir r_dir_perms; 13 14# Enable system server to check the foreign dex usage markers. 15# We need search on top level directories so that we can get to the files 16allow system_server user_profile_data_file:dir search; 17allow system_server user_profile_data_file:file getattr; 18allow system_server user_profile_foreign_dex_data_file:dir { add_name open read write search remove_name }; 19allow system_server user_profile_foreign_dex_data_file:file { getattr rename unlink }; 20 21# /data/resource-cache 22allow system_server resourcecache_data_file:file r_file_perms; 23allow system_server resourcecache_data_file:dir r_dir_perms; 24 25# ptrace to processes in the same domain for debugging crashes. 26allow system_server self:process ptrace; 27 28# Child of the zygote. 29allow system_server zygote:fd use; 30allow system_server zygote:process sigchld; 31allow system_server zygote_tmpfs:file read; 32 33# May kill zygote on crashes. 34allow system_server zygote:process sigkill; 35 36# Read /system/bin/app_process. 37allow system_server zygote_exec:file r_file_perms; 38 39# Needed to close the zygote socket, which involves getopt / getattr 40allow system_server zygote:unix_stream_socket { getopt getattr }; 41 42# system server gets network and bluetooth permissions. 43net_domain(system_server) 44bluetooth_domain(system_server) 45 46# These are the capabilities assigned by the zygote to the 47# system server. 48allow system_server self:capability { 49 ipc_lock 50 kill 51 net_admin 52 net_bind_service 53 net_broadcast 54 net_raw 55 sys_boot 56 sys_nice 57 sys_resource 58 sys_time 59 sys_tty_config 60}; 61 62wakelock_use(system_server) 63 64# Triggered by /proc/pid accesses, not allowed. 65dontaudit system_server self:capability sys_ptrace; 66 67# Trigger module auto-load. 68allow system_server kernel:system module_request; 69 70# Use netlink uevent sockets. 71allow system_server self:netlink_kobject_uevent_socket create_socket_perms; 72 73# Use generic netlink sockets. 74allow system_server self:netlink_socket create_socket_perms; 75allow system_server self:netlink_generic_socket create_socket_perms; 76 77# Use generic "sockets" where the address family is not known 78# to the kernel. 79allow system_server self:socket create_socket_perms; 80 81# Set and get routes directly via netlink. 82allow system_server self:netlink_route_socket nlmsg_write; 83 84# Kill apps. 85allow system_server { appdomain autoplay_app }:process { sigkill signal }; 86 87# Set scheduling info for apps. 88allow system_server { appdomain autoplay_app }:process { getsched setsched }; 89allow system_server audioserver:process { getsched setsched }; 90allow system_server cameraserver:process { getsched setsched }; 91allow system_server mediaserver:process { getsched setsched }; 92 93# Read /proc/pid data for all domains. This is used by ProcessCpuTracker 94# within system_server to keep track of memory and CPU usage for 95# all processes on the device. In addition, /proc/pid files access is needed 96# for dumping stack traces of native processes. 97r_dir_file(system_server, domain) 98 99# Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid. 100allow system_server qtaguid_proc:file rw_file_perms; 101allow system_server qtaguid_device:chr_file rw_file_perms; 102 103# Read /proc/uid_cputime/show_uid_stat. 104allow system_server proc_uid_cputime_showstat:file r_file_perms; 105 106# Write /proc/uid_cputime/remove_uid_range. 107allow system_server proc_uid_cputime_removeuid:file { w_file_perms getattr }; 108 109# Write to /proc/sysrq-trigger. 110allow system_server proc_sysrq:file rw_file_perms; 111 112# Read /sys/kernel/debug/wakeup_sources. 113allow system_server debugfs:file r_file_perms; 114 115# The DhcpClient and WifiWatchdog use packet_sockets 116allow system_server self:packet_socket create_socket_perms; 117 118# NetworkDiagnostics requires explicit bind() calls to ping sockets. These aren't actually the same 119# as raw sockets, but the kernel doesn't yet distinguish between the two. 120allow system_server node:rawip_socket node_bind; 121 122# 3rd party VPN clients require a tun_socket to be created 123allow system_server self:tun_socket create_socket_perms; 124 125# Notify init of death. 126allow system_server init:process sigchld; 127 128# Talk to init and various daemons via sockets. 129unix_socket_connect(system_server, installd, installd) 130unix_socket_connect(system_server, lmkd, lmkd) 131unix_socket_connect(system_server, mtpd, mtp) 132unix_socket_connect(system_server, netd, netd) 133unix_socket_connect(system_server, vold, vold) 134unix_socket_connect(system_server, zygote, zygote) 135unix_socket_connect(system_server, gps, gpsd) 136unix_socket_connect(system_server, racoon, racoon) 137unix_socket_send(system_server, wpa, wpa) 138unix_socket_connect(system_server, uncrypt, uncrypt) 139 140# Communicate over a socket created by surfaceflinger. 141allow system_server surfaceflinger:unix_stream_socket { read write setopt }; 142 143# Perform Binder IPC. 144binder_use(system_server) 145binder_call(system_server, binderservicedomain) 146binder_call(system_server, gatekeeperd) 147binder_call(system_server, fingerprintd) 148binder_call(system_server, { appdomain autoplay_app }) 149binder_call(system_server, dumpstate) 150binder_call(system_server, netd) 151binder_service(system_server) 152 153# Ask debuggerd to dump backtraces for native stacks of interest. 154# 155# This is derived from the list that system server defines as interesting native processes 156# to dump during ANRs or watchdog aborts, defined in NATIVE_STACKS_OF_INTEREST in 157# frameworks/base/services/core/java/com/android/server/Watchdog.java. 158allow system_server { 159 audioserver 160 bluetooth 161 cameraserver 162 drmserver 163 inputflinger 164 mediacodec 165 mediadrmserver 166 mediaextractor 167 mediaserver 168 sdcardd 169 surfaceflinger 170}:debuggerd dump_backtrace; 171 172# Use sockets received over binder from various services. 173allow system_server audioserver:tcp_socket rw_socket_perms; 174allow system_server audioserver:udp_socket rw_socket_perms; 175allow system_server mediaserver:tcp_socket rw_socket_perms; 176allow system_server mediaserver:udp_socket rw_socket_perms; 177 178# Use sockets received over binder from various services. 179allow system_server mediadrmserver:tcp_socket rw_socket_perms; 180allow system_server mediadrmserver:udp_socket rw_socket_perms; 181 182# Check SELinux permissions. 183selinux_check_access(system_server) 184 185# XXX Label sysfs files with a specific type? 186allow system_server sysfs:file rw_file_perms; 187allow system_server sysfs_nfc_power_writable:file rw_file_perms; 188allow system_server sysfs_devices_system_cpu:file w_file_perms; 189allow system_server sysfs_mac_address:file r_file_perms; 190allow system_server sysfs_thermal:dir search; 191allow system_server sysfs_thermal:file r_file_perms; 192 193# TODO: added to match above sysfs rule. Remove me? 194allow system_server sysfs_usb:file w_file_perms; 195 196# Access devices. 197allow system_server device:dir r_dir_perms; 198allow system_server mdns_socket:sock_file rw_file_perms; 199allow system_server alarm_device:chr_file rw_file_perms; 200allow system_server gpu_device:chr_file rw_file_perms; 201allow system_server iio_device:chr_file rw_file_perms; 202allow system_server input_device:dir r_dir_perms; 203allow system_server input_device:chr_file rw_file_perms; 204allow system_server radio_device:chr_file r_file_perms; 205allow system_server tty_device:chr_file rw_file_perms; 206allow system_server usbaccessory_device:chr_file rw_file_perms; 207allow system_server video_device:dir r_dir_perms; 208allow system_server video_device:chr_file rw_file_perms; 209allow system_server adbd_socket:sock_file rw_file_perms; 210allow system_server rtc_device:chr_file rw_file_perms; 211allow system_server audio_device:dir r_dir_perms; 212 213# write access needed for MIDI 214allow system_server audio_device:chr_file rw_file_perms; 215 216# tun device used for 3rd party vpn apps 217allow system_server tun_device:chr_file rw_file_perms; 218 219# Manage system data files. 220allow system_server system_data_file:dir create_dir_perms; 221allow system_server system_data_file:notdevfile_class_set create_file_perms; 222allow system_server keychain_data_file:dir create_dir_perms; 223allow system_server keychain_data_file:file create_file_perms; 224 225# Manage /data/app. 226allow system_server apk_data_file:dir create_dir_perms; 227allow system_server apk_data_file:file { create_file_perms link }; 228allow system_server apk_tmp_file:dir create_dir_perms; 229allow system_server apk_tmp_file:file create_file_perms; 230 231# Manage /data/app-private. 232allow system_server apk_private_data_file:dir create_dir_perms; 233allow system_server apk_private_data_file:file create_file_perms; 234allow system_server apk_private_tmp_file:dir create_dir_perms; 235allow system_server apk_private_tmp_file:file create_file_perms; 236 237# Manage files within asec containers. 238allow system_server asec_apk_file:dir create_dir_perms; 239allow system_server asec_apk_file:file create_file_perms; 240allow system_server asec_public_file:file create_file_perms; 241 242# Manage /data/anr. 243allow system_server anr_data_file:dir create_dir_perms; 244allow system_server anr_data_file:file create_file_perms; 245 246# Manage /data/backup. 247allow system_server backup_data_file:dir create_dir_perms; 248allow system_server backup_data_file:file create_file_perms; 249 250# Write to /data/system/heapdump 251allow system_server heapdump_data_file:dir rw_dir_perms; 252allow system_server heapdump_data_file:file create_file_perms; 253 254# Manage /data/misc/adb. 255allow system_server adb_keys_file:dir create_dir_perms; 256allow system_server adb_keys_file:file create_file_perms; 257 258# Manage /data/misc/sms. 259# TODO: Split into a separate type? 260allow system_server radio_data_file:dir create_dir_perms; 261allow system_server radio_data_file:file create_file_perms; 262 263# Manage /data/misc/systemkeys. 264allow system_server systemkeys_data_file:dir create_dir_perms; 265allow system_server systemkeys_data_file:file create_file_perms; 266 267# Access /data/tombstones. 268allow system_server tombstone_data_file:dir r_dir_perms; 269allow system_server tombstone_data_file:file r_file_perms; 270 271# Manage /data/misc/vpn. 272allow system_server vpn_data_file:dir create_dir_perms; 273allow system_server vpn_data_file:file create_file_perms; 274 275# Manage /data/misc/wifi. 276allow system_server wifi_data_file:dir create_dir_perms; 277allow system_server wifi_data_file:file create_file_perms; 278 279# Manage /data/misc/zoneinfo. 280allow system_server zoneinfo_data_file:dir create_dir_perms; 281allow system_server zoneinfo_data_file:file create_file_perms; 282 283# Walk /data/data subdirectories. 284# Types extracted from seapp_contexts type= fields. 285allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file autoplay_data_file }:dir { getattr read search }; 286# Also permit for unlabeled /data/data subdirectories and 287# for unlabeled asec containers on upgrades from 4.2. 288allow system_server unlabeled:dir r_dir_perms; 289# Read pkg.apk file before it has been relabeled by vold. 290allow system_server unlabeled:file r_file_perms; 291 292# Populate com.android.providers.settings/databases/settings.db. 293allow system_server system_app_data_file:dir create_dir_perms; 294allow system_server system_app_data_file:file create_file_perms; 295 296# Receive and use open app data files passed over binder IPC. 297# Types extracted from seapp_contexts type= fields. 298allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:file { getattr read write }; 299 300# Receive and use open /data/media files passed over binder IPC. 301allow system_server media_rw_data_file:file { getattr read write }; 302 303# Read /file_contexts and /data/security/file_contexts 304security_access_policy(system_server) 305 306# Relabel apk files. 307allow system_server { apk_tmp_file apk_private_tmp_file }:{ dir file } { relabelfrom relabelto }; 308allow system_server { apk_data_file apk_private_data_file }:{ dir file } { relabelfrom relabelto }; 309 310# Relabel wallpaper. 311allow system_server system_data_file:file relabelfrom; 312allow system_server wallpaper_file:file relabelto; 313allow system_server wallpaper_file:file { rw_file_perms rename unlink }; 314 315# Backup of wallpaper imagery uses temporary hard links to avoid data churn 316allow system_server { system_data_file wallpaper_file }:file link; 317 318# ShortcutManager icons 319allow system_server system_data_file:dir relabelfrom; 320allow system_server shortcut_manager_icons:dir { create_dir_perms relabelto }; 321allow system_server shortcut_manager_icons:file create_file_perms; 322 323# Manage ringtones. 324allow system_server ringtone_file:dir { create_dir_perms relabelto }; 325allow system_server ringtone_file:file create_file_perms; 326 327# Relabel icon file. 328allow system_server icon_file:file relabelto; 329allow system_server icon_file:file { rw_file_perms unlink }; 330 331# FingerprintService.java does a restorecon of the directory /data/system/users/[0-9]+/fpdata(/.*)? 332allow system_server system_data_file:dir relabelfrom; 333 334# Property Service write 335set_prop(system_server, system_prop) 336set_prop(system_server, safemode_prop) 337set_prop(system_server, dhcp_prop) 338set_prop(system_server, net_radio_prop) 339set_prop(system_server, system_radio_prop) 340set_prop(system_server, debug_prop) 341set_prop(system_server, powerctl_prop) 342set_prop(system_server, fingerprint_prop) 343set_prop(system_server, device_logging_prop) 344userdebug_or_eng(`set_prop(system_server, wifi_log_prop)') 345 346# ctl interface 347set_prop(system_server, ctl_default_prop) 348set_prop(system_server, ctl_bugreport_prop) 349 350# Create a socket for receiving info from wpa. 351type_transition system_server wifi_data_file:sock_file system_wpa_socket; 352type_transition system_server wpa_socket:sock_file system_wpa_socket; 353allow system_server wpa_socket:dir rw_dir_perms; 354allow system_server system_wpa_socket:sock_file create_file_perms; 355 356# Remove sockets created by wpa_supplicant 357allow system_server wpa_socket:sock_file unlink; 358 359# Create a socket for connections from debuggerd. 360type_transition system_server system_data_file:sock_file system_ndebug_socket "ndebugsocket"; 361allow system_server system_ndebug_socket:sock_file create_file_perms; 362 363# Manage cache files. 364allow system_server { cache_file cache_recovery_file }:dir { relabelfrom create_dir_perms }; 365allow system_server { cache_file cache_recovery_file }:file { relabelfrom create_file_perms }; 366allow system_server { cache_file cache_recovery_file }:fifo_file create_file_perms; 367 368# Run system programs, e.g. dexopt. 369allow system_server system_file:file x_file_perms; 370 371# LocationManager(e.g, GPS) needs to read and write 372# to uart driver and ctrl proc entry 373allow system_server gps_device:chr_file rw_file_perms; 374allow system_server gps_control:file rw_file_perms; 375 376# Allow system_server to use app-created sockets and pipes. 377allow system_server { appdomain autoplay_app }:{ tcp_socket udp_socket } { getattr getopt setopt read write shutdown }; 378allow system_server { appdomain autoplay_app }:{ fifo_file unix_stream_socket } { getattr read write }; 379 380# Allow abstract socket connection 381allow system_server rild:unix_stream_socket connectto; 382 383# BackupManagerService needs to manipulate backup data files 384allow system_server cache_backup_file:dir rw_dir_perms; 385allow system_server cache_backup_file:file create_file_perms; 386# LocalTransport works inside /cache/backup 387allow system_server cache_private_backup_file:dir create_dir_perms; 388allow system_server cache_private_backup_file:file create_file_perms; 389 390# Allow system to talk to usb device 391allow system_server usb_device:chr_file rw_file_perms; 392allow system_server usb_device:dir r_dir_perms; 393 394# Allow system to talk to sensors 395allow system_server sensors_device:chr_file rw_file_perms; 396 397# Read from HW RNG (needed by EntropyMixer). 398allow system_server hw_random_device:chr_file r_file_perms; 399 400# Read and delete files under /dev/fscklogs. 401r_dir_file(system_server, fscklogs) 402allow system_server fscklogs:dir { write remove_name }; 403allow system_server fscklogs:file unlink; 404 405# logd access, system_server inherit logd write socket 406# (urge is to deprecate this long term) 407allow system_server zygote:unix_dgram_socket write; 408 409# Read from log daemon. 410read_logd(system_server) 411 412# Be consistent with DAC permissions. Allow system_server to write to 413# /sys/module/lowmemorykiller/parameters/adj 414# /sys/module/lowmemorykiller/parameters/minfree 415allow system_server sysfs_lowmemorykiller:file { getattr w_file_perms }; 416 417# Read /sys/fs/pstore/console-ramoops 418# Don't worry about overly broad permissions for now, as there's 419# only one file in /sys/fs/pstore 420allow system_server pstorefs:dir r_dir_perms; 421allow system_server pstorefs:file r_file_perms; 422 423# /sys access 424allow system_server sysfs_zram:dir search; 425allow system_server sysfs_zram:file r_file_perms; 426 427allow system_server audioserver_service:service_manager find; 428allow system_server cameraserver_service:service_manager find; 429allow system_server drmserver_service:service_manager find; 430allow system_server batteryproperties_service:service_manager find; 431allow system_server keystore_service:service_manager find; 432allow system_server gatekeeper_service:service_manager find; 433allow system_server fingerprintd_service:service_manager find; 434allow system_server mediaserver_service:service_manager find; 435allow system_server mediaextractor_service:service_manager find; 436allow system_server mediacodec_service:service_manager find; 437allow system_server mediadrmserver_service:service_manager find; 438allow system_server netd_service:service_manager find; 439allow system_server nfc_service:service_manager find; 440allow system_server radio_service:service_manager find; 441allow system_server system_server_service:service_manager { add find }; 442allow system_server surfaceflinger_service:service_manager find; 443 444allow system_server keystore:keystore_key { 445 get_state 446 get 447 insert 448 delete 449 exist 450 list 451 reset 452 password 453 lock 454 unlock 455 is_empty 456 sign 457 verify 458 grant 459 duplicate 460 clear_uid 461 add_auth 462 user_changed 463}; 464 465# Allow system server to search and write to the persistent factory reset 466# protection partition. This block device does not get wiped in a factory reset. 467allow system_server block_device:dir search; 468allow system_server frp_block_device:blk_file rw_file_perms; 469 470# Clean up old cgroups 471allow system_server cgroup:dir { remove_name rmdir }; 472 473# /oem access 474r_dir_file(system_server, oemfs) 475 476# Allow resolving per-user storage symlinks 477allow system_server { mnt_user_file storage_file }:dir { getattr search }; 478allow system_server { mnt_user_file storage_file }:lnk_file { getattr read }; 479 480# Allow statfs() on storage devices, which happens fast enough that 481# we shouldn't be killed during unsafe removal 482allow system_server sdcard_type:dir { getattr search }; 483 484# Traverse into expanded storage 485allow system_server mnt_expand_file:dir r_dir_perms; 486 487# Allow system process to relabel the fingerprint directory after mkdir 488# and delete the directory and files when no longer needed 489allow system_server fingerprintd_data_file:dir { r_dir_perms remove_name rmdir relabelto write }; 490allow system_server fingerprintd_data_file:file { getattr unlink }; 491 492# Allow system process to read network MAC address 493allow system_server sysfs_mac_address:file r_file_perms; 494 495userdebug_or_eng(` 496 # Allow system server to create and write method traces in /data/misc/trace. 497 allow system_server method_trace_data_file:dir w_dir_perms; 498 allow system_server method_trace_data_file:file { create w_file_perms }; 499 500 # Allow system server to read dmesg 501 allow system_server kernel:system syslog_read; 502') 503 504# For AppFuse. 505allow system_server vold:fd use; 506allow system_server fuse_device:chr_file { read write ioctl getattr }; 507 508# For configuring sdcardfs 509allow system_server configfs:dir { create_dir_perms }; 510allow system_server configfs:file { getattr open unlink write }; 511 512# Connect to adbd and use a socket transferred from it. 513# Used for e.g. jdwp. 514allow system_server adbd:unix_stream_socket connectto; 515allow system_server adbd:fd use; 516allow system_server adbd:unix_stream_socket { getattr getopt ioctl read write shutdown }; 517 518# Access to /data/media. 519# This should be removed if sdcardfs is modified to alter the secontext for its 520# accesses to the underlying FS. 521allow system_server media_rw_data_file:dir search; 522 523# Allow invoking tools like "timeout" 524allow system_server toolbox_exec:file rx_file_perms; 525 526# Postinstall 527# 528# For OTA dexopt, allow calls coming from postinstall. 529binder_call(system_server, postinstall) 530 531allow system_server postinstall:fifo_file write; 532allow system_server update_engine:fd use; 533allow system_server update_engine:fifo_file write; 534 535# Access to /data/preloads 536allow system_server preloads_data_file:file { r_file_perms unlink }; 537allow system_server preloads_data_file:dir { r_dir_perms write remove_name }; 538 539### 540### Neverallow rules 541### 542### system_server should NEVER do any of this 543 544# Do not allow opening files from external storage as unsafe ejection 545# could cause the kernel to kill the system_server. 546neverallow system_server sdcard_type:dir { open read write }; 547neverallow system_server sdcard_type:file rw_file_perms; 548 549# system server should never be opening zygote spawned app data 550# files directly. Rather, they should always be passed via a 551# file descriptor. 552# Types extracted from seapp_contexts type= fields, excluding 553# those types that system_server needs to open directly. 554neverallow system_server { bluetooth_data_file nfc_data_file shell_data_file app_data_file }:file open; 555 556# system_server should never be executing dex2oat. This is either 557# a bug (for example, bug 16317188), or represents an attempt by 558# system server to dynamically load a dex file, something we do not 559# want to allow. 560neverallow system_server dex2oat_exec:file no_x_file_perms; 561 562# system_server should never execute anything from /data except for /data/dalvik-cache files. 563neverallow system_server { 564 data_file_type 565 -dalvikcache_data_file #mapping with PROT_EXEC 566}:file no_x_file_perms; 567 568# The only block device system_server should be accessing is 569# the frp_block_device. This helps avoid a system_server to root 570# escalation by writing to raw block devices. 571neverallow system_server { dev_type -frp_block_device }:blk_file no_rw_file_perms; 572 573# system_server should never use JIT functionality 574neverallow system_server self:process execmem; 575neverallow system_server ashmem_device:chr_file execute; 576neverallow system_server system_server_tmpfs:file execute; 577