blob: df8ff81b44beaa6fbf63cd74078ed7cd34aa1479 [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
64# Read/write wallpaper file (opened by system).
Robert Craigfc4c6b72014-01-23 10:05:28 -050065allow appdomain wallpaper_file:file { getattr read write };
Nick Kralevich6634a102013-07-12 18:45:56 -070066
67# Write to /data/anr/traces.txt.
68allow appdomain anr_data_file:dir search;
69allow appdomain anr_data_file:file { open append };
70
Nick Kralevich09e6abd2013-12-13 22:19:45 -080071# Allow apps to send dump information to dumpstate
72allow appdomain dumpstate:fd use;
Stephen Smalleyb0db7122014-03-06 16:03:48 -050073allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown };
Nick Kralevich2e7a3012014-01-10 23:05:25 -080074allow appdomain shell_data_file:file { write getattr };
Nick Kralevich09e6abd2013-12-13 22:19:45 -080075
Nick Kralevich6634a102013-07-12 18:45:56 -070076# Write to /proc/net/xt_qtaguid/ctrl file.
77allow appdomain qtaguid_proc:file rw_file_perms;
78# Everybody can read the xt_qtaguid resource tracking misc dev.
79# So allow all apps to read from /dev/xt_qtaguid.
80allow appdomain qtaguid_device:chr_file r_file_perms;
81
Stephen Smalley3ba90122013-12-12 09:09:53 -050082# Grant GPU access to all processes started by Zygote.
83# They need that to render the standard UI.
84allow appdomain gpu_device:chr_file { rw_file_perms execute };
85
Nick Kralevich6634a102013-07-12 18:45:56 -070086# Use the Binder.
87binder_use(appdomain)
88# Perform binder IPC to binder services.
89binder_call(appdomain, binderservicedomain)
90# Perform binder IPC to other apps.
91binder_call(appdomain, appdomain)
92
Nick Kralevich6634a102013-07-12 18:45:56 -070093# Already connected, unnamed sockets being passed over some other IPC
94# hence no sock_file or connectto permission. This appears to be how
95# Chrome works, may need to be updated as more apps using isolated services
96# are examined.
Stephen Smalleyb0db7122014-03-06 16:03:48 -050097allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
Nick Kralevich6634a102013-07-12 18:45:56 -070098
99# Backup ability for every app. BMS opens and passes the fd
100# to any app that has backup ability. Hence, no open permissions here.
Geremy Condra81560732013-08-30 13:02:30 -0700101allow appdomain backup_data_file:file { read write getattr };
102allow appdomain cache_backup_file:file { read write getattr };
Stephen Smalley9ba844f2014-04-04 09:09:25 -0400103allow appdomain cache_backup_file:dir getattr;
Nick Kralevich6634a102013-07-12 18:45:56 -0700104# Backup ability using 'adb backup'
105allow appdomain system_data_file:lnk_file getattr;
106
Stephen Smalley2737cef2014-03-04 13:44:01 -0500107# Allow read/stat of /data/media files passed by Binder or local socket IPC.
108allow appdomain media_rw_data_file:file { read getattr };
109
Nick Kralevich1545b602014-05-05 11:04:12 -0700110# Read and write /data/data/com.android.providers.telephony files passed over Binder.
111allow appdomain radio_data_file:file { read write getattr };
Stephen Smalley3fbc5362014-03-27 09:45:26 -0400112
Stephen Smalley91a4f8d2014-05-07 13:10:02 -0400113# Read and write system app data files passed over Binder.
114# Motivating case was /data/data/com.android.settings/cache/*.jpg for
115# cropping or taking user photos.
116allow untrusted_app system_app_data_file:file { read write getattr };
117
Stephen Smalleyb0db7122014-03-06 16:03:48 -0500118# Access SDcard.
119allow appdomain sdcard_type:dir create_dir_perms;
120allow appdomain sdcard_type:file create_file_perms;
121
Nick Kralevich0b8c20e2013-10-09 12:27:27 -0700122# Allow apps to use the USB Accessory interface.
123# http://developer.android.com/guide/topics/connectivity/usb/accessory.html
124#
125# USB devices are first opened by the system server (USBDeviceManagerService)
126# and the file descriptor is passed to the right Activity via binder.
127allow appdomain usb_device:chr_file { read write getattr ioctl };
128allow appdomain usbaccessory_device:chr_file { read write getattr };
129
Stephen Smalley527316a2013-12-23 14:48:02 -0500130# For art.
131allow appdomain dalvikcache_data_file:file execute;
132
Stephen Smalley19c50902014-04-09 14:24:33 -0400133# /data/dalvik-cache/profiles
Nick Kralevich86703052014-06-10 18:42:22 -0700134allow appdomain dalvikcache_profiles_data_file:dir { search getattr };
135allow appdomain dalvikcache_profiles_data_file:file rw_file_perms;
Stephen Smalley19c50902014-04-09 14:24:33 -0400136
Torne (Richard Coles)9786af22014-05-23 11:01:58 +0100137# Allow any app to read shared RELRO files.
138allow appdomain shared_relro_file:dir search;
139allow appdomain shared_relro_file:file r_file_perms;
140
Christopher Tate6f6c4252014-05-30 15:21:22 -0700141# Allow apps to read/execute installed binaries
142allow appdomain apk_data_file:file { rx_file_perms execmod };
143
Nick Kralevichfad4d5f2014-06-16 14:19:31 -0700144# /data/resource-cache
145allow appdomain resourcecache_data_file:file r_file_perms;
146allow appdomain resourcecache_data_file:dir r_dir_perms;
147
Nick Kralevich6634a102013-07-12 18:45:56 -0700148###
Stephen Smalley59469372013-12-16 08:55:24 -0500149### CTS-specific rules
150###
151
152# For cts/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/RootProcessScanner.java.
153# Reads /proc/pid/status and statm entries to check that
154# no unexpected root processes are running.
155# Also for cts/tests/tests/security/src/android/security/cts/VoldExploitTest.java
156# Reads /proc/pid/cmdline of vold.
157allow appdomain domain:dir { open read search getattr };
158allow appdomain domain:{ file lnk_file } { open read getattr };
159
160# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
161# testRunAsHasCorrectCapabilities
162allow appdomain runas_exec:file getattr;
163# Others are either allowed elsewhere or not desired.
164
165# For cts/tests/tests/security/src/android/security/cts/SELinuxTest.java
166# Check SELinux policy and contexts.
167selinux_check_access(appdomain)
168selinux_check_context(appdomain)
169# Validate that each process is running in the correct security context.
170allow appdomain domain:process getattr;
171
Mark Salyzyn8ed750e2013-11-12 15:34:52 -0800172# logd access
173read_logd(appdomain)
174# application inherit logd write socket (urge is to deprecate this long term)
175allow appdomain zygote:unix_dgram_socket write;
176
Stephen Smalley59469372013-12-16 08:55:24 -0500177###
Nick Kralevich6634a102013-07-12 18:45:56 -0700178### Neverallow rules
179###
180### These are things that Android apps should NEVER be able to do
181###
182
183# Superuser capabilities.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400184# bluetooth requires net_admin.
185neverallow { appdomain -unconfineddomain -bluetooth } self:capability *;
Nick Kralevich6634a102013-07-12 18:45:56 -0700186neverallow { appdomain -unconfineddomain } self:capability2 *;
187
188# Block device access.
189neverallow { appdomain -unconfineddomain } dev_type:blk_file { read write };
190
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400191# Access to any of the following character devices.
192neverallow { appdomain -unconfineddomain } {
193 audio_device
194 camera_device
195 dm_device
196 radio_device
197 gps_device
198 rpmsg_device
199}:chr_file { read write };
200
201# Note: Try expanding list of app domains in the future.
Nick Kralevich84ed8902014-06-03 17:01:10 -0700202neverallow { untrusted_app isolated_app shell -unconfineddomain } graphics_device:chr_file { read write };
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400203
204neverallow { appdomain -nfc -unconfineddomain } nfc_device:chr_file
205 { read write };
206neverallow { appdomain -bluetooth -unconfineddomain } hci_attach_dev:chr_file
207 { read write };
208neverallow { appdomain -unconfineddomain } tee_device:chr_file { read write };
209
Nick Kralevich6634a102013-07-12 18:45:56 -0700210# Privileged netlink socket interfaces.
211neverallow { appdomain -unconfineddomain }
212 self:{
213 netlink_socket
214 netlink_firewall_socket
215 netlink_tcpdiag_socket
216 netlink_nflog_socket
217 netlink_xfrm_socket
Nick Kralevich6634a102013-07-12 18:45:56 -0700218 netlink_audit_socket
219 netlink_ip6fw_socket
220 netlink_dnrt_socket
221 netlink_kobject_uevent_socket
222 } *;
223
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400224# Sockets under /dev/socket that are not specifically typed.
225neverallow { appdomain -unconfineddomain } socket_device:sock_file write;
226
227# Unix domain sockets.
228neverallow { appdomain -unconfineddomain } adbd_socket:sock_file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400229neverallow { appdomain -unconfineddomain } installd_socket:sock_file write;
230neverallow { appdomain -bluetooth -radio -shell -system_app -unconfineddomain }
231 property_socket:sock_file write;
232neverallow { appdomain -radio -unconfineddomain } rild_socket:sock_file write;
233neverallow { appdomain -unconfineddomain } vold_socket:sock_file write;
234neverallow { appdomain -unconfineddomain } zygote_socket:sock_file write;
235
Nick Kralevich6634a102013-07-12 18:45:56 -0700236# ptrace access to non-app domains.
237neverallow { appdomain -unconfineddomain } { domain -appdomain }:process ptrace;
238
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400239# Write access to /proc/pid entries for any non-app domain.
Nick Kralevich73c5ea72013-10-25 16:53:37 -0700240neverallow { appdomain -unconfineddomain } { domain -appdomain }:file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400241
242# signal access to non-app domains.
243# sigchld allowed for parent death notification.
244# signull allowed for kill(pid, 0) existence test.
245# All others prohibited.
246neverallow { appdomain -unconfineddomain } { domain -appdomain }:process
247 { sigkill sigstop signal };
248
Nick Kralevich6634a102013-07-12 18:45:56 -0700249# Transition to a non-app domain.
Stephen Smalley396015c2014-01-07 12:47:10 -0500250# Exception for the shell domain, can transition to runas, etc.
Stephen Smalley57085442013-09-30 08:47:54 -0400251neverallow { appdomain -shell -unconfineddomain } ~appdomain:process
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400252 { transition dyntransition };
253
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400254# Write to rootfs.
255neverallow { appdomain -unconfineddomain } rootfs:dir_file_class_set
256 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevich6634a102013-07-12 18:45:56 -0700257
258# Write to /system.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400259neverallow { appdomain -unconfineddomain } system_file:dir_file_class_set
260 { create write setattr relabelfrom relabelto append unlink link rename };
261
262# Write to entrypoint executables.
263neverallow { appdomain -unconfineddomain } exec_type:file
264 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevich6634a102013-07-12 18:45:56 -0700265
266# Write to system-owned parts of /data.
267# This is the default type for anything under /data not otherwise
268# specified in file_contexts. Define a different type for portions
269# that should be writable by apps.
270# Exception for system_app for Settings.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400271neverallow { appdomain -unconfineddomain -system_app }
272 system_data_file:dir_file_class_set
273 { create write setattr relabelfrom relabelto append unlink link rename };
274
275# Write to various other parts of /data.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400276neverallow { appdomain -unconfineddomain } drm_data_file:dir_file_class_set
277 { create write setattr relabelfrom relabelto append unlink link rename };
278neverallow { appdomain -unconfineddomain } gps_data_file:dir_file_class_set
279 { create write setattr relabelfrom relabelto append unlink link rename };
280neverallow { appdomain -platform_app -unconfineddomain }
281 apk_data_file:dir_file_class_set
282 { create write setattr relabelfrom relabelto append unlink link rename };
283neverallow { appdomain -platform_app -unconfineddomain }
284 apk_tmp_file:dir_file_class_set
285 { create write setattr relabelfrom relabelto append unlink link rename };
286neverallow { appdomain -platform_app -unconfineddomain }
287 apk_private_data_file:dir_file_class_set
288 { create write setattr relabelfrom relabelto append unlink link rename };
289neverallow { appdomain -platform_app -unconfineddomain }
290 apk_private_tmp_file:dir_file_class_set
291 { create write setattr relabelfrom relabelto append unlink link rename };
292neverallow { appdomain -shell -unconfineddomain }
293 shell_data_file:dir_file_class_set
Nick Kralevich2e7a3012014-01-10 23:05:25 -0800294 { create setattr relabelfrom relabelto append unlink link rename };
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400295neverallow { appdomain -bluetooth -unconfineddomain }
296 bluetooth_data_file:dir_file_class_set
297 { create write setattr relabelfrom relabelto append unlink link rename };
298neverallow { appdomain -unconfineddomain }
299 keystore_data_file:dir_file_class_set
300 { create write setattr relabelfrom relabelto append unlink link rename };
301neverallow { appdomain -unconfineddomain }
302 systemkeys_data_file:dir_file_class_set
303 { create write setattr relabelfrom relabelto append unlink link rename };
304neverallow { appdomain -unconfineddomain }
305 wifi_data_file:dir_file_class_set
306 { create write setattr relabelfrom relabelto append unlink link rename };
307neverallow { appdomain -unconfineddomain }
308 dhcp_data_file:dir_file_class_set
309 { create write setattr relabelfrom relabelto append unlink link rename };
310
311# Access to factory files.
312neverallow { appdomain -unconfineddomain }
313 efs_file:dir_file_class_set { read write };
314
315# Write to various pseudo file systems.
Stephen Smalleydf8af762014-01-13 09:05:01 -0500316neverallow { appdomain -bluetooth -nfc -unconfineddomain }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400317 sysfs:dir_file_class_set write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400318neverallow { appdomain -unconfineddomain }
319 proc:dir_file_class_set write;
320
321# Access to syslog(2) or /proc/kmsg.
Nick Kralevich685e2f92014-05-28 13:48:52 -0700322neverallow { appdomain -system_app }
Nick Kralevichf821b5a2014-05-27 16:49:59 -0700323 kernel:system { syslog_mod syslog_console };
Stephen Smalley42fb8242014-06-11 07:10:09 -0400324neverallow { appdomain -system_app -shell }
Nick Kralevichf821b5a2014-05-27 16:49:59 -0700325 kernel:system syslog_read;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400326
327# Ability to perform any filesystem operation other than statfs(2).
328# i.e. no mount(2), unmount(2), etc.
329neverallow { appdomain -unconfineddomain } fs_type:filesystem ~getattr;
330
331# Ability to set system properties.
332neverallow { appdomain -system_app -radio -shell -bluetooth -unconfineddomain }
333 property_type:property_service set;