• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2021 The Android Open Source Project
2#
3# init.rc for minidroid.
4#
5# IMPORTANT: Do not create world writable files or directories.
6# This is a common source of Android security bugs.
7#
8
9import /init.environ.rc
10import /system/etc/init/mdnsd.rc
11import /system/etc/init/servicemanager.rc
12import /system/etc/init/logd.rc
13# TODO(b/267320398): this file does not exist in -user builds, but init can
14# continue despite that. Remove the import once we can rely on .rc files from
15# /system/etc/init getting loaded automatically.
16import /system/etc/init/logcatd.rc
17
18# Cgroups are mounted right before early-init using list from /etc/cgroups.json
19on early-init
20    # set RLIMIT_NICE to allow priorities from 19 to -20
21    setrlimit nice 40 40
22
23    start ueventd
24
25on init
26    mkdir /mnt/apk 0755 system system
27    mkdir /mnt/extra-apk 0755 root root
28
29    # Mount binderfs
30    mkdir /dev/binderfs
31    mount binder binder /dev/binderfs stats=global
32    chmod 0755 /dev/binderfs
33
34    symlink /dev/binderfs/binder /dev/binder
35    symlink /dev/binderfs/hwbinder /dev/hwbinder
36    symlink /dev/binderfs/vndbinder /dev/vndbinder
37
38    chmod 0666 /dev/binderfs/hwbinder
39    chmod 0666 /dev/binderfs/binder
40    chmod 0666 /dev/binderfs/vndbinder
41
42    # create an empty ld.config.txt before running any non-static exectuables
43    # (apexd and linkerconfig) to suppress "ld.config.txt not found" warnings.
44    write /linkerconfig/ld.config.txt \#
45    chmod 644 /linkerconfig/ld.config.txt
46
47    # Start logd before any other services run to ensure we capture all of their logs.
48    start logd
49
50    # TODO: minidroid does not use microdroid_manager. If/when this is fixed
51    # align this change and others related to microdroid_manager back to the
52    # microdroid init.rc
53    start apexd-vm
54
55    # restorecon so microdroid_manager can create subdirectories
56    restorecon /mnt/extra-apk
57
58    # Wait for apexd to finish activating APEXes before starting more processes.
59    # Note that minidroid starts apexd in VM mode in which apexd doesn't wait for init after setting
60    # apexd.status to activated, but immediately transitions to ready. Therefore, it's not safe to
61    # wait for the activated status, by the time this line is reached it may be already be ready.
62    wait_for_prop apexd.status ready
63    perform_apex_config
64
65    # Notify to microdroid_manager that perform_apex_config is done.
66    # Microdroid_manager shouldn't execute payload before this, because app
67    # payloads are not designed to run with bootstrap bionic
68    setprop apex_config.done true
69
70    setprop ro.debuggable ${ro.boot.microdroid.debuggable:-0}
71    start servicemanager
72
73on property:dev.bootcomplete=1
74    # Stop ueventd to save memory
75    stop ueventd
76
77on init && property:ro.boot.microdroid.debuggable=1
78    # Mount tracefs (with GID=AID_READTRACEFS)
79    mount tracefs tracefs /sys/kernel/tracing gid=3012
80
81on init && property:ro.boot.adb.enabled=1
82    start adbd
83
84# Mount filesystems and start core system services.
85on late-init
86    trigger early-fs
87
88    # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
89    # '--early' can be specified to skip entries with 'latemount'.
90    # /system and /vendor must be mounted by the end of the fs stage,
91    # while /data is optional.
92    trigger fs
93    trigger post-fs
94
95    # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
96    # to only mount entries with 'latemount'. This is needed if '--early' is
97    # specified in the previous mount_all command on the fs stage.
98    # With /system mounted and properties form /system + /factory available,
99    # some services can be started.
100    trigger late-fs
101
102    trigger post-fs-data
103
104    # Load persist properties and override properties (if enabled) from /data.
105    trigger load_persist_props_action
106
107    trigger early-boot
108    trigger boot
109
110on post-fs
111    # Once everything is setup, no need to modify /.
112    # The bind+remount combination allows this to work in containers.
113    mount rootfs rootfs / remount bind ro nodev
114
115    # TODO(b/185767624): change the hard-coded size?
116    mount tmpfs tmpfs /data noatime nosuid nodev rw size=128M
117
118    # We chown/chmod /data again so because mount is run as root + defaults
119    chown system system /data
120    chmod 0771 /data
121
122    # We restorecon /data in case the userdata partition has been reset.
123    restorecon /data
124
125    # set up misc directory structure first so that we can end early boot
126    # and start apexd
127    mkdir /data/misc 01771 system misc
128    # work around b/183668221
129    restorecon /data/misc
130
131    mkdir /data/misc/authfs 0700 root root
132
133on late-fs && property:ro.debuggable=1
134    # Ensure that tracefs has the correct permissions.
135    # This does not work correctly if it is called in post-fs.
136    chmod 0755 /sys/kernel/tracing
137    chmod 0755 /sys/kernel/debug/tracing
138
139on post-fs-data
140    mark_post_data
141
142    mkdir /data/vendor 0771 root root
143    mkdir /data/vendor_ce 0771 root root
144    mkdir /data/vendor_de 0771 root root
145    mkdir /data/vendor/hardware 0771 root root
146
147    # Start tombstoned early to be able to store tombstones.
148    # microdroid doesn't have anr, but tombstoned requires it
149    mkdir /data/anr 0775 system system
150    mkdir /data/tombstones 0771 system system
151    mkdir /data/vendor/tombstones 0771 root root
152
153    start tombstoned
154
155    # For security reasons, /data/local/tmp should always be empty.
156    # Do not place files or directories in /data/local/tmp
157    mkdir /data/local 0751 root root
158    mkdir /data/local/tmp 0771 shell shell
159
160on boot
161    ifup lo
162    hostname localhost
163    domainname localdomain
164    ifup eth1
165
166    setprop sys.boot_completed 1
167    setprop dev.bootcomplete 1
168    write /dev/kmsg "VIRTUAL_DEVICE_BOOT_COMPLETED"
169
170service tombstone_transmit /system/bin/tombstone_transmit.microdroid -cid 2 -port 2000 -remove_tombstones_after_transmitting
171    user system
172    group system
173    shutdown critical
174
175service apexd-vm /system/bin/apexd --vm
176    user root
177    group system
178    oneshot
179    disabled
180    capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER SYS_ADMIN
181
182service ueventd /system/bin/ueventd
183    class core
184    critical
185    seclabel u:r:ueventd:s0
186    shutdown critical
187    user root
188    group root
189    capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER FSETID MKNOD NET_ADMIN SETGID SETUID SYS_MODULE SYS_RAWIO SYS_ADMIN
190
191service console /system/bin/sh
192    class core
193    console
194    disabled
195    user shell
196    group shell log readproc
197    seclabel u:r:shell:s0
198    setenv HOSTNAME console
199
200