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# The DhcpClient and WifiWatchdog use packet_sockets 105allow system_server self:packet_socket create_socket_perms; 106 107# NetworkDiagnostics requires explicit bind() calls to ping sockets. These aren't actually the same 108# as raw sockets, but the kernel doesn't yet distinguish between the two. 109allow system_server node:rawip_socket node_bind; 110 111# 3rd party VPN clients require a tun_socket to be created 112allow system_server self:tun_socket create_socket_perms; 113 114# Notify init of death. 115allow system_server init:process sigchld; 116 117# Talk to init and various daemons via sockets. 118unix_socket_connect(system_server, installd, installd) 119unix_socket_connect(system_server, lmkd, lmkd) 120unix_socket_connect(system_server, mtpd, mtp) 121unix_socket_connect(system_server, netd, netd) 122unix_socket_connect(system_server, vold, vold) 123unix_socket_connect(system_server, zygote, zygote) 124unix_socket_connect(system_server, gps, gpsd) 125unix_socket_connect(system_server, racoon, racoon) 126unix_socket_send(system_server, wpa, wpa) 127 128# Communicate over a socket created by surfaceflinger. 129allow system_server surfaceflinger:unix_stream_socket { read write setopt }; 130 131# Perform Binder IPC. 132binder_use(system_server) 133binder_call(system_server, binderservicedomain) 134binder_call(system_server, gatekeeperd) 135binder_call(system_server, fingerprintd) 136binder_call(system_server, appdomain) 137binder_call(system_server, dumpstate) 138binder_service(system_server) 139 140# Ask debuggerd to dump backtraces for native stacks of interest. 141allow system_server { mediaserver sdcardd surfaceflinger inputflinger }:debuggerd dump_backtrace; 142 143# Read /proc/pid files for dumping stack traces of native processes. 144r_dir_file(system_server, mediaserver) 145r_dir_file(system_server, sdcardd) 146r_dir_file(system_server, surfaceflinger) 147r_dir_file(system_server, inputflinger) 148 149# Use sockets received over binder from various services. 150allow system_server mediaserver:tcp_socket rw_socket_perms; 151allow system_server mediaserver:udp_socket rw_socket_perms; 152 153# Check SELinux permissions. 154selinux_check_access(system_server) 155 156# XXX Label sysfs files with a specific type? 157allow system_server sysfs:file rw_file_perms; 158allow system_server sysfs_nfc_power_writable:file rw_file_perms; 159allow system_server sysfs_devices_system_cpu:file w_file_perms; 160 161# Access devices. 162allow system_server device:dir r_dir_perms; 163allow system_server mdns_socket:sock_file rw_file_perms; 164allow system_server alarm_device:chr_file rw_file_perms; 165allow system_server gpu_device:chr_file rw_file_perms; 166allow system_server iio_device:chr_file rw_file_perms; 167allow system_server input_device:dir r_dir_perms; 168allow system_server input_device:chr_file rw_file_perms; 169allow system_server radio_device:chr_file r_file_perms; 170allow system_server tty_device:chr_file rw_file_perms; 171allow system_server usbaccessory_device:chr_file rw_file_perms; 172allow system_server video_device:dir r_dir_perms; 173allow system_server video_device:chr_file rw_file_perms; 174allow system_server adbd_socket:sock_file rw_file_perms; 175allow system_server rtc_device:chr_file rw_file_perms; 176allow system_server audio_device:dir r_dir_perms; 177 178# write access needed for MIDI 179allow system_server audio_device:chr_file rw_file_perms; 180 181# tun device used for 3rd party vpn apps 182allow system_server tun_device:chr_file rw_file_perms; 183 184# Manage system data files. 185allow system_server system_data_file:dir create_dir_perms; 186allow system_server system_data_file:notdevfile_class_set create_file_perms; 187allow system_server keychain_data_file:dir create_dir_perms; 188allow system_server keychain_data_file:file create_file_perms; 189 190# Manage /data/app. 191allow system_server apk_data_file:dir create_dir_perms; 192allow system_server apk_data_file:file { create_file_perms link }; 193allow system_server apk_tmp_file:dir create_dir_perms; 194allow system_server apk_tmp_file:file create_file_perms; 195 196# Manage /data/app-private. 197allow system_server apk_private_data_file:dir create_dir_perms; 198allow system_server apk_private_data_file:file create_file_perms; 199allow system_server apk_private_tmp_file:dir create_dir_perms; 200allow system_server apk_private_tmp_file:file create_file_perms; 201 202# Manage files within asec containers. 203allow system_server asec_apk_file:dir create_dir_perms; 204allow system_server asec_apk_file:file create_file_perms; 205allow system_server asec_public_file:file create_file_perms; 206 207# Manage /data/anr. 208allow system_server anr_data_file:dir create_dir_perms; 209allow system_server anr_data_file:file create_file_perms; 210 211# Manage /data/backup. 212allow system_server backup_data_file:dir create_dir_perms; 213allow system_server backup_data_file:file create_file_perms; 214 215# Read from /data/dalvik-cache/profiles 216allow system_server dalvikcache_profiles_data_file:dir rw_dir_perms; 217allow system_server dalvikcache_profiles_data_file:file create_file_perms; 218 219# Write to /data/system/heapdump 220allow system_server heapdump_data_file:dir rw_dir_perms; 221allow system_server heapdump_data_file:file create_file_perms; 222 223# Manage /data/misc/adb. 224allow system_server adb_keys_file:dir create_dir_perms; 225allow system_server adb_keys_file:file create_file_perms; 226 227# Manage /data/misc/sms. 228# TODO: Split into a separate type? 229allow system_server radio_data_file:dir create_dir_perms; 230allow system_server radio_data_file:file create_file_perms; 231 232# Manage /data/misc/systemkeys. 233allow system_server systemkeys_data_file:dir create_dir_perms; 234allow system_server systemkeys_data_file:file create_file_perms; 235 236# Access /data/tombstones. 237allow system_server tombstone_data_file:dir r_dir_perms; 238allow system_server tombstone_data_file:file r_file_perms; 239 240# Manage /data/misc/vpn. 241allow system_server vpn_data_file:dir create_dir_perms; 242allow system_server vpn_data_file:file create_file_perms; 243 244# Manage /data/misc/wifi. 245allow system_server wifi_data_file:dir create_dir_perms; 246allow system_server wifi_data_file:file create_file_perms; 247 248# Manage /data/misc/zoneinfo. 249allow system_server zoneinfo_data_file:dir create_dir_perms; 250allow system_server zoneinfo_data_file:file create_file_perms; 251 252# Walk /data/data subdirectories. 253# Types extracted from seapp_contexts type= fields. 254allow 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 }; 255# Also permit for unlabeled /data/data subdirectories and 256# for unlabeled asec containers on upgrades from 4.2. 257allow system_server unlabeled:dir r_dir_perms; 258# Read pkg.apk file before it has been relabeled by vold. 259allow system_server unlabeled:file r_file_perms; 260 261# Populate com.android.providers.settings/databases/settings.db. 262allow system_server system_app_data_file:dir create_dir_perms; 263allow system_server system_app_data_file:file create_file_perms; 264 265# Receive and use open app data files passed over binder IPC. 266# Types extracted from seapp_contexts type= fields. 267allow 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 }; 268 269# Receive and use open /data/media files passed over binder IPC. 270allow system_server media_rw_data_file:file { getattr read write }; 271 272# Read /file_contexts and /data/security/file_contexts 273security_access_policy(system_server) 274 275# Relabel apk files. 276allow system_server { apk_tmp_file apk_private_tmp_file }:{ dir file } { relabelfrom relabelto }; 277allow system_server { apk_data_file apk_private_data_file }:{ dir file } { relabelfrom relabelto }; 278 279# Relabel wallpaper. 280allow system_server system_data_file:file relabelfrom; 281allow system_server wallpaper_file:file relabelto; 282allow system_server wallpaper_file:file { rw_file_perms unlink }; 283 284# Relabel /data/anr. 285allow system_server system_data_file:dir relabelfrom; 286allow system_server anr_data_file:dir relabelto; 287 288# Property Service write 289set_prop(system_server, system_prop) 290set_prop(system_server, dhcp_prop) 291set_prop(system_server, net_radio_prop) 292set_prop(system_server, system_radio_prop) 293set_prop(system_server, debug_prop) 294set_prop(system_server, powerctl_prop) 295set_prop(system_server, fingerprint_prop) 296 297# ctl interface 298set_prop(system_server, ctl_default_prop) 299set_prop(system_server, ctl_dhcp_pan_prop) 300set_prop(system_server, ctl_bugreport_prop) 301 302# Create a socket for receiving info from wpa. 303type_transition system_server wifi_data_file:sock_file system_wpa_socket; 304type_transition system_server wpa_socket:sock_file system_wpa_socket; 305allow system_server wpa_socket:dir rw_dir_perms; 306allow system_server system_wpa_socket:sock_file create_file_perms; 307 308# Remove sockets created by wpa_supplicant 309allow system_server wpa_socket:sock_file unlink; 310 311# Create a socket for connections from debuggerd. 312type_transition system_server system_data_file:sock_file system_ndebug_socket "ndebugsocket"; 313allow system_server system_ndebug_socket:sock_file create_file_perms; 314 315# Manage cache files. 316allow system_server cache_file:dir { relabelfrom create_dir_perms }; 317allow system_server cache_file:file { relabelfrom create_file_perms }; 318allow system_server cache_file:fifo_file create_file_perms; 319 320# Run system programs, e.g. dexopt. 321allow system_server system_file:file x_file_perms; 322 323# LocationManager(e.g, GPS) needs to read and write 324# to uart driver and ctrl proc entry 325allow system_server gps_device:chr_file rw_file_perms; 326allow system_server gps_control:file rw_file_perms; 327 328# Allow system_server to use app-created sockets and pipes. 329allow system_server appdomain:{ tcp_socket udp_socket } { getattr getopt setopt read write shutdown }; 330allow system_server appdomain:{ fifo_file unix_stream_socket } { getattr read write }; 331 332# Allow abstract socket connection 333allow system_server rild:unix_stream_socket connectto; 334 335# BackupManagerService lets PMS create a data backup file 336allow system_server cache_backup_file:file create_file_perms; 337# Relabel /data/backup 338allow system_server backup_data_file:dir { relabelto relabelfrom }; 339# Relabel /cache/.*\.{data|restore} 340allow system_server cache_backup_file:file { relabelto relabelfrom }; 341# LocalTransport creates and relabels /cache/backup 342allow system_server cache_backup_file:dir { relabelto relabelfrom create_dir_perms }; 343 344# Allow system to talk to usb device 345allow system_server usb_device:chr_file rw_file_perms; 346allow system_server usb_device:dir r_dir_perms; 347 348# Allow system to talk to sensors 349allow system_server sensors_device:chr_file rw_file_perms; 350 351# Read from HW RNG (needed by EntropyMixer). 352allow system_server hw_random_device:chr_file r_file_perms; 353 354# Read and delete files under /dev/fscklogs. 355r_dir_file(system_server, fscklogs) 356allow system_server fscklogs:dir { write remove_name }; 357allow system_server fscklogs:file unlink; 358 359# For SELinuxPolicyInstallReceiver 360selinux_manage_policy(system_server) 361 362# logd access, system_server inherit logd write socket 363# (urge is to deprecate this long term) 364allow system_server zygote:unix_dgram_socket write; 365 366# Read from log daemon. 367read_logd(system_server) 368 369# Be consistent with DAC permissions. Allow system_server to write to 370# /sys/module/lowmemorykiller/parameters/adj 371# /sys/module/lowmemorykiller/parameters/minfree 372allow system_server sysfs_lowmemorykiller:file { getattr w_file_perms }; 373 374# Read /sys/fs/pstore/console-ramoops 375# Don't worry about overly broad permissions for now, as there's 376# only one file in /sys/fs/pstore 377allow system_server pstorefs:dir r_dir_perms; 378allow system_server pstorefs:file r_file_perms; 379 380allow system_server drmserver_service:service_manager find; 381allow system_server healthd_service:service_manager find; 382allow system_server keystore_service:service_manager find; 383allow system_server gatekeeper_service:service_manager find; 384allow system_server fingerprintd_service:service_manager find; 385allow system_server mediaserver_service:service_manager find; 386allow system_server nfc_service:service_manager find; 387allow system_server radio_service:service_manager find; 388allow system_server system_server_service:service_manager { add find }; 389allow system_server surfaceflinger_service:service_manager find; 390 391allow system_server keystore:keystore_key { 392 get_state 393 get 394 insert 395 delete 396 exist 397 list 398 reset 399 password 400 lock 401 unlock 402 is_empty 403 sign 404 verify 405 grant 406 duplicate 407 clear_uid 408 add_auth 409 user_changed 410}; 411 412# Allow system server to search and write to the persistent factory reset 413# protection partition. This block device does not get wiped in a factory reset. 414allow system_server block_device:dir search; 415allow system_server frp_block_device:blk_file rw_file_perms; 416 417# Clean up old cgroups 418allow system_server cgroup:dir { remove_name rmdir }; 419 420# /oem access 421r_dir_file(system_server, oemfs) 422 423# Allow resolving per-user storage symlinks 424allow system_server { mnt_user_file storage_file }:dir { getattr search }; 425allow system_server { mnt_user_file storage_file }:lnk_file { getattr read }; 426 427# Allow statfs() on storage devices, which happens fast enough that 428# we shouldn't be killed during unsafe removal 429allow system_server sdcard_type:dir { getattr search }; 430 431# Traverse into expanded storage 432allow system_server mnt_expand_file:dir r_dir_perms; 433 434# Allow system process to relabel the fingerprint directory after mkdir 435allow system_server fingerprintd_data_file:dir {r_dir_perms relabelto}; 436 437### 438### Neverallow rules 439### 440### system_server should NEVER do any of this 441 442# Do not allow opening files from external storage as unsafe ejection 443# could cause the kernel to kill the system_server. 444neverallow system_server sdcard_type:dir { open read write }; 445neverallow system_server sdcard_type:file rw_file_perms; 446 447# system server should never be opening zygote spawned app data 448# files directly. Rather, they should always be passed via a 449# file descriptor. 450# Types extracted from seapp_contexts type= fields, excluding 451# those types that system_server needs to open directly. 452neverallow system_server { bluetooth_data_file nfc_data_file shell_data_file app_data_file }:file open; 453 454# system_server should never be executing dex2oat. This is either 455# a bug (for example, bug 16317188), or represents an attempt by 456# system server to dynamically load a dex file, something we do not 457# want to allow. 458neverallow system_server dex2oat_exec:file no_x_file_perms; 459 460# The only block device system_server should be accessing is 461# the frp_block_device. This helps avoid a system_server to root 462# escalation by writing to raw block devices. 463neverallow system_server { dev_type -frp_block_device }:blk_file no_rw_file_perms; 464