domain.te revision e53d0b0bccf2fd58ce4b4ea3324891937056089a
1dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Rules for all domains.
2dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
3dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Allow reaping by init.
4dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain init:process sigchld;
5dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
6dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Intra-domain accesses.
7bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalleyallow domain self:process {
8bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    fork
9bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    sigchld
10bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    sigkill
11bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    sigstop
12bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    signull
13bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    signal
14bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getsched
15bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setsched
16bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getsession
17bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getpgid
18bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setpgid
19bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getcap
20bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setcap
21bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    getattr
22bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley    setrlimit
23bac4ccce8f1b06ec9c25b98e6690714ba8ad7bafStephen Smalley};
24dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain self:fd use;
25abf31acb01f85ade4b97b05f9893d270b915b7b6dcashmanallow domain proc:dir r_dir_perms;
268666bf25cf5de7c0bddfe858342dabfeea5ff823dcashmanallow domain proc_net:dir search;
27093ea6fb9a284acbce10641f8743de24abd70734SimHyunYongr_dir_file(domain, self)
28dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain self:{ fifo_file file } rw_file_perms;
291601132086b054adc70e7f8f38ed24574c90bc37Stephen Smalleyallow domain self:unix_dgram_socket { create_socket_perms sendto };
301601132086b054adc70e7f8f38ed24574c90bc37Stephen Smalleyallow domain self:unix_stream_socket { create_stream_socket_perms connectto };
31dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
32dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Inherit or receive open files from others.
33dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain init:fd use;
34dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
357d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevichuserdebug_or_eng(`
367d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # Same as adbd rules above, except allow su to do the same thing
377d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:unix_stream_socket connectto;
387d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:fd use;
397d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:unix_stream_socket { getattr getopt read write shutdown };
407d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich
4165feafce6c72ded001619e4f6b975de095941acdNick Kralevich  binder_call({ domain -init }, su)
423dad7b611a448fa43a678ff760c23a00f387947eStephen Smalley
437d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # Running something like "pm dump com.android.bluetooth" requires
447d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # fifo writes
457d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:fifo_file { write getattr };
467d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich
477d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  # allow "gdbserver --attach" to work for su.
487d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich  allow domain su:process sigchld;
49ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich
50ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich  # Allow writing coredumps to /cores/*
51ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich  allow domain coredump_file:file create_file_perms;
52ca62a8b72be35de3781c1f8f16600cfeca874ef5Nick Kralevich  allow domain coredump_file:dir ra_dir_perms;
537d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich')
547d0f955ef09be5b2558da432a1f8cd525c5ccfe4Nick Kralevich
555919d1c86a2a1fea52f840ab30709048bd63f1f5Nick Kralevich###
565919d1c86a2a1fea52f840ab30709048bd63f1f5Nick Kralevich### Talk to debuggerd.
575919d1c86a2a1fea52f840ab30709048bd63f1f5Nick Kralevich###
58dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain debuggerd:process sigchld;
59dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain debuggerd:unix_stream_socket connectto;
60dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
61dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Root fs.
626e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoepallow domain rootfs:dir search;
636e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoepallow domain rootfs:lnk_file read;
64dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
65dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# Device accesses.
66dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain device:dir search;
67712ca0a4d5c3ff77179da2544aafd6eb8e5a70c2Stephen Smalleyallow domain dev_type:lnk_file r_file_perms;
68dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain devpts:dir search;
6920feb75b572a21a7a376d6780cc5c1d636cda610Robert Craigallow domain socket_device:dir r_dir_perms;
70dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain owntty_device:chr_file rw_file_perms;
71dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain null_device:chr_file rw_file_perms;
72f007d03628f98a40c01c12ad105ca6be14fd3c78Nick Kralevichallow domain zero_device:chr_file rw_file_perms;
73dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain ashmem_device:chr_file rw_file_perms;
74dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain binder_device:chr_file rw_file_perms;
75dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain ptmx_device:chr_file rw_file_perms;
76dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain alarm_device:chr_file r_file_perms;
77a2477056ae6a702e7e71b671cd0c47afc1c7da8aAlex Klyubinallow domain urandom_device:chr_file rw_file_perms;
78a2477056ae6a702e7e71b671cd0c47afc1c7da8aAlex Klyubinallow domain random_device:chr_file rw_file_perms;
79949d7cbc29c1a658f00b966a81fd3f710c065fecTom Cherryallow domain properties_device:dir r_dir_perms;
80949d7cbc29c1a658f00b966a81fd3f710c065fecTom Cherryallow domain properties_serial:file r_file_perms;
81949d7cbc29c1a658f00b966a81fd3f710c065fecTom Cherry
825a570a4b6b89a2226970de93887f25a10a2e4548Nick Kralevich# For now, everyone can access core property files
835a570a4b6b89a2226970de93887f25a10a2e4548Nick Kralevich# Device specific properties are not granted by default
845a570a4b6b89a2226970de93887f25a10a2e4548Nick Kralevichget_prop(domain, core_property_type)
85949d7cbc29c1a658f00b966a81fd3f710c065fecTom Cherrydontaudit domain property_type:file audit_access;
86949d7cbc29c1a658f00b966a81fd3f710c065fecTom Cherryallow domain property_contexts:file r_file_perms;
87949d7cbc29c1a658f00b966a81fd3f710c065fecTom Cherry
888138401d57520711bbf801e3f5f6dc029851fe46Paul Lawrenceallow domain init:key search;
8913dec5fa5b860871afea47f85842706095e40527Paul Lawrenceallow domain vold:key search;
90dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
918ed750e9731e6e3a21785e91e9b1cf7390c16738Mark Salyzyn# logd access
928ed750e9731e6e3a21785e91e9b1cf7390c16738Mark Salyzynwrite_logd(domain)
938ed750e9731e6e3a21785e91e9b1cf7390c16738Mark Salyzyn
94dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich# System file accesses.
959a3d1c6bbe73d3e5cfeb582564f971bc1cbe155aJeff Vander Stoepallow domain system_file:dir { search getattr };
966e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoepallow domain system_file:file { execute read open getattr };
976e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoepallow domain system_file:lnk_file read;
98dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevich
99cee729240e8c6a8aec63d10b4dae5d0e619229d8dcashman# read any sysfs symlinks
100cee729240e8c6a8aec63d10b4dae5d0e619229d8dcashmanallow domain sysfs:lnk_file read;
101cee729240e8c6a8aec63d10b4dae5d0e619229d8dcashman
1028ca19368dae676ba8769c15ead2469a9f44e562eNick Kralevich# libc references /data/misc/zoneinfo for timezone related information
1038ca19368dae676ba8769c15ead2469a9f44e562eNick Kralevichr_dir_file(domain, zoneinfo_data_file)
1048ca19368dae676ba8769c15ead2469a9f44e562eNick Kralevich
1054e2d22451f9645f7ab39b94b1ec0f0f5a5c5b2e9Nick Kralevich# Lots of processes access current CPU information
1064e2d22451f9645f7ab39b94b1ec0f0f5a5c5b2e9Nick Kralevichr_dir_file(domain, sysfs_devices_system_cpu)
1074e2d22451f9645f7ab39b94b1ec0f0f5a5c5b2e9Nick Kralevich
1086e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoep# files under /data.
109dbd28d91d3c6d970f1704df8350b0333b51758b1Nick Kralevichallow domain system_data_file:dir { search getattr };
1109a3d1c6bbe73d3e5cfeb582564f971bc1cbe155aJeff Vander Stoepallow domain system_data_file:lnk_file read;
1116e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoep
1126e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoep# required by the dynamic linker
113f4c403d1f6a05a6df36cea5c4096fe098d0c50c8dcashmanallow domain proc:lnk_file { getattr read };
1146e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoep
115f8f937a16fdbb0b9a956f0d1b1c7cf9d7651bf73Nick Kralevich# /proc/cpuinfo
116f8f937a16fdbb0b9a956f0d1b1c7cf9d7651bf73Nick Kralevichallow domain proc_cpuinfo:file r_file_perms;
117f8f937a16fdbb0b9a956f0d1b1c7cf9d7651bf73Nick Kralevich
1186e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoep# toybox loads libselinux which stats /sys/fs/selinux/
11945517a7547de0a9f0c13b5907c243456ec61bf04Jeff Vander Stoepallow domain selinuxfs:dir search;
1206e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoepallow domain selinuxfs:file getattr;
1216e3506e1ba83fb47297c8908016397c8f17840c4Jeff Vander Stoepallow domain sysfs:dir search;
122aef68b779909fe85a0f98bf443851bb30eb8b236Jeff Vander Stoepallow domain selinuxfs:filesystem getattr;
12348b18832c476f0bd8fcb8ee3e308258392f36aafRobert Craig
124be0616baf0c0caf8e1c8a4fdc9b488839f6af27dJeff Vander Stoep# For /acct/uid/*/tasks.
125be0616baf0c0caf8e1c8a4fdc9b488839f6af27dJeff Vander Stoepallow domain cgroup:dir { search write };
126be0616baf0c0caf8e1c8a4fdc9b488839f6af27dJeff Vander Stoepallow domain cgroup:file w_file_perms;
127be0616baf0c0caf8e1c8a4fdc9b488839f6af27dJeff Vander Stoep
12844826cb5e4b20e0f7b7bfa72f64767e5fcc4f253Nick Kralevich# Almost all processes log tracing information to
12944826cb5e4b20e0f7b7bfa72f64767e5fcc4f253Nick Kralevich# /sys/kernel/debug/tracing/trace_marker
13044826cb5e4b20e0f7b7bfa72f64767e5fcc4f253Nick Kralevich# The reason behind this is documented in b/6513400
13144826cb5e4b20e0f7b7bfa72f64767e5fcc4f253Nick Kralevichallow domain debugfs:dir search;
132fe12b61642a0013e04848b399e59d310926c796fNick Kralevichallow domain debugfs_tracing:dir search;
13344826cb5e4b20e0f7b7bfa72f64767e5fcc4f253Nick Kralevichallow domain debugfs_trace_marker:file w_file_perms;
13444826cb5e4b20e0f7b7bfa72f64767e5fcc4f253Nick Kralevich
135fcea7263903b0e953f393ddb15fbfc071b992499dcashman# Filesystem access.
136fcea7263903b0e953f393ddb15fbfc071b992499dcashmanallow domain fs_type:filesystem getattr;
137fcea7263903b0e953f393ddb15fbfc071b992499dcashmanallow domain fs_type:dir getattr;
138fcea7263903b0e953f393ddb15fbfc071b992499dcashman
1392637198f92d5d9c65262e42d78123d216889d546Nick Kralevich###
1402637198f92d5d9c65262e42d78123d216889d546Nick Kralevich### neverallow rules
1412637198f92d5d9c65262e42d78123d216889d546Nick Kralevich###
1422637198f92d5d9c65262e42d78123d216889d546Nick Kralevich
1430d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalley# Do not allow any domain other than init or recovery to create unlabeled files.
1440d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalleyneverallow { domain -init -recovery } unlabeled:dir_file_class_set create;
145cb23ca92f303fca6bb0f48a1beb384e220afe39eStephen Smalley
1465487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# Limit ability to ptrace or read sensitive /proc/pid files of processes
1475487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# with other UIDs to these whitelisted domains.
148a191398812eb35be613541b3822a363919da8586Nick Kralevichneverallow {
149a191398812eb35be613541b3822a363919da8586Nick Kralevich  domain
150a191398812eb35be613541b3822a363919da8586Nick Kralevich  -debuggerd
151a191398812eb35be613541b3822a363919da8586Nick Kralevich  -vold
152a191398812eb35be613541b3822a363919da8586Nick Kralevich  -dumpstate
153a191398812eb35be613541b3822a363919da8586Nick Kralevich  -system_server
15434a468fad2c0b624b0cf383671384d0452dd83e6Dehao Chen  userdebug_or_eng(`-perfprofd')
155a191398812eb35be613541b3822a363919da8586Nick Kralevich} self:capability sys_ptrace;
1565487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley
157b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevich# Limit device node creation to these whitelisted domains.
158e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevichneverallow {
159e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  domain
160e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -kernel
161e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -init
162e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -ueventd
163e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich  -vold
1649c7570ef799616e683471ebdb22ee34a424a0aa0Jeff Vander Stoep  -recovery
165e2651972c13a2aa3f930f5c39d81d41177387bf0Nick Kralevich} self:capability mknod;
166b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevich
167b59dc27a1b580a13c50477d2af1cbdaf95601d8fNick Kralevich# Limit raw I/O to these whitelisted domains.
1681df23cbf8ef4cd35cf6ab832120c2d1a86a46ffdNick Kralevichneverallow { domain -kernel -init -recovery -ueventd -watchdogd -healthd -uncrypt -tee } self:capability sys_rawio;
1695487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley
1707ffb9972076bfbd2abab1df6b4d759d14d55af96Stephen Smalley# No process can map low memory (< CONFIG_LSM_MMAP_MIN_ADDR).
17135a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * self:memprotect mmap_zero;
1727ffb9972076bfbd2abab1df6b4d759d14d55af96Stephen Smalley
1735487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# No domain needs mac_override as it is unused by SELinux.
17435a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * self:capability2 mac_override;
1755487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley
1765487ca00d4788de367a9d099714f6df4d86ef261Stephen Smalley# Only recovery needs mac_admin to set contexts not defined in current policy.
17704ee5dfb80491f8493fedcd099bd4551c9503c83Stephen Smalleyneverallow { domain -recovery } self:capability2 mac_admin;
17804ee5dfb80491f8493fedcd099bd4551c9503c83Stephen Smalley
1791c983327cf7e841183da15934c7ba2e99d0979c0Janis Danisevskis# Once the policy has been loaded there shall be none to modify the policy.
1801c983327cf7e841183da15934c7ba2e99d0979c0Janis Danisevskis# It is sealed.
1811c983327cf7e841183da15934c7ba2e99d0979c0Janis Danisevskisneverallow * kernel:security load_policy;
1823235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley
1831c983327cf7e841183da15934c7ba2e99d0979c0Janis Danisevskis# Only init and the system_server shall use the property_service.
1841c983327cf7e841183da15934c7ba2e99d0979c0Janis Danisevskisneverallow { domain -init -system_server } security_prop:property_service set;
1853235f61aa859af1d1c3d060eb55cf1929bc6914fStephen Smalley
186fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# Only init prior to switching context should be able to set enforcing mode.
187fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# init starts in kernel domain and switches to init domain via setcon in
188fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# the init.rc, so the setenforce occurs while still in kernel. After
189fea6e66fad0dd87e66d4df8255733b6840752316Stephen Smalley# switching domains, there is never any need to setenforce again by init.
19035a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * kernel:security setenforce;
191abae8a9b586c98cf3e7bd08e63473a5ce99ccd27Nick Kralevichneverallow { domain -kernel } kernel:security setcheckreqprot;
1920130154985aa5042b9e40c45fe60492e40004761Stephen Smalley
193853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# No booleans in AOSP policy, so no need to ever set them.
19435a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * kernel:security setbool;
195853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley
196853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# Adjusting the AVC cache threshold.
197853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# Not presently allowed to anything in policy, but possibly something
198853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley# that could be set from init.rc.
199853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalleyneverallow { domain -init } kernel:security setsecparam;
200853ffaad323b3e5db14d3f2e4fbe7fa96160ede4Stephen Smalley
20172c16e32f5dfbf889819973cc2d842a094636d23William Roberts# Only init, ueventd, shell and system_server should be able to access HW RNG
20272c16e32f5dfbf889819973cc2d842a094636d23William Robertsneverallow {
20372c16e32f5dfbf889819973cc2d842a094636d23William Roberts  domain
20472c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -init
20572c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -shell # For CTS and is restricted to getattr in shell.te
20672c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -system_server
20772c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -ueventd
20872c16e32f5dfbf889819973cc2d842a094636d23William Roberts} hw_random_device:chr_file *;
2098d688315aeb053eadc2606badbe4ce52899bb694Alex Klyubin
210a9671c6b9eff0b72ad797e2339865bd24222391bAlex Deymo# Ensure that all entrypoint executables are in exec_type or postinstall_file.
211a9671c6b9eff0b72ad797e2339865bd24222391bAlex Deymoneverallow * { file_type -exec_type -postinstall_file }:file entrypoint;
212ddf98fa8cf11000f91329945abc23ee791adfe69Geremy Condra
213ddf98fa8cf11000f91329945abc23ee791adfe69Geremy Condra# Ensure that nothing in userspace can access /dev/mem or /dev/kmem
21472c16e32f5dfbf889819973cc2d842a094636d23William Robertsneverallow {
21572c16e32f5dfbf889819973cc2d842a094636d23William Roberts  domain
21672c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -init
21772c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -kernel
21872c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -shell # For CTS and is restricted to getattr in shell.te
21972c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -ueventd
22072c16e32f5dfbf889819973cc2d842a094636d23William Roberts} kmem_device:chr_file *;
22172c16e32f5dfbf889819973cc2d842a094636d23William Robertsneverallow * kmem_device:chr_file ~{ create relabelto unlink setattr getattr };
2227adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalley
2237adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalley# Only init should be able to configure kernel usermodehelpers or
2247adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalley# security-sensitive proc settings.
2257adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalleyneverallow { domain -init } usermodehelper:file { append write };
2267adb999e701ee96356c506ffa93fce190791e8b7Stephen Smalleyneverallow { domain -init } proc_security:file { append write };
22795e0842e341352af16bed4055ccf67878c322985Stephen Smalley
22895e0842e341352af16bed4055ccf67878c322985Stephen Smalley# No domain should be allowed to ptrace init.
22935a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * init:process ptrace;
230a730e50bd93cd058b271ce3a4affcc6ac75da58bNick Kralevich
23165feafce6c72ded001619e4f6b975de095941acdNick Kralevich# Init can't do anything with binder calls. If this neverallow rule is being
232a730e50bd93cd058b271ce3a4affcc6ac75da58bNick Kralevich# triggered, it's probably due to a service with no SELinux domain.
23335a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * init:binder *;
234d0919ec25361ffeda3aa44cc2ecaf875f99784c3William Roberts
235d0919ec25361ffeda3aa44cc2ecaf875f99784c3William Roberts# Don't allow raw read/write/open access to block_device
236d0919ec25361ffeda3aa44cc2ecaf875f99784c3William Roberts# Rather force a relabel to a more specific type
237eb43e6548e1c23d9b47b98d6dd429f9887223dfaNick Kralevichneverallow { domain -kernel -init -recovery } block_device:blk_file { open read write };
238a637b2f21eda997f6d1bcb8f2600a5ee3195785dWilliam Roberts
239a637b2f21eda997f6d1bcb8f2600a5ee3195785dWilliam Roberts# Don't allow raw read/write/open access to generic devices.
240a637b2f21eda997f6d1bcb8f2600a5ee3195785dWilliam Roberts# Rather force a relabel to a more specific type.
2410d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalley# init is exempt from this as there are character devices that only it uses.
2420d08d4721a8c18b7d5f7dccde467c3840c03b9a8Stephen Smalley# ueventd is exempt from this, as it is managing these devices.
2437ceb4cce34d3ce88f462820755e1e4829f0e0890Nick Kralevichneverallow { domain -init -ueventd } device:chr_file { open read write };
244b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley
245b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley# Limit what domains can mount filesystems or change their mount flags.
246b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley# sdcard_type / vfat is exempt as a larger set of domains need
247b081cc1e050843ecb7dff687f780787ad05d6143Stephen Smalley# this capability, including device-specific domains.
2486cb2c893b12db00c73009f6ab1f6c69426b0cc05Alex Deymoneverallow { domain -kernel -init -recovery -vold -zygote -update_engine } { fs_type -sdcard_type }:filesystem { mount remount relabelfrom relabelto };
249629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich
250629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich#
251629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich# Assert that, to the extent possible, we're not loading executable content from
2524644ac483667befac441bb541733e489d902bacfStephen Smalley# outside the rootfs or /system partition except for a few whitelisted domains.
253629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich#
254629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevichneverallow {
255629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    domain
256629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -appdomain
257629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -dumpstate
25842fb824ca9f3e46b4419f05083f2694ac67a8229Stephen Smalley    -shell
259629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    userdebug_or_eng(`-su')
260629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -system_server
261629fbc9540b4ab6d780cfa8442160b4923373021Nick Kralevich    -zygote
2626cb2c893b12db00c73009f6ab1f6c69426b0cc05Alex Deymo} { file_type -system_file -exec_type -postinstall_file }:file execute;
2634644ac483667befac441bb541733e489d902bacfStephen Smalleyneverallow {
2644644ac483667befac441bb541733e489d902bacfStephen Smalley    domain
2654644ac483667befac441bb541733e489d902bacfStephen Smalley    -appdomain # for oemfs
2664644ac483667befac441bb541733e489d902bacfStephen Smalley    -recovery # for /tmp/update_binary in tmpfs
2674644ac483667befac441bb541733e489d902bacfStephen Smalley} { fs_type -rootfs }:file execute;
2686c30016136b8ad0bc52a14fb50c6ddd449811cdeWilliam Roberts# Files from cache should never be executed
269549ccf77e3fd23bb6c690da7023441c1007c4fd8Felipe Lemeneverallow domain { cache_file cache_backup_file cache_recovery_file }:file execute;
270ad0d0fc722d04e465ce2b0bfd2f8e04714c75391Stephen Smalley
2717028bdccd5b3e91928d345990587738212973f1dWilliam Roberts# Protect most domains from executing arbitrary content from /data.
2727028bdccd5b3e91928d345990587738212973f1dWilliam Robertsneverallow {
2737028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  domain
2747028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -untrusted_app
275ee9c0b5fb6d0c66756e1890711fe0afdacc7ea0cJeff Vander Stoep  -priv_app
2767028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -shell
2777028bdccd5b3e91928d345990587738212973f1dWilliam Roberts} {
2787028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  data_file_type
2797028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -dalvikcache_data_file
2807028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -system_data_file # shared libs in apks
2817028bdccd5b3e91928d345990587738212973f1dWilliam Roberts  -apk_data_file
2827028bdccd5b3e91928d345990587738212973f1dWilliam Roberts}:file no_x_file_perms;
2837028bdccd5b3e91928d345990587738212973f1dWilliam Roberts
284e9d261ff17648e7d08f8fe86909ad0522fbbafb3Nick Kralevichneverallow { domain userdebug_or_eng(`-shell') } nativetest_data_file:file no_x_file_perms;
285e9d261ff17648e7d08f8fe86909ad0522fbbafb3Nick Kralevich
2864432c6355af55118e94f9260962089f345cba21cNick Kralevich# Only the init property service should write to /data/property and /dev/__properties__
287a17a266e7e466d281f0730449c492de46390fc76Nick Kralevichneverallow { domain -init } property_data_file:dir no_w_dir_perms;
28850ba6318419fc56366377c042f56cec5a2414c51Nick Kralevichneverallow { domain -init } property_data_file:file { no_w_file_perms no_x_file_perms };
28950ba6318419fc56366377c042f56cec5a2414c51Nick Kralevichneverallow { domain -init } property_type:file { no_w_file_perms no_x_file_perms };
29050ba6318419fc56366377c042f56cec5a2414c51Nick Kralevichneverallow { domain -init } properties_device:file { no_w_file_perms no_x_file_perms };
29150ba6318419fc56366377c042f56cec5a2414c51Nick Kralevichneverallow { domain -init } properties_serial:file { no_w_file_perms no_x_file_perms };
29203ce5120722b3b5cb9cd0fec08c22681a96ee3d6Nick Kralevich
29303ce5120722b3b5cb9cd0fec08c22681a96ee3d6Nick Kralevich# Only recovery should be doing writes to /system
29403ce5120722b3b5cb9cd0fec08c22681a96ee3d6Nick Kralevichneverallow { domain -recovery } { system_file exec_type }:dir_file_class_set
2955aac86dc065c069a593e772300f6538e2b88d6beElliott Hughes    { create write setattr relabelfrom append unlink link rename };
2965aac86dc065c069a593e772300f6538e2b88d6beElliott Hughesneverallow { domain -recovery -kernel } { system_file exec_type }:dir_file_class_set relabelto;
29775e2ef92601c485348c40cc8884839fba27046baStephen Smalley
29874df7f593494a00dcc3be410b2d82267b6b31ca0Nick Kralevich# Don't allow mounting on top of /system files or directories
29935a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * exec_type:dir_file_class_set mounton;
300e244f2d3552b312d600b8f08cff33789c1d32894Daniel Rosenbergneverallow { domain -init } system_file:dir_file_class_set mounton;
30174df7f593494a00dcc3be410b2d82267b6b31ca0Nick Kralevich
30204b8a75c2f7532821a2a098a95d884931a91807cStephen Smalley# Nothing should be writing to files in the rootfs.
30335a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * rootfs:file { create write setattr relabelto append unlink link rename };
30404b8a75c2f7532821a2a098a95d884931a91807cStephen Smalley
30575e2ef92601c485348c40cc8884839fba27046baStephen Smalley# Restrict context mounts to specific types marked with
30675e2ef92601c485348c40cc8884839fba27046baStephen Smalley# the contextmount_type attribute.
30735a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * {fs_type -contextmount_type}:filesystem relabelto;
30875e2ef92601c485348c40cc8884839fba27046baStephen Smalley
30975e2ef92601c485348c40cc8884839fba27046baStephen Smalley# Ensure that context mount types are not writable, to ensure that
31075e2ef92601c485348c40cc8884839fba27046baStephen Smalley# the write to /system restriction above is not bypassed via context=
31175e2ef92601c485348c40cc8884839fba27046baStephen Smalley# mount to another type.
31275e2ef92601c485348c40cc8884839fba27046baStephen Smalleyneverallow { domain -recovery } contextmount_type:dir_file_class_set
31375e2ef92601c485348c40cc8884839fba27046baStephen Smalley    { create write setattr relabelfrom relabelto append unlink link rename };
31476206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn
31576206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# Do not allow service_manager add for default_android_service.
31676206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# Instead domains should use a more specific type such as
31776206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# system_app_service rather than the generic type.
31876206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# New service_types are defined in service.te and new mappings
31976206abc9f5140e85da2d4e4845eca2c4f3a6ad5Riley Spahn# from service name to service_type are defined in service_contexts.
32035a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * default_android_service:service_manager add;
32199aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevich
32299aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevich# Require that domains explicitly label unknown properties, and do not allow
32399aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevich# anyone but init to modify unknown properties.
32499aa03dce31ae933b28533901316a9a7c36cbb38Nick Kralevichneverallow { domain -init } default_prop:property_service set;
325d1435604455e5e274c88f6ee0308c7881cddaf20Mark Salyzynneverallow { domain -init } mmc_prop:property_service set;
326f37ce3f3e2ad68da61f709567cd166a83316e3f3dcashman
327e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Robertsneverallow {
328e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Roberts  domain
329e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Roberts  -init
330e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Roberts  -recovery
331e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Roberts  -system_server
332e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Roberts  -shell # Shell is further restricted in shell.te
333e53d0b0bccf2fd58ce4b4ea3324891937056089aWilliam Roberts} frp_block_device:blk_file rw_file_perms;
334206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalley
335a10f789d286d0f28c85488629cc92f5ab6ca8e00David Zeuthen# No domain other than recovery and update_engine can write to system partition(s).
336a10f789d286d0f28c85488629cc92f5ab6ca8e00David Zeuthenneverallow { domain -recovery -update_engine } system_block_device:blk_file write;
337206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalley
338206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalley# No domains other than install_recovery or recovery can write to recovery.
339206b1a6c45f1bae25906018d9c5d968330106826Stephen Smalleyneverallow { domain -install_recovery -recovery } recovery_block_device:blk_file write;
34010ecd05df39b25f4b504f795adafae5f45084a59dcashman
3412c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich# No domains other than a select few can access the misc_block_device. This
3422c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich# block device is reserved for OTA use.
3432c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich# Do not assert this rule on userdebug/eng builds, due to some devices using
3442c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich# this partition for testing purposes.
3452c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevichneverallow {
3462c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  domain
3472c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  userdebug_or_eng(`-domain') # exclude debuggable builds
3482c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  -init
3492c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  -uncrypt
3502c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  -update_engine
3512c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  -vold
3522c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich  -recovery
353d41ad551189c1b7be26a1807980418858b2a132eMihai Serban  -ueventd
3542c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich} misc_block_device:blk_file { append link relabelfrom rename write open read ioctl lock };
3552c7a5f26b96dc35310727b8e63c18445778dbbaaNick Kralevich
35610ecd05df39b25f4b504f795adafae5f45084a59dcashman# Only servicemanager should be able to register with binder as the context manager
35710ecd05df39b25f4b504f795adafae5f45084a59dcashmanneverallow { domain -servicemanager } *:binder set_context_mgr;
3583c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich
3593c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich# Only authorized processes should be writing to files in /data/dalvik-cache
3603c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevichneverallow {
3613c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  domain
3623c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -init # TODO: limit init to relabelfrom for files
3633c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -zygote
3643c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -installd
3653c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich  -dex2oat
3663c77d4d1c113282315fbccf696298e04f99a20b4Nick Kralevich} dalvikcache_data_file:file no_w_file_perms;
36714d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich
368d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalleyneverallow {
369d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  domain
370d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -init
371d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -installd
372d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -dex2oat
373d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley  -zygote
374d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley} dalvikcache_data_file:dir no_w_dir_perms;
375d9bf7b3fc008533a6552887a3451a311c3a2607aStephen Smalley
3768f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashman# Only system_server should be able to send commands via the zygote socket
3778f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashmanneverallow { domain -zygote -system_server } zygote:unix_stream_socket connectto;
3788f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashmanneverallow { domain -system_server } zygote_socket:sock_file write;
3798f81dcad5bb322a75bc61c8b42f8287e2afeaddcdcashman
38014d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# Android does not support System V IPCs.
38114d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
38214d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# The reason for this is due to the fact that, by design, they lead to global
38314d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# kernel resource leakage.
38414d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
38514d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# For example, there is no way to automatically release a SysV semaphore
38614d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# allocated in the kernel when:
38714d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
38814d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# - a buggy or malicious process exits
38914d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# - a non-buggy and non-malicious process crashes or is explicitly killed.
39014d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich#
39114d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# Killing processes automatically to make room for new ones is an
39214d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# important part of Android's application lifecycle implementation. This means
39314d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# that, even assuming only non-buggy and non-malicious code, it is very likely
39414d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# that over time, the kernel global tables used to implement SysV IPCs will fill
39514d5619a1aada9b3186ad9ea280ff75a08e1c368Nick Kralevich# up.
39635a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * *:{ shm sem msg msgq } *;
39774ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevich
39874ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevich# Do not mount on top of symlinks, fifos, or sockets.
39974ddf301a086a829787ed4fd98154a86534cf5d7Nick Kralevich# Feature parity with Chromium LSM.
40035a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * { file_type fs_type dev_type }:{ lnk_file fifo_file sock_file } mounton;
4018bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich
4028bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich# Nobody should be able to execute su on user builds.
4038bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich# On userdebug/eng builds, only dumpstate, shell, and
4048bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevich# su itself execute su.
4058bd13687b0a023ac2acf15175d52cafac9809b52Nick Kralevichneverallow { domain userdebug_or_eng(`-dumpstate -shell -su') } su_exec:file no_x_file_perms;
406359101ac289ad75653c954c07166bc658900bd28Nick Kralevich
407359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# Do not allow the introduction of new execmod rules. Text relocations
408359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# and modification of executable pages are unsafe.
409359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# The only exceptions are for NDK text relocations associated with
410359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# https://code.google.com/p/android/issues/detail?id=23203
411359101ac289ad75653c954c07166bc658900bd28Nick Kralevich# which, long term, need to go away.
41235a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * {
413359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  file_type
414359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -apk_data_file
415359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -app_data_file
416359101ac289ad75653c954c07166bc658900bd28Nick Kralevich  -asec_public_file
417359101ac289ad75653c954c07166bc658900bd28Nick Kralevich}:file execmod;
418359101ac289ad75653c954c07166bc658900bd28Nick Kralevich
4195328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley# Do not allow making the stack or heap executable.
4205328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley# We would also like to minimize execmem but it seems to be
4215328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley# required by some device-specific service domains.
42235a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * self:process { execstack execheap };
4235328d9749db00e8bbb0587913e5cc8bd8281db24Stephen Smalley
42489424bf9470931df90afa4f6d141b3696ad5a632Nick Kralevich# prohibit non-zygote spawned processes from using shared libraries
425998ce77f845cba7f14d4f54de3e87ebf9deafaedNick Kralevich# with text relocations. b/20013628 .
42689424bf9470931df90afa4f6d141b3696ad5a632Nick Kralevichneverallow { domain -appdomain } file_type:file execmod;
427e96c3abe2e86f3ecdfdb7770629e9f73ff1e96d1dcashman
428e96c3abe2e86f3ecdfdb7770629e9f73ff1e96d1dcashmanneverallow { domain -init } proc:{ file dir } mounton;
4294a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley
4304a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# Ensure that all types assigned to processes are included
4314a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# in the domain attribute, so that all allow and neverallow rules
4324a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# written on domain are applied to all processes.
4334a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# This is achieved by ensuring that it is impossible to transition
4344a12d9630ad22566bda75166e088cb05316e1934Stephen Smalley# from a domain to a non-domain type and vice versa.
4354a12d9630ad22566bda75166e088cb05316e1934Stephen Smalleyneverallow domain ~domain:process { transition dyntransition };
4364a12d9630ad22566bda75166e088cb05316e1934Stephen Smalleyneverallow ~domain domain:process { transition dyntransition };
437529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts
438529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts#
439529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# Only system_app and system_server should be creating or writing
440529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# their files. The proper way to share files is to setup
441529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# type transitions to a more specific type or assigning a type
442529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# to its parent directory via a file_contexts entry.
443529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# Example type transition:
444529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts#  mydomain.te:file_type_auto_trans(mydomain, system_data_file, new_file_type)
445529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts#
446529a8634e1d31967db2600ba27e55fc35b7d0195William Robertsneverallow {
447529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  domain
448529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -system_server
449529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -system_app
450529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -init
451529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts  -installd # for relabelfrom and unlink, check for this in explicit neverallow
452529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts} system_data_file:file no_w_file_perms;
453529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# do not grant anything greater than r_file_perms and relabelfrom unlink
454529a8634e1d31967db2600ba27e55fc35b7d0195William Roberts# to installd
455529a8634e1d31967db2600ba27e55fc35b7d0195William Robertsneverallow installd system_data_file:file ~{ r_file_perms relabelfrom unlink };
456d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts
4575470ffeb70617481b75b540fb1ba55bcc0fdb937William Roberts# respect system_app sandboxes
4585470ffeb70617481b75b540fb1ba55bcc0fdb937William Robertsneverallow {
4595470ffeb70617481b75b540fb1ba55bcc0fdb937William Roberts  domain
4605470ffeb70617481b75b540fb1ba55bcc0fdb937William Roberts  -system_app # its own sandbox
4615470ffeb70617481b75b540fb1ba55bcc0fdb937William Roberts  -system_server #populate com.android.providers.settings/databases/settings.db.
4625470ffeb70617481b75b540fb1ba55bcc0fdb937William Roberts  -installd # creation of app sandbox
4631cf262daed9f5cb6fd08b1942208b612492c7bbaWilliam Roberts} system_app_data_file:dir_file_class_set { create unlink open };
4645470ffeb70617481b75b540fb1ba55bcc0fdb937William Roberts
465d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Roberts# Services should respect app sandboxes
466d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Robertsneverallow {
467d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Roberts  domain
468d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Roberts  -appdomain
469d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Roberts  -installd # creation of sandbox
470d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Roberts} app_data_file:dir_file_class_set { create unlink };
471d7bd03c5bba06cce32dcd16bbd21b037927e347bWilliam Roberts
472d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts#
473d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts# Only these domains should transition to shell domain. This domain is
474d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts# permissible for the "shell user". If you need a process to exec a shell
475d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts# script with differing privilege, define a domain and set up a transition.
476d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts#
477d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Robertsneverallow {
478d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  domain
479d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -adbd
480d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -init
481d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -runas
482d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts  -zygote
483d1fa4d3d92c88bde9ecd118c178d0297d0f30f9bWilliam Roberts} shell:process { transition dyntransition };
4849d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley
4859d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley# Minimize read access to shell- or app-writable symlinks.
4869d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley# This is to prevent malicious symlink attacks.
4879d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalleyneverallow {
4889d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  domain
4899d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -appdomain
4909d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -installd
4919d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -uncrypt  # TODO: see if we can remove
4929d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley} app_data_file:lnk_file read;
4939d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley
4949d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalleyneverallow {
4959d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  domain
4969d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -shell
4979d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  userdebug_or_eng(`-uncrypt')
4989d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley  -installd
4999d439d3d4f6d5aa30b090f638f20841a3e3e72b2Stephen Smalley} shell_data_file:lnk_file read;
500f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich
501be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# In addition to the symlink reading restrictions above, restrict
502be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# write access to shell owned directories. The /data/local/tmp
503be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# directory is untrustworthy, and non-whitelisted domains should
504be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# not be trusting any content in those directories.
505be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevichneverallow {
506be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  domain
507be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -adbd
508be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -dumpstate
509be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -installd
510be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -init
511be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -shell
512be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -vold
513be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich} shell_data_file:dir no_w_dir_perms;
514be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich
515be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevichneverallow {
516be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  domain
517be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -adbd
518be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -appdomain
519be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -dumpstate
520be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -init
521be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -installd
522be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -system_server # why?
523be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  userdebug_or_eng(`-uncrypt')
524be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich} shell_data_file:dir { open search };
525be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich
526be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# Same as above for /data/local/tmp files. We allow shell files
527be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich# to be passed around by file descriptor, but not directly opened.
528be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevichneverallow {
529be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  domain
530be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -adbd
531be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -appdomain
532be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -dumpstate
533be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich  -installd
5349e6effa15f17e7951ad63ddd01fd22c1a42be616Nick Kralevich  userdebug_or_eng(`-uncrypt')
535be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich} shell_data_file:file open;
536be98d9cff3af80438239662605c5cf9b757a2df6Nick Kralevich
537f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich# servicemanager is the only process which handles list request
53835a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * ~servicemanager:service_manager list;
539f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich
540f2c4e1283e91f7a91963d1d68a27f515027d97b4Nick Kralevich# only service_manager_types can be added to service_manager
54135a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * ~service_manager_type:service_manager { add find };
542483fd267359a457ca4ac4c4a2cbce38af6c15981Jeff Vander Stoep
54359c23d78c894198f39d9af563f17c05fb266ec3eWilliam Roberts# Prevent assigning non property types to properties
54435a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * ~property_type:property_service set;
545f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts
546f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# Domain types should never be assigned to any files other
547f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# than the /proc/pid files associated with a process. The
548f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# executable file used to enter a domain should be labeled
549f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# with its own _exec type, not with the domain type.
550f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# Conventionally, this looks something like:
551f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# $ cat mydaemon.te
552f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# type mydaemon, domain;
553f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# type mydaemon_exec, exec_type, file_type;
554f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# init_daemon_domain(mydaemon)
555f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# $ grep mydaemon file_contexts
556f25304ee8472c48e7cacdda10b950827017e5cf9William Roberts# /system/bin/mydaemon -- u:object_r:mydaemon_exec:s0
55735a145143076ceee50f387025d8cb3c62e62569eNick Kralevichneverallow * domain:file { execute execute_no_trans entrypoint };
55896b1c9ca6f72f3adfa7f6051568efeb450c3756cNick Kralevich
55996b1c9ca6f72f3adfa7f6051568efeb450c3756cNick Kralevich# Do not allow access to the generic debugfs label. This is too broad.
56096b1c9ca6f72f3adfa7f6051568efeb450c3756cNick Kralevich# Instead, if access to part of debugfs is desired, it should have a
56196b1c9ca6f72f3adfa7f6051568efeb450c3756cNick Kralevich# more specific label.
56296b1c9ca6f72f3adfa7f6051568efeb450c3756cNick Kralevich# TODO: fix system_server and dumpstate
56396b1c9ca6f72f3adfa7f6051568efeb450c3756cNick Kralevichneverallow { domain -init -system_server -dumpstate } debugfs:file no_rw_file_perms;
564a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono
565a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirononeverallow {
566a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  domain
567a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -init
568a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -recovery
569a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -sdcardd
570a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -vold
571a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono} fuse_device:chr_file open;
572a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirononeverallow {
573a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  domain
574a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -dumpstate
575a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -init
576a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -priv_app
577a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -recovery
578a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -sdcardd
57972c16e32f5dfbf889819973cc2d842a094636d23William Roberts  -shell # Restricted by shell.te to only getattr
580a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -system_server
581a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -ueventd
582a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono  -vold
583a20802ddb87befbbd80d19e0a206aeb493528319Daichi Hirono} fuse_device:chr_file *;
58470159fd3bd014bdc97b087146490b7176a8d3cd1Jeff Vander Stoep
58570159fd3bd014bdc97b087146490b7176a8d3cd1Jeff Vander Stoep# Enforce restrictions on kernel module origin.
58670159fd3bd014bdc97b087146490b7176a8d3cd1Jeff Vander Stoep# Do not allow kernel module loading except from system,
58770159fd3bd014bdc97b087146490b7176a8d3cd1Jeff Vander Stoep# vendor, and boot partitions.
58870159fd3bd014bdc97b087146490b7176a8d3cd1Jeff Vander Stoepneverallow * ~{ system_file rootfs }:system module_load;
589