Alex Klyubin | f5446eb | 2017-03-23 14:27:32 -0700 | [diff] [blame] | 1 | typeattribute init coredomain; |
| 2 | |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 3 | tmpfs_domain(init) |
| 4 | |
| 5 | # Transitions to seclabel processes in init.rc |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 6 | domain_trans(init, rootfs, slideshow) |
Tao Bao | ecc7e8c | 2018-09-07 15:05:33 -0700 | [diff] [blame] | 7 | domain_auto_trans(init, charger_exec, charger) |
Jin Qian | 4de505b | 2017-05-02 13:45:08 -0700 | [diff] [blame] | 8 | domain_auto_trans(init, e2fs_exec, e2fs) |
Joel Fernandes | 147cf64 | 2018-11-29 13:07:40 -0800 | [diff] [blame] | 9 | domain_auto_trans(init, bpfloader_exec, bpfloader) |
| 10 | |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 11 | recovery_only(` |
Tao Bao | ecc7e8c | 2018-09-07 15:05:33 -0700 | [diff] [blame] | 12 | # Files in recovery image are labeled as rootfs. |
Bowgo Tsai | 5846c79 | 2017-07-31 18:38:28 +0800 | [diff] [blame] | 13 | domain_trans(init, rootfs, adbd) |
Kelvin Zhang | 19a5785 | 2022-08-30 00:12:26 +0000 | [diff] [blame] | 14 | domain_trans(init, rootfs, hal_bootctl_server) |
Tao Bao | ecc7e8c | 2018-09-07 15:05:33 -0700 | [diff] [blame] | 15 | domain_trans(init, rootfs, charger) |
Jerry Zhang | 1d85efa | 2018-05-29 10:54:16 -0700 | [diff] [blame] | 16 | domain_trans(init, rootfs, fastbootd) |
Sandeep Dhavale | f0ea953 | 2022-11-08 23:57:09 +0000 | [diff] [blame] | 17 | domain_trans(init, rootfs, hal_fastboot_server) |
Yifan Hong | 705db2b | 2021-11-15 18:56:22 -0800 | [diff] [blame] | 18 | domain_trans(init, rootfs, hal_health_server) |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 19 | domain_trans(init, rootfs, recovery) |
Kiyoung Kim | 2c271aa | 2019-12-09 14:57:46 +0900 | [diff] [blame] | 20 | domain_trans(init, rootfs, linkerconfig) |
Yifan Hong | d6b2901 | 2021-11-13 00:22:01 -0800 | [diff] [blame] | 21 | domain_trans(init, rootfs, servicemanager) |
David Anderson | d84b67e | 2021-02-04 12:30:09 -0800 | [diff] [blame] | 22 | domain_trans(init, rootfs, snapuserd) |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 23 | ') |
| 24 | domain_trans(init, shell_exec, shell) |
| 25 | domain_trans(init, init_exec, ueventd) |
Tom Cherry | 621c24c | 2017-09-28 14:34:36 -0700 | [diff] [blame] | 26 | domain_trans(init, init_exec, vendor_init) |
Sandeep Patil | e41af20 | 2017-06-02 16:09:26 -0700 | [diff] [blame] | 27 | domain_trans(init, { rootfs toolbox_exec }, modprobe) |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 28 | userdebug_or_eng(` |
Tom Cherry | 938ab05 | 2018-08-03 10:49:20 -0700 | [diff] [blame] | 29 | # case where logpersistd is actually logcat -f in logd context (nee: logcatd) |
Mark Salyzyn | da62cb4 | 2016-08-10 11:10:02 -0700 | [diff] [blame] | 30 | domain_auto_trans(init, logcat_exec, logpersist) |
Tom Cherry | 938ab05 | 2018-08-03 10:49:20 -0700 | [diff] [blame] | 31 | |
| 32 | # allow init to execute services marked with seclabel u:r:su:s0 in userdebug/eng |
| 33 | allow init su:process transition; |
| 34 | dontaudit init su:process noatsecure; |
| 35 | allow init su:process { siginh rlimitinh }; |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 36 | ') |
Branden Archer | d36b1d5 | 2018-11-27 15:47:12 -0800 | [diff] [blame] | 37 | |
Nikita Ioffe | 23ba976 | 2019-12-09 21:21:55 +0000 | [diff] [blame] | 38 | # Allow init to figure out name of dm-device from it's /dev/block/dm-XX path. |
| 39 | # This is useful in case of remounting ext4 userdata into checkpointing mode, |
| 40 | # since it potentially requires tearing down dm-devices (e.g. dm-bow, dm-crypto) |
| 41 | # that userdata is mounted onto. |
| 42 | allow init sysfs_dm:file read; |
| 43 | |
Bart Van Assche | 9059e21 | 2021-07-29 14:53:51 -0700 | [diff] [blame] | 44 | # Allow init to modify the properties of loop devices. |
| 45 | allow init sysfs_loop:dir r_dir_perms; |
| 46 | allow init sysfs_loop:file rw_file_perms; |
| 47 | |
Bart Van Assche | 60b7d9a | 2021-10-13 16:21:54 +0000 | [diff] [blame] | 48 | # Allow init to examine the properties of block devices. |
Bart Van Assche | 398b0af | 2021-10-13 10:56:57 -0700 | [diff] [blame] | 49 | allow init sysfs_type:file { getattr read }; |
| 50 | # Allow init get the attributes of block devices in /dev/block. |
| 51 | allow init dev_type:dir r_dir_perms; |
| 52 | allow init dev_type:blk_file getattr; |
Bart Van Assche | 60b7d9a | 2021-10-13 16:21:54 +0000 | [diff] [blame] | 53 | |
Michael Rosenfeld | 3ccbebb | 2021-02-10 18:45:35 -0800 | [diff] [blame] | 54 | # Allow init to write to the drop_caches file. |
| 55 | allow init proc_drop_caches:file rw_file_perms; |
| 56 | |
Branden Archer | d36b1d5 | 2018-11-27 15:47:12 -0800 | [diff] [blame] | 57 | # Allow the BoringSSL self test to request a reboot upon failure |
| 58 | set_prop(init, powerctl_prop) |
Nikita Ioffe | 7065e46 | 2019-11-14 12:59:15 +0000 | [diff] [blame] | 59 | |
| 60 | # Only init is allowed to set userspace reboot related properties. |
Nikita Ioffe | 7065e46 | 2019-11-14 12:59:15 +0000 | [diff] [blame] | 61 | set_prop(init, userspace_reboot_exported_prop) |
Nikita Ioffe | 7065e46 | 2019-11-14 12:59:15 +0000 | [diff] [blame] | 62 | neverallow { domain -init } userspace_reboot_exported_prop:property_service set; |
Ryan Savitski | 52b3d31 | 2020-01-14 18:20:06 +0000 | [diff] [blame] | 63 | |
| 64 | # Second-stage init performs a test for whether the kernel has SELinux hooks |
| 65 | # for the perf_event_open() syscall. This is done by testing for the syscall |
| 66 | # outcomes corresponding to this policy. |
| 67 | # TODO(b/137092007): this can be removed once the platform stops supporting |
| 68 | # kernels that precede the perf_event_open hooks (Android common kernels 4.4 |
| 69 | # and 4.9). |
| 70 | allow init self:perf_event { open cpu }; |
Alistair Delva | 178f0ac | 2020-06-05 10:15:30 -0700 | [diff] [blame] | 71 | allow init self:global_capability2_class_set perfmon; |
Ryan Savitski | 52b3d31 | 2020-01-14 18:20:06 +0000 | [diff] [blame] | 72 | neverallow init self:perf_event { kernel tracepoint read write }; |
| 73 | dontaudit init self:perf_event { kernel tracepoint read write }; |
| 74 | |
David Anderson | 0c0c13a | 2020-10-30 00:12:22 -0700 | [diff] [blame] | 75 | # Allow init to communicate with snapuserd to transition Virtual A/B devices |
| 76 | # from the first-stage daemon to the second-stage. |
| 77 | allow init snapuserd_socket:sock_file write; |
| 78 | allow init snapuserd:unix_stream_socket connectto; |
| 79 | # Allow for libsnapshot's use of flock() on /metadata/ota. |
| 80 | allow init ota_metadata_file:dir lock; |
| 81 | |
Jooyung Han | b62be12 | 2021-04-12 21:44:43 +0900 | [diff] [blame] | 82 | # Allow init to restore contexts of vd_device(/dev/block/vd[..]) when labeling |
| 83 | # /dev/block. |
| 84 | allow init vd_device:blk_file relabelto; |
| 85 | |
Ryan Savitski | 52b3d31 | 2020-01-14 18:20:06 +0000 | [diff] [blame] | 86 | # Only init is allowed to set the sysprop indicating whether perf_event_open() |
| 87 | # SELinux hooks were detected. |
| 88 | set_prop(init, init_perf_lsm_hooks_prop) |
| 89 | neverallow { domain -init } init_perf_lsm_hooks_prop:property_service set; |
Inseob Kim | 212e2b6 | 2020-07-14 02:10:37 +0900 | [diff] [blame] | 90 | |
| 91 | # Only init can write vts.native_server.on |
| 92 | set_prop(init, vts_status_prop) |
Inseob Kim | 85acf6e | 2021-03-10 10:42:23 +0900 | [diff] [blame] | 93 | neverallow { domain -init } vts_status_prop:property_service set; |
Inseob Kim | 8c34247 | 2020-07-23 17:54:35 +0900 | [diff] [blame] | 94 | |
| 95 | # Only init can write normal ro.boot. properties |
Inseob Kim | 85acf6e | 2021-03-10 10:42:23 +0900 | [diff] [blame] | 96 | neverallow { domain -init } bootloader_prop:property_service set; |
Inseob Kim | 40c67b2 | 2020-07-25 00:34:56 +0900 | [diff] [blame] | 97 | |
| 98 | # Only init can write hal.instrumentation.enable |
Inseob Kim | 85acf6e | 2021-03-10 10:42:23 +0900 | [diff] [blame] | 99 | neverallow { domain -init } hal_instrumentation_prop:property_service set; |
Inseob Kim | 40c67b2 | 2020-07-25 00:34:56 +0900 | [diff] [blame] | 100 | |
| 101 | # Only init can write ro.property_service.version |
Inseob Kim | 85acf6e | 2021-03-10 10:42:23 +0900 | [diff] [blame] | 102 | neverallow { domain -init } property_service_version_prop:property_service set; |
Paul Crowley | b0c5571 | 2021-02-23 08:40:05 -0800 | [diff] [blame] | 103 | |
| 104 | # Only init can set keystore.boot_level |
Inseob Kim | 85acf6e | 2021-03-10 10:42:23 +0900 | [diff] [blame] | 105 | neverallow { domain -init } keystore_listen_prop:property_service set; |
Alexander Potapenko | 3d52817 | 2021-03-02 16:46:50 +0100 | [diff] [blame] | 106 | |
| 107 | # Allow accessing /sys/kernel/tracing/instances/bootreceiver to set up tracing. |
| 108 | allow init debugfs_bootreceiver_tracing:file w_file_perms; |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 109 | |
Pete Bentley | e6da3b8 | 2022-09-16 15:31:39 +0100 | [diff] [blame] | 110 | # PRNG seeder daemon socket is created and listened on by init before forking. |
| 111 | allow init prng_seeder:unix_stream_socket { create bind listen }; |
| 112 | |
Kalesh Singh | fab8e1c | 2021-11-04 20:47:29 -0700 | [diff] [blame] | 113 | # Devices with kernels where CONFIG_HIST_TRIGGERS isn't enabled will |
| 114 | # attempt to write a non exisiting 'synthetic_events' file, when setting |
| 115 | # up synthetic events. This is a no-op in tracefs. |
| 116 | dontaudit init debugfs_tracing_debug:dir { write add_name }; |
| 117 | |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 118 | # chown/chmod on devices. |
| 119 | allow init { |
| 120 | dev_type |
| 121 | -hw_random_device |
| 122 | -keychord_device |
Elliot Berman | ae5869a | 2023-03-22 17:31:35 -0700 | [diff] [blame] | 123 | -vm_manager_device_type |
Andrew Walbran | a995e84 | 2021-03-29 17:19:12 +0000 | [diff] [blame] | 124 | -port_device |
| 125 | }:chr_file setattr; |