app.te 13.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
###
### Domain for all zygote spawned apps
###
### This file is the base policy for all zygote spawned apps.
### Other policy files, such as isolated_app.te, untrusted_app.te, etc
### extend from this policy. Only policies which should apply to ALL
### zygote spawned apps should be added here.
###

10 11
# Dalvik Compiler JIT Mapping.
allow appdomain self:process execmem;
12
allow appdomain ashmem_device:chr_file execute;
13

14 15 16
# Receive and use open file descriptors inherited from zygote.
allow appdomain zygote:fd use;

17
# gdbserver for ndk-gdb reads the zygote.
18 19
# valgrind needs mmap exec for zygote
allow appdomain zygote_exec:file rx_file_perms;
20 21 22 23

# gdbserver for ndk-gdb ptrace attaches to app process.
allow appdomain self:process ptrace;

24 25 26 27 28 29
# Read system properties managed by zygote.
allow appdomain zygote_tmpfs:file read;

# Notify zygote of death;
allow appdomain zygote:process sigchld;

30 31 32 33 34 35 36
# Notify shell and adbd of death when spawned via runas for ndk-gdb.
allow appdomain shell:process sigchld;
allow appdomain adbd:process sigchld;

# child shell or gdbserver pty access for runas.
allow appdomain devpts:chr_file { getattr read write ioctl };

37
# Use pipes and sockets provided by system_server via binder or local socket.
38
allow appdomain system_server:fifo_file rw_file_perms;
39 40
allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown };
allow appdomain system_server:tcp_socket { read write getattr getopt shutdown };
41

42 43 44
# Communication with other apps via fifos
allow appdomain appdomain:fifo_file rw_file_perms;

45
# Communicate with surfaceflinger.
46
allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown };
47 48 49

# App sandbox file accesses.
allow appdomain app_data_file:dir create_dir_perms;
50
allow appdomain app_data_file:notdevfile_class_set create_file_perms;
51 52 53

# lib subdirectory of /data/data dir is system-owned.
allow appdomain system_data_file:dir r_dir_perms;
54
allow appdomain system_data_file:file { execute execute_no_trans open execmod };
55

56 57 58 59 60 61
# Keychain and user-trusted credentials
allow appdomain keychain_data_file:dir r_dir_perms;
allow appdomain keychain_data_file:file r_file_perms;
allow appdomain misc_user_data_file:dir r_dir_perms;
allow appdomain misc_user_data_file:file r_file_perms;

62 63 64 65
# Access to OEM provided data and apps
allow appdomain oemfs:dir r_dir_perms;
allow appdomain oemfs:file rx_file_perms;

66 67 68 69
# Execute the shell or other system executables.
allow appdomain shell_exec:file rx_file_perms;
allow appdomain system_file:file rx_file_perms;

70 71 72
# Execute dex2oat when apps call dexclassloader
allow appdomain dex2oat_exec:file rx_file_perms;

73
# Read/write wallpaper file (opened by system).
74
allow appdomain wallpaper_file:file { getattr read write };
75 76 77 78 79

# Write to /data/anr/traces.txt.
allow appdomain anr_data_file:dir search;
allow appdomain anr_data_file:file { open append };

Nick Kralevich's avatar
Nick Kralevich committed
80 81
# Allow apps to send dump information to dumpstate
allow appdomain dumpstate:fd use;
82
allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown };
Nick Kralevich's avatar
Nick Kralevich committed
83
allow appdomain shell_data_file:file { write getattr };
Nick Kralevich's avatar
Nick Kralevich committed
84

85 86 87 88 89 90
# Write to /proc/net/xt_qtaguid/ctrl file.
allow appdomain qtaguid_proc:file rw_file_perms;
# Everybody can read the xt_qtaguid resource tracking misc dev.
# So allow all apps to read from /dev/xt_qtaguid.
allow appdomain qtaguid_device:chr_file r_file_perms;

91 92 93 94
# Grant GPU access to all processes started by Zygote.
# They need that to render the standard UI.
allow appdomain gpu_device:chr_file { rw_file_perms execute };

95 96 97 98 99 100 101 102 103 104 105
# Use the Binder.
binder_use(appdomain)
# Perform binder IPC to binder services.
binder_call(appdomain, binderservicedomain)
# Perform binder IPC to other apps.
binder_call(appdomain, appdomain)

# Already connected, unnamed sockets being passed over some other IPC
# hence no sock_file or connectto permission. This appears to be how
# Chrome works, may need to be updated as more apps using isolated services
# are examined.
106
allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
107 108 109

# Backup ability for every app. BMS opens and passes the fd
# to any app that has backup ability. Hence, no open permissions here.
110 111
allow appdomain backup_data_file:file { read write getattr };
allow appdomain cache_backup_file:file { read write getattr };
112
allow appdomain cache_backup_file:dir getattr;
113 114 115
# Backup ability using 'adb backup'
allow appdomain system_data_file:lnk_file getattr;

