blob: 78f460a4d69edab27a3c2a190a6cf5e9dd86b640 [file] [log] [blame]
Nick Kralevichc4507592015-04-24 16:59:43 +00001# init switches to init domain (via init.rc).
Yongqin Liucc38e6d2014-12-05 13:40:22 +08002type init, domain, mlstrustedsubject;
Stephen Smalley2dd4e512012-01-04 12:33:27 -05003tmpfs_domain(init)
Nick Kralevich0c9708b2013-07-10 14:46:05 -07004
Stephen Smalleya523aac2014-10-24 15:56:15 -04005# setrlimit
6allow init self:capability sys_resource;
7
8# Remove /dev/.booting, created before initial policy load or restorecon /dev.
9allow init tmpfs:file unlink;
10
11# Access pty created for fsck.
12allow init devpts:chr_file { read write open };
13
14# Create /dev/fscklogs files.
15allow init fscklogs:file create_file_perms;
16
17# Access /dev/__null__ node created prior to initial policy load.
18allow init tmpfs:chr_file write;
19
20# Access /dev/console.
21allow init console_device:chr_file rw_file_perms;
22
23# Access /dev/tty0.
24allow init tty_device:chr_file rw_file_perms;
25
26# Call mount(2).
27allow init self:capability sys_admin;
28
29# Create and mount on directories in /.
30allow init rootfs:dir create_dir_perms;
31allow init rootfs:dir mounton;
32
33# Mount on /dev/usb-ffs/adb.
34allow init device:dir mounton;
35
Nick Kralevich88093412014-12-23 17:08:58 -080036# Create and remove symlinks in /.
37allow init rootfs:lnk_file { create unlink };
Stephen Smalleya523aac2014-10-24 15:56:15 -040038
39# Mount debugfs on /sys/kernel/debug.
40allow init sysfs:dir mounton;
41
42# Create cgroups mount points in tmpfs and mount cgroups on them.
43allow init tmpfs:dir create_dir_perms;
44allow init tmpfs:dir mounton;
45allow init cgroup:dir create_dir_perms;
46allow init cpuctl_device:dir { create mounton };
47
Nick Kralevich543facc2015-02-27 14:54:40 -080048# Use tmpfs as /data, used for booting when /data is encrypted
49allow init tmpfs:dir relabelfrom;
50
Stephen Smalleya523aac2014-10-24 15:56:15 -040051# Create directories under /dev/cpuctl after chowning it to system.
52allow init self:capability dac_override;
53
54# Set system clock.
55allow init self:capability sys_time;
56
Stephen Smalley5487ca02014-02-10 16:31:04 -050057allow init self:capability { sys_rawio mknod };
58
Stephen Smalley8a0c25e2014-09-23 09:11:30 -040059# Mounting filesystems from block devices.
60allow init dev_type:blk_file r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040061
62# Mounting filesystems.
Stephen Smalley75e2ef92014-06-16 13:05:38 -040063# Only allow relabelto for types used in context= mount options,
64# which should all be assigned the contextmount_type attribute.
65# This can be done in device-specific policy via type or typeattribute
66# declarations.
67allow init fs_type:filesystem ~relabelto;
68allow init unlabeled:filesystem ~relabelto;
69allow init contextmount_type:filesystem relabelto;
70
71# Allow read-only access to context= mounted filesystems.
72allow init contextmount_type:dir r_dir_perms;
73allow init contextmount_type:notdevfile_class_set r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040074
Stephen Smalleyc626a882014-06-23 09:17:51 -040075# restorecon /adb_keys or any other rootfs files to a more specific type.
76allow init rootfs:file relabelfrom;
77
Stephen Smalleya523aac2014-10-24 15:56:15 -040078# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
79# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040080# system/core/init.rc requires at least cache_file and data_file_type.
81# init.<board>.rc files often include device-specific types, so
82# we just allow all file types except /system files here.
Stephen Smalleya523aac2014-10-24 15:56:15 -040083allow init self:capability { chown fowner fsetid };
84allow init {file_type -system_file -exec_type -app_data_file}:dir { create search getattr open read setattr };
Jeff Sharkey4423ecd2015-03-31 15:03:13 -070085allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file -vold_data_file}:dir { write add_name remove_name rmdir relabelfrom };
86allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file -vold_data_file}:file { create getattr open read write setattr relabelfrom unlink };
87allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file -vold_data_file}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
88allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file -vold_data_file}:lnk_file { create getattr setattr relabelfrom unlink };
Nick Kralevich03ce5122014-05-20 11:09:16 -070089allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto;
Stephen Smalleya523aac2014-10-24 15:56:15 -040090allow init sysfs:{ dir file lnk_file } { getattr relabelfrom };
Stephen Smalley32915652014-07-17 14:54:44 -040091allow init sysfs_type:{ dir file lnk_file } relabelto;
Stephen Smalleya523aac2014-10-24 15:56:15 -040092allow init dev_type:dir create_dir_perms;
93allow init dev_type:lnk_file create;
94
95# chown/chmod on pseudo files.
Nick Kralevichfcd86912015-02-06 13:29:25 -080096allow init { fs_type -contextmount_type -sdcard_type -rootfs }:file { open read setattr };
97allow init { fs_type -contextmount_type -sdcard_type -rootfs }:dir { open read setattr search };
Stephen Smalleya523aac2014-10-24 15:56:15 -040098
99# chown/chmod on devices.
Stephen Smalley1c16abd2014-11-10 12:15:33 -0500100allow init { dev_type -kmem_device }:chr_file { read open setattr };
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400101
Stephen Smalley73b03462014-05-30 09:53:00 -0400102# Unlabeled file access for upgrades from 4.2.
103allow init unlabeled:dir { create_dir_perms relabelfrom };
104allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
105
Stephen Smalley3235f612014-05-30 10:25:00 -0400106# Create /data/security from init.rc post-fs-data.
107allow init security_file:dir { create setattr };
108
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400109# Reload policy upon setprop selinux.reload_policy 1.
Stephen Smalley3235f612014-05-30 10:25:00 -0400110r_dir_file(init, security_file)
Stephen Smalleyfea6e662013-12-06 08:05:53 -0500111allow init kernel:security load_policy;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400112
113# Any operation that can modify the kernel ring buffer, e.g. clear
114# or a read that consumes the messages that were read.
Nick Kralevich685e2f92014-05-28 13:48:52 -0700115allow init kernel:system syslog_mod;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400116allow init self:capability2 syslog;
117
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400118# Set usermodehelpers and /proc security settings.
Stephen Smalley7adb9992013-12-06 09:31:40 -0500119allow init usermodehelper:file rw_file_perms;
120allow init proc_security:file rw_file_perms;
Nick Kralevichfed8a2a2014-01-24 20:43:07 -0800121
Stephen Smalleya523aac2014-10-24 15:56:15 -0400122# Write to /proc/sys/kernel/panic_on_oops.
123allow init proc:file w_file_perms;
124
125# Write to /proc/sys/net/ping_group_range and other /proc/sys/net files.
Nick Kralevich5cf39942015-02-25 13:28:40 -0800126allow init proc_net:file w_file_perms;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400127allow init self:capability net_admin;
128
129# Write to /proc/sysrq-trigger.
130allow init proc_sysrq:file w_file_perms;
131
132# Reboot.
133allow init self:capability sys_boot;
134
135# Write to sysfs nodes.
136allow init sysfs_type:dir r_dir_perms;
137allow init sysfs_type:file w_file_perms;
138
Nick Kralevichfed8a2a2014-01-24 20:43:07 -0800139# Transitions to seclabel processes in init.rc
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700140domain_trans(init, rootfs, adbd)
141domain_trans(init, rootfs, healthd)
Sami Tolvanen9d87c642015-02-18 13:59:38 +0000142domain_trans(init, rootfs, slideshow)
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700143recovery_only(`
144 domain_trans(init, rootfs, recovery)
145')
146domain_trans(init, shell_exec, shell)
Nick Kralevichc4507592015-04-24 16:59:43 +0000147domain_trans(init, rootfs, ueventd)
148domain_trans(init, rootfs, watchdogd)
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700149
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700150# Support "adb shell stop"
Stephen Smalleya523aac2014-10-24 15:56:15 -0400151allow init self:capability kill;
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700152allow init domain:process sigkill;
Nick Kralevichcd905ec2014-05-08 23:28:52 -0700153
154# Init creates keystore's directory on boot, and walks through
155# the directory as part of a recursive restorecon.
156allow init keystore_data_file:dir { open create read getattr setattr search };
157allow init keystore_data_file:file { getattr };
Stephen Smalley356f4be2014-05-23 11:26:19 -0400158
Jeff Sharkey4423ecd2015-03-31 15:03:13 -0700159# Init creates vold's directory on boot, and walks through
160# the directory as part of a recursive restorecon.
161allow init vold_data_file:dir { open create read getattr setattr search };
162allow init vold_data_file:file { getattr };
163
Nick Kralevichee49c0e2014-06-07 10:00:59 -0700164# Init creates /data/local/tmp at boot
165allow init shell_data_file:dir { open create read getattr setattr search };
166allow init shell_data_file:file { getattr };
167
Stephen Smalleya523aac2014-10-24 15:56:15 -0400168# Set UID and GID for services.
169allow init self:capability { setuid setgid };
170
Yongqin Liucc38e6d2014-12-05 13:40:22 +0800171# For bootchart to read the /proc/$pid/cmdline file of each process,
172# we need to have following line to allow init to have access
173# to different domains.
174r_dir_file(init, domain)
175
Stephen Smalley356f4be2014-05-23 11:26:19 -0400176# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
177# setexec is for services with seclabel options.
178# setfscreate is for labeling directories and socket files.
179# setsockcreate is for labeling local/unix domain sockets.
180allow init self:process { setexec setfscreate setsockcreate };
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -0400181
Stephen Smalleya523aac2014-10-24 15:56:15 -0400182# Perform SELinux access checks on setting properties.
183selinux_check_access(init)
184
185# Ask the kernel for the new context on services to label their sockets.
186allow init kernel:security compute_create;
187
188# Create sockets for the services.
189allow init domain:unix_stream_socket { create bind };
190allow init domain:unix_dgram_socket { create bind };
191
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -0400192# Create /data/property and files within it.
193allow init property_data_file:dir create_dir_perms;
194allow init property_data_file:file create_file_perms;
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400195
Stephen Smalleyfee49152014-06-19 10:27:02 -0400196# Set any property.
197allow init property_type:property_service set;
198
Nick Kralevich0db95cc2014-06-20 21:15:56 -0700199# Run "ifup lo" to bring up the localhost interface
200allow init self:udp_socket { create ioctl };
Stephen Smalleya523aac2014-10-24 15:56:15 -0400201allow init self:capability net_raw;
Nick Kralevich0db95cc2014-06-20 21:15:56 -0700202
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700203# This line seems suspect, as it should not really need to
204# set scheduling parameters for a kernel domain task.
205allow init kernel:process setsched;
206
Nick Kralevichbeb279c2014-10-20 11:52:19 -0700207# swapon() needs write access to swap device
208# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
209allow init swap_block_device:blk_file rw_file_perms;
210
Stephen Smalley0d08d472014-10-21 10:09:33 -0400211# Read from /dev/hw_random if present.
212# system/core/init/init.c - mix_hwrng_into_linux_rng_action
213allow init hw_random_device:chr_file r_file_perms;
214
215# Create and access /dev files without a specific type,
Stephen Smalleya523aac2014-10-24 15:56:15 -0400216# e.g. /dev/.coldboot_done, /dev/.booting
Stephen Smalley0d08d472014-10-21 10:09:33 -0400217# TODO: Move these files into their own type unless they are
218# only ever accessed by init.
219allow init device:file create_file_perms;
Stephen Smalley0d08d472014-10-21 10:09:33 -0400220
221# Access character devices without a specific type,
222# e.g. /dev/keychord.
223# TODO: Move these devices into their own type unless they
224# are only ever accessed by init.
225allow init device:chr_file { rw_file_perms setattr };
Stephen Smalley0d08d472014-10-21 10:09:33 -0400226
Stephen Smalleya523aac2014-10-24 15:56:15 -0400227# keychord configuration
228allow init self:capability sys_tty_config;
229
Sami Tolvanen35f537c2015-03-05 00:55:29 +0000230# Access device mapper for setting up dm-verity
231allow init dm_device:chr_file rw_file_perms;
232allow init dm_device:blk_file rw_file_perms;
233
234# Access metadata block device for storing dm-verity state
235allow init metadata_block_device:blk_file rw_file_perms;
236
237# Read /sys/fs/pstore/console-ramoops to detect restarts caused
238# by dm-verity detecting corrupted blocks
239allow init pstorefs:dir search;
240allow init pstorefs:file r_file_perms;
241
Paul Lawrence38af1da2015-03-11 15:44:14 -0700242# linux keyring configuration
243allow init init:key { write search setattr };
244
245# Allow init to link temp fs to unencrypted data on userdata
246allow init tmpfs:lnk_file { create read getattr relabelfrom };
247
248# Allow init to manipulate /data/unencrypted
249allow init unencrypted_data_file:{ file lnk_file } create_file_perms;
250allow init unencrypted_data_file:dir create_dir_perms;
251
252unix_socket_connect(init, vold, vold)
253
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400254###
255### neverallow rules
256###
257
258# The init domain is only entered via setcon from the kernel domain,
259# never via an exec-based transition.
Nick Kralevichc4507592015-04-24 16:59:43 +0000260neverallow { domain -kernel} init:process dyntransition;
261neverallow domain init:process transition;
262neverallow init { file_type fs_type }:file entrypoint;
Stephen Smalley018e9402014-09-02 17:05:44 -0400263
264# Never read/follow symlinks created by shell or untrusted apps.
265neverallow init shell_data_file:lnk_file read;
266neverallow init app_data_file:lnk_file read;
Stephen Smalley8a0c25e2014-09-23 09:11:30 -0400267
268# init should never execute a program without changing to another domain.
269neverallow init { file_type fs_type }:file execute_no_trans;