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# Create and use network sockets. 48*e4a36f41SAndroid Build Coastguard Workernet_domain(adbd) 49*e4a36f41SAndroid Build Coastguard Worker 50*e4a36f41SAndroid Build Coastguard Worker# Access /dev/usb-ffs/adb/ep0 51*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:dir search; 52*e4a36f41SAndroid Build Coastguard Workerallow adbd functionfs:file rw_file_perms; 53*e4a36f41SAndroid Build Coastguard Workerallowxperm adbd functionfs:file ioctl { 54*e4a36f41SAndroid Build Coastguard Worker FUNCTIONFS_ENDPOINT_DESC 55*e4a36f41SAndroid Build Coastguard Worker FUNCTIONFS_CLEAR_HALT 56*e4a36f41SAndroid Build Coastguard Worker}; 57*e4a36f41SAndroid Build Coastguard Worker 58*e4a36f41SAndroid Build Coastguard Worker# Use a pseudo tty. 59*e4a36f41SAndroid Build Coastguard Workerallow adbd devpts:chr_file rw_file_perms; 60*e4a36f41SAndroid Build Coastguard Worker 61*e4a36f41SAndroid Build Coastguard Worker# adb push/pull /data/local/tmp. 62*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:dir create_dir_perms; 63*e4a36f41SAndroid Build Coastguard Workerallow adbd shell_data_file:file create_file_perms; 64*e4a36f41SAndroid Build Coastguard Worker 65*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/local/traces/* 66*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:dir r_dir_perms; 67*e4a36f41SAndroid Build Coastguard Workerallow adbd trace_data_file:file r_file_perms; 68*e4a36f41SAndroid Build Coastguard Worker 69*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/misc/profman. 70*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:dir r_dir_perms; 71*e4a36f41SAndroid Build Coastguard Workerallow adbd profman_dump_data_file:file r_file_perms; 72*e4a36f41SAndroid Build Coastguard Worker 73*e4a36f41SAndroid Build Coastguard Worker# adb push/pull sdcard. 74*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:dir search; 75*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:lnk_file r_file_perms; # /sdcard symlink 76*e4a36f41SAndroid Build Coastguard Workerallow adbd tmpfs:lnk_file r_file_perms; # /mnt/sdcard symlink 77*e4a36f41SAndroid Build Coastguard Workerallow adbd sdcard_type:dir create_dir_perms; 78*e4a36f41SAndroid Build Coastguard Workerallow adbd sdcard_type:file create_file_perms; 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker# adb pull /data/anr/traces.txt 81*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:dir r_dir_perms; 82*e4a36f41SAndroid Build Coastguard Workerallow adbd anr_data_file:file r_file_perms; 83*e4a36f41SAndroid Build Coastguard Worker 84*e4a36f41SAndroid Build Coastguard Worker# Set service.adb.*, sys.powerctl, and sys.usb.ffs.ready properties. 85*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, shell_prop) 86*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, powerctl_prop) 87*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, ffs_prop) 88*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, exported_ffs_prop) 89*e4a36f41SAndroid Build Coastguard Worker 90*e4a36f41SAndroid Build Coastguard Worker# Set service.adb.tls.port, persist.adb.wifi. properties 91*e4a36f41SAndroid Build Coastguard Workerset_prop(adbd, adbd_prop) 92*e4a36f41SAndroid Build Coastguard Worker 93*e4a36f41SAndroid Build Coastguard Worker# Access device logging gating property 94*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, device_logging_prop) 95*e4a36f41SAndroid Build Coastguard Worker 96*e4a36f41SAndroid Build Coastguard Worker# Read device's serial number from system properties 97*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, serialno_prop) 98*e4a36f41SAndroid Build Coastguard Worker 99*e4a36f41SAndroid Build Coastguard Worker# Read whether or not Test Harness Mode is enabled 100*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, test_harness_prop) 101*e4a36f41SAndroid Build Coastguard Worker 102*e4a36f41SAndroid Build Coastguard Worker# Read persist.adb.tls_server.enable property 103*e4a36f41SAndroid Build Coastguard Workerget_prop(adbd, system_adbd_prop) 104*e4a36f41SAndroid Build Coastguard Worker 105*e4a36f41SAndroid Build Coastguard Worker# Read device's overlayfs related properties and files 106*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 107*e4a36f41SAndroid Build Coastguard Worker get_prop(adbd, persistent_properties_ready_prop) 108*e4a36f41SAndroid Build Coastguard Worker r_dir_file(adbd, sysfs_dt_firmware_android) 109*e4a36f41SAndroid Build Coastguard Worker') 110*e4a36f41SAndroid Build Coastguard Worker 111*e4a36f41SAndroid Build Coastguard Worker# Run /system/bin/bu 112*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file rx_file_perms; 113*e4a36f41SAndroid Build Coastguard Worker 114*e4a36f41SAndroid Build Coastguard Worker# Perform binder IPC to surfaceflinger (screencap) 115*e4a36f41SAndroid Build Coastguard Worker# XXX Run screencap in a separate domain? 116*e4a36f41SAndroid Build Coastguard Workerbinder_use(adbd) 117*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, surfaceflinger) 118*e4a36f41SAndroid Build Coastguard Workerbinder_call(adbd, gpuservice) 119*e4a36f41SAndroid Build Coastguard Worker# b/13188914 120*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_device:chr_file rw_file_perms; 121*e4a36f41SAndroid Build Coastguard Workerallow adbd ion_device:chr_file rw_file_perms; 122*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, system_file) 123*e4a36f41SAndroid Build Coastguard Worker 124*e4a36f41SAndroid Build Coastguard Worker# Needed for various screenshots 125*e4a36f41SAndroid Build Coastguard Workerhal_client_domain(adbd, hal_graphics_allocator) 126*e4a36f41SAndroid Build Coastguard Worker 127*e4a36f41SAndroid Build Coastguard Worker# Read /data/misc/adb/adb_keys. 128*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:dir search; 129*e4a36f41SAndroid Build Coastguard Workerallow adbd adb_keys_file:file r_file_perms; 130*e4a36f41SAndroid Build Coastguard Worker 131*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 132*e4a36f41SAndroid Build Coastguard Worker # Write debugging information to /data/adb 133*e4a36f41SAndroid Build Coastguard Worker # when persist.adb.trace_mask is set 134*e4a36f41SAndroid Build Coastguard Worker # https://code.google.com/p/android/issues/detail?id=72895 135*e4a36f41SAndroid Build Coastguard Worker allow adbd adb_data_file:dir rw_dir_perms; 136*e4a36f41SAndroid Build Coastguard Worker allow adbd adb_data_file:file create_file_perms; 137*e4a36f41SAndroid Build Coastguard Worker') 138*e4a36f41SAndroid Build Coastguard Worker 139*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb forward to forward the gdbserver socket. 140*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:dir search; 141*e4a36f41SAndroid Build Coastguard Workerallow adbd app_data_file:sock_file write; 142*e4a36f41SAndroid Build Coastguard Workerallow adbd appdomain:unix_stream_socket connectto; 143*e4a36f41SAndroid Build Coastguard Worker 144*e4a36f41SAndroid Build Coastguard Worker# ndk-gdb invokes adb pull of app_process, linker, and libc.so. 145*e4a36f41SAndroid Build Coastguard Workerallow adbd zygote_exec:file r_file_perms; 146*e4a36f41SAndroid Build Coastguard Workerallow adbd system_file:file r_file_perms; 147*e4a36f41SAndroid Build Coastguard Worker 148*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes 149*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:dir r_dir_perms; 150*e4a36f41SAndroid Build Coastguard Workerallow adbd selinuxfs:file r_file_perms; 151*e4a36f41SAndroid Build Coastguard Workerallow adbd kernel:security read_policy; 152*e4a36f41SAndroid Build Coastguard Workerallow adbd service_contexts_file:file r_file_perms; 153*e4a36f41SAndroid Build Coastguard Workerallow adbd file_contexts_file:file r_file_perms; 154*e4a36f41SAndroid Build Coastguard Workerallow adbd seapp_contexts_file:file r_file_perms; 155*e4a36f41SAndroid Build Coastguard Workerallow adbd property_contexts_file:file r_file_perms; 156*e4a36f41SAndroid Build Coastguard Workerallow adbd sepolicy_file:file r_file_perms; 157*e4a36f41SAndroid Build Coastguard Worker 158*e4a36f41SAndroid Build Coastguard Worker# Allow pulling config.gz for CTS purposes 159*e4a36f41SAndroid Build Coastguard Workerallow adbd config_gz:file r_file_perms; 160*e4a36f41SAndroid Build Coastguard Worker 161*e4a36f41SAndroid Build Coastguard Worker# For CTS listening ports test. 162*e4a36f41SAndroid Build Coastguard Workerallow adbd proc_net_tcp_udp:file r_file_perms; 163*e4a36f41SAndroid Build Coastguard Worker 164*e4a36f41SAndroid Build Coastguard Workerallow adbd gpu_service:service_manager find; 165*e4a36f41SAndroid Build Coastguard Workerallow adbd surfaceflinger_service:service_manager find; 166*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:dir search; 167*e4a36f41SAndroid Build Coastguard Workerallow adbd bootchart_data_file:file r_file_perms; 168*e4a36f41SAndroid Build Coastguard Worker 169*e4a36f41SAndroid Build Coastguard Worker# Allow access to external storage; we have several visible mount points under /storage 170*e4a36f41SAndroid Build Coastguard Worker# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary 171*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:dir r_dir_perms; 172*e4a36f41SAndroid Build Coastguard Workerallow adbd storage_file:lnk_file r_file_perms; 173*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:dir r_dir_perms; 174*e4a36f41SAndroid Build Coastguard Workerallow adbd mnt_user_file:lnk_file r_file_perms; 175*e4a36f41SAndroid Build Coastguard Worker 176*e4a36f41SAndroid Build Coastguard Worker# Access to /data/media. 177*e4a36f41SAndroid Build Coastguard Worker# This should be removed if sdcardfs is modified to alter the secontext for its 178*e4a36f41SAndroid Build Coastguard Worker# accesses to the underlying FS. 179*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:dir create_dir_perms; 180*e4a36f41SAndroid Build Coastguard Workerallow adbd media_rw_data_file:file create_file_perms; 181*e4a36f41SAndroid Build Coastguard Worker 182*e4a36f41SAndroid Build Coastguard Workerr_dir_file(adbd, apk_data_file) 183*e4a36f41SAndroid Build Coastguard Worker 184*e4a36f41SAndroid Build Coastguard Workerallow adbd rootfs:dir r_dir_perms; 185*e4a36f41SAndroid Build Coastguard Worker 186*e4a36f41SAndroid Build Coastguard Worker# Allow killing child "perfetto" binary processes, which auto-transition to 187*e4a36f41SAndroid Build Coastguard Worker# their own domain. Allows propagating termination of "adb shell perfetto ..." 188*e4a36f41SAndroid Build Coastguard Worker# invocations. 189*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto:process signal; 190*e4a36f41SAndroid Build Coastguard Worker 191*e4a36f41SAndroid Build Coastguard Worker# Allow to pull Perfetto traces. 192*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:file r_file_perms; 193*e4a36f41SAndroid Build Coastguard Workerallow adbd perfetto_traces_data_file:dir r_dir_perms; 194*e4a36f41SAndroid Build Coastguard Worker 195*e4a36f41SAndroid Build Coastguard Worker# Connect to shell and use a socket transferred from it. 196*e4a36f41SAndroid Build Coastguard Worker# Used for e.g. abb. 197*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:unix_stream_socket { read write shutdown }; 198*e4a36f41SAndroid Build Coastguard Workerallow adbd shell:fd use; 199*e4a36f41SAndroid Build Coastguard Worker 200*e4a36f41SAndroid Build Coastguard Worker### 201*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 202*e4a36f41SAndroid Build Coastguard Worker### 203*e4a36f41SAndroid Build Coastguard Worker 204*e4a36f41SAndroid Build Coastguard Worker# No transitions from adbd to non-shell, non-crash_dump domains. adbd only ever 205*e4a36f41SAndroid Build Coastguard Worker# transitions to the shell domain (except when it crashes). In particular, we 206*e4a36f41SAndroid Build Coastguard Worker# never want to see a transition from adbd to su (aka "adb root") 207*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain -crash_dump -shell }:process transition; 208*e4a36f41SAndroid Build Coastguard Workerneverallow adbd { domain userdebug_or_eng(`-su') recovery_only(`-shell') }:process dyntransition; 209