116 117 118
# Allow read/stat of /data/media files passed by Binder or local socket IPC.
allow appdomain media_rw_data_file:file { read getattr };

119 120
# Read and write /data/data/com.android.providers.telephony files passed over Binder.
allow appdomain radio_data_file:file { read write getattr };
121

122 123 124 125 126
# Read and write system app data files passed over Binder.
# Motivating case was /data/data/com.android.settings/cache/*.jpg for
# cropping or taking user photos.
allow untrusted_app system_app_data_file:file { read write getattr };

127
# Access SDcard via the fuse mount.
128 129
allow appdomain fuse:dir create_dir_perms;
allow appdomain fuse:file create_file_perms;
130

131 132 133 134
# Access OBBs (vfat images) mounted by vold (b/17633509)
allow appdomain vfat:dir r_dir_perms;
allow appdomain vfat:file r_file_perms;

135 136 137 138 139 140 141 142
# Allow apps to use the USB Accessory interface.
# http://developer.android.com/guide/topics/connectivity/usb/accessory.html
#
# USB devices are first opened by the system server (USBDeviceManagerService)
# and the file descriptor is passed to the right Activity via binder.
allow appdomain usb_device:chr_file { read write getattr ioctl };
allow appdomain usbaccessory_device:chr_file { read write getattr };

143 144
# For art.
allow appdomain dalvikcache_data_file:file execute;
145
allow appdomain dalvikcache_data_file:lnk_file r_file_perms;
146

147
# /data/dalvik-cache/profiles
148 149
allow appdomain dalvikcache_profiles_data_file:dir { search getattr };
allow appdomain dalvikcache_profiles_data_file:file rw_file_perms;
150

151 152 153 154
# Allow any app to read shared RELRO files.
allow appdomain shared_relro_file:dir search;
allow appdomain shared_relro_file:file r_file_perms;

155
# Allow apps to read/execute installed binaries
156
allow appdomain apk_data_file:dir r_dir_perms;
157 158
allow appdomain apk_data_file:file { rx_file_perms execmod };

159 160 161 162
# /data/resource-cache
allow appdomain resourcecache_data_file:file r_file_perms;
allow appdomain resourcecache_data_file:dir r_dir_perms;

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
###
### CTS-specific rules
###

# For cts/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/RootProcessScanner.java.
# Reads /proc/pid/status and statm entries to check that
# no unexpected root processes are running.
# Also for cts/tests/tests/security/src/android/security/cts/VoldExploitTest.java
# Reads /proc/pid/cmdline of vold.
allow appdomain domain:dir { open read search getattr };
allow appdomain domain:{ file lnk_file } { open read getattr };

# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
# testRunAsHasCorrectCapabilities
allow appdomain runas_exec:file getattr;
# Others are either allowed elsewhere or not desired.

# For cts/tests/tests/security/src/android/security/cts/SELinuxTest.java
# Check SELinux policy and contexts.
selinux_check_access(appdomain)
selinux_check_context(appdomain)
# Validate that each process is running in the correct security context.
allow appdomain domain:process getattr;

187 188
# logd access
read_logd(appdomain)
189
control_logd(appdomain)
190 191 192
# application inherit logd write socket (urge is to deprecate this long term)
allow appdomain zygote:unix_dgram_socket write;

193 194 195 196
allow appdomain keystore:keystore_key { test get insert delete exist saw sign verify };

use_keystore(appdomain)

197 198 199 200 201 202 203
###
### Neverallow rules
###
### These are things that Android apps should NEVER be able to do
###

# Superuser capabilities.
204
# bluetooth requires net_admin and wake_alarm.
205 206
neverallow { appdomain -bluetooth } self:capability *;
neverallow { appdomain -bluetooth } self:capability2 *;
207 208

# Block device access.
209
neverallow appdomain dev_type:blk_file { read write };
210

211
# Access to any of the following character devices.
212
neverallow appdomain {
213 214 215 216 217 218 219 220 221
    audio_device
    camera_device
    dm_device
    radio_device
    gps_device
    rpmsg_device
}:chr_file { read write };

# Note: Try expanding list of app domains in the future.
222
neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write };
223

224
neverallow { appdomain -nfc } nfc_device:chr_file
225
    { read write };
226
neverallow { appdomain -bluetooth } hci_attach_dev:chr_file
227
    { read write };
228
neverallow appdomain tee_device:chr_file { read write };
229

230
# Privileged netlink socket interfaces.
231
neverallow appdomain
232
    domain:{
233 234 235 236 237 238 239 240 241
        netlink_firewall_socket
        netlink_tcpdiag_socket
        netlink_nflog_socket
        netlink_xfrm_socket
        netlink_audit_socket
        netlink_ip6fw_socket
        netlink_dnrt_socket
    } *;

