Stephen Smalley | 2dd4e51 | 2012-01-04 12:33:27 -0500 | [diff] [blame] | 1 | # init switches to init domain (via init.rc). |
| 2 | type init, domain; |
Stephen Smalley | 2dd4e51 | 2012-01-04 12:33:27 -0500 | [diff] [blame] | 3 | # init is unconfined. |
| 4 | unconfined_domain(init) |
| 5 | tmpfs_domain(init) |
Nick Kralevich | 0c9708b | 2013-07-10 14:46:05 -0700 | [diff] [blame] | 6 | |
Stephen Smalley | 5487ca0 | 2014-02-10 16:31:04 -0500 | [diff] [blame] | 7 | allow init self:capability { sys_rawio mknod }; |
| 8 | |
Stephen Smalley | 8a0c25e | 2014-09-23 09:11:30 -0400 | [diff] [blame] | 9 | # Mounting filesystems from block devices. |
| 10 | allow init dev_type:blk_file r_file_perms; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 11 | |
| 12 | # Mounting filesystems. |
Stephen Smalley | 75e2ef9 | 2014-06-16 13:05:38 -0400 | [diff] [blame] | 13 | # Only allow relabelto for types used in context= mount options, |
| 14 | # which should all be assigned the contextmount_type attribute. |
| 15 | # This can be done in device-specific policy via type or typeattribute |
| 16 | # declarations. |
| 17 | allow init fs_type:filesystem ~relabelto; |
| 18 | allow init unlabeled:filesystem ~relabelto; |
| 19 | allow init contextmount_type:filesystem relabelto; |
| 20 | |
| 21 | # Allow read-only access to context= mounted filesystems. |
| 22 | allow init contextmount_type:dir r_dir_perms; |
| 23 | allow init contextmount_type:notdevfile_class_set r_file_perms; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 24 | |
Stephen Smalley | c626a88 | 2014-06-23 09:17:51 -0400 | [diff] [blame] | 25 | # restorecon /adb_keys or any other rootfs files to a more specific type. |
| 26 | allow init rootfs:file relabelfrom; |
| 27 | |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 28 | # restorecon and restorecon_recursive calls from init.rc files. |
| 29 | # system/core/init.rc requires at least cache_file and data_file_type. |
| 30 | # init.<board>.rc files often include device-specific types, so |
| 31 | # we just allow all file types except /system files here. |
Nick Kralevich | 03ce512 | 2014-05-20 11:09:16 -0700 | [diff] [blame] | 32 | allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto; |
Stephen Smalley | 3291565 | 2014-07-17 14:54:44 -0400 | [diff] [blame] | 33 | allow init sysfs_type:{ dir file lnk_file } relabelto; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 34 | |
Stephen Smalley | 73b0346 | 2014-05-30 09:53:00 -0400 | [diff] [blame] | 35 | # Unlabeled file access for upgrades from 4.2. |
| 36 | allow init unlabeled:dir { create_dir_perms relabelfrom }; |
| 37 | allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom }; |
| 38 | |
Stephen Smalley | 3235f61 | 2014-05-30 10:25:00 -0400 | [diff] [blame] | 39 | # Create /data/security from init.rc post-fs-data. |
| 40 | allow init security_file:dir { create setattr }; |
| 41 | |
| 42 | # setprop selinux.reload_policy 1 from init.rc post-fs-data. |
| 43 | allow init security_prop:property_service set; |
| 44 | |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 45 | # Reload policy upon setprop selinux.reload_policy 1. |
Stephen Smalley | 3235f61 | 2014-05-30 10:25:00 -0400 | [diff] [blame] | 46 | r_dir_file(init, security_file) |
Stephen Smalley | fea6e66 | 2013-12-06 08:05:53 -0500 | [diff] [blame] | 47 | allow init kernel:security load_policy; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 48 | |
| 49 | # Any operation that can modify the kernel ring buffer, e.g. clear |
| 50 | # or a read that consumes the messages that were read. |
Nick Kralevich | 685e2f9 | 2014-05-28 13:48:52 -0700 | [diff] [blame] | 51 | allow init kernel:system syslog_mod; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 52 | |
| 53 | # Set usermodehelpers and /proc security settings. |
Stephen Smalley | 7adb999 | 2013-12-06 09:31:40 -0500 | [diff] [blame] | 54 | allow init usermodehelper:file rw_file_perms; |
| 55 | allow init proc_security:file rw_file_perms; |
Nick Kralevich | fed8a2a | 2014-01-24 20:43:07 -0800 | [diff] [blame] | 56 | |
| 57 | # Transitions to seclabel processes in init.rc |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 58 | domain_trans(init, rootfs, adbd) |
| 59 | domain_trans(init, rootfs, healthd) |
| 60 | recovery_only(` |
| 61 | domain_trans(init, rootfs, recovery) |
| 62 | ') |
| 63 | domain_trans(init, shell_exec, shell) |
| 64 | domain_trans(init, rootfs, ueventd) |
| 65 | domain_trans(init, rootfs, watchdogd) |
| 66 | |
| 67 | # Certain domains need LD_PRELOAD passed from init. |
| 68 | # https://android-review.googlesource.com/94851 |
Nick Kralevich | 8a5b28d | 2014-07-16 18:42:36 -0700 | [diff] [blame] | 69 | # For now, allow it to most domains. |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 70 | # TODO: scope this down. |
Nick Kralevich | 8a5b28d | 2014-07-16 18:42:36 -0700 | [diff] [blame] | 71 | allow init { domain -lmkd }:process noatsecure; |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 72 | |
| 73 | # Support "adb shell stop" |
| 74 | allow init domain:process sigkill; |
Nick Kralevich | cd905ec | 2014-05-08 23:28:52 -0700 | [diff] [blame] | 75 | |
| 76 | # Init creates keystore's directory on boot, and walks through |
| 77 | # the directory as part of a recursive restorecon. |
| 78 | allow init keystore_data_file:dir { open create read getattr setattr search }; |
| 79 | allow init keystore_data_file:file { getattr }; |
Stephen Smalley | 356f4be | 2014-05-23 11:26:19 -0400 | [diff] [blame] | 80 | |
Nick Kralevich | ee49c0e | 2014-06-07 10:00:59 -0700 | [diff] [blame] | 81 | # Init creates /data/local/tmp at boot |
| 82 | allow init shell_data_file:dir { open create read getattr setattr search }; |
| 83 | allow init shell_data_file:file { getattr }; |
| 84 | |
Stephen Smalley | 356f4be | 2014-05-23 11:26:19 -0400 | [diff] [blame] | 85 | # Use setexeccon(), setfscreatecon(), and setsockcreatecon(). |
| 86 | # setexec is for services with seclabel options. |
| 87 | # setfscreate is for labeling directories and socket files. |
| 88 | # setsockcreate is for labeling local/unix domain sockets. |
| 89 | allow init self:process { setexec setfscreate setsockcreate }; |
Stephen Smalley | ad0d0fc | 2014-05-29 09:22:16 -0400 | [diff] [blame] | 90 | |
| 91 | # Create /data/property and files within it. |
| 92 | allow init property_data_file:dir create_dir_perms; |
| 93 | allow init property_data_file:file create_file_perms; |
Stephen Smalley | bac4ccc | 2014-06-18 10:09:35 -0400 | [diff] [blame] | 94 | |
Stephen Smalley | fee4915 | 2014-06-19 10:27:02 -0400 | [diff] [blame] | 95 | # Set any property. |
| 96 | allow init property_type:property_service set; |
| 97 | |
Nick Kralevich | 0db95cc | 2014-06-20 21:15:56 -0700 | [diff] [blame] | 98 | # Run "ifup lo" to bring up the localhost interface |
| 99 | allow init self:udp_socket { create ioctl }; |
| 100 | |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 101 | # This line seems suspect, as it should not really need to |
| 102 | # set scheduling parameters for a kernel domain task. |
| 103 | allow init kernel:process setsched; |
| 104 | |
Stephen Smalley | bac4ccc | 2014-06-18 10:09:35 -0400 | [diff] [blame] | 105 | ### |
| 106 | ### neverallow rules |
| 107 | ### |
| 108 | |
| 109 | # The init domain is only entered via setcon from the kernel domain, |
| 110 | # never via an exec-based transition. |
| 111 | neverallow { domain -kernel} init:process dyntransition; |
| 112 | neverallow domain init:process transition; |
| 113 | neverallow init { file_type fs_type }:file entrypoint; |
Stephen Smalley | 018e940 | 2014-09-02 17:05:44 -0400 | [diff] [blame] | 114 | |
| 115 | # Never read/follow symlinks created by shell or untrusted apps. |
| 116 | neverallow init shell_data_file:lnk_file read; |
| 117 | neverallow init app_data_file:lnk_file read; |
Stephen Smalley | 8a0c25e | 2014-09-23 09:11:30 -0400 | [diff] [blame] | 118 | |
| 119 | # init should never execute a program without changing to another domain. |
| 120 | neverallow init { file_type fs_type }:file execute_no_trans; |