blob: e24215249146502c3b47824b80d142886d6aa0a3 [file] [log] [blame]
Nick Kralevich748fdef2013-07-12 16:33:29 -07001###
2### Domain for all zygote spawned apps
3###
4### This file is the base policy for all zygote spawned apps.
5### Other policy files, such as isolated_app.te, untrusted_app.te, etc
6### extend from this policy. Only policies which should apply to ALL
7### zygote spawned apps should be added here.
8###
Stephen Smalley2dd4e512012-01-04 12:33:27 -05009
Stephen Smalleyad7df7b2013-12-20 08:24:12 -050010# Dalvik Compiler JIT Mapping.
11allow appdomain self:process execmem;
Stephen Smalleye7ec2f52013-12-23 16:18:55 -050012allow appdomain ashmem_device:chr_file execute;
Stephen Smalleyad7df7b2013-12-20 08:24:12 -050013
Nick Kralevich6634a102013-07-12 18:45:56 -070014# Receive and use open file descriptors inherited from zygote.
15allow appdomain zygote:fd use;
16
Stephen Smalley48759ca2013-10-29 14:42:39 -040017# gdbserver for ndk-gdb reads the zygote.
Nick Kralevich4fce0ef2014-05-22 15:00:25 -070018# valgrind needs mmap exec for zygote
19allow appdomain zygote_exec:file rx_file_perms;
Stephen Smalley48759ca2013-10-29 14:42:39 -040020
21# gdbserver for ndk-gdb ptrace attaches to app process.
22allow appdomain self:process ptrace;
23
Nick Kralevich6634a102013-07-12 18:45:56 -070024# Read system properties managed by zygote.
25allow appdomain zygote_tmpfs:file read;
26
27# Notify zygote of death;
28allow appdomain zygote:process sigchld;
29
Stephen Smalley48759ca2013-10-29 14:42:39 -040030# Notify shell and adbd of death when spawned via runas for ndk-gdb.
31allow appdomain shell:process sigchld;
32allow appdomain adbd:process sigchld;
33
34# child shell or gdbserver pty access for runas.
35allow appdomain devpts:chr_file { getattr read write ioctl };
36
Stephen Smalley3dad7b62014-03-05 09:50:08 -050037# Use pipes and sockets provided by system_server via binder or local socket.
Alex Klyubin1fdee112013-09-13 15:59:04 -070038allow appdomain system_server:fifo_file rw_file_perms;
Stephen Smalley3dad7b62014-03-05 09:50:08 -050039allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown };
40allow appdomain system_server:tcp_socket { read write getattr getopt shutdown };
Nick Kralevich6634a102013-07-12 18:45:56 -070041
Nick Kralevich82fc3b52013-12-06 13:31:16 -080042# Communication with other apps via fifos
43allow appdomain appdomain:fifo_file rw_file_perms;
44
Nick Kralevich6634a102013-07-12 18:45:56 -070045# Communicate with surfaceflinger.
Stephen Smalleyb0db7122014-03-06 16:03:48 -050046allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown };
Nick Kralevich6634a102013-07-12 18:45:56 -070047
48# App sandbox file accesses.
49allow appdomain app_data_file:dir create_dir_perms;
Stephen Smalley65317122013-12-11 09:08:09 -050050allow appdomain app_data_file:notdevfile_class_set create_file_perms;
Nick Kralevich6634a102013-07-12 18:45:56 -070051
Nick Kralevich6634a102013-07-12 18:45:56 -070052# lib subdirectory of /data/data dir is system-owned.
53allow appdomain system_data_file:dir r_dir_perms;
Nick Kralevich78706f92014-06-02 14:49:10 -070054allow appdomain system_data_file:file { execute execute_no_trans open execmod };
Nick Kralevich6634a102013-07-12 18:45:56 -070055
Jeff Sharkey6736bac2014-04-24 13:31:29 -070056# Access to OEM provided data and apps
57allow appdomain oemfs:dir r_dir_perms;
58allow appdomain oemfs:file rx_file_perms;
59
Nick Kralevich6634a102013-07-12 18:45:56 -070060# Execute the shell or other system executables.
61allow appdomain shell_exec:file rx_file_perms;
62allow appdomain system_file:file rx_file_perms;
63
Ed Heyl8ee37b42014-07-14 23:32:08 -070064# Execute dex2oat when apps call dexclassloader
65allow appdomain dex2oat_exec:file rx_file_perms;
66
Nick Kralevich6634a102013-07-12 18:45:56 -070067# Read/write wallpaper file (opened by system).
Robert Craigfc4c6b72014-01-23 10:05:28 -050068allow appdomain wallpaper_file:file { getattr read write };
Nick Kralevich6634a102013-07-12 18:45:56 -070069
70# Write to /data/anr/traces.txt.
71allow appdomain anr_data_file:dir search;
72allow appdomain anr_data_file:file { open append };
73
Nick Kralevich09e6abd2013-12-13 22:19:45 -080074# Allow apps to send dump information to dumpstate
75allow appdomain dumpstate:fd use;
Stephen Smalleyb0db7122014-03-06 16:03:48 -050076allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown };
Nick Kralevich2e7a3012014-01-10 23:05:25 -080077allow appdomain shell_data_file:file { write getattr };
Nick Kralevich09e6abd2013-12-13 22:19:45 -080078
Nick Kralevich6634a102013-07-12 18:45:56 -070079# Write to /proc/net/xt_qtaguid/ctrl file.
80allow appdomain qtaguid_proc:file rw_file_perms;
81# Everybody can read the xt_qtaguid resource tracking misc dev.
82# So allow all apps to read from /dev/xt_qtaguid.
83allow appdomain qtaguid_device:chr_file r_file_perms;
84
Stephen Smalley3ba90122013-12-12 09:09:53 -050085# Grant GPU access to all processes started by Zygote.
86# They need that to render the standard UI.
87allow appdomain gpu_device:chr_file { rw_file_perms execute };
88
Nick Kralevich6634a102013-07-12 18:45:56 -070089# Use the Binder.
90binder_use(appdomain)
91# Perform binder IPC to binder services.
92binder_call(appdomain, binderservicedomain)
93# Perform binder IPC to other apps.
94binder_call(appdomain, appdomain)
95
Nick Kralevich6634a102013-07-12 18:45:56 -070096# Already connected, unnamed sockets being passed over some other IPC
97# hence no sock_file or connectto permission. This appears to be how
98# Chrome works, may need to be updated as more apps using isolated services
99# are examined.
Stephen Smalleyb0db7122014-03-06 16:03:48 -0500100allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
Nick Kralevich6634a102013-07-12 18:45:56 -0700101
102# Backup ability for every app. BMS opens and passes the fd
103# to any app that has backup ability. Hence, no open permissions here.
Geremy Condra81560732013-08-30 13:02:30 -0700104allow appdomain backup_data_file:file { read write getattr };
105allow appdomain cache_backup_file:file { read write getattr };
Stephen Smalley9ba844f2014-04-04 09:09:25 -0400106allow appdomain cache_backup_file:dir getattr;
Nick Kralevich6634a102013-07-12 18:45:56 -0700107# Backup ability using 'adb backup'
108allow appdomain system_data_file:lnk_file getattr;
109
Stephen Smalley2737cef2014-03-04 13:44:01 -0500110# Allow read/stat of /data/media files passed by Binder or local socket IPC.
111allow appdomain media_rw_data_file:file { read getattr };
112
Nick Kralevich1545b602014-05-05 11:04:12 -0700113# Read and write /data/data/com.android.providers.telephony files passed over Binder.
114allow appdomain radio_data_file:file { read write getattr };
Stephen Smalley3fbc5362014-03-27 09:45:26 -0400115
Stephen Smalley91a4f8d2014-05-07 13:10:02 -0400116# Read and write system app data files passed over Binder.
117# Motivating case was /data/data/com.android.settings/cache/*.jpg for
118# cropping or taking user photos.
119allow untrusted_app system_app_data_file:file { read write getattr };
120
Stephen Smalleycf610692014-06-20 14:13:14 -0400121# Access SDcard via the fuse mount.
Ed Heyle9c90bd2014-07-14 23:29:21 -0700122allow appdomain fuse:dir create_dir_perms;
123allow appdomain fuse:file create_file_perms;
Stephen Smalleyb0db7122014-03-06 16:03:48 -0500124
Nick Kralevich0b8c20e2013-10-09 12:27:27 -0700125# Allow apps to use the USB Accessory interface.
126# http://developer.android.com/guide/topics/connectivity/usb/accessory.html
127#
128# USB devices are first opened by the system server (USBDeviceManagerService)
129# and the file descriptor is passed to the right Activity via binder.
130allow appdomain usb_device:chr_file { read write getattr ioctl };
131allow appdomain usbaccessory_device:chr_file { read write getattr };
132
Stephen Smalley527316a2013-12-23 14:48:02 -0500133# For art.
134allow appdomain dalvikcache_data_file:file execute;
135
Stephen Smalley19c50902014-04-09 14:24:33 -0400136# /data/dalvik-cache/profiles
Nick Kralevich86703052014-06-10 18:42:22 -0700137allow appdomain dalvikcache_profiles_data_file:dir { search getattr };
138allow appdomain dalvikcache_profiles_data_file:file rw_file_perms;
Stephen Smalley19c50902014-04-09 14:24:33 -0400139
Torne (Richard Coles)9786af22014-05-23 11:01:58 +0100140# Allow any app to read shared RELRO files.
141allow appdomain shared_relro_file:dir search;
142allow appdomain shared_relro_file:file r_file_perms;
143
Christopher Tate6f6c4252014-05-30 15:21:22 -0700144# Allow apps to read/execute installed binaries
145allow appdomain apk_data_file:file { rx_file_perms execmod };
146
Nick Kralevichfad4d5f2014-06-16 14:19:31 -0700147# /data/resource-cache
148allow appdomain resourcecache_data_file:file r_file_perms;
149allow appdomain resourcecache_data_file:dir r_dir_perms;
150
Nick Kralevich6634a102013-07-12 18:45:56 -0700151###
Stephen Smalley59469372013-12-16 08:55:24 -0500152### CTS-specific rules
153###
154
155# For cts/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/RootProcessScanner.java.
156# Reads /proc/pid/status and statm entries to check that
157# no unexpected root processes are running.
158# Also for cts/tests/tests/security/src/android/security/cts/VoldExploitTest.java
159# Reads /proc/pid/cmdline of vold.
160allow appdomain domain:dir { open read search getattr };
161allow appdomain domain:{ file lnk_file } { open read getattr };
162
163# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
164# testRunAsHasCorrectCapabilities
165allow appdomain runas_exec:file getattr;
166# Others are either allowed elsewhere or not desired.
167
168# For cts/tests/tests/security/src/android/security/cts/SELinuxTest.java
169# Check SELinux policy and contexts.
170selinux_check_access(appdomain)
171selinux_check_context(appdomain)
172# Validate that each process is running in the correct security context.
173allow appdomain domain:process getattr;
174
Mark Salyzyn8ed750e2013-11-12 15:34:52 -0800175# logd access
176read_logd(appdomain)
177# application inherit logd write socket (urge is to deprecate this long term)
178allow appdomain zygote:unix_dgram_socket write;
179
Riley Spahn1196d2a2014-06-17 14:58:52 -0700180allow appdomain keystore:keystore_key { test get insert delete exist saw sign verify };
Riley Spahn1196d2a2014-06-17 14:58:52 -0700181
182use_keystore(appdomain)
183
Stephen Smalley59469372013-12-16 08:55:24 -0500184###
Nick Kralevich6634a102013-07-12 18:45:56 -0700185### Neverallow rules
186###
187### These are things that Android apps should NEVER be able to do
188###
189
190# Superuser capabilities.
Sharvil Nanavati77eb3522014-06-29 10:45:03 -0700191# bluetooth requires net_admin and wake_alarm.
Nick Kralevichbe660692014-07-04 10:12:13 -0700192neverallow { appdomain -bluetooth } self:capability *;
193neverallow { appdomain -bluetooth } self:capability2 *;
Nick Kralevich6634a102013-07-12 18:45:56 -0700194
195# Block device access.
Nick Kralevichbe660692014-07-04 10:12:13 -0700196neverallow appdomain dev_type:blk_file { read write };
Nick Kralevich6634a102013-07-12 18:45:56 -0700197
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400198# Access to any of the following character devices.
Nick Kralevichbe660692014-07-04 10:12:13 -0700199neverallow appdomain {
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400200 audio_device
201 camera_device
202 dm_device
203 radio_device
204 gps_device
205 rpmsg_device
206}:chr_file { read write };
207
208# Note: Try expanding list of app domains in the future.
Nick Kralevichbe660692014-07-04 10:12:13 -0700209neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write };
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400210
Nick Kralevichbe660692014-07-04 10:12:13 -0700211neverallow { appdomain -nfc } nfc_device:chr_file
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400212 { read write };
Nick Kralevichbe660692014-07-04 10:12:13 -0700213neverallow { appdomain -bluetooth } hci_attach_dev:chr_file
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400214 { read write };
Nick Kralevichbe660692014-07-04 10:12:13 -0700215neverallow appdomain tee_device:chr_file { read write };
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400216
Nick Kralevich6634a102013-07-12 18:45:56 -0700217# Privileged netlink socket interfaces.
Nick Kralevichbe660692014-07-04 10:12:13 -0700218neverallow appdomain
Nick Kralevich6634a102013-07-12 18:45:56 -0700219 self:{
220 netlink_socket
221 netlink_firewall_socket
222 netlink_tcpdiag_socket
223 netlink_nflog_socket
224 netlink_xfrm_socket
Nick Kralevich6634a102013-07-12 18:45:56 -0700225 netlink_audit_socket
226 netlink_ip6fw_socket
227 netlink_dnrt_socket
228 netlink_kobject_uevent_socket
229 } *;
230
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400231# Sockets under /dev/socket that are not specifically typed.
Nick Kralevichbe660692014-07-04 10:12:13 -0700232neverallow appdomain socket_device:sock_file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400233
234# Unix domain sockets.
Nick Kralevichbe660692014-07-04 10:12:13 -0700235neverallow appdomain adbd_socket:sock_file write;
236neverallow appdomain installd_socket:sock_file write;
237neverallow { appdomain -bluetooth -radio -shell -system_app }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400238 property_socket:sock_file write;
Nick Kralevichbe660692014-07-04 10:12:13 -0700239neverallow { appdomain -radio } rild_socket:sock_file write;
240neverallow appdomain vold_socket:sock_file write;
241neverallow appdomain zygote_socket:sock_file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400242
Nick Kralevich6634a102013-07-12 18:45:56 -0700243# ptrace access to non-app domains.
Nick Kralevichbe660692014-07-04 10:12:13 -0700244neverallow appdomain { domain -appdomain }:process ptrace;
Nick Kralevich6634a102013-07-12 18:45:56 -0700245
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400246# Write access to /proc/pid entries for any non-app domain.
Nick Kralevichbe660692014-07-04 10:12:13 -0700247neverallow appdomain { domain -appdomain }:file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400248
249# signal access to non-app domains.
250# sigchld allowed for parent death notification.
251# signull allowed for kill(pid, 0) existence test.
252# All others prohibited.
Nick Kralevichbe660692014-07-04 10:12:13 -0700253neverallow appdomain { domain -appdomain }:process
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400254 { sigkill sigstop signal };
255
Nick Kralevich6634a102013-07-12 18:45:56 -0700256# Transition to a non-app domain.
Stephen Smalley396015c2014-01-07 12:47:10 -0500257# Exception for the shell domain, can transition to runas, etc.
Stephen Smalleyd990a782014-07-29 14:50:30 -0400258neverallow { appdomain -shell } { domain -appdomain }:process
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400259 { transition dyntransition };
260
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400261# Write to rootfs.
Nick Kralevichbe660692014-07-04 10:12:13 -0700262neverallow appdomain rootfs:dir_file_class_set
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400263 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevich6634a102013-07-12 18:45:56 -0700264
265# Write to /system.
Nick Kralevichbe660692014-07-04 10:12:13 -0700266neverallow appdomain system_file:dir_file_class_set
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400267 { create write setattr relabelfrom relabelto append unlink link rename };
268
269# Write to entrypoint executables.
Nick Kralevichbe660692014-07-04 10:12:13 -0700270neverallow appdomain exec_type:file
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400271 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevich6634a102013-07-12 18:45:56 -0700272
273# Write to system-owned parts of /data.
274# This is the default type for anything under /data not otherwise
275# specified in file_contexts. Define a different type for portions
276# that should be writable by apps.
277# Exception for system_app for Settings.
Nick Kralevichbe660692014-07-04 10:12:13 -0700278neverallow { appdomain -system_app }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400279 system_data_file:dir_file_class_set
280 { create write setattr relabelfrom relabelto append unlink link rename };
281
282# Write to various other parts of /data.
Nick Kralevichbe660692014-07-04 10:12:13 -0700283neverallow appdomain drm_data_file:dir_file_class_set
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400284 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700285neverallow appdomain gps_data_file:dir_file_class_set
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400286 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700287neverallow { appdomain -platform_app }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400288 apk_data_file:dir_file_class_set
289 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700290neverallow { appdomain -platform_app }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400291 apk_tmp_file:dir_file_class_set
292 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700293neverallow { appdomain -platform_app }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400294 apk_private_data_file:dir_file_class_set
295 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700296neverallow { appdomain -platform_app }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400297 apk_private_tmp_file:dir_file_class_set
298 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700299neverallow { appdomain -shell }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400300 shell_data_file:dir_file_class_set
Nick Kralevich2e7a3012014-01-10 23:05:25 -0800301 { create setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700302neverallow { appdomain -bluetooth }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400303 bluetooth_data_file:dir_file_class_set
304 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700305neverallow appdomain
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400306 keystore_data_file:dir_file_class_set
307 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700308neverallow appdomain
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400309 systemkeys_data_file:dir_file_class_set
310 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700311neverallow appdomain
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400312 wifi_data_file:dir_file_class_set
313 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevichbe660692014-07-04 10:12:13 -0700314neverallow appdomain
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400315 dhcp_data_file:dir_file_class_set
316 { create write setattr relabelfrom relabelto append unlink link rename };
317
318# Access to factory files.
Nick Kralevichbe660692014-07-04 10:12:13 -0700319neverallow appdomain
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400320 efs_file:dir_file_class_set { read write };
321
322# Write to various pseudo file systems.
Nick Kralevichbe660692014-07-04 10:12:13 -0700323neverallow { appdomain -bluetooth -nfc }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400324 sysfs:dir_file_class_set write;
Nick Kralevichbe660692014-07-04 10:12:13 -0700325neverallow appdomain
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400326 proc:dir_file_class_set write;
327
328# Access to syslog(2) or /proc/kmsg.
Nick Kralevich685e2f92014-05-28 13:48:52 -0700329neverallow { appdomain -system_app }
Nick Kralevichf821b5a2014-05-27 16:49:59 -0700330 kernel:system { syslog_mod syslog_console };
Stephen Smalley42fb8242014-06-11 07:10:09 -0400331neverallow { appdomain -system_app -shell }
Nick Kralevichf821b5a2014-05-27 16:49:59 -0700332 kernel:system syslog_read;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400333
334# Ability to perform any filesystem operation other than statfs(2).
335# i.e. no mount(2), unmount(2), etc.
Nick Kralevichbe660692014-07-04 10:12:13 -0700336neverallow appdomain fs_type:filesystem ~getattr;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400337
338# Ability to set system properties.
Nick Kralevichbe660692014-07-04 10:12:13 -0700339neverallow { appdomain -system_app -radio -shell -bluetooth }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400340 property_type:property_service set;