domain.te revision 59c23d78c894198f39d9af563f17c05fb266ec3e
1dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Rules for all domains.
2dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
3dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Allow reaping by init.
4dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain init:process sigchld;
5dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
6dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Read access to properties mapping.
7dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain kernel:fd use;
8dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain tmpfs:file { read getattr };
9301555e6f3445cda4ccec0240c37848a1d3b9d0edcashmanallow domain tmpfs:lnk_file { read getattr };
10dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
11dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Search /storage/emulated tmpfs mount.
12dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain tmpfs:dir r_dir_perms;
13dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
14dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Intra-domain accesses.
15bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalleyallow domain self:process {
16bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    fork
17bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    sigchld
18bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    sigkill
19bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    sigstop
20bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    signull
21bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    signal
22bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getsched
23bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setsched
24bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getsession
25bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getpgid
26bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setpgid
27bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getcap
28bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setcap
29bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getattr
30bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setrlimit
31bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley};
32dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain self:fd use;
33dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain self:dir r_dir_perms;
34dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain self:lnk_file r_file_perms;
35dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain self:{ fifo_file file } rw_file_perms;
361601132086b054adc70e7f8f38ed24574c90bc37Stephen Smalleyallow domain self:unix_dgram_socket { create_socket_perms sendto };
371601132086b054adc70e7f8f38ed24574c90bc37Stephen Smalleyallow domain self:unix_stream_socket { create_stream_socket_perms connectto };
38dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
39dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Inherit or receive open files from others.
40dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain init:fd use;
411fdee11df2552e29da0c48e3432f26f7a93e3bffAlex Klyubinallow domain system_server:fd use;
42dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
43dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Connect to adbd and use a socket transferred from it.
44c4021cebcf19a4c3f95395f7715a3cc9ed2b44c0Stephen Smalley# This is used for e.g. adb backup/restore.
45dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain adbd:unix_stream_socket connectto;
46dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain adbd:fd use;
47f4d39ca123e58f12947fedf231e051a06ba51752Nick Kralevichallow domain adbd:unix_stream_socket { getattr getopt ioctl read write shutdown };
48dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
497d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevichuserdebug_or_eng(`
507d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # Same as adbd rules above, except allow su to do the same thing
517d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:unix_stream_socket connectto;
527d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:fd use;
537d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:unix_stream_socket { getattr getopt read write shutdown };
547d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich
5565feafce6c72ded001619e4f6b975de095941acdNick Kralevich  binder_call({ domain -init }, su)
563dad7b611a448fa43a678ff760c23a00f387947eStephen Smalley
577d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # Running something like "pm dump com.android.bluetooth" requires
587d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # fifo writes
597d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:fifo_file { write getattr };
607d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich
617d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # allow "gdbserver --attach" to work for su.
627d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:process sigchld;
63ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich
64ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich  # Allow writing coredumps to /cores/*
65ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich  allow domain coredump_file:file create_file_perms;
66ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich  allow domain coredump_file:dir ra_dir_perms;
677d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich')
687d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich
695919d1c86a2a1fea52f840ab30709048bd63f1f5Nick Kralevich###
705919d1c86a2a1fea52f840ab30709048bd63f1f5Nick Kralevich### Talk to debuggerd.
715919d1c86a2a1fea52f840ab30709048bd63f1f5Nick Kralevich###
72dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain debuggerd:process sigchld;
73dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain debuggerd:unix_stream_socket connectto;
74dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
75dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Root fs.
76dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain rootfs:dir r_dir_perms;
776634a1080e6617854d0b29bc65bb1c852ad3d5b6Nick Kralevichallow domain rootfs:file r_file_perms;
78712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalleyallow domain rootfs:lnk_file r_file_perms;
79dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
80dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Device accesses.
81dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain device:dir search;
82712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalleyallow domain dev_type:lnk_file r_file_perms;
83dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain devpts:dir search;
84dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain device:file read;
8520feb75b572a21a7a376d6780cc5c1d636cda610Robert Craigallow domain socket_device:dir r_dir_perms;
86dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain owntty_device:chr_file rw_file_perms;
87dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain null_device:chr_file rw_file_perms;
88f007d03628f98a40c01c12ad105ca6be14fd3c78Nick Kralevichallow domain zero_device:chr_file rw_file_perms;
89dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain ashmem_device:chr_file rw_file_perms;
90dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain binder_device:chr_file rw_file_perms;
91dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain ptmx_device:chr_file rw_file_perms;
92dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain alarm_device:chr_file r_file_perms;
93a2477056ae6a702e7e71b671cd0c47afc1c7da8aAlex Klyubinallow domain urandom_device:chr_file rw_file_perms;
94a2477056ae6a702e7e71b671cd0c47afc1c7da8aAlex Klyubinallow domain random_device:chr_file rw_file_perms;
95dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain properties_device:file r_file_perms;
968138401d57520711bbf801e3f5f6dc029851fe46Paul Lawrenceallow domain init:key search;
9713dec5fa5b860871afea47f85842706095e40527Paul Lawrenceallow domain vold:key search;
98dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
998ed750e9731e6e3a21785e91e9b1cf7390c16738Mark Salyzyn# logd access
1008ed750e9731e6e3a21785e91e9b1cf7390c16738Mark Salyzynwrite_logd(domain)
1018ed750e9731e6e3a21785e91e9b1cf7390c16738Mark Salyzyn
102dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Filesystem accesses.
103dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain fs_type:filesystem getattr;
104dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain fs_type:dir getattr;
105dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
106dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# System file accesses.
107dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain system_file:dir r_dir_perms;
108dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain system_file:file r_file_perms;
109dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain system_file:file execute;
110712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalleyallow domain system_file:lnk_file r_file_perms;
111dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
112dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Read files already opened under /data.
113dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain system_data_file:dir { search getattr };
114dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain system_data_file:file { getattr read };
115712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalleyallow domain system_data_file:lnk_file r_file_perms;
116dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
117dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Read apk files under /data/app.
11881560733a47633036133ce548bf638bc3d91f5cfGeremy Condraallow domain apk_data_file:dir { getattr search };
119dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain apk_data_file:file r_file_perms;
1206f6c425563f4faa4e1e12bf430c32d0b81a78f64Christopher Tateallow domain apk_data_file:lnk_file r_file_perms;
121dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
122dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Read /data/dalvik-cache.
123dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain dalvikcache_data_file:dir { search getattr };
124dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain dalvikcache_data_file:file r_file_perms;
125dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
126dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Read already opened /cache files.
127dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain cache_file:dir r_dir_perms;
128dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain cache_file:file { getattr read };
129712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalleyallow domain cache_file:lnk_file r_file_perms;
130dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
1317466f9b69341e3d86b0242d8ad18ae98d22f05a2Nick Kralevich# Read timezone related information
1327466f9b69341e3d86b0242d8ad18ae98d22f05a2Nick Kralevichr_dir_file(domain, zoneinfo_data_file)
1337466f9b69341e3d86b0242d8ad18ae98d22f05a2Nick Kralevich
134dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# For /acct/uid/*/tasks.
135dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain cgroup:dir { search write };
136dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain cgroup:file w_file_perms;
137dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
138dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich#Allow access to ion memory allocation device
139dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain ion_device:chr_file rw_file_perms;
140dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
141dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Read access to pseudo filesystems.
142dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichr_dir_file(domain, proc)
143dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichr_dir_file(domain, sysfs)
144967f39a6e88c60b5f65a37397d6619197a1d0514Nick Kralevichr_dir_file(domain, sysfs_devices_system_cpu)
145dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichr_dir_file(domain, inotify)
146dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichr_dir_file(domain, cgroup)
1475cf3994d8ab039f9ba47164ef9d13e2ddb5e7acdNick Kralevichr_dir_file(domain, proc_net)
1482de02877a30e73bdf30fb2bf9cc4957f9ddbf996Nick Kralevichallow domain proc_cpuinfo:file r_file_perms;
149dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
150dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# debugfs access
151dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain debugfs:dir r_dir_perms;
1528758cc5f8b341352e553e62989e7eab57b094e1dNick Kralevichallow domain debugfs:file w_file_perms;
153dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
154712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalley# Get SELinux enforcing status.
15500b180dfb8195fa559f45e812c9c2a82bdbd9c40Stephen Smalleyallow domain selinuxfs:dir r_dir_perms;
15600b180dfb8195fa559f45e812c9c2a82bdbd9c40Stephen Smalleyallow domain selinuxfs:file r_file_perms;
157712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalley
158f926817875dfabc7698013bead30f5aaf7867bdfStephen Smalley# /data/security files
159dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain security_file:dir { search getattr };
160dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain security_file:file getattr;
161f926817875dfabc7698013bead30f5aaf7867bdfStephen Smalleyallow domain security_file:lnk_file r_file_perms;
1620c9708b2af4ea345277a47ae7bc1ce890e90d2bcNick Kralevich
16348b18832c476f0bd8fcb8ee3e308258392f36aafRobert Craig# World readable asec image contents
16448b18832c476f0bd8fcb8ee3e308258392f36aafRobert Craigallow domain asec_public_file:file r_file_perms;
16548b18832c476f0bd8fcb8ee3e308258392f36aafRobert Craigallow domain { asec_public_file asec_apk_file }:dir r_dir_perms;
16648b18832c476f0bd8fcb8ee3e308258392f36aafRobert Craig
1672637198f92d5d9c65262e42d78123d216889d546Nick Kralevich###
1682637198f92d5d9c65262e42d78123d216889d546Nick Kralevich### neverallow rules
1692637198f92d5d9c65262e42d78123d216889d546Nick Kralevich###
1702637198f92d5d9c65262e42d78123d216889d546Nick Kralevich
1710d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalley# Do not allow any domain other than init or recovery to create unlabeled files.
1720d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalleyneverallow { domain -init -recovery } unlabeled:dir_file_class_set create;
173cb23ca92f303fca6bb0f48a1beb384e220afe39eStephen Smalley
1745487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# Limit ability to ptrace or read sensitive /proc/pid files of processes
1755487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# with other UIDs to these whitelisted domains.
176a191398812eb35be613541b3822a363919da8586Nick Kralevichneverallow {
177a191398812eb35be613541b3822a363919da8586Nick Kralevich  domain
178a191398812eb35be613541b3822a363919da8586Nick Kralevich  -debuggerd
179a191398812eb35be613541b3822a363919da8586Nick Kralevich  -vold
180a191398812eb35be613541b3822a363919da8586Nick Kralevich  -dumpstate
181a191398812eb35be613541b3822a363919da8586Nick Kralevich  -system_server
18234a468fad2c0b624b0cf383671384d0452dd83e6Dehao Chen  userdebug_or_eng(`-perfprofd')
183a191398812eb35be613541b3822a363919da8586Nick Kralevich} self:capability sys_ptrace;
1845487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley
185b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevich# Limit device node creation to these whitelisted domains.
186e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevichneverallow {
187e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  domain
188e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -kernel
189e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -init
190e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -ueventd
191e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -vold
1929c7570ef799616e683471ebdb22ee34a424a0aa0Jeff Vander Stoep  -recovery
193e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich} self:capability mknod;
194b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevich
195b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevich# Limit raw I/O to these whitelisted domains.
196b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevichneverallow { domain -kernel -init -recovery -ueventd -watchdogd -healthd -vold -uncrypt -tee } self:capability sys_rawio;
1975487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley
1987ffb9972076bfbd2abab1df6b4d759d14d55af96Stephen Smalley# No process can map low memory (< CONFIG_LSM_MMAP_MIN_ADDR).
1997ffb9972076bfbd2abab1df6b4d759d14d55af96Stephen Smalleyneverallow domain self:memprotect mmap_zero;
2007ffb9972076bfbd2abab1df6b4d759d14d55af96Stephen Smalley
2015487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# No domain needs mac_override as it is unused by SELinux.
20204ee5dfb80491f8493fedcd099bd4551c9503c83Stephen Smalleyneverallow domain self:capability2 mac_override;
2035487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley
2045487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# Only recovery needs mac_admin to set contexts not defined in current policy.
20504ee5dfb80491f8493fedcd099bd4551c9503c83Stephen Smalleyneverallow { domain -recovery } self:capability2 mac_admin;
20604ee5dfb80491f8493fedcd099bd4551c9503c83Stephen Smalley
2074abd409af0e7d7fb908e5f04fa1ed946e2996dceNick Kralevich# Only init should be able to load SELinux policies.
208fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# The first load technically occurs while still in the kernel domain,
209fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# but this does not trigger a denial since there is no policy yet.
2104abd409af0e7d7fb908e5f04fa1ed946e2996dceNick Kralevich# Policy reload requires allowing this to the init domain.
2114abd409af0e7d7fb908e5f04fa1ed946e2996dceNick Kralevichneverallow { domain -init } kernel:security load_policy;
212fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley
2133235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# Only init and the system_server can set selinux.reload_policy 1
2143235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# to trigger a policy reload.
2153235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalleyneverallow { domain -init -system_server } security_prop:property_service set;
2163235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley
2173235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# Only init and system_server can write to /data/security, where runtime
2183235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# policy updates live.
2193235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# Only init can relabel /data/security (for init.rc restorecon_recursive /data).
2203235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalleyneverallow { domain -init } security_file:{ dir file lnk_file } { relabelfrom relabelto };
2213235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# Only init and system_server can create/setattr directories with this type.
2223235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# init is for init.rc mkdir /data/security.
2233235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# system_server is for creating subdirectories under /data/security.
2243235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalleyneverallow { domain -init -system_server } security_file:dir { create setattr };
2253235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley# Only system_server can create subdirectories and files under /data/security.
2263235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalleyneverallow { domain -system_server } security_file:dir { rename write add_name remove_name rmdir };
2273235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalleyneverallow { domain -system_server } security_file:file { create setattr write append unlink link rename };
2283235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalleyneverallow { domain -system_server } security_file:lnk_file { create setattr unlink rename };
2293235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley
230fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# Only init prior to switching context should be able to set enforcing mode.
231fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# init starts in kernel domain and switches to init domain via setcon in
232fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# the init.rc, so the setenforce occurs while still in kernel. After
233fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# switching domains, there is never any need to setenforce again by init.
234abae8a9b586c98cf3e7bd08e63473a5ce99ccd27Nick Kralevichneverallow domain kernel:security setenforce;
235abae8a9b586c98cf3e7bd08e63473a5ce99ccd27Nick Kralevichneverallow { domain -kernel } kernel:security setcheckreqprot;
2360130154985aa5042b9e40c45fe60492e40004761Stephen Smalley
237853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# No booleans in AOSP policy, so no need to ever set them.
238853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalleyneverallow domain kernel:security setbool;
239853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley
240853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# Adjusting the AVC cache threshold.
241853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# Not presently allowed to anything in policy, but possibly something
242853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# that could be set from init.rc.
243853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalleyneverallow { domain -init } kernel:security setsecparam;
244853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley
24585c5fc21c8a6259ec74686d62cf2c9a3fe01a56eWilliam Roberts# Only init, ueventd and system_server should be able to access HW RNG
2460d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalleyneverallow { domain -init -system_server -ueventd } hw_random_device:chr_file *;
2478d688315aeb053eadc2606badbe4ce52899bb694Alex Klyubin
2480130154985aa5042b9e40c45fe60492e40004761Stephen Smalley# Ensure that all entrypoint executables are in exec_type.
2490130154985aa5042b9e40c45fe60492e40004761Stephen Smalleyneverallow domain { file_type -exec_type }:file entrypoint;
250ddf98fa8cf11000f91329945abc23ee791adfe69Geremy Condra
251ddf98fa8cf11000f91329945abc23ee791adfe69Geremy Condra# Ensure that nothing in userspace can access /dev/mem or /dev/kmem
252ddf98fa8cf11000f91329945abc23ee791adfe69Geremy Condraneverallow { domain -kernel -ueventd -init } kmem_device:chr_file *;
253ddf98fa8cf11000f91329945abc23ee791adfe69Geremy Condraneverallow domain kmem_device:chr_file ~{ create relabelto unlink setattr };
2547adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalley
2557adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalley# Only init should be able to configure kernel usermodehelpers or
2567adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalley# security-sensitive proc settings.
2577adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalleyneverallow { domain -init } usermodehelper:file { append write };
2587adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalleyneverallow { domain -init } proc_security:file { append write };
25995e0842e341352af16bed4055ccf67878c322985Stephen Smalley
26095e0842e341352af16bed4055ccf67878c322985Stephen Smalley# No domain should be allowed to ptrace init.
26195e0842e341352af16bed4055ccf67878c322985Stephen Smalleyneverallow domain init:process ptrace;
262a730e50bd93cd058b271ce3a4affcc6ac75da58bNick Kralevich
26365feafce6c72ded001619e4f6b975de095941acdNick Kralevich# Init can't do anything with binder calls. If this neverallow rule is being
264a730e50bd93cd058b271ce3a4affcc6ac75da58bNick Kralevich# triggered, it's probably due to a service with no SELinux domain.
26565feafce6c72ded001619e4f6b975de095941acdNick Kralevichneverallow domain init:binder *;
266d0919ec25361ffeda3aa44cc2ecaf875f99784c3William Roberts
267d0919ec25361ffeda3aa44cc2ecaf875f99784c3William Roberts# Don't allow raw read/write/open access to block_device
268d0919ec25361ffeda3aa44cc2ecaf875f99784c3William Roberts# Rather force a relabel to a more specific type
2697e86e19d587f3922ece9ac52bba0fdf64561a4deNick Kralevichneverallow { domain -kernel -init -recovery -uncrypt } block_device:blk_file { open read write };
270a637b2f21eda997f6d1bcb8f2600a5ee3195785dWilliam Roberts
271a637b2f21eda997f6d1bcb8f2600a5ee3195785dWilliam Roberts# Don't allow raw read/write/open access to generic devices.
272a637b2f21eda997f6d1bcb8f2600a5ee3195785dWilliam Roberts# Rather force a relabel to a more specific type.
2730d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalley# init is exempt from this as there are character devices that only it uses.
2740d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalley# ueventd is exempt from this, as it is managing these devices.
2757ceb4cce34d3ce88f462820755e1e4829f0e0890Nick Kralevichneverallow { domain -init -ueventd } device:chr_file { open read write };
276b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley
277b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley# Limit what domains can mount filesystems or change their mount flags.
278b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley# sdcard_type / vfat is exempt as a larger set of domains need
279b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley# this capability, including device-specific domains.
280b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalleyneverallow { domain -kernel -init -recovery -vold -zygote } { fs_type -sdcard_type }:filesystem { mount remount relabelfrom relabelto };
281629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich
282629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich#
283629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich# Assert that, to the extent possible, we're not loading executable content from
2844644ac483667befac441bb541733e489d902bacfStephen Smalley# outside the rootfs or /system partition except for a few whitelisted domains.
285629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich#
286629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevichneverallow {
287629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    domain
288629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -appdomain
289629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -dumpstate
29042fb824ca9f3e46b4419f05083f2694ac67a8229Stephen Smalley    -shell
291629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    userdebug_or_eng(`-su')
292629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -system_server
293629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -zygote
294629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich} { file_type -system_file -exec_type }:file execute;
2954644ac483667befac441bb541733e489d902bacfStephen Smalleyneverallow {
2964644ac483667befac441bb541733e489d902bacfStephen Smalley    domain
2974644ac483667befac441bb541733e489d902bacfStephen Smalley    -appdomain # for oemfs
2984644ac483667befac441bb541733e489d902bacfStephen Smalley    -recovery # for /tmp/update_binary in tmpfs
2994644ac483667befac441bb541733e489d902bacfStephen Smalley} { fs_type -rootfs }:file execute;
3006c30016136b8ad0bc52a14fb50c6ddd449811cdeWilliam Roberts# Files from cache should never be executed
3016c30016136b8ad0bc52a14fb50c6ddd449811cdeWilliam Robertsneverallow domain { cache_file cache_backup_file }:file execute;
302ad0d0fc722d04e465ce2b0bfd2f8e04714c75391Stephen Smalley
3037028bdccd5b3e91928d345990587738212973f1dWilliam Roberts# Protect most domains from executing arbitrary content from /data.
3047028bdccd5b3e91928d345990587738212973f1dWilliam Robertsneverallow {
3057028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  domain
3067028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -untrusted_app
3077028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -shell
3087028bdccd5b3e91928d345990587738212973f1dWilliam Roberts} {
3097028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  data_file_type
3107028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -dalvikcache_data_file
3117028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -system_data_file # shared libs in apks
3127028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -apk_data_file
3137028bdccd5b3e91928d345990587738212973f1dWilliam Roberts}:file no_x_file_perms;
3147028bdccd5b3e91928d345990587738212973f1dWilliam Roberts
315ad0d0fc722d04e465ce2b0bfd2f8e04714c75391Stephen Smalley# Only the init property service should write to /data/property.
316a17a266e7e466d281f0730449c492de46390fc76Nick Kralevichneverallow { domain -init } property_data_file:dir no_w_dir_perms;
317a17a266e7e466d281f0730449c492de46390fc76Nick Kralevichneverallow { domain -init } property_data_file:file no_w_file_perms;
31803ce5120722b3b5cb9cd0fec08c22681a96ee3d6Nick Kralevich
31903ce5120722b3b5cb9cd0fec08c22681a96ee3d6Nick Kralevich# Only recovery should be doing writes to /system
32003ce5120722b3b5cb9cd0fec08c22681a96ee3d6Nick Kralevichneverallow { domain -recovery } { system_file exec_type }:dir_file_class_set
3215aac86dc065c069a593e772300f6538e2b88d6beElliott Hughes    { create write setattr relabelfrom append unlink link rename };
3225aac86dc065c069a593e772300f6538e2b88d6beElliott Hughesneverallow { domain -recovery -kernel } { system_file exec_type }:dir_file_class_set relabelto;
32375e2ef92601c485348c40cc8884839fba27046baStephen Smalley
32474df7f593494a00dcc3be410b2d82267b6b31ca0Nick Kralevich# Don't allow mounting on top of /system files or directories
325e244f2d3552b312d600b8f08cff33789c1d32894Daniel Rosenbergneverallow domain exec_type:dir_file_class_set mounton;
326e244f2d3552b312d600b8f08cff33789c1d32894Daniel Rosenbergneverallow { domain -init } system_file:dir_file_class_set mounton;
32774df7f593494a00dcc3be410b2d82267b6b31ca0Nick Kralevich
32804b8a75c2f7532821a2a098a95d884931a91807cStephen Smalley# Nothing should be writing to files in the rootfs.
3297ceb4cce34d3ce88f462820755e1e4829f0e0890Nick Kralevichneverallow domain rootfs:file { create write setattr relabelto append unlink link rename };
33004b8a75c2f7532821a2a098a95d884931a91807cStephen Smalley
33175e2ef92601c485348c40cc8884839fba27046baStephen Smalley# Restrict context mounts to specific types marked with
33275e2ef92601c485348c40cc8884839fba27046baStephen Smalley# the contextmount_type attribute.
33375e2ef92601c485348c40cc8884839fba27046baStephen Smalleyneverallow domain {fs_type -contextmount_type}:filesystem relabelto;
33475e2ef92601c485348c40cc8884839fba27046baStephen Smalley
33575e2ef92601c485348c40cc8884839fba27046baStephen Smalley# Ensure that context mount types are not writable, to ensure that
33675e2ef92601c485348c40cc8884839fba27046baStephen Smalley# the write to /system restriction above is not bypassed via context=
33775e2ef92601c485348c40cc8884839fba27046baStephen Smalley# mount to another type.
33875e2ef92601c485348c40cc8884839fba27046baStephen Smalleyneverallow { domain -recovery } contextmount_type:dir_file_class_set
33975e2ef92601c485348c40cc8884839fba27046baStephen Smalley    { create write setattr relabelfrom relabelto append unlink link rename };
34076206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn
34176206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# Do not allow service_manager add for default_android_service.
34276206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# Instead domains should use a more specific type such as
34376206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# system_app_service rather than the generic type.
34476206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# New service_types are defined in service.te and new mappings
34576206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# from service name to service_type are defined in service_contexts.
34676206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahnneverallow domain default_android_service:service_manager add;
34799aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevich
34899aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevich# Require that domains explicitly label unknown properties, and do not allow
34999aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevich# anyone but init to modify unknown properties.
35099aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevichneverallow { domain -init } default_prop:property_service set;
351f37ce3f3e2ad68da61f709567cd166a83316e3f3dcashman
352f37ce3f3e2ad68da61f709567cd166a83316e3f3dcashmanneverallow { domain -init -recovery -system_server } frp_block_device:blk_file rw_file_perms;
353206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalley
354a10f789d286d0f28c85488629cc92f5ab6ca8e00David Zeuthen# No domain other than recovery and update_engine can write to system partition(s).
355a10f789d286d0f28c85488629cc92f5ab6ca8e00David Zeuthenneverallow { domain -recovery -update_engine } system_block_device:blk_file write;
356206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalley
357206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalley# No domains other than install_recovery or recovery can write to recovery.
358206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalleyneverallow { domain -install_recovery -recovery } recovery_block_device:blk_file write;
35910ecd05df39b25f4b504f795adafae5f45084a59dcashman
36010ecd05df39b25f4b504f795adafae5f45084a59dcashman# Only servicemanager should be able to register with binder as the context manager
36110ecd05df39b25f4b504f795adafae5f45084a59dcashmanneverallow { domain -servicemanager } *:binder set_context_mgr;
3623c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich
3633c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich# Only authorized processes should be writing to files in /data/dalvik-cache
3643c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich# (excluding /data/dalvik-cache/profiles, which is labeled differently)
3653c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevichneverallow {
3663c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  domain
3673c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -init # TODO: limit init to relabelfrom for files
3683c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -zygote
3693c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -installd
3703c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -dex2oat
3713c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich} dalvikcache_data_file:file no_w_file_perms;
37214d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich
373d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalleyneverallow {
374d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  domain
375d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -init
376d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -installd
377d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -dex2oat
378d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -zygote
379d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley} dalvikcache_data_file:dir no_w_dir_perms;
380d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley
3818f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashman# Only system_server should be able to send commands via the zygote socket
3828f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashmanneverallow { domain -zygote -system_server } zygote:unix_stream_socket connectto;
3838f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashmanneverallow { domain -system_server } zygote_socket:sock_file write;
3848f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashman
38514d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# Android does not support System V IPCs.
38614d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
38714d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# The reason for this is due to the fact that, by design, they lead to global
38814d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# kernel resource leakage.
38914d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
39014d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# For example, there is no way to automatically release a SysV semaphore
39114d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# allocated in the kernel when:
39214d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
39314d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# - a buggy or malicious process exits
39414d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# - a non-buggy and non-malicious process crashes or is explicitly killed.
39514d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
39614d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# Killing processes automatically to make room for new ones is an
39714d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# important part of Android's application lifecycle implementation. This means
39814d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# that, even assuming only non-buggy and non-malicious code, it is very likely
39914d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# that over time, the kernel global tables used to implement SysV IPCs will fill
40014d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# up.
40114d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevichneverallow domain domain:{ shm sem msg msgq } *;
40274ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevich
40374ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevich# Do not mount on top of symlinks, fifos, or sockets.
40474ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevich# Feature parity with Chromium LSM.
40574ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevichneverallow domain { file_type fs_type dev_type }:{ lnk_file fifo_file sock_file } mounton;
4068bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich
4078bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich# Nobody should be able to execute su on user builds.
4088bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich# On userdebug/eng builds, only dumpstate, shell, and
4098bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich# su itself execute su.
4108bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevichneverallow { domain userdebug_or_eng(`-dumpstate -shell -su') } su_exec:file no_x_file_perms;
411359101ac289ad75653c954c07166bc658900bd28Nick Kralevich
412359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# Do not allow the introduction of new execmod rules. Text relocations
413359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# and modification of executable pages are unsafe.
414359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# The only exceptions are for NDK text relocations associated with
415359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# https://code.google.com/p/android/issues/detail?id=23203
416359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# which, long term, need to go away.
417359101ac289ad75653c954c07166bc658900bd28Nick Kralevichneverallow domain {
418359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  file_type
419998ce77f845cba7f14d4f54de3e87ebf9deafaedNick Kralevich  -system_file      # needs to die. b/20013628
420359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -system_data_file
421359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -apk_data_file
422359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -app_data_file
423359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -asec_public_file
424359101ac289ad75653c954c07166bc658900bd28Nick Kralevich}:file execmod;
425359101ac289ad75653c954c07166bc658900bd28Nick Kralevich
4265328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley# Do not allow making the stack or heap executable.
4275328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley# We would also like to minimize execmem but it seems to be
4285328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley# required by some device-specific service domains.
4295328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalleyneverallow domain self:process { execstack execheap };
4305328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley
431998ce77f845cba7f14d4f54de3e87ebf9deafaedNick Kralevich# TODO: prohibit non-zygote spawned processes from using shared libraries
432998ce77f845cba7f14d4f54de3e87ebf9deafaedNick Kralevich# with text relocations. b/20013628 .
433998ce77f845cba7f14d4f54de3e87ebf9deafaedNick Kralevich# neverallow { domain -appdomain } file_type:file execmod;
434e96c3abe2e86f3ecdfdb7770629e9f73ff1e96d1dcashman
435e96c3abe2e86f3ecdfdb7770629e9f73ff1e96d1dcashmanneverallow { domain -init } proc:{ file dir } mounton;
4364a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley
4374a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# Ensure that all types assigned to processes are included
4384a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# in the domain attribute, so that all allow and neverallow rules
4394a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# written on domain are applied to all processes.
4404a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# This is achieved by ensuring that it is impossible to transition
4414a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# from a domain to a non-domain type and vice versa.
4424a12d9630ad22566bda75166e088cb05316e1934Stephen Smalleyneverallow domain ~domain:process { transition dyntransition };
4434a12d9630ad22566bda75166e088cb05316e1934Stephen Smalleyneverallow ~domain domain:process { transition dyntransition };
444529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts
445529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts#
446529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# Only system_app and system_server should be creating or writing
447529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# their files. The proper way to share files is to setup
448529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# type transitions to a more specific type or assigning a type
449529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# to its parent directory via a file_contexts entry.
450529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# Example type transition:
451529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts#  mydomain.te:file_type_auto_trans(mydomain, system_data_file, new_file_type)
452529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts#
453529a8634e1d31967db2600ba27e55fc35b7d0195William Robertsneverallow {
454529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  domain
455529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -system_server
456529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -system_app
457529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -init
458529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -installd # for relabelfrom and unlink, check for this in explicit neverallow
459529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts} system_data_file:file no_w_file_perms;
460529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# do not grant anything greater than r_file_perms and relabelfrom unlink
461529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# to installd
462529a8634e1d31967db2600ba27e55fc35b7d0195William Robertsneverallow installd system_data_file:file ~{ r_file_perms relabelfrom unlink };
463d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts
464d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts#
465d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts# Only these domains should transition to shell domain. This domain is
466d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts# permissible for the "shell user". If you need a process to exec a shell
467d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts# script with differing privilege, define a domain and set up a transition.
468d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts#
469d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Robertsneverallow {
470d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  domain
471d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -adbd
472d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -init
473d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -runas
474d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -zygote
475d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts} shell:process { transition dyntransition };
4769d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley
4779d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley# Minimize read access to shell- or app-writable symlinks.
4789d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley# This is to prevent malicious symlink attacks.
4799d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalleyneverallow {
4809d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  domain
4819d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -appdomain
4829d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -installd
4839d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -uncrypt  # TODO: see if we can remove
4849d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley} app_data_file:lnk_file read;
4859d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley
4869d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalleyneverallow {
4879d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  domain
4889d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -shell
4899d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  userdebug_or_eng(`-uncrypt')
4909d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -installd
4919d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley} shell_data_file:lnk_file read;
492f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich
493be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# In addition to the symlink reading restrictions above, restrict
494be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# write access to shell owned directories. The /data/local/tmp
495be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# directory is untrustworthy, and non-whitelisted domains should
496be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# not be trusting any content in those directories.
497be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevichneverallow {
498be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  domain
499be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -adbd
500be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -dumpstate
501be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -installd
502be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -init
503be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -shell
504be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -vold
505be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich} shell_data_file:dir no_w_dir_perms;
506be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich
507be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevichneverallow {
508be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  domain
509be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -adbd
510be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -appdomain
511be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -dumpstate
512be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -init
513be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -installd
514be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -system_server # why?
515be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  userdebug_or_eng(`-uncrypt')
516be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich} shell_data_file:dir { open search };
517be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich
518be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# Same as above for /data/local/tmp files. We allow shell files
519be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# to be passed around by file descriptor, but not directly opened.
520be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevichneverallow {
521be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  domain
522be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -adbd
523be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -appdomain
524be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -dumpstate
525be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -installd
5269e6effa15f17e7951ad63ddd01fd22c1a42be616Nick Kralevich  userdebug_or_eng(`-uncrypt')
527be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich} shell_data_file:file open;
528be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich
529f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich# servicemanager is the only process which handles list request
530f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevichneverallow domain ~servicemanager:service_manager list;
531f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich
532f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich# only service_manager_types can be added to service_manager
533f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevichneverallow domain ~service_manager_type:service_manager { add find };
534483fd267359a457ca4ac4c4a2cbce38af6c15981Jeff Vander Stoep
535483fd267359a457ca4ac4c4a2cbce38af6c15981Jeff Vander Stoep# logpersist is only allowed on userdebug/eng builds
536483fd267359a457ca4ac4c4a2cbce38af6c15981Jeff Vander Stoepneverallow { domain userdebug_or_eng(`-logd -shell') } misc_logd_file:file rw_file_perms;
53759c23d78c894198f39d9af563f17c05fb266ec3eWilliam Roberts
53859c23d78c894198f39d9af563f17c05fb266ec3eWilliam Roberts# Prevent assigning non property types to properties
53959c23d78c894198f39d9af563f17c05fb266ec3eWilliam Robertsneverallow domain ~property_type:property_service set;
540