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, mlstrustedsubject; 6 7# Define a type for tmpfs-backed ashmem regions. 8tmpfs_domain(system_server) 9 10# Dalvik Compiler JIT Mapping. 11allow system_server self:process execmem; 12allow system_server ashmem_device:chr_file execute; 13allow system_server system_server_tmpfs:file execute; 14 15# For art. 16allow system_server dalvikcache_data_file:file execute; 17allow system_server dalvikcache_data_file:dir r_dir_perms; 18 19# /data/resource-cache 20allow system_server resourcecache_data_file:file r_file_perms; 21allow system_server resourcecache_data_file:dir r_dir_perms; 22 23# ptrace to processes in the same domain for debugging crashes. 24allow system_server self:process ptrace; 25 26# Child of the zygote. 27allow system_server zygote:fd use; 28allow system_server zygote:process sigchld; 29allow system_server zygote_tmpfs:file read; 30 31# May kill zygote on crashes. 32allow system_server zygote:process sigkill; 33 34# Read /system/bin/app_process. 35allow system_server zygote_exec:file r_file_perms; 36 37# Needed to close the zygote socket, which involves getopt / getattr 38allow system_server zygote:unix_stream_socket { getopt getattr }; 39 40# system server gets network and bluetooth permissions. 41net_domain(system_server) 42bluetooth_domain(system_server) 43 44# These are the capabilities assigned by the zygote to the 45# system server. 46allow system_server self:capability { 47 kill 48 net_admin 49 net_bind_service 50 net_broadcast 51 net_raw 52 sys_boot 53 sys_nice 54 sys_resource 55 sys_time 56 sys_tty_config 57}; 58 59wakelock_use(system_server) 60 61# Triggered by /proc/pid accesses, not allowed. 62dontaudit system_server self:capability sys_ptrace; 63 64# Trigger module auto-load. 65allow system_server kernel:system module_request; 66 67# Use netlink uevent sockets. 68allow system_server self:netlink_kobject_uevent_socket create_socket_perms; 69 70# Use generic netlink sockets. 71allow system_server self:netlink_socket create_socket_perms; 72 73# Set and get routes directly via netlink. 74allow system_server self:netlink_route_socket nlmsg_write; 75 76# Kill apps. 77allow system_server appdomain:process { sigkill signal }; 78 79# Set scheduling info for apps. 80allow system_server appdomain:process { getsched setsched }; 81allow system_server mediaserver:process { getsched setsched }; 82 83# Read /proc/pid data for all domains. This is used by ProcessCpuTracker 84# within system_server to keep track of memory and CPU usage for 85# all processes on the device. 86r_dir_file(system_server, domain) 87 88# Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid. 89allow system_server qtaguid_proc:file rw_file_perms; 90allow system_server qtaguid_device:chr_file rw_file_perms; 91 92# Read /proc/uid_cputime/show_uid_stat. 93allow system_server proc_uid_cputime_showstat:file r_file_perms; 94 95# Write /proc/uid_cputime/remove_uid_range. 96allow system_server proc_uid_cputime_removeuid:file { w_file_perms getattr }; 97 98# Write to /proc/sysrq-trigger. 99allow system_server proc_sysrq:file rw_file_perms; 100 101# Read /sys/kernel/debug/wakeup_sources. 102allow system_server debugfs:file r_file_perms; 103 104# WifiWatchdog uses a packet_socket 105allow system_server self:packet_socket create_socket_perms; 106 107# 3rd party VPN clients require a tun_socket to be created 108allow system_server self:tun_socket create_socket_perms; 109 110# Notify init of death. 111allow system_server init:process sigchld; 112 113# Talk to init and various daemons via sockets. 114unix_socket_connect(system_server, installd, installd) 115unix_socket_connect(system_server, lmkd, lmkd) 116unix_socket_connect(system_server, mtpd, mtp) 117unix_socket_connect(system_server, netd, netd) 118unix_socket_connect(system_server, vold, vold) 119unix_socket_connect(system_server, zygote, zygote) 120unix_socket_connect(system_server, gps, gpsd) 121unix_socket_connect(system_server, racoon, racoon) 122unix_socket_send(system_server, wpa, wpa) 123 124# Communicate over a socket created by surfaceflinger. 125allow system_server surfaceflinger:unix_stream_socket { read write setopt }; 126 127# Perform Binder IPC. 128binder_use(system_server) 129binder_call(system_server, binderservicedomain) 130binder_call(system_server, gatekeeperd) 131binder_call(system_server, fingerprintd) 132binder_call(system_server, appdomain) 133binder_call(system_server, dumpstate) 134binder_service(system_server) 135 136# Ask debuggerd to dump backtraces for native stacks of interest. 137allow system_server { mediaserver sdcardd surfaceflinger inputflinger }:debuggerd dump_backtrace; 138 139# Read /proc/pid files for dumping stack traces of native processes. 140r_dir_file(system_server, mediaserver) 141r_dir_file(system_server, sdcardd) 142r_dir_file(system_server, surfaceflinger) 143r_dir_file(system_server, inputflinger) 144 145# Use sockets received over binder from various services. 146allow system_server mediaserver:tcp_socket rw_socket_perms; 147allow system_server mediaserver:udp_socket rw_socket_perms; 148 149# Check SELinux permissions. 150selinux_check_access(system_server) 151 152# XXX Label sysfs files with a specific type? 153allow system_server sysfs:file rw_file_perms; 154allow system_server sysfs_nfc_power_writable:file rw_file_perms; 155allow system_server sysfs_devices_system_cpu:file w_file_perms; 156 157# Access devices. 158allow system_server device:dir r_dir_perms; 159allow system_server mdns_socket:sock_file rw_file_perms; 160allow system_server alarm_device:chr_file rw_file_perms; 161allow system_server gpu_device:chr_file rw_file_perms; 162allow system_server iio_device:chr_file rw_file_perms; 163allow system_server input_device:dir r_dir_perms; 164allow system_server input_device:chr_file rw_file_perms; 165allow system_server radio_device:chr_file r_file_perms; 166allow system_server tty_device:chr_file rw_file_perms; 167allow system_server usbaccessory_device:chr_file rw_file_perms; 168allow system_server video_device:dir r_dir_perms; 169allow system_server video_device:chr_file rw_file_perms; 170allow system_server adbd_socket:sock_file rw_file_perms; 171allow system_server rtc_device:chr_file rw_file_perms; 172allow system_server audio_device:dir r_dir_perms; 173 174# write access needed for MIDI 175allow system_server audio_device:chr_file rw_file_perms; 176 177# tun device used for 3rd party vpn apps 178allow system_server tun_device:chr_file rw_file_perms; 179 180# Manage system data files. 181allow system_server system_data_file:dir create_dir_perms; 182allow system_server system_data_file:notdevfile_class_set create_file_perms; 183allow system_server keychain_data_file:dir create_dir_perms; 184allow system_server keychain_data_file:file create_file_perms; 185 186# Manage /data/app. 187allow system_server apk_data_file:dir create_dir_perms; 188allow system_server apk_data_file:file { create_file_perms link }; 189allow system_server apk_tmp_file:dir create_dir_perms; 190allow system_server apk_tmp_file:file create_file_perms; 191 192# Manage /data/app-private. 193allow system_server apk_private_data_file:dir create_dir_perms; 194allow system_server apk_private_data_file:file create_file_perms; 195allow system_server apk_private_tmp_file:dir create_dir_perms; 196allow system_server apk_private_tmp_file:file create_file_perms; 197 198# Manage files within asec containers. 199allow system_server asec_apk_file:dir create_dir_perms; 200allow system_server asec_apk_file:file create_file_perms; 201allow system_server asec_public_file:file create_file_perms; 202 203# Manage /data/anr. 204allow system_server anr_data_file:dir create_dir_perms; 205allow system_server anr_data_file:file create_file_perms; 206 207# Manage /data/backup. 208allow system_server backup_data_file:dir create_dir_perms; 209allow system_server backup_data_file:file create_file_perms; 210 211# Read from /data/dalvik-cache/profiles 212allow system_server dalvikcache_profiles_data_file:dir rw_dir_perms; 213allow system_server dalvikcache_profiles_data_file:file create_file_perms; 214 215# Write to /data/system/heapdump 216allow system_server heapdump_data_file:dir rw_dir_perms; 217allow system_server heapdump_data_file:file create_file_perms; 218 219# Manage /data/misc/adb. 220allow system_server adb_keys_file:dir create_dir_perms; 221allow system_server adb_keys_file:file create_file_perms; 222 223# Manage /data/misc/sms. 224# TODO: Split into a separate type? 225allow system_server radio_data_file:dir create_dir_perms; 226allow system_server radio_data_file:file create_file_perms; 227 228# Manage /data/misc/systemkeys. 229allow system_server systemkeys_data_file:dir create_dir_perms; 230allow system_server systemkeys_data_file:file create_file_perms; 231 232# Access /data/tombstones. 233allow system_server tombstone_data_file:dir r_dir_perms; 234allow system_server tombstone_data_file:file r_file_perms; 235 236# Manage /data/misc/vpn. 237allow system_server vpn_data_file:dir create_dir_perms; 238allow system_server vpn_data_file:file create_file_perms; 239 240# Manage /data/misc/wifi. 241allow system_server wifi_data_file:dir create_dir_perms; 242allow system_server wifi_data_file:file create_file_perms; 243 244# Manage /data/misc/zoneinfo. 245allow system_server zoneinfo_data_file:dir create_dir_perms; 246allow system_server zoneinfo_data_file:file create_file_perms; 247 248# Walk /data/data subdirectories. 249# Types extracted from seapp_contexts type= fields. 250allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:dir { getattr read search }; 251# Also permit for unlabeled /data/data subdirectories and 252# for unlabeled asec containers on upgrades from 4.2. 253allow system_server unlabeled:dir r_dir_perms; 254# Read pkg.apk file before it has been relabeled by vold. 255allow system_server unlabeled:file r_file_perms; 256 257# Populate com.android.providers.settings/databases/settings.db. 258allow system_server system_app_data_file:dir create_dir_perms; 259allow system_server system_app_data_file:file create_file_perms; 260 261# Receive and use open app data files passed over binder IPC. 262# Types extracted from seapp_contexts type= fields. 263allow 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 }; 264 265# Receive and use open /data/media files passed over binder IPC. 266allow system_server media_rw_data_file:file { getattr read write }; 267 268# Read /file_contexts and /data/security/file_contexts 269security_access_policy(system_server) 270 271# Relabel apk files. 272allow system_server { apk_tmp_file apk_private_tmp_file }:{ dir file } { relabelfrom relabelto }; 273allow system_server { apk_data_file apk_private_data_file }:{ dir file } { relabelfrom relabelto }; 274 275# Relabel wallpaper. 276allow system_server system_data_file:file relabelfrom; 277allow system_server wallpaper_file:file relabelto; 278allow system_server wallpaper_file:file { rw_file_perms unlink }; 279 280# Relabel /data/anr. 281allow system_server system_data_file:dir relabelfrom; 282allow system_server anr_data_file:dir relabelto; 283 284# Property Service write 285set_prop(system_server, system_prop) 286set_prop(system_server, dhcp_prop) 287set_prop(system_server, net_radio_prop) 288set_prop(system_server, system_radio_prop) 289set_prop(system_server, debug_prop) 290set_prop(system_server, powerctl_prop) 291set_prop(system_server, fingerprint_prop) 292 293# ctl interface 294set_prop(system_server, ctl_default_prop) 295set_prop(system_server, ctl_dhcp_pan_prop) 296set_prop(system_server, ctl_bugreport_prop) 297 298# Create a socket for receiving info from wpa. 299type_transition system_server wifi_data_file:sock_file system_wpa_socket; 300type_transition system_server wpa_socket:sock_file system_wpa_socket; 301allow system_server wpa_socket:dir rw_dir_perms; 302allow system_server system_wpa_socket:sock_file create_file_perms; 303 304# Remove sockets created by wpa_supplicant 305allow system_server wpa_socket:sock_file unlink; 306 307# Create a socket for connections from debuggerd. 308type_transition system_server system_data_file:sock_file system_ndebug_socket "ndebugsocket"; 309allow system_server system_ndebug_socket:sock_file create_file_perms; 310 311# Manage cache files. 312allow system_server cache_file:dir { relabelfrom create_dir_perms }; 313allow system_server cache_file:file { relabelfrom create_file_perms }; 314allow system_server cache_file:fifo_file create_file_perms; 315 316# Run system programs, e.g. dexopt. 317allow system_server system_file:file x_file_perms; 318 319# LocationManager(e.g, GPS) needs to read and write 320# to uart driver and ctrl proc entry 321allow system_server gps_device:chr_file rw_file_perms; 322allow system_server gps_control:file rw_file_perms; 323 324# Allow system_server to use app-created sockets and pipes. 325allow system_server appdomain:{ tcp_socket udp_socket } { getattr getopt setopt read write shutdown }; 326allow system_server appdomain:{ fifo_file unix_stream_socket } { getattr read write }; 327 328# Allow abstract socket connection 329allow system_server rild:unix_stream_socket connectto; 330 331# BackupManagerService lets PMS create a data backup file 332allow system_server cache_backup_file:file create_file_perms; 333# Relabel /data/backup 334allow system_server backup_data_file:dir { relabelto relabelfrom }; 335# Relabel /cache/.*\.{data|restore} 336allow system_server cache_backup_file:file { relabelto relabelfrom }; 337# LocalTransport creates and relabels /cache/backup 338allow system_server cache_backup_file:dir { relabelto relabelfrom create_dir_perms }; 339 340# Allow system to talk to usb device 341allow system_server usb_device:chr_file rw_file_perms; 342allow system_server usb_device:dir r_dir_perms; 343 344# Allow system to talk to sensors 345allow system_server sensors_device:chr_file rw_file_perms; 346 347# Read from HW RNG (needed by EntropyMixer). 348allow system_server hw_random_device:chr_file r_file_perms; 349 350# Read and delete files under /dev/fscklogs. 351r_dir_file(system_server, fscklogs) 352allow system_server fscklogs:dir { write remove_name }; 353allow system_server fscklogs:file unlink; 354 355# For SELinuxPolicyInstallReceiver 356selinux_manage_policy(system_server) 357 358# logd access, system_server inherit logd write socket 359# (urge is to deprecate this long term) 360allow system_server zygote:unix_dgram_socket write; 361 362# Read from log daemon. 363read_logd(system_server) 364 365# Be consistent with DAC permissions. Allow system_server to write to 366# /sys/module/lowmemorykiller/parameters/adj 367# /sys/module/lowmemorykiller/parameters/minfree 368allow system_server sysfs_lowmemorykiller:file { getattr w_file_perms }; 369 370# Read /sys/fs/pstore/console-ramoops 371# Don't worry about overly broad permissions for now, as there's 372# only one file in /sys/fs/pstore 373allow system_server pstorefs:dir r_dir_perms; 374allow system_server pstorefs:file r_file_perms; 375 376allow system_server drmserver_service:service_manager find; 377allow system_server healthd_service:service_manager find; 378allow system_server keystore_service:service_manager find; 379allow system_server gatekeeper_service:service_manager find; 380allow system_server fingerprintd_service:service_manager find; 381allow system_server mediaserver_service:service_manager find; 382allow system_server nfc_service:service_manager find; 383allow system_server radio_service:service_manager find; 384allow system_server system_server_service:service_manager { add find }; 385allow system_server surfaceflinger_service:service_manager find; 386 387allow system_server keystore:keystore_key { 388 get_state 389 get 390 insert 391 delete 392 exist 393 list 394 reset 395 password 396 lock 397 unlock 398 is_empty 399 sign 400 verify 401 grant 402 duplicate 403 clear_uid 404 add_auth 405 user_changed 406}; 407 408# Allow system server to search and write to the persistent factory reset 409# protection partition. This block device does not get wiped in a factory reset. 410allow system_server block_device:dir search; 411allow system_server frp_block_device:blk_file rw_file_perms; 412 413# Clean up old cgroups 414allow system_server cgroup:dir { remove_name rmdir }; 415 416# /oem access 417r_dir_file(system_server, oemfs) 418 419# Allow resolving per-user storage symlinks 420allow system_server { mnt_user_file storage_file }:dir { getattr search }; 421allow system_server { mnt_user_file storage_file }:lnk_file { getattr read }; 422 423# Allow statfs() on storage devices, which happens fast enough that 424# we shouldn't be killed during unsafe removal 425allow system_server sdcard_type:dir { getattr search }; 426 427# Traverse into expanded storage 428allow system_server mnt_expand_file:dir r_dir_perms; 429 430# Allow system process to relabel the fingerprint directory after mkdir 431allow system_server fingerprintd_data_file:dir {r_dir_perms relabelto}; 432 433### 434### Neverallow rules 435### 436### system_server should NEVER do any of this 437 438# Do not allow opening files from external storage as unsafe ejection 439# could cause the kernel to kill the system_server. 440neverallow system_server sdcard_type:dir { open read write }; 441neverallow system_server sdcard_type:file rw_file_perms; 442 443# system server should never be opening zygote spawned app data 444# files directly. Rather, they should always be passed via a 445# file descriptor. 446# Types extracted from seapp_contexts type= fields, excluding 447# those types that system_server needs to open directly. 448neverallow system_server { bluetooth_data_file nfc_data_file shell_data_file app_data_file }:file open; 449 450# system_server should never be executing dex2oat. This is either 451# a bug (for example, bug 16317188), or represents an attempt by 452# system server to dynamically load a dex file, something we do not 453# want to allow. 454neverallow system_server dex2oat_exec:file no_x_file_perms; 455 456# The only block device system_server should be accessing is 457# the frp_block_device. This helps avoid a system_server to root 458# escalation by writing to raw block devices. 459neverallow system_server { dev_type -frp_block_device }:blk_file no_rw_file_perms; 460