Commit graph

2962 commits

Author SHA1 Message Date
Nikita Ioffe
bee7b8c811 Add basic support for remounting ext4 userdata into checkpoint
Metadata encrypted ext4 userdata and v2 encryption keys will be
supported in follow up CLs.

Test: adb shell /system/bin/vdc checkpoint startCheckpoint 1
Test: adb reboot userspace
Bug: 135984674
Bug: 143970043
Change-Id: I8dbf3bddd811cf54d3f2b2ee2c1ea64159d8c6e0
2019-12-02 11:59:51 +00:00
Nikita Ioffe
57d7bb695b Fix typo in userspace reboot watchdog
Test: adb reboot userspace
Bug: 135984674
Change-Id: I4003683307a22e8d744748fb1311c16eb5ee1428
2019-11-28 18:25:24 +00:00
Treehugger Robot
1b0ea6c3b3 Merge "init: fix subcontext tests running as non-root." 2019-11-21 05:15:35 +00:00
Tom Cherry
1c005f3a78 init: fix subcontext tests running as non-root.
A recently added subcontext test was failing beause it was running as
non-root, but GTEST_SKIP() didn't work as I expected it to.

In retrospect, all of these tests except for the property one, can
easily run as root, so this changes allows all of these tests to run
as root, while fixing the original issue.

Bug: 144707143
Test: root and nonroot subcontext unit tests
Change-Id: Ia835597701698f6be2101f92d6f4c9450bd3c7dd
2019-11-20 15:55:16 -08:00
Nikita Ioffe
23dbd6dc11 Make userspace_reboot.in_progress sysprop-as-api
sys.init.userspace_reboot.in_progress will be used to notify all
the processes (including vendor ones) that userspace reboot is
happening, hence it should be treated as stable public api.

All other sys.init.userspace_reboot.* props will be internal to /system
partition and don't require any stability guarantees.

Test: builds
Test: adb reboot userspace
Bug: 135984674
Change-Id: Ifb64a6bfae2de76bac67edea68df44e33c9cfe2d
2019-11-15 20:07:58 +00:00
Nikita Ioffe
dc4bd2714c Merge "Add a very basic userspace reboot watchdog" 2019-11-15 15:21:19 +00:00
Tom Cherry
bc1d0b09cc Merge "init: make CheckPropertyTriggers() more efficient" 2019-11-14 23:37:30 +00:00
Nikita Ioffe
82a431eb2f Add a very basic userspace reboot watchdog
Watchdog is just a forked process that is going to fall back to the
full reboot in case device wasn't able to boot in given amount of time.

Currently this amount is hard-coded to 1 minute, but in the future it
will be controlled by a read-only property.

Also added sync calls before and after tearing down services.

Test: adb reboot userspace
Bug: 135984674
Change-Id: Ie6053c9446a6761deae6dc104036bb35b09ef0e2
2019-11-14 23:10:54 +00:00
Tom Cherry
1efc4849d7 init: make CheckPropertyTriggers() more efficient
Previously CheckPropertyTriggers() tried to do the entire property
triggers check with one loop.  However, that would require calling
GetProperty() on all properties for all triggers just in case the
property that is being set is used by a given trigger.

This change first checks that the property being set exists in each
trigger and that its value is set such that the trigger would be
triggered, only then does it check that other property triggers are
set to the right value.

Bug: 143922756
Test: boot
Test: substantially fewer GetProperty() calls from
      CheckPropertyTriggers()

Change-Id: I0228cf47328b31963eaf3fc689fb60f711532df4
2019-11-14 09:19:07 -08:00
Nikita Ioffe
c0df1874ad Add sysprops for start & end of userspace reboot
There will be useful in debugging/logging events to statsd.

Also as part of this CL, sys.init.userspace_reboot.in_progress property
is now used as a mean of synchronization. It is set directly in
DoUserspaceReboot, to make sure that all the setprop actions triggered
by userspace-reboot-requested were processed.

