blob: 9f68bb85dbcf75391499baa265fefaa350e63bd9 [file] [log] [blame]
Elliott Hughes46e832f2015-04-22 18:38:41 -07001# init is its own domain.
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
Elliott Hughes46e832f2015-04-22 18:38:41 -07005# The init domain is entered by execing init.
6type init_exec, exec_type, file_type;
7
8# /dev/__null__ node created by init.
9allow init tmpfs:chr_file create_file_perms;
10
11#
12# init direct restorecon calls.
13#
14# /dev/socket
15allow init { device socket_device }:dir relabelto;
16# /dev/__properties__
17allow init tmpfs:file relabelfrom;
18allow init properties_device:file relabelto;
19
Stephen Smalleya523aac2014-10-24 15:56:15 -040020# setrlimit
21allow init self:capability sys_resource;
22
23# Remove /dev/.booting, created before initial policy load or restorecon /dev.
24allow init tmpfs:file unlink;
25
26# Access pty created for fsck.
27allow init devpts:chr_file { read write open };
28
29# Create /dev/fscklogs files.
30allow init fscklogs:file create_file_perms;
31
32# Access /dev/__null__ node created prior to initial policy load.
33allow init tmpfs:chr_file write;
34
35# Access /dev/console.
36allow init console_device:chr_file rw_file_perms;
37
38# Access /dev/tty0.
39allow init tty_device:chr_file rw_file_perms;
40
41# Call mount(2).
42allow init self:capability sys_admin;
43
44# Create and mount on directories in /.
45allow init rootfs:dir create_dir_perms;
46allow init rootfs:dir mounton;
47
Elliott Hughes46e832f2015-04-22 18:38:41 -070048allow init proc:dir mounton;
49
Stephen Smalleya523aac2014-10-24 15:56:15 -040050# Mount on /dev/usb-ffs/adb.
51allow init device:dir mounton;
52
Nick Kralevich88093412014-12-23 17:08:58 -080053# Create and remove symlinks in /.
54allow init rootfs:lnk_file { create unlink };
Stephen Smalleya523aac2014-10-24 15:56:15 -040055
56# Mount debugfs on /sys/kernel/debug.
57allow init sysfs:dir mounton;
58
59# Create cgroups mount points in tmpfs and mount cgroups on them.
60allow init tmpfs:dir create_dir_perms;
61allow init tmpfs:dir mounton;
62allow init cgroup:dir create_dir_perms;
63allow init cpuctl_device:dir { create mounton };
64
Nick Kralevich543facc2015-02-27 14:54:40 -080065# Use tmpfs as /data, used for booting when /data is encrypted
66allow init tmpfs:dir relabelfrom;
67
Stephen Smalleya523aac2014-10-24 15:56:15 -040068# Create directories under /dev/cpuctl after chowning it to system.
69allow init self:capability dac_override;
70
71# Set system clock.
72allow init self:capability sys_time;
73
Stephen Smalley5487ca02014-02-10 16:31:04 -050074allow init self:capability { sys_rawio mknod };
75
Stephen Smalley8a0c25e2014-09-23 09:11:30 -040076# Mounting filesystems from block devices.
77allow init dev_type:blk_file r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040078
79# Mounting filesystems.
Stephen Smalley75e2ef92014-06-16 13:05:38 -040080# Only allow relabelto for types used in context= mount options,
81# which should all be assigned the contextmount_type attribute.
82# This can be done in device-specific policy via type or typeattribute
83# declarations.
84allow init fs_type:filesystem ~relabelto;
85allow init unlabeled:filesystem ~relabelto;
86allow init contextmount_type:filesystem relabelto;
87
88# Allow read-only access to context= mounted filesystems.
89allow init contextmount_type:dir r_dir_perms;
90allow init contextmount_type:notdevfile_class_set r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040091
Stephen Smalleyc626a882014-06-23 09:17:51 -040092# restorecon /adb_keys or any other rootfs files to a more specific type.
93allow init rootfs:file relabelfrom;
94
Stephen Smalleya523aac2014-10-24 15:56:15 -040095# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
96# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040097# system/core/init.rc requires at least cache_file and data_file_type.
98# init.<board>.rc files often include device-specific types, so
99# we just allow all file types except /system files here.
Stephen Smalleya523aac2014-10-24 15:56:15 -0400100allow init self:capability { chown fowner fsetid };
101allow init {file_type -system_file -exec_type -app_data_file}:dir { create search getattr open read setattr };
Jeff Sharkey4423ecd2015-03-31 15:03:13 -0700102allow 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 };
103allow 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 };
104allow 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 };
105allow 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 -0700106allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400107allow init sysfs:{ dir file lnk_file } { getattr relabelfrom };
Stephen Smalley32915652014-07-17 14:54:44 -0400108allow init sysfs_type:{ dir file lnk_file } relabelto;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400109allow init dev_type:dir create_dir_perms;
110allow init dev_type:lnk_file create;
111
112# chown/chmod on pseudo files.
Nick Kralevichfcd86912015-02-06 13:29:25 -0800113allow init { fs_type -contextmount_type -sdcard_type -rootfs }:file { open read setattr };
114allow init { fs_type -contextmount_type -sdcard_type -rootfs }:dir { open read setattr search };
Stephen Smalleya523aac2014-10-24 15:56:15 -0400115
116# chown/chmod on devices.
Stephen Smalley1c16abd2014-11-10 12:15:33 -0500117allow init { dev_type -kmem_device }:chr_file { read open setattr };
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400118
Stephen Smalley73b03462014-05-30 09:53:00 -0400119# Unlabeled file access for upgrades from 4.2.
120allow init unlabeled:dir { create_dir_perms relabelfrom };
121allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
122
Stephen Smalley3235f612014-05-30 10:25:00 -0400123# Create /data/security from init.rc post-fs-data.
124allow init security_file:dir { create setattr };
125
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400126# Reload policy upon setprop selinux.reload_policy 1.
Stephen Smalley3235f612014-05-30 10:25:00 -0400127r_dir_file(init, security_file)
Stephen Smalleyfea6e662013-12-06 08:05:53 -0500128allow init kernel:security load_policy;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400129
130# Any operation that can modify the kernel ring buffer, e.g. clear
131# or a read that consumes the messages that were read.
Nick Kralevich685e2f92014-05-28 13:48:52 -0700132allow init kernel:system syslog_mod;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400133allow init self:capability2 syslog;
134
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -0400135# Set usermodehelpers and /proc security settings.
Stephen Smalley7adb9992013-12-06 09:31:40 -0500136allow init usermodehelper:file rw_file_perms;
137allow init proc_security:file rw_file_perms;
Nick Kralevichfed8a2a2014-01-24 20:43:07 -0800138
Stephen Smalleya523aac2014-10-24 15:56:15 -0400139# Write to /proc/sys/kernel/panic_on_oops.
140allow init proc:file w_file_perms;
141
142# Write to /proc/sys/net/ping_group_range and other /proc/sys/net files.
Nick Kralevich5cf39942015-02-25 13:28:40 -0800143allow init proc_net:file w_file_perms;
Stephen Smalleya523aac2014-10-24 15:56:15 -0400144allow init self:capability net_admin;
145
146# Write to /proc/sysrq-trigger.
147allow init proc_sysrq:file w_file_perms;
148
149# Reboot.
150allow init self:capability sys_boot;
151
152# Write to sysfs nodes.
153allow init sysfs_type:dir r_dir_perms;
154allow init sysfs_type:file w_file_perms;
155
Nick Kralevichfed8a2a2014-01-24 20:43:07 -0800156# Transitions to seclabel processes in init.rc
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700157domain_trans(init, rootfs, adbd)
158domain_trans(init, rootfs, healthd)
Sami Tolvanen9d87c642015-02-18 13:59:38 +0000159domain_trans(init, rootfs, slideshow)
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700160recovery_only(`
161 domain_trans(init, rootfs, recovery)
162')
163domain_trans(init, shell_exec, shell)
Elliott Hughes46e832f2015-04-22 18:38:41 -0700164domain_trans(init, init_exec, ueventd)
165domain_trans(init, init_exec, watchdogd)
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700166
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700167# Support "adb shell stop"
Stephen Smalleya523aac2014-10-24 15:56:15 -0400168allow init self:capability kill;
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700169allow init domain:process sigkill;
Nick Kralevichcd905ec2014-05-08 23:28:52 -0700170
171# Init creates keystore's directory on boot, and walks through
172# the directory as part of a recursive restorecon.
173allow init keystore_data_file:dir { open create read getattr setattr search };
174allow init keystore_data_file:file { getattr };
Stephen Smalley356f4be2014-05-23 11:26:19 -0400175
Jeff Sharkey4423ecd2015-03-31 15:03:13 -0700176# Init creates vold's directory on boot, and walks through
177# the directory as part of a recursive restorecon.
178allow init vold_data_file:dir { open create read getattr setattr search };
179allow init vold_data_file:file { getattr };
180
Nick Kralevichee49c0e2014-06-07 10:00:59 -0700181# Init creates /data/local/tmp at boot
182allow init shell_data_file:dir { open create read getattr setattr search };
183allow init shell_data_file:file { getattr };
184
Stephen Smalleya523aac2014-10-24 15:56:15 -0400185# Set UID and GID for services.
186allow init self:capability { setuid setgid };
187
Yongqin Liucc38e6d2014-12-05 13:40:22 +0800188# For bootchart to read the /proc/$pid/cmdline file of each process,
189# we need to have following line to allow init to have access
190# to different domains.
191r_dir_file(init, domain)
192
Stephen Smalley356f4be2014-05-23 11:26:19 -0400193# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
194# setexec is for services with seclabel options.
195# setfscreate is for labeling directories and socket files.
196# setsockcreate is for labeling local/unix domain sockets.
197allow init self:process { setexec setfscreate setsockcreate };
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -0400198
Stephen Smalleya523aac2014-10-24 15:56:15 -0400199# Perform SELinux access checks on setting properties.
200selinux_check_access(init)
201
202# Ask the kernel for the new context on services to label their sockets.
203allow init kernel:security compute_create;
204
205# Create sockets for the services.
206allow init domain:unix_stream_socket { create bind };
207allow init domain:unix_dgram_socket { create bind };
208
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -0400209# Create /data/property and files within it.
210allow init property_data_file:dir create_dir_perms;
211allow init property_data_file:file create_file_perms;
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400212
Stephen Smalleyfee49152014-06-19 10:27:02 -0400213# Set any property.
214allow init property_type:property_service set;
215
Nick Kralevich0db95cc2014-06-20 21:15:56 -0700216# Run "ifup lo" to bring up the localhost interface
217allow init self:udp_socket { create ioctl };
Stephen Smalleya523aac2014-10-24 15:56:15 -0400218allow init self:capability net_raw;
Nick Kralevich0db95cc2014-06-20 21:15:56 -0700219
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700220# This line seems suspect, as it should not really need to
221# set scheduling parameters for a kernel domain task.
222allow init kernel:process setsched;
223
Nick Kralevichbeb279c2014-10-20 11:52:19 -0700224# swapon() needs write access to swap device
225# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
226allow init swap_block_device:blk_file rw_file_perms;
227
Stephen Smalley0d08d472014-10-21 10:09:33 -0400228# Read from /dev/hw_random if present.
229# system/core/init/init.c - mix_hwrng_into_linux_rng_action
230allow init hw_random_device:chr_file r_file_perms;
231
232# Create and access /dev files without a specific type,
Stephen Smalleya523aac2014-10-24 15:56:15 -0400233# e.g. /dev/.coldboot_done, /dev/.booting
Stephen Smalley0d08d472014-10-21 10:09:33 -0400234# TODO: Move these files into their own type unless they are
235# only ever accessed by init.
236allow init device:file create_file_perms;
Stephen Smalley0d08d472014-10-21 10:09:33 -0400237
238# Access character devices without a specific type,
239# e.g. /dev/keychord.
240# TODO: Move these devices into their own type unless they
241# are only ever accessed by init.
242allow init device:chr_file { rw_file_perms setattr };
Stephen Smalley0d08d472014-10-21 10:09:33 -0400243
Stephen Smalleya523aac2014-10-24 15:56:15 -0400244# keychord configuration
245allow init self:capability sys_tty_config;
246
Sami Tolvanen35f537c2015-03-05 00:55:29 +0000247# Access device mapper for setting up dm-verity
248allow init dm_device:chr_file rw_file_perms;
249allow init dm_device:blk_file rw_file_perms;
250
251# Access metadata block device for storing dm-verity state
252allow init metadata_block_device:blk_file rw_file_perms;
253
254# Read /sys/fs/pstore/console-ramoops to detect restarts caused
255# by dm-verity detecting corrupted blocks
256allow init pstorefs:dir search;
257allow init pstorefs:file r_file_perms;
258
Paul Lawrence38af1da2015-03-11 15:44:14 -0700259# linux keyring configuration
260allow init init:key { write search setattr };
261
262# Allow init to link temp fs to unencrypted data on userdata
263allow init tmpfs:lnk_file { create read getattr relabelfrom };
264
265# Allow init to manipulate /data/unencrypted
266allow init unencrypted_data_file:{ file lnk_file } create_file_perms;
267allow init unencrypted_data_file:dir create_dir_perms;
268
269unix_socket_connect(init, vold, vold)
270
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400271###
272### neverallow rules
273###
274
275# The init domain is only entered via setcon from the kernel domain,
276# never via an exec-based transition.
Elliott Hughes46e832f2015-04-22 18:38:41 -0700277neverallow domain init:process dyntransition;
278neverallow { domain -kernel} init:process transition;
279neverallow init { file_type fs_type -init_exec }:file entrypoint;
Stephen Smalley018e9402014-09-02 17:05:44 -0400280
281# Never read/follow symlinks created by shell or untrusted apps.
282neverallow init shell_data_file:lnk_file read;
283neverallow init app_data_file:lnk_file read;
Stephen Smalley8a0c25e2014-09-23 09:11:30 -0400284
285# init should never execute a program without changing to another domain.
286neverallow init { file_type fs_type }:file execute_no_trans;