1*e4a36f41SAndroid Build Coastguard Worker### ADB daemon 2*e4a36f41SAndroid Build Coastguard Worker 3*e4a36f41SAndroid Build Coastguard Workertypeattribute adbd coredomain; 4*e4a36f41SAndroid Build Coastguard Workertypeattribute adbd mlstrustedsubject; 5*e4a36f41SAndroid Build Coastguard Worker 6*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(adbd) 7*e4a36f41SAndroid Build Coastguard Worker 8*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(adbd, shell_exec, shell) 9*e4a36f41SAndroid Build Coastguard Worker 10*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 11*e4a36f41SAndroid Build Coastguard Worker allow adbd self:process setcurrent; 12*e4a36f41SAndroid Build Coastguard Worker allow adbd su:process dyntransition; 13*e4a36f41SAndroid Build Coastguard Worker') 14*e4a36f41SAndroid Build Coastguard Worker 15*e4a36f41SAndroid Build Coastguard Worker# When 'adb shell' is executed in recovery mode, adbd explicitly 16*e4a36f41SAndroid Build Coastguard Worker# switches into shell domain using setcon() because the shell executable 17*e4a36f41SAndroid Build Coastguard Worker# is not labeled as shell but as rootfs. 18*e4a36f41SAndroid Build Coastguard Workerrecovery_only(` 19*e4a36f41SAndroid Build Coastguard Worker domain_trans(adbd, rootfs, shell) 20*e4a36f41SAndroid Build Coastguard Worker allow adbd shell:process dyntransition; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker # Allows reboot fastboot to enter fastboot directly 23*e4a36f41SAndroid Build Coastguard Worker unix_socket_connect(adbd, recovery, recovery) 24*e4a36f41SAndroid Build Coastguard Worker') 25*e4a36f41SAndroid Build Coastguard Worker 26*e4a36f41SAndroid Build Coastguard Worker# Control Perfetto traced and obtain traces from it. 27*e4a36f41SAndroid Build Coastguard Worker# Needed to allow port forwarding directly to traced. 28*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(adbd, traced_consumer, traced) 29*e4a36f41SAndroid Build Coastguard Worker 30*e4a36f41SAndroid Build Coastguard Worker# Do not sanitize the environment or open fds of the shell. Allow signaling 31*e4a36f41SAndroid Build Coastguard Worker# created processes. 32*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:process { noatsecure signal }; 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Worker# Set UID and GID to shell. Set supplementary groups. 35*e4a36f41SAndroid Build Coastguard Workerallow adbd self:global_capability_class_set { setuid setgid }; 36*e4a36f41SAndroid Build Coastguard Worker 37*e4a36f41SAndroid Build Coastguard Worker# Drop capabilities from bounding set on user builds. 38*e4a36f41SAndroid Build Coastguard Workerallow adbd self:global_capability_class_set setpcap; 39*e4a36f41SAndroid Build Coastguard Worker 40*e4a36f41SAndroid Build Coastguard Worker# ignore spurious denials for adbd when disk space is low. 41*e4a36f41SAndroid Build Coastguard Workerdontaudit adbd self:global_capability_class_set sys_resource; 42*e4a36f41SAndroid Build Coastguard Worker 43*e4a36f41SAndroid Build Coastguard Worker# adbd probes for vsock support. Do not generate denials when 44*e4a36f41SAndroid Build Coastguard Worker# this occurs. (b/123569840) 45*e4a36f41SAndroid Build Coastguard Workerdontaudit adbd self:{ socket vsock_socket } create; 46*e4a36f41SAndroid Build Coastguard Worker 47*e4a36f41SAndroid Build Coastguard Worker# Allow adbd inside vm to forward vm's vsock. 48*e4a36f41SAndroid Build Coastguard Workerallow adbd self:vsock_socket { create_socket_perms_no_ioctl listen accept }; 49*e4a36f41SAndroid Build Coastguard Worker 50*e4a36f41SAndroid Build Coastguard Worker# Create and use network sockets. 51*e4a36f41SAndroid Build Coastguard Workernet_domain(adbd) 52*e4a36f41SAndroid Build Coastguard Worker 53*e4a36f41SAndroid Build Coastguard Worker# Access /dev/usb-ffs/adb/ep0 54*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:dir search; 55*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:file rw_file_perms; 56*e4a36f41SAndroid Build Coastguard Workerallowxperm adbd functionfs:file ioctl { 57*e4a36f41SAndroid Build Coastguard Worker FUNCTIONFS_ENDPOINT_DESC 58*e4a36f41SAndroid Build Coastguard Worker FUNCTIONFS_CLEAR_HALT 59*e4a36f41SAndroid Build Coastguard Worker}; 60*e4a36f41SAndroid Build Coastguard Worker 61*e4a36f41SAndroid Build Coastguard Worker# Use a pseudo tty. 62*e4a36f41SAndroid Build Coastguard Workerallow adbd devpts:chr_file rw_file_perms; 63*e4a36f41SAndroid Build Coastguard Worker 64*e4a36f41SAndroid Build Coastguard Worker# adb push/pull /data/local/tmp. 65*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:dir create_dir_perms; 66*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:file create_file_perms; 67*e4a36f41SAndroid Build Coastguard Worker 68*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/local/traces/* 69*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:dir r_dir_perms; 70*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:file r_file_perms; 71*e4a36f41SAndroid Build Coastguard Worker 72*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/misc/profman. 73*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:dir r_dir_perms; 74*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:file r_file_perms; 75*e4a36f41SAndroid Build Coastguard Worker 76*e4a36f41SAndroid Build Coastguard Worker# adb push/pull sdcard. 77*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:dir search; 78*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:lnk_file r_file_perms; # /sdcard symlink 79*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:lnk_file r_file_perms; # /mnt/sdcard symlink 80*e4a36f41SAndroid Build Coastguard Workerallow adbd sdcard_type:dir create_dir_perms; 81*e4a36f41SAndroid Build Coastguard Workerallow adbd sdcard_type:file create_file_perms; 82*e4a36f41SAndroid Build Coastguard Worker 83*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/anr/traces.txt 84*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:dir r_dir_perms; 85*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:file r_file_perms; 86*e4a36f41SAndroid Build Coastguard Worker 87*e4a36f41SAndroid Build Coastguard Worker# adb pull /vendor/framework/* 88*e4a36f41SAndroid Build Coastguard Workerallow adbd vendor_framework_file:dir r_dir_perms; 89*e4a36f41SAndroid Build Coastguard Workerallow adbd vendor_framework_file:file r_file_perms; 90*e4a36f41SAndroid Build Coastguard Worker 91*e4a36f41SAndroid Build Coastguard Worker# Set service.adb.*, sys.powerctl, and sys.usb.ffs.ready properties. 92*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, shell_prop) 93*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, powerctl_prop) 94*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, ffs_config_prop) 95*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, ffs_control_prop) 96*e4a36f41SAndroid Build Coastguard Worker 97*e4a36f41SAndroid Build Coastguard Worker# Set service.adb.tcp.port, service.adb.tls.port, persist.adb.wifi.* properties 98*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, adbd_prop) 99*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, adbd_config_prop) 100*e4a36f41SAndroid Build Coastguard Worker 101*e4a36f41SAndroid Build Coastguard Worker# Allow adbd start/stop mdnsd via ctl.start 102*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, ctl_mdnsd_prop) 103*e4a36f41SAndroid Build Coastguard Worker 104*e4a36f41SAndroid Build Coastguard Worker# Access device logging gating property 105*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, device_logging_prop) 106*e4a36f41SAndroid Build Coastguard Worker 107*e4a36f41SAndroid Build Coastguard Worker# Read device's serial number from system properties 108*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, serialno_prop) 109*e4a36f41SAndroid Build Coastguard Worker 110*e4a36f41SAndroid Build Coastguard Worker# Read whether or not Test Harness Mode is enabled 111*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, test_harness_prop) 112*e4a36f41SAndroid Build Coastguard Worker 113*e4a36f41SAndroid Build Coastguard Worker# Read persist.adb.tls_server.enable property 114*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, system_adbd_prop) 115*e4a36f41SAndroid Build Coastguard Worker 116*e4a36f41SAndroid Build Coastguard Worker# Read device's overlayfs related properties and files 117*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 118*e4a36f41SAndroid Build Coastguard Worker get_prop(adbd, persistent_properties_ready_prop) 119*e4a36f41SAndroid Build Coastguard Worker r_dir_file(adbd, sysfs_dt_firmware_android) 120*e4a36f41SAndroid Build Coastguard Worker') 121*e4a36f41SAndroid Build Coastguard Worker 122*e4a36f41SAndroid Build Coastguard Worker# Run /system/bin/bu 123*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file rx_file_perms; 124*e4a36f41SAndroid Build Coastguard Worker 125*e4a36f41SAndroid Build Coastguard Worker# Perform binder IPC to surfaceflinger (screencap) 126*e4a36f41SAndroid Build Coastguard Worker# XXX Run screencap in a separate domain? 127*e4a36f41SAndroid Build Coastguard Workerbinder_use(adbd) 128*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, surfaceflinger) 129*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, gpuservice) 130*e4a36f41SAndroid Build Coastguard Worker# b/13188914 131*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_device:chr_file rw_file_perms; 132*e4a36f41SAndroid Build Coastguard Workerallow adbd ion_device:chr_file rw_file_perms; 133*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, system_file) 134*e4a36f41SAndroid Build Coastguard Worker 135*e4a36f41SAndroid Build Coastguard Worker# Needed for various screenshots 136*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(adbd, hal_graphics_allocator) 137*e4a36f41SAndroid Build Coastguard Worker 138*e4a36f41SAndroid Build Coastguard Worker# Read /data/misc/adb/adb_keys. 139*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:dir search; 140*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:file r_file_perms; 141*e4a36f41SAndroid Build Coastguard Worker 142*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 143*e4a36f41SAndroid Build Coastguard Worker # Write debugging information to /data/adb 144*e4a36f41SAndroid Build Coastguard Worker # when persist.adb.trace_mask is set 145*e4a36f41SAndroid Build Coastguard Worker # https://code.google.com/p/android/issues/detail?id=72895 146*e4a36f41SAndroid Build Coastguard Worker allow adbd adb_data_file:dir rw_dir_perms; 147*e4a36f41SAndroid Build Coastguard Worker allow adbd adb_data_file:file create_file_perms; 148*e4a36f41SAndroid Build Coastguard Worker') 149*e4a36f41SAndroid Build Coastguard Worker 150*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb forward to forward the gdbserver socket. 151*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:dir search; 152*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:sock_file write; 153*e4a36f41SAndroid Build Coastguard Workerallow adbd appdomain:unix_stream_socket connectto; 154*e4a36f41SAndroid Build Coastguard Worker 155*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb pull of app_process, linker, and libc.so. 156*e4a36f41SAndroid Build Coastguard Workerallow adbd zygote_exec:file r_file_perms; 157*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file r_file_perms; 158*e4a36f41SAndroid Build Coastguard Worker 159*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes 160*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:dir r_dir_perms; 161*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:file r_file_perms; 162*e4a36f41SAndroid Build Coastguard Workerallow adbd kernel:security read_policy; 163*e4a36f41SAndroid Build Coastguard Workerallow adbd service_contexts_file:file r_file_perms; 164*e4a36f41SAndroid Build Coastguard Workerallow adbd file_contexts_file:file r_file_perms; 165*e4a36f41SAndroid Build Coastguard Workerallow adbd seapp_contexts_file:file r_file_perms; 166*e4a36f41SAndroid Build Coastguard Workerallow adbd property_contexts_file:file r_file_perms; 167*e4a36f41SAndroid Build Coastguard Workerallow adbd sepolicy_file:file r_file_perms; 168*e4a36f41SAndroid Build Coastguard Worker 169*e4a36f41SAndroid Build Coastguard Worker# Allow pulling config.gz for CTS purposes 170*e4a36f41SAndroid Build Coastguard Workerallow adbd config_gz:file r_file_perms; 171*e4a36f41SAndroid Build Coastguard Worker 172*e4a36f41SAndroid Build Coastguard Worker# For CTS listening ports test. 173*e4a36f41SAndroid Build Coastguard Workerallow adbd proc_net_tcp_udp:file r_file_perms; 174*e4a36f41SAndroid Build Coastguard Worker 175*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_service:service_manager find; 176*e4a36f41SAndroid Build Coastguard Workerallow adbd surfaceflinger_service:service_manager find; 177*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:dir search; 178*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:file r_file_perms; 179*e4a36f41SAndroid Build Coastguard Worker 180*e4a36f41SAndroid Build Coastguard Worker# Allow access to external storage; we have several visible mount points under /storage 181*e4a36f41SAndroid Build Coastguard Worker# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary 182*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:dir r_dir_perms; 183*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:lnk_file r_file_perms; 184*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:dir r_dir_perms; 185*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:lnk_file r_file_perms; 186*e4a36f41SAndroid Build Coastguard Worker 187*e4a36f41SAndroid Build Coastguard Worker# Access to /data/media. 188*e4a36f41SAndroid Build Coastguard Worker# This should be removed if sdcardfs is modified to alter the secontext for its 189*e4a36f41SAndroid Build Coastguard Worker# accesses to the underlying FS. 190*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:dir create_dir_perms; 191*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:file create_file_perms; 192*e4a36f41SAndroid Build Coastguard Worker 193*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, apk_data_file) 194*e4a36f41SAndroid Build Coastguard Worker 195*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:dir r_dir_perms; 196*e4a36f41SAndroid Build Coastguard Worker 197*e4a36f41SAndroid Build Coastguard Worker# Allow killing child "perfetto" binary processes, which auto-transition to 198*e4a36f41SAndroid Build Coastguard Worker# their own domain. Allows propagating termination of "adb shell perfetto ..." 199*e4a36f41SAndroid Build Coastguard Worker# invocations. 200*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto:process signal; 201*e4a36f41SAndroid Build Coastguard Worker 202*e4a36f41SAndroid Build Coastguard Worker# Allow to pull Perfetto traces. 203*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:file r_file_perms; 204*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:dir r_dir_perms; 205*e4a36f41SAndroid Build Coastguard Worker 206*e4a36f41SAndroid Build Coastguard Worker# Allow to push and manage configs in /data/misc/perfetto-configs. 207*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_configs_data_file:dir rw_dir_perms; 208*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_configs_data_file:file create_file_perms; 209*e4a36f41SAndroid Build Coastguard Worker 210*e4a36f41SAndroid Build Coastguard Worker# Connect to shell and use a socket transferred from it. 211*e4a36f41SAndroid Build Coastguard Worker# Used for e.g. abb. 212*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:unix_stream_socket { read write shutdown }; 213*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:fd use; 214*e4a36f41SAndroid Build Coastguard Worker 215*e4a36f41SAndroid Build Coastguard Worker# Allow pull /vendor/apex files for CTS tests 216*e4a36f41SAndroid Build Coastguard Workerallow adbd vendor_apex_file:dir search; 217*e4a36f41SAndroid Build Coastguard Workerallow adbd vendor_apex_file:file r_file_perms; 218*e4a36f41SAndroid Build Coastguard Worker 219*e4a36f41SAndroid Build Coastguard Worker# Allow adb pull of updated apex files in /data/apex/active. 220*e4a36f41SAndroid Build Coastguard Workerallow adbd apex_data_file:dir search; 221*e4a36f41SAndroid Build Coastguard Workerallow adbd staging_data_file:file r_file_perms; 222*e4a36f41SAndroid Build Coastguard Worker 223*e4a36f41SAndroid Build Coastguard Worker# Allow adbd to pull /apex/apex-info-list.xml for CTS tests. 224*e4a36f41SAndroid Build Coastguard Workerallow adbd apex_info_file:file r_file_perms; 225*e4a36f41SAndroid Build Coastguard Worker 226*e4a36f41SAndroid Build Coastguard Worker### 227*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 228*e4a36f41SAndroid Build Coastguard Worker### 229*e4a36f41SAndroid Build Coastguard Worker 230*e4a36f41SAndroid Build Coastguard Worker# No transitions from adbd to non-shell, non-crash_dump domains. adbd only ever 231*e4a36f41SAndroid Build Coastguard Worker# transitions to the shell domain (except when it crashes). In particular, we 232*e4a36f41SAndroid Build Coastguard Worker# never want to see a transition from adbd to su (aka "adb root") 233*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain -crash_dump -shell }:process transition; 234*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain userdebug_or_eng(`-su') recovery_only(`-shell') }:process dyntransition; 235