Test: adb reboot userspace
Test: adb shell getprop sys.init.userspace_reboot.last_started
Test: adb shell getprop sys.init.userspace_reboot.last_finished
Bug: 135984674
Change-Id: I9debcd4f058e790855200d5295344dafb30e496a
2019-11-14 01:38:05 +00:00
Tom Cherry
18278d2e9c init: make triggering shutdown from vendor_init better
Previously, we assumed that TriggerShutdown() should never be called
from vendor_init and used property service as a back up in case it
ever did.  We have since then found out that vendor_init may indeed
call TriggerShutdown() and we want to make it just as strict as it is
in init, wherein it will immediately start the shutdown sequence
without executing any further commands.

Test: init unit tests, trigger shuttdown from init and vendor_init
Change-Id: I1f44dae801a28269eb8127879a8b7d6adff6f353
2019-11-13 12:41:34 -08:00
Tom Cherry
e91c76b210 Merge "init: check property type in host_init_verifier" 2019-11-13 18:41:17 +00:00
Tom Cherry
edad2bf9b6 Use PLOG and TEMP_FAILURE_RETRY for uevent socket errors
Use TEMP_FAILURE_RETRY() for recvmsg() to prevent failing
unnecessarily from EINTR.  Use PLOG(ERROR) in ueventd to display the
actual error if reading from the uevent socket does fail.

Test: build
Change-Id: I64a22698ce6ffc7573f75b57803551c7b6940e30
2019-11-13 07:21:42 -08:00
Tom Cherry
47cdf6c078 Merge "Move init and ueventd scripts from / to /system/etc" 2019-11-13 14:36:47 +00:00
Tom Cherry
b5f2ec06f5 init: check property type in host_init_verifier
We have all of the 'type' information for properties available during
build time, so let's check this when setting properties in init.

Test: setprop apexd.status bad results in:
host_init_verifier: Command 'setprop apexd.status bad'
(out/soong/.intermediates/system/core/rootdir/init.rc/android_x86_core/init.rc:927)
failed: Property type check failed, value doesn't match expected type
'enum starting ready'
host_init_verifier: Failed to parse init script
'out/soong/.intermediates/system/core/rootdir/init.rc/android_x86_core/init.rc'
with 1 errors
Test: CF builds without that error

Change-Id: Iaad07747c09f4a10b2b816c455d6e8a485357ab9
2019-11-12 10:19:21 -08:00
Tom Cherry
c9f5353ad3 Move init and ueventd scripts from / to /system/etc
There is no reason for these scripts to continue to exist in /, when
they are better suited for /system/etc.  There are problems keeping
them at / as well, particularly that they cannot be updated with
overlayfs.

Bug: 131087886
Bug: 140313207
Test: build/boot
Merged-In: I043d9a02ba588ca37ceba2c4e28ed631792b2586
Change-Id: I043d9a02ba588ca37ceba2c4e28ed631792b2586
2019-11-08 10:15:49 -08:00
Nikita Ioffe
838f5ccf9b Merge "userspace reboot: don't re-install keyring when remounting userdata" 2019-11-08 17:38:00 +00:00
Suren Baghdasaryan
8106c8e09f Merge changes from topic "native process registration"
* changes:
  init: Add support for native service registration with lmkd
  lmkd: Support process types when registering a process
  lmkd: Add library function to unregister a process
  lmkd: Prepare lmkd to support connection from init process
  lmkd: Restrict process record modifications to the client that created it
2019-11-08 17:25:10 +00:00
Treehugger Robot
be49555bca Merge "Do not run init CTS test on secondary ABI" 2019-11-08 16:29:44 +00:00
Nikita Ioffe
63898aa2b2 userspace reboot: don't re-install keyring when remounting userdata
From the implementation of FscryptInstallKeyring it looks like it will
install a new keyring on each call.

