blob: b0d7c95d66e69dfa5716932062271476366c0dce [file] [log] [blame]
Nick Kralevichdbd28d92013-06-27 15:11:02 -07001# Rules for all domains.
2
3# Allow reaping by init.
4allow domain init:process sigchld;
5
6# Read access to properties mapping.
7allow domain kernel:fd use;
8allow domain tmpfs:file { read getattr };
9
10# Search /storage/emulated tmpfs mount.
11allow domain tmpfs:dir r_dir_perms;
12
Nick Kralevichdbd28d92013-06-27 15:11:02 -070013# Intra-domain accesses.
Stephen Smalley356f4be2014-05-23 11:26:19 -040014allow domain self:process ~{ execmem execstack execheap ptrace setexec setfscreate setcurrent setkeycreate setsockcreate };
Nick Kralevichdbd28d92013-06-27 15:11:02 -070015allow domain self:fd use;
16allow domain self:dir r_dir_perms;
17allow domain self:lnk_file r_file_perms;
18allow domain self:{ fifo_file file } rw_file_perms;
Stephen Smalley16011322014-02-24 15:06:11 -050019allow domain self:unix_dgram_socket { create_socket_perms sendto };
20allow domain self:unix_stream_socket { create_stream_socket_perms connectto };
Nick Kralevichdbd28d92013-06-27 15:11:02 -070021
22# Inherit or receive open files from others.
23allow domain init:fd use;
Alex Klyubin1fdee112013-09-13 15:59:04 -070024allow domain system_server:fd use;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070025
26# Connect to adbd and use a socket transferred from it.
Stephen Smalleyc4021ce2014-01-03 14:38:41 -050027# This is used for e.g. adb backup/restore.
Nick Kralevichdbd28d92013-06-27 15:11:02 -070028allow domain adbd:unix_stream_socket connectto;
29allow domain adbd:fd use;
Stephen Smalleyc4021ce2014-01-03 14:38:41 -050030allow domain adbd:unix_stream_socket { getattr getopt read write shutdown };
Nick Kralevichdbd28d92013-06-27 15:11:02 -070031
Nick Kralevich7d0f9552014-01-18 18:07:06 -080032userdebug_or_eng(`
33 # Same as adbd rules above, except allow su to do the same thing
34 allow domain su:unix_stream_socket connectto;
35 allow domain su:fd use;
36 allow domain su:unix_stream_socket { getattr getopt read write shutdown };
37
Stephen Smalley3dad7b62014-03-05 09:50:08 -050038 binder_call(domain, su)
39
Nick Kralevich7d0f9552014-01-18 18:07:06 -080040 # Running something like "pm dump com.android.bluetooth" requires
41 # fifo writes
42 allow domain su:fifo_file { write getattr };
43
44 # allow "gdbserver --attach" to work for su.
45 allow domain su:process sigchld;
46')
47
Nick Kralevich5919d1c2013-07-15 11:41:24 -070048###
49### Talk to debuggerd.
50###
Nick Kralevichdbd28d92013-06-27 15:11:02 -070051allow domain debuggerd:process sigchld;
52allow domain debuggerd:unix_stream_socket connectto;
53
54# Root fs.
55allow domain rootfs:dir r_dir_perms;
Nick Kralevich6634a102013-07-12 18:45:56 -070056allow domain rootfs:file r_file_perms;
Stephen Smalley712ca0a2013-10-23 13:25:53 -040057allow domain rootfs:lnk_file r_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070058
59# Device accesses.
60allow domain device:dir search;
Stephen Smalley712ca0a2013-10-23 13:25:53 -040061allow domain dev_type:lnk_file r_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070062allow domain devpts:dir search;
63allow domain device:file read;
Robert Craig20feb752014-03-06 10:16:53 -050064allow domain socket_device:dir r_dir_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070065allow domain owntty_device:chr_file rw_file_perms;
66allow domain null_device:chr_file rw_file_perms;
Nick Kralevichf007d032014-05-20 06:01:55 -070067allow domain zero_device:chr_file rw_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070068allow domain ashmem_device:chr_file rw_file_perms;
69allow domain binder_device:chr_file rw_file_perms;
70allow domain ptmx_device:chr_file rw_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070071allow domain log_device:dir search;
72allow domain log_device:chr_file rw_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070073allow domain alarm_device:chr_file r_file_perms;
Alex Klyubina2477052013-09-10 11:13:15 -070074allow domain urandom_device:chr_file rw_file_perms;
75allow domain random_device:chr_file rw_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070076allow domain properties_device:file r_file_perms;
77
Mark Salyzyn8ed750e2013-11-12 15:34:52 -080078# logd access
79write_logd(domain)
80
Nick Kralevichdbd28d92013-06-27 15:11:02 -070081# Filesystem accesses.
82allow domain fs_type:filesystem getattr;
83allow domain fs_type:dir getattr;
84
85# System file accesses.
86allow domain system_file:dir r_dir_perms;
87allow domain system_file:file r_file_perms;
88allow domain system_file:file execute;
Stephen Smalley712ca0a2013-10-23 13:25:53 -040089allow domain system_file:lnk_file r_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070090
91# Read files already opened under /data.
92allow domain system_data_file:dir { search getattr };
93allow domain system_data_file:file { getattr read };
Stephen Smalley712ca0a2013-10-23 13:25:53 -040094allow domain system_data_file:lnk_file r_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -070095
96# Read apk files under /data/app.
Geremy Condra81560732013-08-30 13:02:30 -070097allow domain apk_data_file:dir { getattr search };
Nick Kralevichdbd28d92013-06-27 15:11:02 -070098allow domain apk_data_file:file r_file_perms;
99
100# Read /data/dalvik-cache.
101allow domain dalvikcache_data_file:dir { search getattr };
102allow domain dalvikcache_data_file:file r_file_perms;
Stephen Smalley19c50902014-04-09 14:24:33 -0400103allow domain dalvikcache_profiles_data_file:dir { search getattr };
104allow domain dalvikcache_profiles_data_file:file r_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700105
106# Read already opened /cache files.
107allow domain cache_file:dir r_dir_perms;
108allow domain cache_file:file { getattr read };
Stephen Smalley712ca0a2013-10-23 13:25:53 -0400109allow domain cache_file:lnk_file r_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700110
Nick Kralevich7466f9b2013-12-12 15:32:42 -0800111# Read timezone related information
112r_dir_file(domain, zoneinfo_data_file)
113
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700114# For /acct/uid/*/tasks.
115allow domain cgroup:dir { search write };
116allow domain cgroup:file w_file_perms;
117
118#Allow access to ion memory allocation device
119allow domain ion_device:chr_file rw_file_perms;
120
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700121# Read access to pseudo filesystems.
122r_dir_file(domain, proc)
123r_dir_file(domain, sysfs)
Nick Kralevich967f39a2013-10-30 14:12:21 -0700124r_dir_file(domain, sysfs_devices_system_cpu)
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700125r_dir_file(domain, inotify)
126r_dir_file(domain, cgroup)
Robert Craig529fcbe2014-01-07 13:46:56 -0500127r_dir_file(domain, proc_net)
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700128
129# debugfs access
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700130allow domain debugfs:dir r_dir_perms;
Nick Kralevich8758cc52013-07-11 11:30:20 -0700131allow domain debugfs:file w_file_perms;
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700132
Stephen Smalley712ca0a2013-10-23 13:25:53 -0400133# Get SELinux enforcing status.
134selinux_getenforce(domain)
135
Stephen Smalleyf9268172014-02-24 11:35:39 -0500136# /data/security files
Nick Kralevichdbd28d92013-06-27 15:11:02 -0700137allow domain security_file:dir { search getattr };
138allow domain security_file:file getattr;
Stephen Smalleyf9268172014-02-24 11:35:39 -0500139allow domain security_file:lnk_file r_file_perms;
Nick Kralevich0c9708b2013-07-10 14:46:05 -0700140
Robert Craig48b18832014-02-04 11:36:41 -0500141# World readable asec image contents
142allow domain asec_public_file:file r_file_perms;
143allow domain { asec_public_file asec_apk_file }:dir r_dir_perms;
144
Nick Kralevich5ce079b2014-05-16 17:45:01 -0700145######## Backwards compatibility - Unlabeled files ############
146
147# Revert to DAC rules when looking at unlabeled files. Over time, the number
148# of unlabeled files should decrease.
149# TODO: delete these rules in the future.
150#
151allow domain unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
152allow domain unlabeled:dir { create_dir_perms relabelfrom };
Nick Kralevich7a186b32014-05-19 16:33:51 -0700153auditallow { domain -init -installd } unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
154auditallow { domain -init -kernel -installd } unlabeled:dir { create_dir_perms relabelfrom };
Nick Kralevich5ce079b2014-05-16 17:45:01 -0700155auditallow kernel unlabeled:dir ~search;
Nick Kralevich7a186b32014-05-19 16:33:51 -0700156auditallow installd unlabeled:dir ~{ getattr search relabelfrom };
157auditallow installd unlabeled:notdevfile_class_set ~{ getattr relabelfrom };
Nick Kralevich5ce079b2014-05-16 17:45:01 -0700158
Nick Kralevich26371982013-07-15 17:10:35 -0700159###
160### neverallow rules
161###
162
Stephen Smalley5487ca02014-02-10 16:31:04 -0500163# Limit ability to ptrace or read sensitive /proc/pid files of processes
164# with other UIDs to these whitelisted domains.
165neverallow { domain -debuggerd -vold -dumpstate -system_server } self:capability sys_ptrace;
166
167# Limit device node creation and raw I/O to these whitelisted domains.
Nick Kralevich96eeb1e2014-02-19 13:33:32 -0800168neverallow { domain -kernel -init -recovery -ueventd -watchdogd -healthd -vold -uncrypt } self:capability { sys_rawio mknod };
Stephen Smalley5487ca02014-02-10 16:31:04 -0500169
Stephen Smalley7ffb9972014-05-14 14:05:49 -0400170# No process can map low memory (< CONFIG_LSM_MMAP_MIN_ADDR).
171neverallow domain self:memprotect mmap_zero;
172
Stephen Smalley5487ca02014-02-10 16:31:04 -0500173# No domain needs mac_override as it is unused by SELinux.
Stephen Smalley04ee5df2014-01-30 13:23:08 -0500174neverallow domain self:capability2 mac_override;
Stephen Smalley5487ca02014-02-10 16:31:04 -0500175
176# Only recovery needs mac_admin to set contexts not defined in current policy.
Stephen Smalley04ee5df2014-01-30 13:23:08 -0500177neverallow { domain -recovery } self:capability2 mac_admin;
178
Stephen Smalleyfea6e662013-12-06 08:05:53 -0500179# Only init should be able to load SELinux policies.
180# The first load technically occurs while still in the kernel domain,
181# but this does not trigger a denial since there is no policy yet.
182# Policy reload requires allowing this to the init domain.
183neverallow { domain -init } kernel:security load_policy;
184
185# Only init prior to switching context should be able to set enforcing mode.
186# init starts in kernel domain and switches to init domain via setcon in
187# the init.rc, so the setenforce occurs while still in kernel. After
188# switching domains, there is never any need to setenforce again by init.
Nick Kralevichabae8a92014-05-12 14:32:59 -0700189neverallow domain kernel:security setenforce;
190neverallow { domain -kernel } kernel:security setcheckreqprot;
Stephen Smalley01301542013-09-27 10:38:14 -0400191
Stephen Smalley853ffaa2014-03-06 13:02:50 -0500192# No booleans in AOSP policy, so no need to ever set them.
193neverallow domain kernel:security setbool;
194
195# Adjusting the AVC cache threshold.
196# Not presently allowed to anything in policy, but possibly something
197# that could be set from init.rc.
198neverallow { domain -init } kernel:security setsecparam;
199
William Roberts85c5fc22013-10-06 15:36:11 -0400200# Only init, ueventd and system_server should be able to access HW RNG
201neverallow { domain -init -system_server -ueventd -unconfineddomain } hw_random_device:chr_file *;
Alex Klyubin8d688312013-10-03 13:35:56 -0700202
Stephen Smalley01301542013-09-27 10:38:14 -0400203# Ensure that all entrypoint executables are in exec_type.
204neverallow domain { file_type -exec_type }:file entrypoint;
Geremy Condraddf98fa2013-10-31 11:17:23 -0700205
206# Ensure that nothing in userspace can access /dev/mem or /dev/kmem
207neverallow { domain -kernel -ueventd -init } kmem_device:chr_file *;
208neverallow domain kmem_device:chr_file ~{ create relabelto unlink setattr };
Stephen Smalley7adb9992013-12-06 09:31:40 -0500209
210# Only init should be able to configure kernel usermodehelpers or
211# security-sensitive proc settings.
212neverallow { domain -init } usermodehelper:file { append write };
213neverallow { domain -init } proc_security:file { append write };
Stephen Smalley95e08422013-12-09 12:49:47 -0500214
215# No domain should be allowed to ptrace init.
216neverallow domain init:process ptrace;
Nick Kralevicha730e502014-01-03 20:44:07 -0800217
218# Init can't receive binder calls. If this neverallow rule is being
219# triggered, it's probably due to a service with no SELinux domain.
220neverallow domain init:binder call;
William Robertsd0919ec2014-01-30 09:10:28 -0800221
222# Don't allow raw read/write/open access to block_device
223# Rather force a relabel to a more specific type
Nick Kralevich96eeb1e2014-02-19 13:33:32 -0800224neverallow { domain -kernel -init -recovery -vold -uncrypt } block_device:blk_file { open read write };
William Robertsa637b2f2014-01-30 09:15:45 -0800225
226# Don't allow raw read/write/open access to generic devices.
227# Rather force a relabel to a more specific type.
228# ueventd is exempt from this, as its managing these devices.
229neverallow { domain -unconfineddomain -ueventd } device:chr_file { open read write };
Stephen Smalleyb081cc12014-02-10 13:29:38 -0500230
231# Limit what domains can mount filesystems or change their mount flags.
232# sdcard_type / vfat is exempt as a larger set of domains need
233# this capability, including device-specific domains.
234neverallow { domain -kernel -init -recovery -vold -zygote } { fs_type -sdcard_type }:filesystem { mount remount relabelfrom relabelto };
Nick Kralevich629fbc92014-05-23 16:08:23 -0700235
236#
237# Assert that, to the extent possible, we're not loading executable content from
238# outside the /system partition except for a few whitelisted domains.
239#
240neverallow {
241 domain
242 -appdomain
243 -dumpstate
244 -shelldomain
245 userdebug_or_eng(`-su')
246 -system_server
247 -zygote
248} { file_type -system_file -exec_type }:file execute;