blob: 1aa6b2377cc234b9fdb976af32d3b46d92787d93 [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
134allow appdomain dalvikcache_profiles_data_file:file write;
135
Torne (Richard Coles)9786af22014-05-23 11:01:58 +0100136# Allow any app to read shared RELRO files.
137allow appdomain shared_relro_file:dir search;
138allow appdomain shared_relro_file:file r_file_perms;
139
Christopher Tate6f6c4252014-05-30 15:21:22 -0700140# Allow apps to read/execute installed binaries
141allow appdomain apk_data_file:file { rx_file_perms execmod };
142
Nick Kralevich6634a102013-07-12 18:45:56 -0700143###
Stephen Smalley59469372013-12-16 08:55:24 -0500144### CTS-specific rules
145###
146
147# For cts/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/RootProcessScanner.java.
148# Reads /proc/pid/status and statm entries to check that
149# no unexpected root processes are running.
150# Also for cts/tests/tests/security/src/android/security/cts/VoldExploitTest.java
151# Reads /proc/pid/cmdline of vold.
152allow appdomain domain:dir { open read search getattr };
153allow appdomain domain:{ file lnk_file } { open read getattr };
154
155# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
156# testRunAsHasCorrectCapabilities
157allow appdomain runas_exec:file getattr;
158# Others are either allowed elsewhere or not desired.
159
160# For cts/tests/tests/security/src/android/security/cts/SELinuxTest.java
161# Check SELinux policy and contexts.
162selinux_check_access(appdomain)
163selinux_check_context(appdomain)
164# Validate that each process is running in the correct security context.
165allow appdomain domain:process getattr;
166
Mark Salyzyn8ed750e2013-11-12 15:34:52 -0800167# logd access
168read_logd(appdomain)
169# application inherit logd write socket (urge is to deprecate this long term)
170allow appdomain zygote:unix_dgram_socket write;
171
Stephen Smalley59469372013-12-16 08:55:24 -0500172###
Nick Kralevich6634a102013-07-12 18:45:56 -0700173### Neverallow rules
174###
175### These are things that Android apps should NEVER be able to do
176###
177
178# Superuser capabilities.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400179# bluetooth requires net_admin.
180neverallow { appdomain -unconfineddomain -bluetooth } self:capability *;
Nick Kralevich6634a102013-07-12 18:45:56 -0700181neverallow { appdomain -unconfineddomain } self:capability2 *;
182
183# Block device access.
184neverallow { appdomain -unconfineddomain } dev_type:blk_file { read write };
185
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400186# Access to any of the following character devices.
187neverallow { appdomain -unconfineddomain } {
188 audio_device
189 camera_device
190 dm_device
191 radio_device
192 gps_device
193 rpmsg_device
194}:chr_file { read write };
195
196# Note: Try expanding list of app domains in the future.
Greg Hackmann70047892014-05-06 15:42:18 -0700197neverallow { untrusted_app isolated_app shell -unconfineddomain } {
198 adf_device
199 graphics_device
200}:chr_file { read write };
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400201
202neverallow { appdomain -nfc -unconfineddomain } nfc_device:chr_file
203 { read write };
204neverallow { appdomain -bluetooth -unconfineddomain } hci_attach_dev:chr_file
205 { read write };
206neverallow { appdomain -unconfineddomain } tee_device:chr_file { read write };
207
Nick Kralevich6634a102013-07-12 18:45:56 -0700208# Privileged netlink socket interfaces.
209neverallow { appdomain -unconfineddomain }
210 self:{
211 netlink_socket
212 netlink_firewall_socket
213 netlink_tcpdiag_socket
214 netlink_nflog_socket
215 netlink_xfrm_socket
Nick Kralevich6634a102013-07-12 18:45:56 -0700216 netlink_audit_socket
217 netlink_ip6fw_socket
218 netlink_dnrt_socket
219 netlink_kobject_uevent_socket
220 } *;
221
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400222# Sockets under /dev/socket that are not specifically typed.
223neverallow { appdomain -unconfineddomain } socket_device:sock_file write;
224
225# Unix domain sockets.
226neverallow { appdomain -unconfineddomain } adbd_socket:sock_file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400227neverallow { appdomain -unconfineddomain } installd_socket:sock_file write;
228neverallow { appdomain -bluetooth -radio -shell -system_app -unconfineddomain }
229 property_socket:sock_file write;
230neverallow { appdomain -radio -unconfineddomain } rild_socket:sock_file write;
231neverallow { appdomain -unconfineddomain } vold_socket:sock_file write;
232neverallow { appdomain -unconfineddomain } zygote_socket:sock_file write;
233
Nick Kralevich6634a102013-07-12 18:45:56 -0700234# ptrace access to non-app domains.
235neverallow { appdomain -unconfineddomain } { domain -appdomain }:process ptrace;
236
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400237# Write access to /proc/pid entries for any non-app domain.
Nick Kralevich73c5ea72013-10-25 16:53:37 -0700238neverallow { appdomain -unconfineddomain } { domain -appdomain }:file write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400239
240# signal access to non-app domains.
241# sigchld allowed for parent death notification.
242# signull allowed for kill(pid, 0) existence test.
243# All others prohibited.
244neverallow { appdomain -unconfineddomain } { domain -appdomain }:process
245 { sigkill sigstop signal };
246
Nick Kralevich6634a102013-07-12 18:45:56 -0700247# Transition to a non-app domain.
Stephen Smalley396015c2014-01-07 12:47:10 -0500248# Exception for the shell domain, can transition to runas, etc.
Stephen Smalley57085442013-09-30 08:47:54 -0400249neverallow { appdomain -shell -unconfineddomain } ~appdomain:process
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400250 { transition dyntransition };
251
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400252# Write to rootfs.
253neverallow { appdomain -unconfineddomain } rootfs:dir_file_class_set
254 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevich6634a102013-07-12 18:45:56 -0700255
256# Write to /system.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400257neverallow { appdomain -unconfineddomain } system_file:dir_file_class_set
258 { create write setattr relabelfrom relabelto append unlink link rename };
259
260# Write to entrypoint executables.
261neverallow { appdomain -unconfineddomain } exec_type:file
262 { create write setattr relabelfrom relabelto append unlink link rename };
Nick Kralevich6634a102013-07-12 18:45:56 -0700263
264# Write to system-owned parts of /data.
265# This is the default type for anything under /data not otherwise
266# specified in file_contexts. Define a different type for portions
267# that should be writable by apps.
268# Exception for system_app for Settings.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400269neverallow { appdomain -unconfineddomain -system_app }
270 system_data_file:dir_file_class_set
271 { create write setattr relabelfrom relabelto append unlink link rename };
272
273# Write to various other parts of /data.
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400274neverallow { appdomain -unconfineddomain } drm_data_file:dir_file_class_set
275 { create write setattr relabelfrom relabelto append unlink link rename };
276neverallow { appdomain -unconfineddomain } gps_data_file:dir_file_class_set
277 { create write setattr relabelfrom relabelto append unlink link rename };
278neverallow { appdomain -platform_app -unconfineddomain }
279 apk_data_file:dir_file_class_set
280 { create write setattr relabelfrom relabelto append unlink link rename };
281neverallow { appdomain -platform_app -unconfineddomain }
282 apk_tmp_file:dir_file_class_set
283 { create write setattr relabelfrom relabelto append unlink link rename };
284neverallow { appdomain -platform_app -unconfineddomain }
285 apk_private_data_file:dir_file_class_set
286 { create write setattr relabelfrom relabelto append unlink link rename };
287neverallow { appdomain -platform_app -unconfineddomain }
288 apk_private_tmp_file:dir_file_class_set
289 { create write setattr relabelfrom relabelto append unlink link rename };
290neverallow { appdomain -shell -unconfineddomain }
291 shell_data_file:dir_file_class_set
Nick Kralevich2e7a3012014-01-10 23:05:25 -0800292 { create setattr relabelfrom relabelto append unlink link rename };
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400293neverallow { appdomain -bluetooth -unconfineddomain }
294 bluetooth_data_file:dir_file_class_set
295 { create write setattr relabelfrom relabelto append unlink link rename };
296neverallow { appdomain -unconfineddomain }
297 keystore_data_file:dir_file_class_set
298 { create write setattr relabelfrom relabelto append unlink link rename };
299neverallow { appdomain -unconfineddomain }
300 systemkeys_data_file:dir_file_class_set
301 { create write setattr relabelfrom relabelto append unlink link rename };
302neverallow { appdomain -unconfineddomain }
303 wifi_data_file:dir_file_class_set
304 { create write setattr relabelfrom relabelto append unlink link rename };
305neverallow { appdomain -unconfineddomain }
306 dhcp_data_file:dir_file_class_set
307 { create write setattr relabelfrom relabelto append unlink link rename };
308
309# Access to factory files.
310neverallow { appdomain -unconfineddomain }
311 efs_file:dir_file_class_set { read write };
312
313# Write to various pseudo file systems.
Stephen Smalleydf8af762014-01-13 09:05:01 -0500314neverallow { appdomain -bluetooth -nfc -unconfineddomain }
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400315 sysfs:dir_file_class_set write;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400316neverallow { appdomain -unconfineddomain }
317 proc:dir_file_class_set write;
318
319# Access to syslog(2) or /proc/kmsg.
Nick Kralevich685e2f92014-05-28 13:48:52 -0700320neverallow { appdomain -system_app }
Nick Kralevichf821b5a2014-05-27 16:49:59 -0700321 kernel:system { syslog_mod syslog_console };
Nick Kralevich685e2f92014-05-28 13:48:52 -0700322neverallow { appdomain -system_app -shelldomain }
Nick Kralevichf821b5a2014-05-27 16:49:59 -0700323 kernel:system syslog_read;
Stephen Smalley2a273ad2013-09-27 10:55:59 -0400324
325# Ability to perform any filesystem operation other than statfs(2).
326# i.e. no mount(2), unmount(2), etc.
327neverallow { appdomain -unconfineddomain } fs_type:filesystem ~getattr;
328
329# Ability to set system properties.
330neverallow { appdomain -system_app -radio -shell -bluetooth -unconfineddomain }
331 property_type:property_service set;