1# 2# System Server aka system_server spawned by zygote. 3# Most of the framework services run in this process. 4# 5 6typeattribute system_server coredomain; 7typeattribute system_server mlstrustedsubject; 8 9# Define a type for tmpfs-backed ashmem regions. 10tmpfs_domain(system_server) 11 12# Create a socket for connections from crash_dump. 13type_transition system_server system_data_file:sock_file system_ndebug_socket "ndebugsocket"; 14 15allow system_server zygote_tmpfs:file read; 16 17# For art. 18allow system_server dalvikcache_data_file:dir r_dir_perms; 19allow system_server dalvikcache_data_file:file r_file_perms; 20 21# When running system server under --invoke-with, we'll try to load the boot image under the 22# system server domain, following links to the system partition. 23with_asan(`allow system_server dalvikcache_data_file:lnk_file r_file_perms;') 24 25# /data/resource-cache 26allow system_server resourcecache_data_file:file r_file_perms; 27allow system_server resourcecache_data_file:dir r_dir_perms; 28 29# ptrace to processes in the same domain for debugging crashes. 30allow system_server self:process ptrace; 31 32# Child of the zygote. 33allow system_server zygote:fd use; 34allow system_server zygote:process sigchld; 35 36# May kill zygote on crashes. 37allow system_server zygote:process sigkill; 38allow system_server crash_dump:process sigkill; 39allow system_server webview_zygote:process sigkill; 40 41# Read /system/bin/app_process. 42allow system_server zygote_exec:file r_file_perms; 43 44# Needed to close the zygote socket, which involves getopt / getattr 45allow system_server zygote:unix_stream_socket { getopt getattr }; 46 47# system server gets network and bluetooth permissions. 48net_domain(system_server) 49# in addition to ioctls allowlisted for all domains, also allow system_server 50# to use privileged ioctls commands. Needed to set up VPNs. 51allowxperm system_server self:udp_socket ioctl priv_sock_ioctls; 52bluetooth_domain(system_server) 53 54# These are the capabilities assigned by the zygote to the 55# system server. 56allow system_server self:global_capability_class_set { 57 ipc_lock 58 kill 59 net_admin 60 net_bind_service 61 net_broadcast 62 net_raw 63 sys_boot 64 sys_nice 65 sys_ptrace 66 sys_time 67 sys_tty_config 68}; 69 70wakelock_use(system_server) 71 72# Trigger module auto-load. 73allow system_server kernel:system module_request; 74 75# Allow alarmtimers to be set 76allow system_server self:global_capability2_class_set wake_alarm; 77 78# Create and share netlink_netfilter_sockets for tetheroffload. 79allow system_server self:netlink_netfilter_socket create_socket_perms_no_ioctl; 80 81# Use netlink uevent sockets. 82allow system_server self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl; 83 84# Use generic netlink sockets. 85allow system_server self:netlink_socket create_socket_perms_no_ioctl; 86allow system_server self:netlink_generic_socket create_socket_perms_no_ioctl; 87 88# libvintf reads the kernel config to verify vendor interface compatibility. 89allow system_server config_gz:file { read open }; 90 91# Use generic "sockets" where the address family is not known 92# to the kernel. The ioctl permission is specifically omitted here, but may 93# be added to device specific policy along with the ioctl commands to be 94# allowlisted. 95allow system_server self:socket create_socket_perms_no_ioctl; 96 97# Set and get routes directly via netlink. 98allow system_server self:netlink_route_socket nlmsg_write; 99 100# Kill apps. 101allow system_server appdomain:process { getpgid sigkill signal }; 102 103# Set scheduling info for apps. 104allow system_server appdomain:process { getsched setsched }; 105allow system_server audioserver:process { getsched setsched }; 106allow system_server hal_audio:process { getsched setsched }; 107allow system_server hal_bluetooth:process { getsched setsched }; 108allow system_server mediacodec:process { getsched setsched }; 109allow system_server cameraserver:process { getsched setsched }; 110allow system_server hal_camera:process { getsched setsched }; 111allow system_server mediaserver:process { getsched setsched }; 112allow system_server bootanim:process { getsched setsched }; 113 114# Allow system_server to write to /proc/<pid>/timerslack_ns 115allow system_server appdomain:file w_file_perms; 116allow system_server audioserver:file w_file_perms; 117allow system_server mediacodec:file w_file_perms; 118allow system_server cameraserver:file w_file_perms; 119allow system_server hal_audio_server:file w_file_perms; 120 121# Read /proc/pid data for all domains. This is used by ProcessCpuTracker 122# within system_server to keep track of memory and CPU usage for 123# all processes on the device. In addition, /proc/pid files access is needed 124# for dumping stack traces of native processes. 125r_dir_file(system_server, domain) 126 127# Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid. 128allow system_server qtaguid_proc:file rw_file_perms; 129allow system_server qtaguid_device:chr_file rw_file_perms; 130 131# Write /proc/uid_cputime/remove_uid_range. 132allow system_server proc_uid_cputime_removeuid:file { w_file_perms getattr }; 133 134# Write /proc/uid_procstat/set. 135allow system_server proc_uid_procstat_set:file { w_file_perms getattr }; 136 137# Write to /proc/sysrq-trigger. 138allow system_server proc_sysrq:file rw_file_perms; 139 140# Read /sys/kernel/debug/wakeup_sources. 141allow system_server debugfs:file r_file_perms; 142allow system_server debugfs_wakeup_sources:file r_file_perms; 143 144# Delete /data/misc/stats-data/ and /data/misc/stats-service/ directories. 145allow system_server stats_data_file:dir { open read remove_name search write }; 146allow system_server stats_data_file:file unlink; 147 148# The DhcpClient and WifiWatchdog use packet_sockets 149allow system_server self:packet_socket create_socket_perms_no_ioctl; 150 151# NetworkDiagnostics requires explicit bind() calls to ping sockets. These aren't actually the same 152# as raw sockets, but the kernel doesn't yet distinguish between the two. 153allow system_server node:rawip_socket node_bind; 154 155# 3rd party VPN clients require a tun_socket to be created 156allow system_server self:tun_socket create_socket_perms_no_ioctl; 157 158# Talk to init and various daemons via sockets. 159unix_socket_connect(system_server, lmkd, lmkd) 160unix_socket_connect(system_server, mtpd, mtp) 161unix_socket_connect(system_server, netd, netd) 162unix_socket_connect(system_server, zygote, zygote) 163unix_socket_connect(system_server, racoon, racoon) 164unix_socket_connect(system_server, uncrypt, uncrypt) 165 166# Communicate over a socket created by surfaceflinger. 167allow system_server surfaceflinger:unix_stream_socket { read write setopt }; 168 169# Communicate over a socket created by webview_zygote. 170allow system_server webview_zygote:unix_stream_socket { read write connectto setopt }; 171 172# Perform Binder IPC. 173binder_use(system_server) 174binder_call(system_server, appdomain) 175binder_call(system_server, binderservicedomain) 176binder_call(system_server, dumpstate) 177binder_call(system_server, fingerprintd) 178binder_call(system_server, gatekeeperd) 179binder_call(system_server, installd) 180binder_call(system_server, incidentd) 181binder_call(system_server, netd) 182binder_call(system_server, statsd) 183binder_call(system_server, storaged) 184binder_call(system_server, vold) 185binder_call(system_server, wificond) 186binder_call(system_server, wpantund) 187binder_service(system_server) 188 189# Use HALs 190hal_client_domain(system_server, hal_allocator) 191hal_client_domain(system_server, hal_authsecret) 192hal_client_domain(system_server, hal_broadcastradio) 193hal_client_domain(system_server, hal_configstore) 194hal_client_domain(system_server, hal_contexthub) 195hal_client_domain(system_server, hal_fingerprint) 196hal_client_domain(system_server, hal_gnss) 197hal_client_domain(system_server, hal_graphics_allocator) 198hal_client_domain(system_server, hal_health) 199hal_client_domain(system_server, hal_ir) 200hal_client_domain(system_server, hal_light) 201hal_client_domain(system_server, hal_memtrack) 202hal_client_domain(system_server, hal_neuralnetworks) 203hal_client_domain(system_server, hal_oemlock) 204allow system_server hal_codec2_hwservice:hwservice_manager find; 205allow system_server hal_omx_hwservice:hwservice_manager find; 206allow system_server hidl_token_hwservice:hwservice_manager find; 207hal_client_domain(system_server, hal_power) 208hal_client_domain(system_server, hal_sensors) 209hal_client_domain(system_server, hal_tetheroffload) 210hal_client_domain(system_server, hal_thermal) 211hal_client_domain(system_server, hal_tv_cec) 212hal_client_domain(system_server, hal_tv_input) 213hal_client_domain(system_server, hal_usb) 214hal_client_domain(system_server, hal_usb_gadget) 215hal_client_domain(system_server, hal_vibrator) 216hal_client_domain(system_server, hal_vr) 217hal_client_domain(system_server, hal_weaver) 218hal_client_domain(system_server, hal_wifi) 219hal_client_domain(system_server, hal_wifi_hostapd) 220hal_client_domain(system_server, hal_wifi_offload) 221hal_client_domain(system_server, hal_wifi_supplicant) 222 223binder_call(system_server, mediacodec) 224 225# Talk with graphics composer fences 226allow system_server hal_graphics_composer:fd use; 227 228# Use RenderScript always-passthrough HAL 229allow system_server hal_renderscript_hwservice:hwservice_manager find; 230 231# Offer HwBinder services 232add_hwservice(system_server, fwk_scheduler_hwservice) 233add_hwservice(system_server, fwk_sensor_hwservice) 234 235# Talk to tombstoned to get ANR traces. 236unix_socket_connect(system_server, tombstoned_intercept, tombstoned) 237 238# List HAL interfaces to get ANR traces. 239allow system_server hwservicemanager:hwservice_manager list; 240 241# Send signals to trigger ANR traces. 242allow system_server { 243 # This is derived from the list that system server defines as interesting native processes 244 # to dump during ANRs or watchdog aborts, defined in NATIVE_STACKS_OF_INTEREST in 245 # frameworks/base/services/core/java/com/android/server/Watchdog.java. 246 audioserver 247 cameraserver 248 drmserver 249 inputflinger 250 mediadrmserver 251 mediaextractor 252 mediaserver 253 mediametrics 254 sdcardd 255 statsd 256 surfaceflinger 257 258 # This list comes from HAL_INTERFACES_OF_INTEREST in 259 # frameworks/base/services/core/java/com/android/server/Watchdog.java. 260 hal_audio_server 261 hal_bluetooth_server 262 hal_camera_server 263 hal_graphics_composer_server 264 hal_sensors_server 265 hal_vr_server 266 mediacodec # TODO(b/36375899): hal_omx_server 267}:process { signal }; 268 269# Use sockets received over binder from various services. 270allow system_server audioserver:tcp_socket rw_socket_perms; 271allow system_server audioserver:udp_socket rw_socket_perms; 272allow system_server mediaserver:tcp_socket rw_socket_perms; 273allow system_server mediaserver:udp_socket rw_socket_perms; 274 275# Use sockets received over binder from various services. 276allow system_server mediadrmserver:tcp_socket rw_socket_perms; 277allow system_server mediadrmserver:udp_socket rw_socket_perms; 278 279# Get file context 280allow system_server file_contexts_file:file r_file_perms; 281# access for mac_permissions 282allow system_server mac_perms_file: file r_file_perms; 283# Check SELinux permissions. 284selinux_check_access(system_server) 285 286allow system_server sysfs_type:dir search; 287 288r_dir_file(system_server, sysfs_android_usb) 289allow system_server sysfs_android_usb:file w_file_perms; 290 291r_dir_file(system_server, sysfs_ipv4) 292allow system_server sysfs_ipv4:file w_file_perms; 293 294r_dir_file(system_server, sysfs_rtc) 295r_dir_file(system_server, sysfs_switch) 296r_dir_file(system_server, sysfs_wakeup_reasons) 297 298allow system_server sysfs_nfc_power_writable:file rw_file_perms; 299allow system_server sysfs_mac_address:file r_file_perms; 300allow system_server sysfs_power:dir search; 301allow system_server sysfs_power:file rw_file_perms; 302allow system_server sysfs_thermal:dir search; 303allow system_server sysfs_thermal:file r_file_perms; 304 305# TODO: Remove when HALs are forced into separate processes 306allow system_server sysfs_vibrator:file { write append }; 307 308# TODO: added to match above sysfs rule. Remove me? 309allow system_server sysfs_usb:file w_file_perms; 310 311# Access devices. 312allow system_server device:dir r_dir_perms; 313allow system_server mdns_socket:sock_file rw_file_perms; 314allow system_server alarm_device:chr_file rw_file_perms; 315allow system_server gpu_device:chr_file rw_file_perms; 316allow system_server iio_device:chr_file rw_file_perms; 317allow system_server input_device:dir r_dir_perms; 318allow system_server input_device:chr_file rw_file_perms; 319allow system_server radio_device:chr_file r_file_perms; 320allow system_server tty_device:chr_file rw_file_perms; 321allow system_server usbaccessory_device:chr_file rw_file_perms; 322allow system_server video_device:dir r_dir_perms; 323allow system_server video_device:chr_file rw_file_perms; 324allow system_server adbd_socket:sock_file rw_file_perms; 325allow system_server rtc_device:chr_file rw_file_perms; 326allow system_server audio_device:dir r_dir_perms; 327 328# write access needed for MIDI 329allow system_server audio_device:chr_file rw_file_perms; 330 331# tun device used for 3rd party vpn apps 332allow system_server tun_device:chr_file rw_file_perms; 333 334# Manage system data files. 335allow system_server system_data_file:dir create_dir_perms; 336allow system_server system_data_file:notdevfile_class_set create_file_perms; 337allow system_server keychain_data_file:dir create_dir_perms; 338allow system_server keychain_data_file:file create_file_perms; 339allow system_server keychain_data_file:lnk_file create_file_perms; 340 341# Manage /data/app. 342allow system_server apk_data_file:dir create_dir_perms; 343allow system_server apk_data_file:{ file lnk_file } { create_file_perms link }; 344allow system_server apk_tmp_file:dir create_dir_perms; 345allow system_server apk_tmp_file:file create_file_perms; 346 347# Access /vendor/{app,framework,overlay} 348r_dir_file(system_server, vendor_app_file) 349r_dir_file(system_server, vendor_framework_file) 350r_dir_file(system_server, vendor_overlay_file) 351 352# Manage /data/app-private. 353allow system_server apk_private_data_file:dir create_dir_perms; 354allow system_server apk_private_data_file:file create_file_perms; 355allow system_server apk_private_tmp_file:dir create_dir_perms; 356allow system_server apk_private_tmp_file:file create_file_perms; 357 358# Manage files within asec containers. 359allow system_server asec_apk_file:dir create_dir_perms; 360allow system_server asec_apk_file:file create_file_perms; 361allow system_server asec_public_file:file create_file_perms; 362 363# Manage /data/anr. 364# 365# TODO: Some of these permissions can be withdrawn once we've switched to the 366# new stack dumping mechanism, see b/32064548 and the rules below. In particular, 367# the system_server should never need to create a new anr_data_file:file or write 368# to one, but it will still need to read and append to existing files. 369allow system_server anr_data_file:dir create_dir_perms; 370allow system_server anr_data_file:file create_file_perms; 371 372# New stack dumping scheme : request an output FD from tombstoned via a unix 373# domain socket. 374# 375# Allow system_server to connect and write to the tombstoned java trace socket in 376# order to dump its traces. Also allow the system server to write its traces to 377# dumpstate during bugreport capture and incidentd during incident collection. 378unix_socket_connect(system_server, tombstoned_java_trace, tombstoned) 379allow system_server tombstoned:fd use; 380allow system_server dumpstate:fifo_file append; 381allow system_server incidentd:fifo_file append; 382 383# Read /data/misc/incidents - only read. The fd will be sent over binder, 384# with no DAC access to it, for dropbox to read. 385allow system_server incident_data_file:file read; 386 387# Allow dropbox to read /data/misc/perfetto-traces. Only the fd is sent over 388# binder. 389allow system_server perfetto_traces_data_file:file read; 390allow system_server perfetto:fd use; 391 392# Allow dropbox to read /data/misc/perfprofd. Only the fd is sent over binder. 393userdebug_or_eng(` 394 allow system_server perfprofd_data_file:file read; 395 allow system_server perfprofd:fd use; 396') 397 398# Manage /data/backup. 399allow system_server backup_data_file:dir create_dir_perms; 400allow system_server backup_data_file:file create_file_perms; 401 402# Write to /data/system/heapdump 403allow system_server heapdump_data_file:dir rw_dir_perms; 404allow system_server heapdump_data_file:file create_file_perms; 405 406# Manage /data/misc/adb. 407allow system_server adb_keys_file:dir create_dir_perms; 408allow system_server adb_keys_file:file create_file_perms; 409 410# Manage /data/misc/network_watchlist 411allow system_server network_watchlist_data_file:dir create_dir_perms; 412allow system_server network_watchlist_data_file:file create_file_perms; 413 414# Manage /data/misc/sms. 415# TODO: Split into a separate type? 416allow system_server radio_data_file:dir create_dir_perms; 417allow system_server radio_data_file:file create_file_perms; 418 419# Manage /data/misc/systemkeys. 420allow system_server systemkeys_data_file:dir create_dir_perms; 421allow system_server systemkeys_data_file:file create_file_perms; 422 423# Manage /data/misc/textclassifier. 424allow system_server textclassifier_data_file:dir create_dir_perms; 425allow system_server textclassifier_data_file:file create_file_perms; 426 427# Access /data/tombstones. 428allow system_server tombstone_data_file:dir r_dir_perms; 429allow system_server tombstone_data_file:file r_file_perms; 430 431# Manage /data/misc/vpn. 432allow system_server vpn_data_file:dir create_dir_perms; 433allow system_server vpn_data_file:file create_file_perms; 434 435# Manage /data/misc/wifi. 436allow system_server wifi_data_file:dir create_dir_perms; 437allow system_server wifi_data_file:file create_file_perms; 438 439# Manage /data/misc/zoneinfo. 440allow system_server zoneinfo_data_file:dir create_dir_perms; 441allow system_server zoneinfo_data_file:file create_file_perms; 442 443# Walk /data/data subdirectories. 444# Types extracted from seapp_contexts type= fields. 445allow 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 }; 446# Also permit for unlabeled /data/data subdirectories and 447# for unlabeled asec containers on upgrades from 4.2. 448allow system_server unlabeled:dir r_dir_perms; 449# Read pkg.apk file before it has been relabeled by vold. 450allow system_server unlabeled:file r_file_perms; 451 452# Populate com.android.providers.settings/databases/settings.db. 453allow system_server system_app_data_file:dir create_dir_perms; 454allow system_server system_app_data_file:file create_file_perms; 455 456# Receive and use open app data files passed over binder IPC. 457# Types extracted from seapp_contexts type= fields. 458allow 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 append }; 459 460# Access to /data/media for measuring disk usage. 461allow system_server media_rw_data_file:dir { search getattr open read }; 462 463# Receive and use open /data/media files passed over binder IPC. 464# Also used for measuring disk usage. 465allow system_server media_rw_data_file:file { getattr read write append }; 466 467# Relabel apk files. 468allow system_server { apk_tmp_file apk_private_tmp_file }:{ dir file } { relabelfrom relabelto }; 469allow system_server { apk_data_file apk_private_data_file }:{ dir file } { relabelfrom relabelto }; 470 471# Relabel wallpaper. 472allow system_server system_data_file:file relabelfrom; 473allow system_server wallpaper_file:file relabelto; 474allow system_server wallpaper_file:file { rw_file_perms rename unlink }; 475 476# Backup of wallpaper imagery uses temporary hard links to avoid data churn 477allow system_server { system_data_file wallpaper_file }:file link; 478 479# ShortcutManager icons 480allow system_server system_data_file:dir relabelfrom; 481allow system_server shortcut_manager_icons:dir { create_dir_perms relabelto }; 482allow system_server shortcut_manager_icons:file create_file_perms; 483 484# Manage ringtones. 485allow system_server ringtone_file:dir { create_dir_perms relabelto }; 486allow system_server ringtone_file:file create_file_perms; 487 488# Relabel icon file. 489allow system_server icon_file:file relabelto; 490allow system_server icon_file:file { rw_file_perms unlink }; 491 492# FingerprintService.java does a restorecon of the directory /data/system/users/[0-9]+/fpdata(/.*)? 493allow system_server system_data_file:dir relabelfrom; 494 495# Property Service write 496set_prop(system_server, system_prop) 497set_prop(system_server, exported_system_prop) 498set_prop(system_server, exported2_system_prop) 499set_prop(system_server, exported3_system_prop) 500set_prop(system_server, safemode_prop) 501set_prop(system_server, dhcp_prop) 502set_prop(system_server, net_radio_prop) 503set_prop(system_server, net_dns_prop) 504set_prop(system_server, system_radio_prop) 505set_prop(system_server, exported_system_radio_prop) 506set_prop(system_server, debug_prop) 507set_prop(system_server, powerctl_prop) 508set_prop(system_server, fingerprint_prop) 509set_prop(system_server, exported_fingerprint_prop) 510set_prop(system_server, device_logging_prop) 511set_prop(system_server, dumpstate_options_prop) 512set_prop(system_server, overlay_prop) 513set_prop(system_server, exported_overlay_prop) 514set_prop(system_server, pm_prop) 515set_prop(system_server, exported_pm_prop) 516userdebug_or_eng(`set_prop(system_server, wifi_log_prop)') 517 518# ctl interface 519set_prop(system_server, ctl_default_prop) 520set_prop(system_server, ctl_bugreport_prop) 521 522# cppreopt property 523set_prop(system_server, cppreopt_prop) 524 525# BootReceiver to read ro.boot.bootreason 526get_prop(system_server, bootloader_boot_reason_prop) 527# PowerManager to read persist.sys.boot.reason 528get_prop(system_server, last_boot_reason_prop) 529 530# Collect metrics on boot time created by init 531get_prop(system_server, boottime_prop) 532 533# Read device's serial number from system properties 534get_prop(system_server, serialno_prop) 535 536# Read/write the property which keeps track of whether this is the first start of system_server 537set_prop(system_server, firstboot_prop) 538 539# Audio service in system server can read exported audio properties, 540# such as camera shutter enforcement 541get_prop(system_server, exported_audio_prop) 542 543# Create a socket for connections from debuggerd. 544allow system_server system_ndebug_socket:sock_file create_file_perms; 545 546# Manage cache files. 547allow system_server cache_file:lnk_file r_file_perms; 548allow system_server { cache_file cache_recovery_file }:dir { relabelfrom create_dir_perms }; 549allow system_server { cache_file cache_recovery_file }:file { relabelfrom create_file_perms }; 550allow system_server { cache_file cache_recovery_file }:fifo_file create_file_perms; 551 552allow system_server system_file:dir r_dir_perms; 553allow system_server system_file:lnk_file r_file_perms; 554 555# LocationManager(e.g, GPS) needs to read and write 556# to uart driver and ctrl proc entry 557allow system_server gps_control:file rw_file_perms; 558 559# Allow system_server to use app-created sockets and pipes. 560allow system_server appdomain:{ tcp_socket udp_socket } { getattr getopt setopt read write shutdown }; 561allow system_server appdomain:{ fifo_file unix_stream_socket } { getattr read write }; 562 563# BackupManagerService needs to manipulate backup data files 564allow system_server cache_backup_file:dir rw_dir_perms; 565allow system_server cache_backup_file:file create_file_perms; 566# LocalTransport works inside /cache/backup 567allow system_server cache_private_backup_file:dir create_dir_perms; 568allow system_server cache_private_backup_file:file create_file_perms; 569 570# Allow system to talk to usb device 571allow system_server usb_device:chr_file rw_file_perms; 572allow system_server usb_device:dir r_dir_perms; 573 574# Read from HW RNG (needed by EntropyMixer). 575allow system_server hw_random_device:chr_file r_file_perms; 576 577# Read and delete files under /dev/fscklogs. 578r_dir_file(system_server, fscklogs) 579allow system_server fscklogs:dir { write remove_name }; 580allow system_server fscklogs:file unlink; 581 582# logd access, system_server inherit logd write socket 583# (urge is to deprecate this long term) 584allow system_server zygote:unix_dgram_socket write; 585 586# Read from log daemon. 587read_logd(system_server) 588read_runtime_log_tags(system_server) 589 590# Be consistent with DAC permissions. Allow system_server to write to 591# /sys/module/lowmemorykiller/parameters/adj 592# /sys/module/lowmemorykiller/parameters/minfree 593allow system_server sysfs_lowmemorykiller:file { getattr w_file_perms }; 594 595# Read /sys/fs/pstore/console-ramoops 596# Don't worry about overly broad permissions for now, as there's 597# only one file in /sys/fs/pstore 598allow system_server pstorefs:dir r_dir_perms; 599allow system_server pstorefs:file r_file_perms; 600 601# /sys access 602allow system_server sysfs_zram:dir search; 603allow system_server sysfs_zram:file r_file_perms; 604 605add_service(system_server, system_server_service); 606allow system_server audioserver_service:service_manager find; 607allow system_server batteryproperties_service:service_manager find; 608allow system_server cameraserver_service:service_manager find; 609allow system_server drmserver_service:service_manager find; 610allow system_server dumpstate_service:service_manager find; 611allow system_server fingerprintd_service:service_manager find; 612allow system_server hal_fingerprint_service:service_manager find; 613allow system_server gatekeeper_service:service_manager find; 614allow system_server incident_service:service_manager find; 615allow system_server installd_service:service_manager find; 616allow system_server keystore_service:service_manager find; 617allow system_server mediaserver_service:service_manager find; 618allow system_server mediametrics_service:service_manager find; 619allow system_server mediaextractor_service:service_manager find; 620allow system_server mediacodec_service:service_manager find; 621allow system_server mediadrmserver_service:service_manager find; 622allow system_server netd_service:service_manager find; 623allow system_server nfc_service:service_manager find; 624allow system_server radio_service:service_manager find; 625allow system_server stats_service:service_manager find; 626allow system_server storaged_service:service_manager find; 627allow system_server surfaceflinger_service:service_manager find; 628allow system_server vold_service:service_manager find; 629allow system_server wificond_service:service_manager find; 630 631add_service(system_server, batteryproperties_service) 632 633allow system_server keystore:keystore_key { 634 get_state 635 get 636 insert 637 delete 638 exist 639 list 640 reset 641 password 642 lock 643 unlock 644 is_empty 645 sign 646 verify 647 grant 648 duplicate 649 clear_uid 650 add_auth 651 user_changed 652}; 653 654# Allow system server to search and write to the persistent factory reset 655# protection partition. This block device does not get wiped in a factory reset. 656allow system_server block_device:dir search; 657allow system_server frp_block_device:blk_file rw_file_perms; 658 659# Clean up old cgroups 660allow system_server cgroup:dir { remove_name rmdir }; 661 662# /oem access 663r_dir_file(system_server, oemfs) 664 665# Allow resolving per-user storage symlinks 666allow system_server { mnt_user_file storage_file }:dir { getattr search }; 667allow system_server { mnt_user_file storage_file }:lnk_file { getattr read }; 668 669# Allow statfs() on storage devices, which happens fast enough that 670# we shouldn't be killed during unsafe removal 671allow system_server sdcard_type:dir { getattr search }; 672 673# Traverse into expanded storage 674allow system_server mnt_expand_file:dir r_dir_perms; 675 676# Allow system process to relabel the fingerprint directory after mkdir 677# and delete the directory and files when no longer needed 678allow system_server fingerprintd_data_file:dir { r_dir_perms remove_name rmdir relabelto write }; 679allow system_server fingerprintd_data_file:file { getattr unlink }; 680 681# Allow system process to read network MAC address 682allow system_server sysfs_mac_address:file r_file_perms; 683 684userdebug_or_eng(` 685 # Allow system server to create and write method traces in /data/misc/trace. 686 allow system_server method_trace_data_file:dir w_dir_perms; 687 allow system_server method_trace_data_file:file { create w_file_perms }; 688 689 # Allow system server to read dmesg 690 allow system_server kernel:system syslog_read; 691 692 # Allow writing and removing window traces in /data/misc/wmtrace. 693 allow system_server wm_trace_data_file:dir rw_dir_perms; 694 allow system_server wm_trace_data_file:file { getattr setattr create unlink w_file_perms }; 695') 696 697# For AppFuse. 698allow system_server vold:fd use; 699allow system_server fuse_device:chr_file { read write ioctl getattr }; 700allow system_server app_fuse_file:dir rw_dir_perms; 701allow system_server app_fuse_file:file { read write open getattr append }; 702 703# For configuring sdcardfs 704allow system_server configfs:dir { create_dir_perms }; 705allow system_server configfs:file { getattr open create unlink write }; 706 707# Connect to adbd and use a socket transferred from it. 708# Used for e.g. jdwp. 709allow system_server adbd:unix_stream_socket connectto; 710allow system_server adbd:fd use; 711allow system_server adbd:unix_stream_socket { getattr getopt ioctl read write shutdown }; 712 713# Allow invoking tools like "timeout" 714allow system_server toolbox_exec:file rx_file_perms; 715 716# Postinstall 717# 718# For OTA dexopt, allow calls coming from postinstall. 719binder_call(system_server, postinstall) 720 721allow system_server postinstall:fifo_file write; 722allow system_server update_engine:fd use; 723allow system_server update_engine:fifo_file write; 724 725# Access to /data/preloads 726allow system_server preloads_data_file:file { r_file_perms unlink }; 727allow system_server preloads_data_file:dir { r_dir_perms write remove_name rmdir }; 728allow system_server preloads_media_file:file { r_file_perms unlink }; 729allow system_server preloads_media_file:dir { r_dir_perms write remove_name rmdir }; 730 731r_dir_file(system_server, cgroup) 732allow system_server ion_device:chr_file r_file_perms; 733 734r_dir_file(system_server, proc_asound) 735r_dir_file(system_server, proc_net) 736r_dir_file(system_server, proc_qtaguid_stat) 737allow system_server { 738 proc_loadavg 739 proc_meminfo 740 proc_pagetypeinfo 741 proc_pipe_conf 742 proc_stat 743 proc_uid_cputime_showstat 744 proc_uid_time_in_state 745 proc_uid_concurrent_active_time 746 proc_uid_concurrent_policy_time 747 proc_version 748 proc_vmallocinfo 749}:file r_file_perms; 750 751allow system_server proc_uid_time_in_state:dir r_dir_perms; 752allow system_server proc_uid_cpupower:file r_file_perms; 753 754r_dir_file(system_server, rootfs) 755 756# Allow WifiService to start, stop, and read wifi-specific trace events. 757allow system_server debugfs_tracing_instances:dir search; 758allow system_server debugfs_wifi_tracing:dir search; 759allow system_server debugfs_wifi_tracing:file rw_file_perms; 760 761# allow system_server to exec shell, asanwrapper & zygote(app_process) on ASAN builds. Needed to run 762# asanwrapper. 763with_asan(` 764 allow system_server shell_exec:file rx_file_perms; 765 allow system_server asanwrapper_exec:file rx_file_perms; 766 allow system_server zygote_exec:file rx_file_perms; 767') 768 769# allow system_server to read the eBPF maps that stores the traffic stats information amd clean up 770# the map after snapshot is recorded 771allow system_server fs_bpf:dir search; 772allow system_server fs_bpf:file read; 773allow system_server netd:bpf map_read; 774 775# ART Profiles. 776# Allow system_server to open profile snapshots for read. 777# System server never reads the actual content. It passes the descriptor to 778# to privileged apps which acquire the permissions to inspect the profiles. 779allow system_server user_profile_data_file:dir { getattr search }; 780allow system_server user_profile_data_file:file { getattr open read }; 781 782# System server may dump profile data for debuggable apps in the /data/misc/profman. 783# As such it needs to be able create files but it should never read from them. 784allow system_server profman_dump_data_file:file { create getattr setattr w_file_perms}; 785allow system_server profman_dump_data_file:dir w_dir_perms; 786 787# On userdebug build we may profile system server. Allow it to write and create its own profile. 788userdebug_or_eng(` 789 allow system_server user_profile_data_file:file create_file_perms; 790') 791 792userdebug_or_eng(` 793 # Allow system server to notify mediaextractor of the plugin update. 794 allow system_server mediaextractor_update_service:service_manager find; 795') 796 797# UsbDeviceManager uses /dev/usb-ffs 798allow system_server functionfs:dir search; 799allow system_server functionfs:file rw_file_perms; 800 801### 802### Neverallow rules 803### 804### system_server should NEVER do any of this 805 806# Do not allow opening files from external storage as unsafe ejection 807# could cause the kernel to kill the system_server. 808neverallow system_server sdcard_type:dir { open read write }; 809neverallow system_server sdcard_type:file rw_file_perms; 810 811# system server should never be operating on zygote spawned app data 812# files directly. Rather, they should always be passed via a 813# file descriptor. 814# Types extracted from seapp_contexts type= fields, excluding 815# those types that system_server needs to open directly. 816neverallow system_server { bluetooth_data_file nfc_data_file shell_data_file app_data_file }:file { open create unlink link }; 817 818# Forking and execing is inherently dangerous and racy. See, for 819# example, https://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them 820# Prevent the addition of new file execs to stop the problem from 821# getting worse. b/28035297 822neverallow system_server { 823 file_type 824 -toolbox_exec 825 -logcat_exec 826 with_asan(`-shell_exec -asanwrapper_exec -zygote_exec') 827}:file execute_no_trans; 828 829# Ensure that system_server doesn't perform any domain transitions other than 830# transitioning to the crash_dump domain when a crash occurs. 831neverallow system_server { domain -crash_dump }:process transition; 832neverallow system_server *:process dyntransition; 833 834# Only allow crash_dump to connect to system_ndebug_socket. 835neverallow { domain -init -system_server -crash_dump } system_ndebug_socket:sock_file { open write }; 836 837# system_server should never be executing dex2oat. This is either 838# a bug (for example, bug 16317188), or represents an attempt by 839# system server to dynamically load a dex file, something we do not 840# want to allow. 841neverallow system_server dex2oat_exec:file no_x_file_perms; 842 843# system_server should never execute or load executable shared libraries 844# in /data 845neverallow system_server data_file_type:file no_x_file_perms; 846 847# The only block device system_server should be accessing is 848# the frp_block_device. This helps avoid a system_server to root 849# escalation by writing to raw block devices. 850neverallow system_server { dev_type -frp_block_device }:blk_file no_rw_file_perms; 851 852# system_server should never use JIT functionality 853neverallow system_server self:process execmem; 854neverallow system_server ashmem_device:chr_file execute; 855 856# TODO: deal with tmpfs_domain pub/priv split properly 857neverallow system_server system_server_tmpfs:file execute; 858 859# dexoptanalyzer is currently used only for secondary dex files which 860# system_server should never access. 861neverallow system_server dexoptanalyzer_exec:file no_x_file_perms; 862 863# No ptracing others 864neverallow system_server { domain -system_server }:process ptrace; 865 866# CAP_SYS_RESOURCE was traditionally needed for sensitive /proc/PID 867# file read access. However, that is now unnecessary (b/34951864) 868neverallow system_server system_server:global_capability_class_set sys_resource; 869