1*e4a36f41SAndroid Build Coastguard Worker# Domain for shell processes spawned by ADB or console service. 2*e4a36f41SAndroid Build Coastguard Workertype shell, domain, mlstrustedsubject; 3*e4a36f41SAndroid Build Coastguard Workertype shell_exec, system_file_type, exec_type, file_type; 4*e4a36f41SAndroid Build Coastguard Worker 5*e4a36f41SAndroid Build Coastguard Worker# Create and use network sockets. 6*e4a36f41SAndroid Build Coastguard Workernet_domain(shell) 7*e4a36f41SAndroid Build Coastguard Worker 8*e4a36f41SAndroid Build Coastguard Worker# logcat 9*e4a36f41SAndroid Build Coastguard Workerread_logd(shell) 10*e4a36f41SAndroid Build Coastguard Workercontrol_logd(shell) 11*e4a36f41SAndroid Build Coastguard Worker# logcat -L (directly, or via dumpstate) 12*e4a36f41SAndroid Build Coastguard Workerallow shell pstorefs:dir search; 13*e4a36f41SAndroid Build Coastguard Workerallow shell pstorefs:file r_file_perms; 14*e4a36f41SAndroid Build Coastguard Worker 15*e4a36f41SAndroid Build Coastguard Worker# Root fs. 16*e4a36f41SAndroid Build Coastguard Workerallow shell rootfs:dir r_dir_perms; 17*e4a36f41SAndroid Build Coastguard Worker 18*e4a36f41SAndroid Build Coastguard Worker# read files in /data/anr 19*e4a36f41SAndroid Build Coastguard Workerallow shell anr_data_file:dir r_dir_perms; 20*e4a36f41SAndroid Build Coastguard Workerallow shell anr_data_file:file r_file_perms; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Access /data/local/tmp. 23*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:dir create_dir_perms; 24*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:file create_file_perms; 25*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:file rx_file_perms; 26*e4a36f41SAndroid Build Coastguard Workerallow shell shell_data_file:lnk_file create_file_perms; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# Read and delete from /data/local/traces. 29*e4a36f41SAndroid Build Coastguard Workerallow shell trace_data_file:file { r_file_perms unlink }; 30*e4a36f41SAndroid Build Coastguard Workerallow shell trace_data_file:dir { r_dir_perms remove_name write }; 31*e4a36f41SAndroid Build Coastguard Worker 32*e4a36f41SAndroid Build Coastguard Worker# Access /data/misc/profman. 33*e4a36f41SAndroid Build Coastguard Workerallow shell profman_dump_data_file:dir { write remove_name r_dir_perms }; 34*e4a36f41SAndroid Build Coastguard Workerallow shell profman_dump_data_file:file { unlink r_file_perms }; 35*e4a36f41SAndroid Build Coastguard Worker 36*e4a36f41SAndroid Build Coastguard Worker# Read/execute files in /data/nativetest 37*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 38*e4a36f41SAndroid Build Coastguard Worker allow shell nativetest_data_file:dir r_dir_perms; 39*e4a36f41SAndroid Build Coastguard Worker allow shell nativetest_data_file:file rx_file_perms; 40*e4a36f41SAndroid Build Coastguard Worker') 41*e4a36f41SAndroid Build Coastguard Worker 42*e4a36f41SAndroid Build Coastguard Worker# adb bugreport 43*e4a36f41SAndroid Build Coastguard Workerunix_socket_connect(shell, dumpstate, dumpstate) 44*e4a36f41SAndroid Build Coastguard Worker 45*e4a36f41SAndroid Build Coastguard Workerallow shell devpts:chr_file rw_file_perms; 46*e4a36f41SAndroid Build Coastguard Workerallow shell tty_device:chr_file rw_file_perms; 47*e4a36f41SAndroid Build Coastguard Workerallow shell console_device:chr_file rw_file_perms; 48*e4a36f41SAndroid Build Coastguard Worker 49*e4a36f41SAndroid Build Coastguard Workerallow shell input_device:dir r_dir_perms; 50*e4a36f41SAndroid Build Coastguard Workerallow shell input_device:chr_file r_file_perms; 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, system_file) 53*e4a36f41SAndroid Build Coastguard Workerallow shell system_file:file x_file_perms; 54*e4a36f41SAndroid Build Coastguard Workerallow shell toolbox_exec:file rx_file_perms; 55*e4a36f41SAndroid Build Coastguard Workerallow shell tzdatacheck_exec:file rx_file_perms; 56*e4a36f41SAndroid Build Coastguard Workerallow shell shell_exec:file rx_file_perms; 57*e4a36f41SAndroid Build Coastguard Workerallow shell zygote_exec:file rx_file_perms; 58*e4a36f41SAndroid Build Coastguard Worker 59*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, apk_data_file) 60*e4a36f41SAndroid Build Coastguard Worker 61*e4a36f41SAndroid Build Coastguard Worker# Set properties. 62*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, shell_prop) 63*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, ctl_bugreport_prop) 64*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, ctl_dumpstate_prop) 65*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, dumpstate_prop) 66*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, exported_dumpstate_prop) 67*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, debug_prop) 68*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, powerctl_prop) 69*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, log_tag_prop) 70*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, wifi_log_prop) 71*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start/stop traced via the persist.traced.enable 72*e4a36f41SAndroid Build Coastguard Worker# property (which also takes care of /data/misc initialization). 73*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, traced_enabled_prop) 74*e4a36f41SAndroid Build Coastguard Worker# adjust is_loggable properties 75*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`set_prop(shell, log_prop)') 76*e4a36f41SAndroid Build Coastguard Worker# logpersist script 77*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`set_prop(shell, logpersistd_logging_prop)') 78*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start/stop heapprofd via the persist.heapprofd.enable 79*e4a36f41SAndroid Build Coastguard Worker# property. 80*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, heapprofd_enabled_prop) 81*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start/stop traced_perf via the persist.traced_perf.enable 82*e4a36f41SAndroid Build Coastguard Worker# property. 83*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, traced_perf_enabled_prop) 84*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start/stop gsid via ctl.start|stop|restart gsid. 85*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, ctl_gsid_prop) 86*e4a36f41SAndroid Build Coastguard Worker# Allow shell to enable Dynamic System Update 87*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, dynamic_system_prop) 88*e4a36f41SAndroid Build Coastguard Worker# Allow shell to mock an OTA using persist.pm.mock-upgrade 89*e4a36f41SAndroid Build Coastguard Workerset_prop(shell, mock_ota_prop) 90*e4a36f41SAndroid Build Coastguard Worker 91*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 92*e4a36f41SAndroid Build Coastguard Worker # "systrace --boot" support - allow boottrace service to run 93*e4a36f41SAndroid Build Coastguard Worker allow shell boottrace_data_file:dir rw_dir_perms; 94*e4a36f41SAndroid Build Coastguard Worker allow shell boottrace_data_file:file create_file_perms; 95*e4a36f41SAndroid Build Coastguard Worker set_prop(shell, persist_debug_prop) 96*e4a36f41SAndroid Build Coastguard Worker') 97*e4a36f41SAndroid Build Coastguard Worker 98*e4a36f41SAndroid Build Coastguard Worker# Read device's serial number from system properties 99*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, serialno_prop) 100*e4a36f41SAndroid Build Coastguard Worker 101*e4a36f41SAndroid Build Coastguard Worker# Allow shell to read the vendor security patch level for CTS 102*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, vendor_security_patch_level_prop) 103*e4a36f41SAndroid Build Coastguard Worker 104*e4a36f41SAndroid Build Coastguard Worker# Read state of logging-related properties 105*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, device_logging_prop) 106*e4a36f41SAndroid Build Coastguard Worker 107*e4a36f41SAndroid Build Coastguard Worker# Read state of boot reason properties 108*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, bootloader_boot_reason_prop) 109*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, last_boot_reason_prop) 110*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, system_boot_reason_prop) 111*e4a36f41SAndroid Build Coastguard Worker 112*e4a36f41SAndroid Build Coastguard Worker# Allow reading the outcome of perf_event_open LSM support test for CTS. 113*e4a36f41SAndroid Build Coastguard Workerget_prop(shell, init_perf_lsm_hooks_prop) 114*e4a36f41SAndroid Build Coastguard Worker 115*e4a36f41SAndroid Build Coastguard Worker# allow shell access to services 116*e4a36f41SAndroid Build Coastguard Workerallow shell servicemanager:service_manager list; 117*e4a36f41SAndroid Build Coastguard Worker# don't allow shell to access GateKeeper service 118*e4a36f41SAndroid Build Coastguard Worker# TODO: why is this so broad? Tightening candidate? It needs at list: 119*e4a36f41SAndroid Build Coastguard Worker# - dumpstate_service (so it can receive dumpstate progress updates) 120*e4a36f41SAndroid Build Coastguard Workerallow shell { 121*e4a36f41SAndroid Build Coastguard Worker service_manager_type 122*e4a36f41SAndroid Build Coastguard Worker -apex_service 123*e4a36f41SAndroid Build Coastguard Worker -dnsresolver_service 124*e4a36f41SAndroid Build Coastguard Worker -gatekeeper_service 125*e4a36f41SAndroid Build Coastguard Worker -incident_service 126*e4a36f41SAndroid Build Coastguard Worker -installd_service 127*e4a36f41SAndroid Build Coastguard Worker -iorapd_service 128*e4a36f41SAndroid Build Coastguard Worker -netd_service 129*e4a36f41SAndroid Build Coastguard Worker -system_suspend_control_service 130*e4a36f41SAndroid Build Coastguard Worker -virtual_touchpad_service 131*e4a36f41SAndroid Build Coastguard Worker -vold_service 132*e4a36f41SAndroid Build Coastguard Worker -vr_hwc_service 133*e4a36f41SAndroid Build Coastguard Worker -default_android_service 134*e4a36f41SAndroid Build Coastguard Worker}:service_manager find; 135*e4a36f41SAndroid Build Coastguard Workerallow shell dumpstate:binder call; 136*e4a36f41SAndroid Build Coastguard Worker 137*e4a36f41SAndroid Build Coastguard Worker# allow shell to get information from hwservicemanager 138*e4a36f41SAndroid Build Coastguard Worker# for instance, listing hardware services with lshal 139*e4a36f41SAndroid Build Coastguard Workerhwbinder_use(shell) 140*e4a36f41SAndroid Build Coastguard Workerallow shell hwservicemanager:hwservice_manager list; 141*e4a36f41SAndroid Build Coastguard Worker 142*e4a36f41SAndroid Build Coastguard Worker# allow shell to look through /proc/ for lsmod, ps, top, netstat, vmstat. 143*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, proc_net_type) 144*e4a36f41SAndroid Build Coastguard Worker 145*e4a36f41SAndroid Build Coastguard Workerallow shell { 146*e4a36f41SAndroid Build Coastguard Worker proc_asound 147*e4a36f41SAndroid Build Coastguard Worker proc_filesystems 148*e4a36f41SAndroid Build Coastguard Worker proc_interrupts 149*e4a36f41SAndroid Build Coastguard Worker proc_loadavg # b/124024827 150*e4a36f41SAndroid Build Coastguard Worker proc_meminfo 151*e4a36f41SAndroid Build Coastguard Worker proc_modules 152*e4a36f41SAndroid Build Coastguard Worker proc_pid_max 153*e4a36f41SAndroid Build Coastguard Worker proc_slabinfo 154*e4a36f41SAndroid Build Coastguard Worker proc_stat 155*e4a36f41SAndroid Build Coastguard Worker proc_timer 156*e4a36f41SAndroid Build Coastguard Worker proc_uptime 157*e4a36f41SAndroid Build Coastguard Worker proc_version 158*e4a36f41SAndroid Build Coastguard Worker proc_vmstat 159*e4a36f41SAndroid Build Coastguard Worker proc_zoneinfo 160*e4a36f41SAndroid Build Coastguard Worker}:file r_file_perms; 161*e4a36f41SAndroid Build Coastguard Worker 162*e4a36f41SAndroid Build Coastguard Worker# allow listing network interfaces under /sys/class/net. 163*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_net:dir r_dir_perms; 164*e4a36f41SAndroid Build Coastguard Worker 165*e4a36f41SAndroid Build Coastguard Workerr_dir_file(shell, cgroup) 166*e4a36f41SAndroid Build Coastguard Workerallow shell domain:dir { search open read getattr }; 167*e4a36f41SAndroid Build Coastguard Workerallow shell domain:{ file lnk_file } { open read getattr }; 168*e4a36f41SAndroid Build Coastguard Worker 169*e4a36f41SAndroid Build Coastguard Worker# statvfs() of /proc and other labeled filesystems 170*e4a36f41SAndroid Build Coastguard Worker# (yaffs2, jffs2, ext2, ext3, ext4, xfs, btrfs, f2fs, squashfs, overlay) 171*e4a36f41SAndroid Build Coastguard Workerallow shell { proc labeledfs }:filesystem getattr; 172*e4a36f41SAndroid Build Coastguard Worker 173*e4a36f41SAndroid Build Coastguard Worker# stat() of /dev 174*e4a36f41SAndroid Build Coastguard Workerallow shell device:dir getattr; 175*e4a36f41SAndroid Build Coastguard Worker 176*e4a36f41SAndroid Build Coastguard Worker# allow shell to read /proc/pid/attr/current for ps -Z 177*e4a36f41SAndroid Build Coastguard Workerallow shell domain:process getattr; 178*e4a36f41SAndroid Build Coastguard Worker 179*e4a36f41SAndroid Build Coastguard Worker# Allow pulling the SELinux policy for CTS purposes 180*e4a36f41SAndroid Build Coastguard Workerallow shell selinuxfs:dir r_dir_perms; 181*e4a36f41SAndroid Build Coastguard Workerallow shell selinuxfs:file r_file_perms; 182*e4a36f41SAndroid Build Coastguard Worker 183*e4a36f41SAndroid Build Coastguard Worker# enable shell domain to read/write files/dirs for bootchart data 184*e4a36f41SAndroid Build Coastguard Worker# User will creates the start and stop file via adb shell 185*e4a36f41SAndroid Build Coastguard Worker# and read other files created by init process under /data/bootchart 186*e4a36f41SAndroid Build Coastguard Workerallow shell bootchart_data_file:dir rw_dir_perms; 187*e4a36f41SAndroid Build Coastguard Workerallow shell bootchart_data_file:file create_file_perms; 188*e4a36f41SAndroid Build Coastguard Worker 189*e4a36f41SAndroid Build Coastguard Worker# Make sure strace works for the non-privileged shell user 190*e4a36f41SAndroid Build Coastguard Workerallow shell self:process ptrace; 191*e4a36f41SAndroid Build Coastguard Worker 192*e4a36f41SAndroid Build Coastguard Worker# allow shell to get battery info 193*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs:dir r_dir_perms; 194*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_batteryinfo:dir r_dir_perms; 195*e4a36f41SAndroid Build Coastguard Workerallow shell sysfs_batteryinfo:file r_file_perms; 196*e4a36f41SAndroid Build Coastguard Worker 197*e4a36f41SAndroid Build Coastguard Worker# Allow access to ion memory allocation device. 198*e4a36f41SAndroid Build Coastguard Workerallow shell ion_device:chr_file rw_file_perms; 199*e4a36f41SAndroid Build Coastguard Worker 200*e4a36f41SAndroid Build Coastguard Worker# 201*e4a36f41SAndroid Build Coastguard Worker# filesystem test for insecure chr_file's is done 202*e4a36f41SAndroid Build Coastguard Worker# via a host side test 203*e4a36f41SAndroid Build Coastguard Worker# 204*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:dir r_dir_perms; 205*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:chr_file getattr; 206*e4a36f41SAndroid Build Coastguard Worker 207*e4a36f41SAndroid Build Coastguard Worker# /dev/fd is a symlink 208*e4a36f41SAndroid Build Coastguard Workerallow shell proc:lnk_file getattr; 209*e4a36f41SAndroid Build Coastguard Worker 210*e4a36f41SAndroid Build Coastguard Worker# 211*e4a36f41SAndroid Build Coastguard Worker# filesystem test for insucre blk_file's is done 212*e4a36f41SAndroid Build Coastguard Worker# via hostside test 213*e4a36f41SAndroid Build Coastguard Worker# 214*e4a36f41SAndroid Build Coastguard Workerallow shell dev_type:blk_file getattr; 215*e4a36f41SAndroid Build Coastguard Worker 216*e4a36f41SAndroid Build Coastguard Worker# read selinux policy files 217*e4a36f41SAndroid Build Coastguard Workerallow shell file_contexts_file:file r_file_perms; 218*e4a36f41SAndroid Build Coastguard Workerallow shell property_contexts_file:file r_file_perms; 219*e4a36f41SAndroid Build Coastguard Workerallow shell seapp_contexts_file:file r_file_perms; 220*e4a36f41SAndroid Build Coastguard Workerallow shell service_contexts_file:file r_file_perms; 221*e4a36f41SAndroid Build Coastguard Workerallow shell sepolicy_file:file r_file_perms; 222*e4a36f41SAndroid Build Coastguard Worker 223*e4a36f41SAndroid Build Coastguard Worker# Allow shell to start up vendor shell 224*e4a36f41SAndroid Build Coastguard Workerallow shell vendor_shell_exec:file rx_file_perms; 225*e4a36f41SAndroid Build Coastguard Worker 226*e4a36f41SAndroid Build Coastguard Worker# Everything is labeled as rootfs in recovery mode. Allow shell to 227*e4a36f41SAndroid Build Coastguard Worker# execute them. 228*e4a36f41SAndroid Build Coastguard Workerrecovery_only(` 229*e4a36f41SAndroid Build Coastguard Worker allow shell rootfs:file rx_file_perms; 230*e4a36f41SAndroid Build Coastguard Worker') 231*e4a36f41SAndroid Build Coastguard Worker 232*e4a36f41SAndroid Build Coastguard Worker### 233*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 234*e4a36f41SAndroid Build Coastguard Worker### 235*e4a36f41SAndroid Build Coastguard Worker 236*e4a36f41SAndroid Build Coastguard Worker# Do not allow shell to hard link to any files. 237*e4a36f41SAndroid Build Coastguard Worker# In particular, if shell hard links to app data 238*e4a36f41SAndroid Build Coastguard Worker# files, installd will not be able to guarantee the deletion 239*e4a36f41SAndroid Build Coastguard Worker# of the linked to file. Hard links also contribute to security 240*e4a36f41SAndroid Build Coastguard Worker# bugs, so we want to ensure the shell user never has this 241*e4a36f41SAndroid Build Coastguard Worker# capability. 242*e4a36f41SAndroid Build Coastguard Workerneverallow shell file_type:file link; 243*e4a36f41SAndroid Build Coastguard Worker 244*e4a36f41SAndroid Build Coastguard Worker# Do not allow privileged socket ioctl commands 245*e4a36f41SAndroid Build Coastguard Workerneverallowxperm shell domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls; 246*e4a36f41SAndroid Build Coastguard Worker 247*e4a36f41SAndroid Build Coastguard Worker# limit shell access to sensitive char drivers to 248*e4a36f41SAndroid Build Coastguard Worker# only getattr required for host side test. 249*e4a36f41SAndroid Build Coastguard Workerneverallow shell { 250*e4a36f41SAndroid Build Coastguard Worker fuse_device 251*e4a36f41SAndroid Build Coastguard Worker hw_random_device 252*e4a36f41SAndroid Build Coastguard Worker port_device 253*e4a36f41SAndroid Build Coastguard Worker}:chr_file ~getattr; 254*e4a36f41SAndroid Build Coastguard Worker 255*e4a36f41SAndroid Build Coastguard Worker# Limit shell to only getattr on blk devices for host side tests. 256*e4a36f41SAndroid Build Coastguard Workerneverallow shell dev_type:blk_file ~getattr; 257*e4a36f41SAndroid Build Coastguard Worker 258*e4a36f41SAndroid Build Coastguard Worker# b/30861057: Shell access to existing input devices is an abuse 259*e4a36f41SAndroid Build Coastguard Worker# vector. The shell user can inject events that look like they 260*e4a36f41SAndroid Build Coastguard Worker# originate from the touchscreen etc. 261*e4a36f41SAndroid Build Coastguard Worker# Everyone should have already moved to UiAutomation#injectInputEvent 262*e4a36f41SAndroid Build Coastguard Worker# if they are running instrumentation tests (i.e. CTS), Monkey for 263*e4a36f41SAndroid Build Coastguard Worker# their stress tests, and the input command (adb shell input ...) for 264*e4a36f41SAndroid Build Coastguard Worker# injecting swipes and things. 265*e4a36f41SAndroid Build Coastguard Workerneverallow shell input_device:chr_file no_w_file_perms; 266