blob: a6fadbd573e33ebdbe09f935ab76d34a7e76195c [file] [log] [blame]
Stephen Smalley2dd4e512012-01-04 12:33:27 -05001# init switches to init domain (via init.rc).
2type init, domain;
Stephen Smalley2dd4e512012-01-04 12:33:27 -05003# init is unconfined.
4unconfined_domain(init)
5tmpfs_domain(init)
Nick Kralevich0c9708b2013-07-10 14:46:05 -07006
Stephen Smalley5487ca02014-02-10 16:31:04 -05007allow init self:capability { sys_rawio mknod };
8
Stephen Smalley8a0c25e2014-09-23 09:11:30 -04009# Mounting filesystems from block devices.
10allow init dev_type:blk_file r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040011
12# Mounting filesystems.
Stephen Smalley75e2ef92014-06-16 13:05:38 -040013# 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.
17allow init fs_type:filesystem ~relabelto;
18allow init unlabeled:filesystem ~relabelto;
19allow init contextmount_type:filesystem relabelto;
20
21# Allow read-only access to context= mounted filesystems.
22allow init contextmount_type:dir r_dir_perms;
23allow init contextmount_type:notdevfile_class_set r_file_perms;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040024
Stephen Smalleyc626a882014-06-23 09:17:51 -040025# restorecon /adb_keys or any other rootfs files to a more specific type.
26allow init rootfs:file relabelfrom;
27
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040028# 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 Kralevich03ce5122014-05-20 11:09:16 -070032allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto;
Stephen Smalley32915652014-07-17 14:54:44 -040033allow init sysfs_type:{ dir file lnk_file } relabelto;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040034
Stephen Smalley73b03462014-05-30 09:53:00 -040035# Unlabeled file access for upgrades from 4.2.
36allow init unlabeled:dir { create_dir_perms relabelfrom };
37allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
38
Stephen Smalley3235f612014-05-30 10:25:00 -040039# Create /data/security from init.rc post-fs-data.
40allow init security_file:dir { create setattr };
41
42# setprop selinux.reload_policy 1 from init.rc post-fs-data.
43allow init security_prop:property_service set;
44
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040045# Reload policy upon setprop selinux.reload_policy 1.
Stephen Smalley3235f612014-05-30 10:25:00 -040046r_dir_file(init, security_file)
Stephen Smalleyfea6e662013-12-06 08:05:53 -050047allow init kernel:security load_policy;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040048
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 Kralevich685e2f92014-05-28 13:48:52 -070051allow init kernel:system syslog_mod;
Stephen Smalleyeb1bbf22014-05-29 14:35:55 -040052
53# Set usermodehelpers and /proc security settings.
Stephen Smalley7adb9992013-12-06 09:31:40 -050054allow init usermodehelper:file rw_file_perms;
55allow init proc_security:file rw_file_perms;
Nick Kralevichfed8a2a2014-01-24 20:43:07 -080056
57# Transitions to seclabel processes in init.rc
Nick Kralevicha7c04dc2014-07-03 22:13:14 -070058domain_trans(init, rootfs, adbd)
59domain_trans(init, rootfs, healthd)
60recovery_only(`
61 domain_trans(init, rootfs, recovery)
62')
63domain_trans(init, shell_exec, shell)
64domain_trans(init, rootfs, ueventd)
65domain_trans(init, rootfs, watchdogd)
66
67# Certain domains need LD_PRELOAD passed from init.
68# https://android-review.googlesource.com/94851
Nick Kralevich8a5b28d2014-07-16 18:42:36 -070069# For now, allow it to most domains.
Nick Kralevicha7c04dc2014-07-03 22:13:14 -070070# TODO: scope this down.
Nick Kralevich8a5b28d2014-07-16 18:42:36 -070071allow init { domain -lmkd }:process noatsecure;
Nick Kralevicha7c04dc2014-07-03 22:13:14 -070072
73# Support "adb shell stop"
74allow init domain:process sigkill;
Nick Kralevichcd905ec2014-05-08 23:28:52 -070075
76# Init creates keystore's directory on boot, and walks through
77# the directory as part of a recursive restorecon.
78allow init keystore_data_file:dir { open create read getattr setattr search };
79allow init keystore_data_file:file { getattr };
Stephen Smalley356f4be2014-05-23 11:26:19 -040080
Nick Kralevichee49c0e2014-06-07 10:00:59 -070081# Init creates /data/local/tmp at boot
82allow init shell_data_file:dir { open create read getattr setattr search };
83allow init shell_data_file:file { getattr };
84
Stephen Smalley356f4be2014-05-23 11:26:19 -040085# 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.
89allow init self:process { setexec setfscreate setsockcreate };
Stephen Smalleyad0d0fc2014-05-29 09:22:16 -040090
91# Create /data/property and files within it.
92allow init property_data_file:dir create_dir_perms;
93allow init property_data_file:file create_file_perms;
Stephen Smalleybac4ccc2014-06-18 10:09:35 -040094
Stephen Smalleyfee49152014-06-19 10:27:02 -040095# Set any property.
96allow init property_type:property_service set;
97
Nick Kralevich0db95cc2014-06-20 21:15:56 -070098# Run "ifup lo" to bring up the localhost interface
99allow init self:udp_socket { create ioctl };
100
Nick Kralevicha7c04dc2014-07-03 22:13:14 -0700101# This line seems suspect, as it should not really need to
102# set scheduling parameters for a kernel domain task.
103allow init kernel:process setsched;
104
Stephen Smalleybac4ccc2014-06-18 10:09:35 -0400105###
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.
111neverallow { domain -kernel} init:process dyntransition;
112neverallow domain init:process transition;
113neverallow init { file_type fs_type }:file entrypoint;
Stephen Smalley018e9402014-09-02 17:05:44 -0400114
115# Never read/follow symlinks created by shell or untrusted apps.
116neverallow init shell_data_file:lnk_file read;
117neverallow init app_data_file:lnk_file read;
Stephen Smalley8a0c25e2014-09-23 09:11:30 -0400118
119# init should never execute a program without changing to another domain.
120neverallow init { file_type fs_type }:file execute_no_trans;