1*e4a36f41SAndroid Build Coastguard Worker### 2*e4a36f41SAndroid Build Coastguard Worker### neverallow rules for untrusted app domains 3*e4a36f41SAndroid Build Coastguard Worker### 4*e4a36f41SAndroid Build Coastguard Worker 5*e4a36f41SAndroid Build Coastguard Workerdefine(`all_untrusted_apps',`{ 6*e4a36f41SAndroid Build Coastguard Worker ephemeral_app 7*e4a36f41SAndroid Build Coastguard Worker isolated_app 8*e4a36f41SAndroid Build Coastguard Worker isolated_app_all 9*e4a36f41SAndroid Build Coastguard Worker isolated_compute_app 10*e4a36f41SAndroid Build Coastguard Worker mediaprovider 11*e4a36f41SAndroid Build Coastguard Worker mediaprovider_app 12*e4a36f41SAndroid Build Coastguard Worker untrusted_app 13*e4a36f41SAndroid Build Coastguard Worker untrusted_app_25 14*e4a36f41SAndroid Build Coastguard Worker untrusted_app_27 15*e4a36f41SAndroid Build Coastguard Worker untrusted_app_29 16*e4a36f41SAndroid Build Coastguard Worker untrusted_app_30 17*e4a36f41SAndroid Build Coastguard Worker untrusted_app_all 18*e4a36f41SAndroid Build Coastguard Worker}') 19*e4a36f41SAndroid Build Coastguard Worker# Receive or send uevent messages. 20*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker# Receive or send generic netlink messages 23*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps domain:netlink_socket *; 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Worker# Read or write kernel printk buffer 26*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps kmsg_device:chr_file no_rw_file_perms; 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Worker# Too much leaky information in debugfs. It's a security 29*e4a36f41SAndroid Build Coastguard Worker# best practice to ensure these files aren't readable. 30*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps { debugfs_type -debugfs_kcov }:file read; 31*e4a36f41SAndroid Build Coastguard Workerneverallow {all_untrusted_apps userdebug_or_eng(`-domain')} debugfs_type:{ file lnk_file } read; 32*e4a36f41SAndroid Build Coastguard Worker 33*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to register services. 34*e4a36f41SAndroid Build Coastguard Worker# Only trusted components of Android should be registering 35*e4a36f41SAndroid Build Coastguard Worker# services. 36*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps service_manager_type:service_manager add; 37*e4a36f41SAndroid Build Coastguard Worker 38*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to use VendorBinder 39*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps vndbinder_device:chr_file *; 40*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps vndservice_manager_type:service_manager *; 41*e4a36f41SAndroid Build Coastguard Worker 42*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to connect to the property service 43*e4a36f41SAndroid Build Coastguard Worker# or set properties. b/10243159 44*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write; 45*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto; 46*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider } property_type:property_service set; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to modify temporarily staged APKs. 49*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *; 50*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read map }; 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# net.dns properties are not a public API. Disallow untrusted apps from reading this property. 53*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps } net_dns_prop:file read; 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# radio_cdma_ecm_prop properties are not a public API. Disallow untrusted apps from reading this property. 56*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps } radio_cdma_ecm_prop:file read; 57*e4a36f41SAndroid Build Coastguard Worker 58*e4a36f41SAndroid Build Coastguard Worker# Shared libraries created by trusted components within an app home 59*e4a36f41SAndroid Build Coastguard Worker# directory can be dlopen()ed. To maintain the W^X property, these files 60*e4a36f41SAndroid Build Coastguard Worker# must never be writable to the app. 61*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps app_exec_data_file:file 62*e4a36f41SAndroid Build Coastguard Worker { append create link relabelfrom relabelto rename setattr write }; 63*e4a36f41SAndroid Build Coastguard Worker 64*e4a36f41SAndroid Build Coastguard Worker# Block calling execve() on files in an apps home directory. 65*e4a36f41SAndroid Build Coastguard Worker# This is a W^X violation (loading executable code from a writable 66*e4a36f41SAndroid Build Coastguard Worker# home directory). For compatibility, allow for targetApi <= 28. 67*e4a36f41SAndroid Build Coastguard Worker# b/112357170 68*e4a36f41SAndroid Build Coastguard Workerneverallow { 69*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 70*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_25 71*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_27 72*e4a36f41SAndroid Build Coastguard Worker -runas_app 73*e4a36f41SAndroid Build Coastguard Worker} { app_data_file privapp_data_file }:file execute_no_trans; 74*e4a36f41SAndroid Build Coastguard Worker 75*e4a36f41SAndroid Build Coastguard Workeris_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, ` 76*e4a36f41SAndroid Build Coastguard Worker # block apps from executing files in their storage areas 77*e4a36f41SAndroid Build Coastguard Worker # this is a stronger and more desirable guarantee than blocking execute_no_trans, but 78*e4a36f41SAndroid Build Coastguard Worker # execute cannot be blocked on all of app_data_file without causing 79*e4a36f41SAndroid Build Coastguard Worker # backwards compatibility issues (see b/237289679) 80*e4a36f41SAndroid Build Coastguard Worker neverallow appdomain storage_area_content_file:file execute; 81*e4a36f41SAndroid Build Coastguard Worker') 82*e4a36f41SAndroid Build Coastguard Worker 83*e4a36f41SAndroid Build Coastguard Workeris_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, ` 84*e4a36f41SAndroid Build Coastguard Worker # dont allow apps to modify their own directories of storage areas 85*e4a36f41SAndroid Build Coastguard Worker neverallow appdomain storage_area_app_dir:dir_file_class_set { 86*e4a36f41SAndroid Build Coastguard Worker create write setattr relabelfrom relabelto append unlink link rename 87*e4a36f41SAndroid Build Coastguard Worker }; 88*e4a36f41SAndroid Build Coastguard Worker') 89*e4a36f41SAndroid Build Coastguard Worker 90*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to invoke dex2oat. This was historically required 91*e4a36f41SAndroid Build Coastguard Worker# by ART for compiling secondary dex files but has been removed in Q. 92*e4a36f41SAndroid Build Coastguard Worker# Exempt legacy apps (targetApi<=28) for compatibility. 93*e4a36f41SAndroid Build Coastguard Workerneverallow { 94*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 95*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_25 96*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_27 97*e4a36f41SAndroid Build Coastguard Worker} dex2oat_exec:file no_x_file_perms; 98*e4a36f41SAndroid Build Coastguard Worker 99*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to be assigned mlstrustedsubject. 100*e4a36f41SAndroid Build Coastguard Worker# This would undermine the per-user isolation model being 101*e4a36f41SAndroid Build Coastguard Worker# enforced via levelFrom=user in seapp_contexts and the mls 102*e4a36f41SAndroid Build Coastguard Worker# constraints. As there is no direct way to specify a neverallow 103*e4a36f41SAndroid Build Coastguard Worker# on attribute assignment, this relies on the fact that fork 104*e4a36f41SAndroid Build Coastguard Worker# permission only makes sense within a domain (hence should 105*e4a36f41SAndroid Build Coastguard Worker# never be granted to any other domain within mlstrustedsubject) 106*e4a36f41SAndroid Build Coastguard Worker# and an untrusted app is allowed fork permission to itself. 107*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps mlstrustedsubject:process fork; 108*e4a36f41SAndroid Build Coastguard Worker 109*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to hard link to any files. 110*e4a36f41SAndroid Build Coastguard Worker# In particular, if an untrusted app links to other app data 111*e4a36f41SAndroid Build Coastguard Worker# files, installd will not be able to guarantee the deletion 112*e4a36f41SAndroid Build Coastguard Worker# of the linked to file. Hard links also contribute to security 113*e4a36f41SAndroid Build Coastguard Worker# bugs, so we want to ensure untrusted apps never have this 114*e4a36f41SAndroid Build Coastguard Worker# capability. 115*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps file_type:file link; 116*e4a36f41SAndroid Build Coastguard Worker 117*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to access network MAC address file 118*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps sysfs_net:file no_rw_file_perms; 119*e4a36f41SAndroid Build Coastguard Worker 120*e4a36f41SAndroid Build Coastguard Worker# Do not allow any write access to files in /sys 121*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms }; 122*e4a36f41SAndroid Build Coastguard Worker 123*e4a36f41SAndroid Build Coastguard Worker# Apps may never access the default sysfs label. 124*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps sysfs:file no_rw_file_perms; 125*e4a36f41SAndroid Build Coastguard Worker 126*e4a36f41SAndroid Build Coastguard Worker# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the 127*e4a36f41SAndroid Build Coastguard Worker# ioctl permission, or 3. disallow the socket class. 128*e4a36f41SAndroid Build Coastguard Workerneverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls; 129*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl; 130*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps *:{ 131*e4a36f41SAndroid Build Coastguard Worker socket netlink_socket packet_socket key_socket appletalk_socket 132*e4a36f41SAndroid Build Coastguard Worker netlink_tcpdiag_socket netlink_nflog_socket 133*e4a36f41SAndroid Build Coastguard Worker netlink_xfrm_socket netlink_audit_socket 134*e4a36f41SAndroid Build Coastguard Worker netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket 135*e4a36f41SAndroid Build Coastguard Worker netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket 136*e4a36f41SAndroid Build Coastguard Worker netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket 137*e4a36f41SAndroid Build Coastguard Worker netlink_rdma_socket netlink_crypto_socket sctp_socket 138*e4a36f41SAndroid Build Coastguard Worker ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket 139*e4a36f41SAndroid Build Coastguard Worker atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket 140*e4a36f41SAndroid Build Coastguard Worker bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket 141*e4a36f41SAndroid Build Coastguard Worker alg_socket nfc_socket kcm_socket qipcrtr_socket smc_socket xdp_socket 142*e4a36f41SAndroid Build Coastguard Worker} *; 143*e4a36f41SAndroid Build Coastguard Worker 144*e4a36f41SAndroid Build Coastguard Worker# Apps can read/write an already open vsock (e.g. created by 145*e4a36f41SAndroid Build Coastguard Worker# virtualizationservice) but nothing more than that (e.g. creating a 146*e4a36f41SAndroid Build Coastguard Worker# new vsock, etc.) 147*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps *:vsock_socket ~{ getattr getopt read write }; 148*e4a36f41SAndroid Build Coastguard Worker 149*e4a36f41SAndroid Build Coastguard Worker# Disallow sending RTM_GETLINK messages on netlink sockets. 150*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps domain:netlink_route_socket { bind nlmsg_readpriv }; 151*e4a36f41SAndroid Build Coastguard Workerneverallow priv_app domain:netlink_route_socket { bind nlmsg_readpriv }; 152*e4a36f41SAndroid Build Coastguard Worker 153*e4a36f41SAndroid Build Coastguard Worker# Disallow sending RTM_GETNEIGH{TBL} messages on netlink sockets. 154*e4a36f41SAndroid Build Coastguard Workerneverallow { 155*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 156*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_25 157*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_27 158*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_29 159*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_30 160*e4a36f41SAndroid Build Coastguard Worker} domain:netlink_route_socket nlmsg_getneigh; 161*e4a36f41SAndroid Build Coastguard Worker 162*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps access to /cache 163*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms }; 164*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr }; 165*e4a36f41SAndroid Build Coastguard Worker 166*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to create/unlink files outside of its sandbox, 167*e4a36f41SAndroid Build Coastguard Worker# internal storage or sdcard. 168*e4a36f41SAndroid Build Coastguard Worker# World accessible data locations allow application to fill the device 169*e4a36f41SAndroid Build Coastguard Worker# with unaccounted for data. This data will not get removed during 170*e4a36f41SAndroid Build Coastguard Worker# application un-installation. 171*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider } { 172*e4a36f41SAndroid Build Coastguard Worker fs_type 173*e4a36f41SAndroid Build Coastguard Worker -sdcard_type 174*e4a36f41SAndroid Build Coastguard Worker -fuse 175*e4a36f41SAndroid Build Coastguard Worker file_type 176*e4a36f41SAndroid Build Coastguard Worker -app_data_file # The apps sandbox itself 177*e4a36f41SAndroid Build Coastguard Worker -privapp_data_file 178*e4a36f41SAndroid Build Coastguard Worker is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `-storage_area_content_file') 179*e4a36f41SAndroid Build Coastguard Worker -app_exec_data_file # stored within the app sandbox directory 180*e4a36f41SAndroid Build Coastguard Worker -media_rw_data_file # Internal storage. Known that apps can 181*e4a36f41SAndroid Build Coastguard Worker # leave artfacts here after uninstall. 182*e4a36f41SAndroid Build Coastguard Worker -user_profile_data_file # Access to profile files 183*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(` 184*e4a36f41SAndroid Build Coastguard Worker -method_trace_data_file # only on ro.debuggable=1 185*e4a36f41SAndroid Build Coastguard Worker -coredump_file # userdebug/eng only 186*e4a36f41SAndroid Build Coastguard Worker ') 187*e4a36f41SAndroid Build Coastguard Worker}:dir_file_class_set { create unlink }; 188*e4a36f41SAndroid Build Coastguard Worker 189*e4a36f41SAndroid Build Coastguard Worker# No untrusted component except mediaprovider_app should be touching /dev/fuse 190*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -mediaprovider_app } fuse_device:chr_file *; 191*e4a36f41SAndroid Build Coastguard Worker 192*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to directly open the tun_device 193*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps tun_device:chr_file open; 194*e4a36f41SAndroid Build Coastguard Worker# The tun_device ioctls below are not allowed, to prove equivalence 195*e4a36f41SAndroid Build Coastguard Worker# to the kernel patch at 196*e4a36f41SAndroid Build Coastguard Worker# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21 197*e4a36f41SAndroid Build Coastguard Workerneverallowxperm all_untrusted_apps tun_device:chr_file ioctl ~{ FIOCLEX FIONCLEX TUNGETIFF }; 198*e4a36f41SAndroid Build Coastguard Worker 199*e4a36f41SAndroid Build Coastguard Worker# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553) 200*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps anr_data_file:file ~{ open append }; 201*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps anr_data_file:dir ~search; 202*e4a36f41SAndroid Build Coastguard Worker 203*e4a36f41SAndroid Build Coastguard Worker# Avoid reads from generically labeled /proc files 204*e4a36f41SAndroid Build Coastguard Worker# Create a more specific label if needed 205*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps { 206*e4a36f41SAndroid Build Coastguard Worker proc 207*e4a36f41SAndroid Build Coastguard Worker proc_asound 208*e4a36f41SAndroid Build Coastguard Worker proc_kmsg 209*e4a36f41SAndroid Build Coastguard Worker proc_loadavg 210*e4a36f41SAndroid Build Coastguard Worker proc_mounts 211*e4a36f41SAndroid Build Coastguard Worker proc_pagetypeinfo 212*e4a36f41SAndroid Build Coastguard Worker proc_slabinfo 213*e4a36f41SAndroid Build Coastguard Worker proc_stat 214*e4a36f41SAndroid Build Coastguard Worker proc_swaps 215*e4a36f41SAndroid Build Coastguard Worker proc_uptime 216*e4a36f41SAndroid Build Coastguard Worker proc_version 217*e4a36f41SAndroid Build Coastguard Worker proc_vmallocinfo 218*e4a36f41SAndroid Build Coastguard Worker proc_vmstat 219*e4a36f41SAndroid Build Coastguard Worker}:file { no_rw_file_perms no_x_file_perms }; 220*e4a36f41SAndroid Build Coastguard Worker 221*e4a36f41SAndroid Build Coastguard Worker# /proc/filesystems is accessible to mediaprovider_app only since it handles 222*e4a36f41SAndroid Build Coastguard Worker# external storage 223*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps - mediaprovider_app } proc_filesystems:file { no_rw_file_perms no_x_file_perms }; 224*e4a36f41SAndroid Build Coastguard Worker 225*e4a36f41SAndroid Build Coastguard Worker# Avoid all access to kernel configuration 226*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms }; 227*e4a36f41SAndroid Build Coastguard Worker 228*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps access to preloads data files 229*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms; 230*e4a36f41SAndroid Build Coastguard Worker 231*e4a36f41SAndroid Build Coastguard Worker# Locking of files on /system could lead to denial of service attacks 232*e4a36f41SAndroid Build Coastguard Worker# against privileged system components 233*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps system_file:file lock; 234*e4a36f41SAndroid Build Coastguard Worker 235*e4a36f41SAndroid Build Coastguard Worker# Do not permit untrusted apps to perform actions on HwBinder service_manager 236*e4a36f41SAndroid Build Coastguard Worker# other than find actions for services listed below 237*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps *:hwservice_manager ~find; 238*e4a36f41SAndroid Build Coastguard Worker 239*e4a36f41SAndroid Build Coastguard Worker# Do not permit access from apps which host arbitrary code to the protected services 240*e4a36f41SAndroid Build Coastguard Worker# The two main reasons for this are: 241*e4a36f41SAndroid Build Coastguard Worker# 1. Protected HwBinder servers do not perform client authentication because 242*e4a36f41SAndroid Build Coastguard Worker# vendor code does not have a way to understand apps or their relation to 243*e4a36f41SAndroid Build Coastguard Worker# caller UID information and, even if it did, those services either operate 244*e4a36f41SAndroid Build Coastguard Worker# at a level below that of apps (e.g., HALs) or must not rely on app identity 245*e4a36f41SAndroid Build Coastguard Worker# for authorization. Thus, to be safe, the default assumption for all added 246*e4a36f41SAndroid Build Coastguard Worker# vendor services is that they treat all their clients as equally authorized 247*e4a36f41SAndroid Build Coastguard Worker# to perform operations offered by the service. 248*e4a36f41SAndroid Build Coastguard Worker# 2. HAL servers contain code with higher incidence rate of security issues 249*e4a36f41SAndroid Build Coastguard Worker# than system/core components and have access to lower layes of the stack 250*e4a36f41SAndroid Build Coastguard Worker# (all the way down to hardware) thus increasing opportunities for bypassing 251*e4a36f41SAndroid Build Coastguard Worker# the Android security model. 252*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps protected_hwservice:hwservice_manager find; 253*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps protected_service:service_manager find; 254*e4a36f41SAndroid Build Coastguard Worker 255*e4a36f41SAndroid Build Coastguard Worker# SELinux is not an API for untrusted apps to use 256*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps selinuxfs:file no_rw_file_perms; 257*e4a36f41SAndroid Build Coastguard Worker 258*e4a36f41SAndroid Build Coastguard Worker# Access to /proc/tty/drivers, to allow apps to determine if they 259*e4a36f41SAndroid Build Coastguard Worker# are running in an emulated environment. 260*e4a36f41SAndroid Build Coastguard Worker# b/33214085 b/33814662 b/33791054 b/33211769 261*e4a36f41SAndroid Build Coastguard Worker# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java 262*e4a36f41SAndroid Build Coastguard Worker# This will go away in a future Android release 263*e4a36f41SAndroid Build Coastguard Workerneverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms; 264*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms; 265*e4a36f41SAndroid Build Coastguard Worker 266*e4a36f41SAndroid Build Coastguard Worker# Untrusted apps are not allowed to use cgroups. 267*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps cgroup:file *; 268*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps cgroup_v2:file *; 269*e4a36f41SAndroid Build Coastguard Worker 270*e4a36f41SAndroid Build Coastguard Worker# /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps 271*e4a36f41SAndroid Build Coastguard Worker# must not use it. 272*e4a36f41SAndroid Build Coastguard Workerneverallow { 273*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 274*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_25 275*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_27 276*e4a36f41SAndroid Build Coastguard Worker} mnt_sdcard_file:lnk_file *; 277*e4a36f41SAndroid Build Coastguard Worker 278*e4a36f41SAndroid Build Coastguard Worker# Only privileged apps may find the incident service 279*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps incident_service:service_manager find; 280*e4a36f41SAndroid Build Coastguard Worker 281*e4a36f41SAndroid Build Coastguard Worker# Only privileged apps may find stats service 282*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps stats_service:service_manager find; 283*e4a36f41SAndroid Build Coastguard Worker 284*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted app to read hidden system proprerties. 285*e4a36f41SAndroid Build Coastguard Worker# We do not include in the exclusions other normally untrusted applications such as mediaprovider 286*e4a36f41SAndroid Build Coastguard Worker# due to the specific logging use cases. 287*e4a36f41SAndroid Build Coastguard Worker# Context: b/193912100 288*e4a36f41SAndroid Build Coastguard Workerneverallow { 289*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 290*e4a36f41SAndroid Build Coastguard Worker -mediaprovider 291*e4a36f41SAndroid Build Coastguard Worker -mediaprovider_app 292*e4a36f41SAndroid Build Coastguard Worker} { userdebug_or_eng_prop }:file read; 293*e4a36f41SAndroid Build Coastguard Worker 294*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted app to access /dev/socket/mdnsd since U. The socket is 295*e4a36f41SAndroid Build Coastguard Worker# used to communicate to the mdnsd responder. The mdnsd responder will be 296*e4a36f41SAndroid Build Coastguard Worker# replaced by a java implementation which is integrated into the system server. 297*e4a36f41SAndroid Build Coastguard Worker# For untrusted apps running with API level 33-, they still have access to 298*e4a36f41SAndroid Build Coastguard Worker# /dev/socket/mdnsd for backward compatibility. 299*e4a36f41SAndroid Build Coastguard Workerneverallow { 300*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 301*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_25 302*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_27 303*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_29 304*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_30 305*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_32 306*e4a36f41SAndroid Build Coastguard Worker} mdnsd_socket:sock_file write; 307*e4a36f41SAndroid Build Coastguard Workerneverallow { 308*e4a36f41SAndroid Build Coastguard Worker all_untrusted_apps 309*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_25 310*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_27 311*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_29 312*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_30 313*e4a36f41SAndroid Build Coastguard Worker -untrusted_app_32 314*e4a36f41SAndroid Build Coastguard Worker} mdnsd:unix_stream_socket connectto; 315*e4a36f41SAndroid Build Coastguard Worker 316*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted apps to use anonymous inodes. At the moment, 317*e4a36f41SAndroid Build Coastguard Worker# type transitions are the only way to distinguish between different 318*e4a36f41SAndroid Build Coastguard Worker# anon_inode usages like userfaultfd and io_uring. This prevents us from 319*e4a36f41SAndroid Build Coastguard Worker# creating a more fine-grained neverallow policy for each anon_inode usage. 320*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps domain:anon_inode *; 321*e4a36f41SAndroid Build Coastguard Worker 322*e4a36f41SAndroid Build Coastguard Worker# Do not allow untrusted app access to hidraw devices. 323*e4a36f41SAndroid Build Coastguard Workerneverallow all_untrusted_apps hidraw_device:chr_file *; 324