242 243 244
# These messages are broadcast messages from the kernel to userspace.
# Do not allow the writing of netlink messages, which has been a source
# of rooting vulns in the past.
245
neverallow appdomain domain:netlink_kobject_uevent_socket { write append };
246

247
# Sockets under /dev/socket that are not specifically typed.
248
neverallow appdomain socket_device:sock_file write;
249 250

# Unix domain sockets.
251 252
neverallow appdomain adbd_socket:sock_file write;
neverallow appdomain installd_socket:sock_file write;
253
neverallow { appdomain -bluetooth -radio -shell -system_app -nfc }
254
    property_socket:sock_file write;
255 256 257
neverallow { appdomain -radio } rild_socket:sock_file write;
neverallow appdomain vold_socket:sock_file write;
neverallow appdomain zygote_socket:sock_file write;
258

259
# ptrace access to non-app domains.
260
neverallow appdomain { domain -appdomain }:process ptrace;
261

262
# Write access to /proc/pid entries for any non-app domain.
263
neverallow appdomain { domain -appdomain }:file write;
264 265 266 267 268

# signal access to non-app domains.
# sigchld allowed for parent death notification.
# signull allowed for kill(pid, 0) existence test.
# All others prohibited.
269
neverallow appdomain { domain -appdomain }:process
270 271
    { sigkill sigstop signal };

272
# Transition to a non-app domain.
Stephen Smalley's avatar
Stephen Smalley committed
273
# Exception for the shell domain, can transition to runas, etc.
274
neverallow { appdomain -shell } { domain -appdomain }:process
275 276 277
    { transition dyntransition };

# Write to rootfs.
278
neverallow appdomain rootfs:dir_file_class_set
279
    { create write setattr relabelfrom relabelto append unlink link rename };
280 281

# Write to /system.
282
neverallow appdomain system_file:dir_file_class_set
283 284 285
    { create write setattr relabelfrom relabelto append unlink link rename };

# Write to entrypoint executables.
286
neverallow appdomain exec_type:file
287
    { create write setattr relabelfrom relabelto append unlink link rename };
288 289 290 291 292 293

# Write to system-owned parts of /data.
# This is the default type for anything under /data not otherwise
# specified in file_contexts.  Define a different type for portions
# that should be writable by apps.
# Exception for system_app for Settings.
294
neverallow { appdomain -system_app }
295 296 297 298
    system_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };

# Write to various other parts of /data.
299
neverallow appdomain drm_data_file:dir_file_class_set
300
    { create write setattr relabelfrom relabelto append unlink link rename };
301 302
neverallow { appdomain -system_app }
    gps_data_file:dir_file_class_set
303
    { create write setattr relabelfrom relabelto append unlink link rename };
304
neverallow { appdomain -platform_app }
305 306
    apk_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
307
neverallow { appdomain -platform_app }
308 309
    apk_tmp_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
310
neverallow { appdomain -platform_app }
311 312
    apk_private_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
313
neverallow { appdomain -platform_app }
314 315
    apk_private_tmp_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
316
neverallow { appdomain -shell }
317
    shell_data_file:dir_file_class_set
Nick Kralevich's avatar
Nick Kralevich committed
318
    { create setattr relabelfrom relabelto append unlink link rename };
319
neverallow { appdomain -bluetooth }
320 321
    bluetooth_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
322
neverallow appdomain
323 324
    keystore_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
325
neverallow appdomain
326 327
    systemkeys_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
328
neverallow appdomain
329 330
    wifi_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };
331
neverallow appdomain
332 333 334 335
    dhcp_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };

# Access to factory files.
336 337
neverallow appdomain efs_file:dir_file_class_set write;
neverallow { appdomain -shell } efs_file:dir_file_class_set read;
338 339

# Write to various pseudo file systems.
340
neverallow { appdomain -bluetooth -nfc }
341
    sysfs:dir_file_class_set write;
342
neverallow appdomain
343 344 345
    proc:dir_file_class_set write;

# Access to syslog(2) or /proc/kmsg.
346
neverallow { appdomain -system_app }
Nick Kralevich's avatar
Nick Kralevich committed
347
    kernel:system { syslog_mod syslog_console };
Stephen Smalley's avatar
Stephen Smalley committed
348
neverallow { appdomain -system_app -shell }
Nick Kralevich's avatar
Nick Kralevich committed
349
    kernel:system syslog_read;
350 351 352

# Ability to perform any filesystem operation other than statfs(2).
# i.e. no mount(2), unmount(2), etc.
353
neverallow appdomain fs_type:filesystem ~getattr;
354 355

# Ability to set system properties.
356
neverallow { appdomain -system_app -radio -shell -bluetooth -nfc }
357
    property_type:property_service set;