blob: 1283ec70938c08d1b49df9efb617782320407e09 [file] [log] [blame]
Stephen Smalley2dd4e512012-01-04 12:33:27 -05001# init switches to init domain (via init.rc).
2type init, domain;
Stephen Smalleya523aac2014-10-24 15:56:15 -04003permissive_or_unconfined(init)
Stephen Smalley2dd4e512012-01-04 12:33:27 -05004tmpfs_domain(init)
Nick Kralevich0c9708b2013-07-10 14:46:05 -07005
Stephen Smalleya523aac2014-10-24 15:56:15 -04006# setrlimit
7allow init self:capability sys_resource;
8
9# Remove /dev/.booting, created before initial policy load or restorecon /dev.
10allow init tmpfs:file unlink;
11
12# Access pty created for fsck.
13allow init devpts:chr_file { read write open };
14
15# Create /dev/fscklogs files.
16allow init fscklogs:file create_file_perms;
17
18# Access /dev/__null__ node created prior to initial policy load.
19allow init tmpfs:chr_file write;
20
21# Access /dev/console.
22allow init console_device:chr_file rw_file_perms;
23
24# Access /dev/tty0.
25allow init tty_device:chr_file rw_file_perms;
26
27# Call mount(2).
28allow init self:capability sys_admin;
29
30# Create and mount on directories in /.
31allow init rootfs:dir create_dir_perms;
32allow init rootfs:dir mounton;
33
34# Mount on /dev/usb-ffs/adb.
35allow init device:dir mounton;
36
Nick Kralevich88093412014-12-23 17:08:58 -080037# Create and remove symlinks in /.
38allow init rootfs:lnk_file { create unlink };
Stephen Smalleya523aac2014-10-24 15:56:15 -040039
40# Mount debugfs on /sys/kernel/debug.
41allow init sysfs:dir mounton;
42
43# Create cgroups mount points in tmpfs and mount cgroups on them.
44allow init tmpfs:dir create_dir_perms;
45allow init tmpfs:dir mounton;
46allow init cgroup:dir create_dir_perms;
47allow init cpuctl_device:dir { create mounton };
48
49# Create directories under /dev/cpuctl after chowning it to system.
50allow init self:capability dac_override;
51
52# Set system clock.
53allow init self:capability sys_time;
54
Stephen Smalley5487ca02014-02-10 16:31:04 -050055allow init self:capability { sys_rawio mknod };
56
Stephen Smalley8a0c25e2014-09-23 09:11:30 -040057# Mounting filesystems from block devices.
58allow init dev_type:blk_file r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040059
60# Mounting filesystems.
Stephen Smalley75e2ef92014-06-16 13:05:38 -040061# Only allow relabelto for types used in context= mount options,
62# which should all be assigned the contextmount_type attribute.
63# This can be done in device-specific policy via type or typeattribute
64# declarations.
65allow init fs_type:filesystem ~relabelto;
66allow init unlabeled:filesystem ~relabelto;
67allow init contextmount_type:filesystem relabelto;
68
69# Allow read-only access to context= mounted filesystems.
70allow init contextmount_type:dir r_dir_perms;
71allow init contextmount_type:notdevfile_class_set r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040072
Stephen Smalleyc626a882014-06-23 09:17:51 -040073# restorecon /adb_keys or any other rootfs files to a more specific type.
74allow init rootfs:file relabelfrom;
75
Stephen Smalleya523aac2014-10-24 15:56:15 -040076# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
77# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040078# system/core/init.rc requires at least cache_file and data_file_type.
79# init.<board>.rc files often include device-specific types, so
80# we just allow all file types except /system files here.
Stephen Smalleya523aac2014-10-24 15:56:15 -040081allow init self:capability { chown fowner fsetid };
82allow init {file_type -system_file -exec_type -app_data_file}:dir { create search getattr open read setattr };
Stephen Smalleyc4575722014-10-30 16:50:25 -040083allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:dir { write add_name remove_name rmdir relabelfrom };
Stephen Smalleya523aac2014-10-24 15:56:15 -040084allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:file { create getattr open read write setattr relabelfrom unlink };
85allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
86allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:lnk_file { create getattr setattr relabelfrom unlink };
Nick Kralevich03ce5122014-05-20 11:09:16 -070087allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto;
Stephen Smalleya523aac2014-10-24 15:56:15 -040088allow init sysfs:{ dir file lnk_file } { getattr relabelfrom };
Stephen Smalley32915652014-07-17 14:54:44 -040089allow init sysfs_type:{ dir file lnk_file } relabelto;
Stephen Smalleya523aac2014-10-24 15:56:15 -040090allow init dev_type:dir create_dir_perms;
91allow init dev_type:lnk_file create;
92
93# chown/chmod on pseudo files.
Nick Kralevichfcd86912015-02-06 13:29:25 -080094allow init { fs_type -contextmount_type -sdcard_type -rootfs }:file { open read setattr };
95allow init { fs_type -contextmount_type -sdcard_type -rootfs }:dir { open read setattr search };
Stephen Smalleya523aac2014-10-24 15:56:15 -040096
97# chown/chmod on devices.
Stephen Smalley1c16abd2014-11-10 12:15:33 -050098allow init { dev_type -kmem_device }:chr_file { read open setattr };
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040099
Stephen Smalley73b03462014-05-30 09:53:00 -0400100# Unlabeled file access for upgrades from 4.2.
101allow init unlabeled:dir { create_dir_perms relabelfrom };
102allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
103
Stephen Smalley3235f612014-05-30 10:25:00 -0400104# Create /data/security from init.rc post-fs-data.
105allow init security_file:dir { create setattr };
106
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400107# Reload policy upon setprop selinux.reload_policy 1.
Stephen Smalley3235f612014-05-30 10:25:00 -0400108r_dir_file(init, security_file)
Stephen Smalleyfea6e662013-12-06 08:05:53 -0500109allow init kernel:security load_policy;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400110
111# Any operation that can modify the kernel ring buffer, e.g. clear
112# or a read that consumes the messages that were read.
Nick Kralevich685e2f92014-05-28 13:48:52 -0700113allow init kernel:system syslog_mod;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400114allow init self:capability2 syslog;
115
116# Triggered by chmod 0444 /sys/fs/selinux/policy.
117allow init kernel:security read_policy;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400118
119# Set usermodehelpers and /proc security settings.
Stephen Smalley7adb9992013-12-06 09:31:40 -0500120allow init usermodehelper:file rw_file_perms;
121allow init proc_security:file rw_file_perms;
Nick Kralevichfed8a2a2014-01-24 20:43:07 -0800122
Stephen Smalleya523aac2014-10-24 15:56:15 -0400123# Write to /proc/sys/kernel/panic_on_oops.
124allow init proc:file w_file_perms;
125
126# Write to /proc/sys/net/ping_group_range and other /proc/sys/net files.
Nick Kralevich99940d12015-01-14 14:12:14 -0800127allow init proc_net:file rw_file_perms;
128allow init proc_net:dir r_dir_perms;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400129allow init self:capability net_admin;
130
131# Write to /proc/sysrq-trigger.
132allow init proc_sysrq:file w_file_perms;
133
134# Reboot.
135allow init self:capability sys_boot;
136
137# Write to sysfs nodes.
138allow init sysfs_type:dir r_dir_perms;
139allow init sysfs_type:file w_file_perms;
140
Nick Kralevichfed8a2a2014-01-24 20:43:07 -0800141# Transitions to seclabel processes in init.rc
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700142domain_trans(init, rootfs, adbd)
143domain_trans(init, rootfs, healthd)
144recovery_only(`
145 domain_trans(init, rootfs, recovery)
146')
147domain_trans(init, shell_exec, shell)
148domain_trans(init, rootfs, ueventd)
149domain_trans(init, rootfs, watchdogd)
150
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700151# Support "adb shell stop"
Stephen Smalleya523aac2014-10-24 15:56:15 -0400152allow init self:capability kill;
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700153allow init domain:process sigkill;
Nick Kralevichcd905ec2014-05-08 23:28:52 -0700154
155# Init creates keystore's directory on boot, and walks through
156# the directory as part of a recursive restorecon.
157allow init keystore_data_file:dir { open create read getattr setattr search };
158allow init keystore_data_file:file { getattr };
Stephen Smalley356f4be2014-05-23 11:26:19 -0400159
Nick Kralevichee49c0e2014-06-07 10:00:59 -0700160# Init creates /data/local/tmp at boot
161allow init shell_data_file:dir { open create read getattr setattr search };
162allow init shell_data_file:file { getattr };
163
Stephen Smalleya523aac2014-10-24 15:56:15 -0400164# Set UID and GID for services.
165allow init self:capability { setuid setgid };
166
Stephen Smalley356f4be2014-05-23 11:26:19 -0400167# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
168# setexec is for services with seclabel options.
169# setfscreate is for labeling directories and socket files.
170# setsockcreate is for labeling local/unix domain sockets.
171allow init self:process { setexec setfscreate setsockcreate };
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -0400172
Stephen Smalleya523aac2014-10-24 15:56:15 -0400173# Perform SELinux access checks on setting properties.
174selinux_check_access(init)
175
176# Ask the kernel for the new context on services to label their sockets.
177allow init kernel:security compute_create;
178
179# Create sockets for the services.
180allow init domain:unix_stream_socket { create bind };
181allow init domain:unix_dgram_socket { create bind };
182
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -0400183# Create /data/property and files within it.
184allow init property_data_file:dir create_dir_perms;
185allow init property_data_file:file create_file_perms;
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400186
Stephen Smalleyfee49152014-06-19 10:27:02 -0400187# Set any property.
188allow init property_type:property_service set;
189
Nick Kralevich0db95cc2014-06-20 21:15:56 -0700190# Run "ifup lo" to bring up the localhost interface
191allow init self:udp_socket { create ioctl };
Stephen Smalleya523aac2014-10-24 15:56:15 -0400192allow init self:capability net_raw;
Nick Kralevich0db95cc2014-06-20 21:15:56 -0700193
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700194# This line seems suspect, as it should not really need to
195# set scheduling parameters for a kernel domain task.
196allow init kernel:process setsched;
197
Nick Kralevichbeb279c2014-10-20 11:52:19 -0700198# swapon() needs write access to swap device
199# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
200allow init swap_block_device:blk_file rw_file_perms;
201
Stephen Smalley0d08d472014-10-21 10:09:33 -0400202# Read from /dev/hw_random if present.
203# system/core/init/init.c - mix_hwrng_into_linux_rng_action
204allow init hw_random_device:chr_file r_file_perms;
205
206# Create and access /dev files without a specific type,
Stephen Smalleya523aac2014-10-24 15:56:15 -0400207# e.g. /dev/.coldboot_done, /dev/.booting
Stephen Smalley0d08d472014-10-21 10:09:33 -0400208# TODO: Move these files into their own type unless they are
209# only ever accessed by init.
210allow init device:file create_file_perms;
Stephen Smalley0d08d472014-10-21 10:09:33 -0400211
212# Access character devices without a specific type,
213# e.g. /dev/keychord.
214# TODO: Move these devices into their own type unless they
215# are only ever accessed by init.
216allow init device:chr_file { rw_file_perms setattr };
Stephen Smalley0d08d472014-10-21 10:09:33 -0400217
Stephen Smalleya523aac2014-10-24 15:56:15 -0400218# keychord configuration
219allow init self:capability sys_tty_config;
220
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400221###
222### neverallow rules
223###
224
225# The init domain is only entered via setcon from the kernel domain,
226# never via an exec-based transition.
227neverallow { domain -kernel} init:process dyntransition;
228neverallow domain init:process transition;
229neverallow init { file_type fs_type }:file entrypoint;
Stephen Smalley018e9402014-09-02 17:05:44 -0400230
231# Never read/follow symlinks created by shell or untrusted apps.
232neverallow init shell_data_file:lnk_file read;
233neverallow init app_data_file:lnk_file read;
Stephen Smalley8a0c25e2014-09-23 09:11:30 -0400234
235# init should never execute a program without changing to another domain.
236neverallow init { file_type fs_type }:file execute_no_trans;