Another approach would be change FscryptInstallKeyring to first call
request_key[0] (http://man7.org/linux/man-pages/man2/request_key.2.html),
and don't add keyring in case request_key succeeded, but it looks like
that libkeyutils doesn't provide such functionality.

Since I was there, I've also added checks that we are not trying to
remount userdata on FDE devices.

Test: adb reboot userspace
Bug: 135984674
Change-Id: I2e063d7d87a3c2c26810e913a33e3a5c0364332b
2019-11-08 16:11:04 +00:00
Tom Cherry
a4eeeadcd3 Do not run init CTS test on secondary ABI
Init unit tests refer to libraries that do not exist for the
secondary ABI, and we'd rather test the libraries on the device than
statically link them, so only test the primary ABI.

Init will only run on the primary ABI in any case, and doesn't have
much arch specific code in it.

Bug: 143560509
Test: build
Change-Id: I3c1883b3b55e5a06391d2885242f38c74eab621d
2019-11-07 16:06:38 -08:00
Paul Crowley
449282c021 Merge "Make encryption action an argument to mkdir" 2019-11-07 20:06:47 +00:00
Suren Baghdasaryan
c29c2baa69 init: Add support for native service registration with lmkd
init should be able to register native services with lmkd so that they
can be killed when needed. Only processes with oom_score_adjust not
equal to the default -1000 will be registered with lmkd because with the
score that low the process is unkillable anyway.
Inform lmkd when a registered process is killed so that the record can be
removed.
Change init.rc to start lmkd during init phase so that it is there to
register other services.
Replace hardcoded oom_score_adj values with appropriate definitions.

Bug: 129011369
Test: boot and verify native service registration
Change-Id: Ie5ed62203395120d86dc1c8250fae01aa0b3c511
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-11-07 18:19:31 +00:00
Nikita Ioffe
ab91ee986b userspace reboot: unmount apexes and switch to bootstrap namespace
This will bring device to the state closer to the one during normal boot

Bug: 135984674
Test: adb install system/apex/shim/com.android.apex.cts.shim.v1.apex
Test: adb reboot userspace
Test: verified install succeeded
Change-Id: I6ef73bde2ca817c8a62bf19b8f1895dd0d6d2829
2019-11-07 02:13:38 +00:00
Nikita Ioffe
dbee3618be Merge "Make remount into checkpointing for ext4 userdata a no-op" 2019-11-07 02:12:57 +00:00
Treehugger Robot
e4cb2c49e3 Merge "Move comments into selinux.h and fix" 2019-11-07 00:52:42 +00:00
Nikita Ioffe
42697d3f18 Make remount into checkpointing for ext4 userdata a no-op
We are going to teamfood userspace reboot soon, and in order to gather
as much data as possible we are fine with ignoring checkpointing for the
devices with ext4 (teamfood will be a very limited set of people that
are aware what they've signed for).

As result of this, we don't need to reset vold and kill zram backing
device. Added a TODO to restore that functionality if needed.

Since I was there, fixed yet another typo in userspace-reboot-resume -_-

Bug: 135984674
Test: adb reboot userspace
Change-Id: I2b7a93aaf738fe9bec9d606d7e11aefb325550b1
2019-11-06 20:12:08 +00:00
Paul Crowley
68258e8444 Make encryption action an argument to mkdir
FscryptSetDirectoryPolicy no longer tries to infer the action from the
filename. Well mostly; it still assumes top-level directories in /data
should be encrypted unless the mkdir arguments say otherwise, but
it warns.

Bug: 26641735
Test: boot, check log messages
Change-Id: Id6d2cea7fb856f17323897d85cf6190c981b443c
2019-11-05 16:26:43 -08:00
Paul Crowley
f831f10abe Move comments into selinux.h and fix
Make comments imperative, remove redundant words, clarify API level.

Bug: 26641735
Test: treehugger
Change-Id: Icad6001321aa2274b70fdcc74f6fe176f0b2d0db
2019-11-05 09:48:24 -08:00
Mark Salyzyn
283e41de76 Merge "first_stage_init: if console enabled allow for errors in module loading" 2019-11-01 21:52:42 +00:00
Yifan Hong
8fb7f773f0 init: hack for /charger symlink
Legacy symlink from /charger to /system/bin/charger is
removed. Instead, all Android R devices are required
to use /system/bin/charger instead.

See hardware/interfaces/health/2.1/README.md for details.

Bug: 142286265
Test: charger mode
Change-Id: Ib478a864ef68647bc9fc14650ca3d382952b80c8
2019-10-31 18:37:02 -07:00
Mark Salyzyn
a7144f7eb2 first_stage_init: if console enabled allow for errors in module loading
Allow for module load errors if first stage console is enabled, userdebug
development builds, load what you can and continue.

Test: compile
Bug: 141311820
Change-Id: I30f3ee1129373f6ffedcf03807c212c60d4c39aa
2019-10-31 10:30:45 -07:00
Paul Crowley
7160fc1139 fs_mgr: Add stable_inodes flag to encrypted ext4
Also put libfscrypt into fs_mgr via whole_static_libs
since it's now a dependency.

Bug: 143307095
Test: we can use the inline policy on it
Change-Id: I82d7d5330abef76ce82accea25d2663748e87a8b
2019-10-30 13:35:48 -07:00
Nikita Ioffe
8a603a7f9b Merge "Userspace reboot: Support remounting userdata for f2fs" 2019-10-28 16:28:23 +00:00
Paul Crowley
82f1cbea1e Merge "Use new libfscrypt interface" 2019-10-25 18:05:26 +00:00
Nikita Ioffe
12a36076a7 Userspace reboot: Support remounting userdata for f2fs
Test: adb reboot userspace
Test: adb shell /system/bin/vdc startCheckpoint 1;
      adb reboot userspace
Bug: 135984674
Change-Id: I227f2c1cc18495d893decb2df5173fc7a7919df6
2019-10-25 16:27:10 +01:00
Paul Crowley
9107e6f4f1 Use new libfscrypt interface
Bug: 143307095
Test: treehugger
Change-Id: Icc97ff5b32e8d291a75c62640b4d9b8e4f64de09
2019-10-24 20:47:48 -07:00
Nikita Ioffe
e7ec8c81e4 init/reboot.cpp: user lower_snake_case instead of camelCase
Also removed unused parameter from TryUmountAndFsck.

Test: builds
Change-Id: I1a892a0356afb08bf0680476ae1170ea568c65e2
2019-10-25 00:44:26 +01:00
Steven Moreland
5d9cdae3f3 Merge "host_init_verifier: use libhidlmetadata" 2019-10-23 23:07:30 +00:00
Tom Cherry
5310db82b0 init: only provide control message results for devices launching > Q
This is a behavior change and may have unintended consequences,
especially in Java, where failed property sets create exceptions.
Therefore, we only provide this new behavior to devices launching > Q.

Bug: 137070994
Test: build
Change-Id: If0b44aedc5c887ea6ea16dd3ec551ac2bf793cef
2019-10-23 08:09:56 -07:00
David Anderson
c243e19936 Merge "Integrate libsnapshot with the boot control HAL." 2019-10-17 19:57:04 +00:00
David Anderson
dfe6d07a4b Integrate libsnapshot with the boot control HAL.
This patch translates UpdateState states into a MergeStatus from
IBootControl 1.1, and asks the HAL to store it. Unfortunately this patch
has to work around a few issues.

The first issue is that Soong doesn't allow including only the headers
from a HAL. The second issue is that entraining the headers requires
linking to libraries that would otherwise not be needed in init.

To address this, we now have three ways of linking to libsnapshot:
  1. libsnapshot - Has access to gsid and HALs.
  2. libsnapshot_nobinder - Has access to HALs, but not binder (for
                            recovery).
  3. libsnapshot_init - Does not use binder or HALs.

The HAL code is #ifdef'd behind LIBSNAPSHOT_USE_HAL and we make use of
forward declarations and dependency injection to minimize its spread.

Bug: 139154945
Test: libsnapshot_test gtest
Change-Id: I21ffd8a79a43d0589f2f71f346ac1b019584a183
2019-10-16 16:09:38 -07:00
Steven Moreland
422a758568 host_init_verifier: use libhidlmetadata
Since it's available in C++, it's easier to build host_init_verifier
with this than create a new way to export the json file.

Bug: 141567104
Test: manually change hidl interface in a manifest
host_init_verifier: system/core/rootdir/init.rc: 69:
host_init_verifier: Interface is not in the known set of hidl_interfaces: 'android.hardwar.edne@1.0::IFoo'. Please ensure the interface is spelled correctly and built by a hidl_interface target.
Change-Id: Ic73dcb51855cb751734bc497d8e69f379966c511
2019-10-15 14:59:18 -07:00
Tom Cherry
a5a107fb6d Merge "init: trigger shutdown directly from builtins" 2019-10-14 13:48:52 +00:00
Tom Cherry
0dbfea7b07 init: trigger shutdown directly from builtins
Especially now that property_service is a thread, there may be some
delay between when init sets sys.powerctl and when the main thread of
init receives this and triggers shutdown.  It's possible that
outstanding init commands are run during this gap and that is not
desirable.

Instead, have builtins call TriggerShutdown() directly, so we can be
sure that the next action that init runs will be to shutdown the
device.

Test: reboot works
Test: reboot into recovery due to bad /data works
Change-Id: I26fb9f4f57f46c7451b8b58187138cfedd6fd9eb
2019-10-11 13:45:42 -07:00
Nikita Ioffe
aaab596687 Only allow alphanumerical characters, '-' and '_' in event trigger names
This should help in preventing silly typos like "on foo:"

Test: atest CtsInitTestCases
Test: builds
Bug: 135984674
Change-Id: I6e4e18970e957d25dea9f557f0d31a759fbe6150
2019-10-11 17:44:54 +01:00
Nikita Ioffe
3f4b0d6113 userspace reboot: stop post-data services and wait for them to be killed
* Refactored code around stopping services a little bit to reuse it
  between full reboot and userspace reboot.
* Add a scope_guard to fallback to full reboot in case userspace reboot
  fails.
* In case of userspace reboot init will also wait for services to be
  terminated/killed and log the ones that didn't react to
  SIGTERM/SIGKILL in time.
* If some of the services didn't react to SIGKILL, fail userspace reboot.

Test: adb reboot userspace
Bug: 135984674
Change-Id: I820c7bc406169333b0f929f0eea028d8384eb2ac
2019-10-10 18:13:42 +01:00
Elliott Hughes
4d7d903e2b Merge "init: actually report which signal is causing the reboot." 2019-10-08 17:13:59 +00:00
Nikita Ioffe
f1933c910d Merge "Add a skeleton of userspace reboot" 2019-10-08 14:42:36 +00:00
Nikita Ioffe
ba6968e636 Add a skeleton of userspace reboot
This CL only draws boundaries between userspace and full reboots, and
adds some functionality that will be required for userspace reboot:

* Whenever device is shutting down is now controlled in reboot.cpp,
  since during userspace reboot this state can change.
* Now it's also possible to restart handling of control messages inside
  property service. In case of userspace reboot, init will restart it
  after stopping post-data services.
* New userspace-reboot-requested trigger is added similar to shutdown
  one for full reboot.

Test: adb reboot
Test: adb reboot userspace
Bug: 135984674
Change-Id: Id55a53ba781d2b90ce40449037b6d8d47e72c476
2019-10-08 12:16:06 +01:00