Commit graph

3054 commits

Author SHA1 Message Date
Bernie Innocenti
8d144f6612 Merge "Fix missing Result::ok() call in init" 2020-03-01 15:14:39 +00:00
Bernie Innocenti
50dfcb02c8 Fix missing Result::ok() call in init
Test: m init
Change-Id: Ifc11f856704e6f8d08764b6ba2876423992fb8c2
2020-02-29 05:57:04 +00:00
Nikita Ioffe
6963f81a2b Stop & Resume property service when switching to bootstrap namespace
Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 149745936
Change-Id: I9d30b75f4b4177175ce086c3b6a7c0bba9a17396
2020-02-28 11:37:22 +00:00
Nikita Ioffe
3ad292025c Reset post_data_ and services_update_finished_ on userspace reboot
Test: adb reboot userspace
Bug: 143970043
Change-Id: I77d47a8460b1526337a318547a59141334e11cdd
2020-02-27 20:46:27 +00:00
Nikita Ioffe
d485bbbb51 If userspace reboot watchdog triggers, don't store reason in persistent property
If init is wedged, then the write will never succeed and reboot won't
happen.

Also, in case of normal reboot, move call to PersistRebootReason to the
top of DoReboot() function, to make sure we persist it even if /data is
not mounted.

Test: builds
Test: adb shell svc power reboot userspace
Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 148767783
Change-Id: I4ae40e1f6fdc41cc0bcae57020fa3d3385dda1b4
2020-02-27 13:06:37 +00:00
Howard Yen
bb578203a6 init: prevent persist.sys.usb.config initalized as none,adb
Prevent appending ",adb" to persist.sys.usb.config if "none" is
explicitly defined in default prop.

Bug: 150130503
Test: persist.sys.usb.config initalized correctly
Change-Id: I3b5de6fd102e252019e843f39f0875f5aaea7486
Merged-In: I3b5de6fd102e252019e843f39f0875f5aaea7486
2020-02-27 07:53:48 +08:00
David Anderson
a31834a4b6 Merge "init: Make sure ImageManager status files are labelled." 2020-02-26 17:56:03 +00:00
David Anderson
c991f347b2 init: Make sure ImageManager status files are labelled.
adb remount and snapshot-based updates use ImageManager in first-stage
init. This creates status files, which need to be labelled.

Bug: 148834619
Test: manual test
Change-Id: I72949fca2889f9e5612049844a78bf9355b48797
2020-02-25 09:09:08 -08:00
Tom Cherry
0fcb22868d Merge "init: handle property service callbacks asynchronously" 2020-02-25 16:22:28 +00:00
Tom Cherry
d9de138e47 Merge "Refactor libinit_test_utils to not use libinit and expose its libraries" 2020-02-24 16:10:56 +00:00
Elliott Hughes
f77f6f003c Remove various bits of dead code and unused workarounds.
Test: treehugger
Change-Id: I68fcd5da304d04ff4da3c3f3712fb79ce6b5791e
Merged-In: I68fcd5da304d04ff4da3c3f3712fb79ce6b5791e
2020-02-22 16:53:24 +00:00
Tom Cherry
7205c62933 init: handle property service callbacks asynchronously
A previous change moved property_service into its own thread, since
there was otherwise a deadlock whenever a process called by init would
try to set a property.  This new thread, however, would send a message
via a blocking socket to init for each property that it received,
since init may need to take action depending on which property it is.
Unfortunately, this means that the deadlock is still possible, the
only difference is the socket's buffer must be filled before init deadlocks.

There are possible partial solutions here: the socket's buffer may be
increased or property_service may only send messages for the
properties that init will take action on, however all of these
solutions still lead to eventual deadlock.  The only complete solution
is to handle these messages asynchronously.

This change, therefore, adds the following:
1) A lock for instructing init to reboot
2) A lock for waiting on properties
3) A lock for queueing new properties
4) A lock for any actions with ServiceList or any Services, enforced
   through thread annotations, particularly since this code was not
   designed with the intention of being multi-threaded.

Bug: 146877356
Bug: 148236233
Test: boot
Test: kill hwservicemanager without deadlock
Change-Id: I84108e54217866205a48c45e8b59355012c32ea8
2020-02-20 14:58:06 -08:00
Tom Cherry
a2f9136b2c Refactor libinit_test_utils to not use libinit and expose its libraries
Users of libinit_test_utils must include all libraries that it uses.
If it uses libinit, then there is a large number of libraries that
must be included.  To avoid this, make libinit_test_utils only use
init_common_sources and the small number of required libraries that go
along with those sources.  Additionally, expose these sources as a
default for users of libinit_test_utils.

Test: build
Change-Id: I224fa7e0590d073e4cd40412b5dcb6f72a64b6bf
2020-02-20 11:31:35 -08:00
Nikita Ioffe
d0bc0b6f1e Store reason in case of userspace-reboot watchdog reboot
Test: adb reboot userspace
Bug: 148767783
Change-Id: I58cf103fd5ce47eadae334376109492d0cc1c1c6
2020-02-19 20:12:07 +00:00
Mark Salyzyn
ee016ce0b3 bootstat: enhance last reboot reason property with file backing
Helps with support of recovery and rollback boot reason history, by
also using /metadata/bootstat/persist.sys.boot.reason to file the
reboot reason.

Test: manual
Bug: 129007837
Change-Id: Id1d21c404067414847bef14a0c43f70cafe1a3e2
2020-02-14 13:24:16 -08:00
Bowgo Tsai
196cc58781 Preserving /avb/* keys to /metadata
Those keys will be used for key revocation check by DSU installation
service. Note that failing to copy those keys to /metadata is NOT fatal,
because it is auxiliary to perform public key matching prior to booting
into DSU images on next boot. The actual key matching will still be done
on next DSU boot.

Bug: 146910547
Test: boot device, checks the avb keys are copied to /metadata/gsi/dsu/avb/.
Change-Id: I25a4eba82e84288bac7a859205c920628a063651
2020-02-13 15:15:20 +08:00
Steven Moreland
504e6647ff libinit_test_utils: -= libhidl-gen-utils header
Bug: N/A
Test: N/A
Change-Id: Idd558c395dfe19af9fe654941cd77bc94d3d74f4
2020-02-10 10:41:29 -08:00
Steven Moreland
579e4b3d2b Merge "libinit_test_utils: don't assume interface format" 2020-02-10 17:44:05 +00:00
Nikita Ioffe
15e4f6fe5a Merge "Don't log userspace_reboot.started/finished properties from init" 2020-02-10 17:22:03 +00:00
Tom Cherry
2157b2065e Merge "init: group source files better in Android.bp" 2020-02-10 14:49:02 +00:00
Steven Moreland
bb44cd6ea1 libinit_test_utils: don't assume interface format
These can be AIDL or HIDL interfaces. Avoiding assuming the format here.

Bug: 141008902
Test: vts_ibase_test
Change-Id: If60367e3a46c74a1d28548379655f5e211f58b73
2020-02-07 13:39:35 -08:00
Nikita Ioffe
85ff4ab9a4 Don't log userspace_reboot.started/finished properties from init
Instead they will be logged from system_server. This CL just prepares
grounds for logging CL to land.

Test: adb reboot userspace
Bug: 148767783
Change-Id: Ie9482ef735344ecfb0de8a37785d314a3c0417ff
2020-02-07 14:41:39 +00:00
Treehugger Robot
39e990d477 Merge "Convert system/core to Result::ok()" 2020-02-07 06:14:16 +00:00
Tom Cherry
66196495f2 init: group source files better in Android.bp
Test: build
Change-Id: I780a82122a08840257c44bff0b93ea6b25f0b2f0
2020-02-06 12:03:05 -08:00
Tom Cherry
62662cf189 Merge "init: use ErrnoErrorf() instead of ErrnoError() << StringPrintf()" 2020-02-06 19:14:37 +00:00
Tom Cherry
91bbe9ef56 Merge "Check Errorf()/ErrnoErrorf() format string at compile time" 2020-02-06 19:14:15 +00:00
Bernie Innocenti
cecebbbacc Convert system/core to Result::ok()
No functionality changes, this is a mechanical cleanup.

Test: m
Test: cd system/core && atest
Change-Id: Ifdaa3ce1947ed578f656d5a446978726eb416c36
2020-02-06 17:04:27 +00:00
Tom Cherry
57b9428471 init: use ErrnoErrorf() instead of ErrnoError() << StringPrintf()
Test: force init to print this line and see the log message
Change-Id: Ibb74572347f915cd76cc50f4c19126b66f562810
2020-02-05 07:57:14 -08:00
Tom Cherry
f8e6bf6d81 Check Errorf()/ErrnoErrorf() format string at compile time
fmtlib provides compile time checking of format strings that we're not
currently using.  This change makes Errorf() and ErrnoErrorf() into
macros such that we can take advantage of this capability.

Test: build successfully normally
Test: fail the build if using an invalid format string
Change-Id: Icb8ba8cb973bbd1fa4755a62e7598bdbb0113757
2020-02-05 07:57:14 -08:00
Bowgo Tsai
e0f5c10691 first_stage_mount: reading all avb_keys before chroot
Avb keys used to verify a partition are stored in the first-stage
ramdisk. However, after /system is mounted, init will chroot into it.
This makes those keys inaccessible for later mounts, e.g., /vendor or
/product.

This change retains avb keys by reading all of them before chroot
into /system.

Note that it is intentional to perform public matching for both
preload_avb_key_blobs and fstab_entry.avb_keys in libfs_avb.
As some keys might only be availble before init chroots into /system,
e.g., /avb/key1 in the first-stage ramdisk, while other keys might
only be available after the chroot, e.g., /system/etc/avb/key2.

Bug: 147585411
Test: specify avb_keys for a partition and checks the keys are preloaded
Test: atest libfs_avb_test
Test: atest libfs_avb_internal_test
Change-Id: I6bd490c4215480db2937cdfc3fea0d616e224a91
2020-02-05 15:51:41 +08:00
Bernie Innocenti
1cc76dfe84 Delete dangerous comparison operators from base::expected
These operators were included because they're present in the draft
standard proposal of std::expected, but they were deemed to lead to
bugs, particularly when T is implicitly convertible to bool.

Change-Id: Ib149decf1f230198f358dc1ae0eaed71961363f6
Test: m
2020-02-04 12:55:23 +00:00
Tom Cherry
db8881b769 Merge "init: handle process actions when waiting for exec services" 2020-02-03 14:02:40 +00:00
Tom Cherry
44d5ec37a7 init: handle process actions when waiting for exec services
We currently do not handle process actions (restarting services or
exiting timedout services) when we are waiting for an exec service,
but this seems to be the wrong behavior.  Particularly, an exec
service may depend on a previously started service and if that service
crashes, we will deadlock unless init restarts it.

Bug: 146920034
Test: build, boot
Change-Id: Id2fc936b8a7b989862ba4c32c398a544941e0e76
2020-01-31 08:33:36 -08:00
Nikita Ioffe
abe52dcb88 Merge "Whitelist reboot reasons related to userspace reboot failure" 2020-01-31 15:11:12 +00:00
David Anderson
21dcbd15bc Merge "remount: Use /data for backing scratch storage." 2020-01-29 17:55:06 +00:00
David Anderson
c13586faea remount: Use /data for backing scratch storage.
Currently, this is only enabled for Virtual A/B devices. When /data uses
F2FS, then proper pinning support must be enabled.

Because /data cannot be mounted in recovery, we can't delete the scratch
image backed by /data while in fastbootd. Instead, we mark it as
disabled in /metadata. The remount command now has an init script that
checks for and removes a disabled scratch partition.

Bug: 134949511
Test: adb remount on V A/B device with patched F2FS
Change-Id: Ifc8720378259654472d3822e97059b6c366f601d
2020-01-28 12:04:38 -08:00
Nikita Ioffe
764c1ac8ba Trigger boot animation on userspace reboot
Also reset some more properties to make bootanimation work properly.

Test: adb reboot userspace
Bug: 148172262
Change-Id: I0154d4fe9377c019150f5b1a709c406925db584d
2020-01-28 10:42:44 +00:00
Nikita Ioffe
4a787d96ce Whitelist reboot reasons related to userspace reboot failure
Test: system/core/bootstat/boot_reason_test.sh
Bug: 135984674
Change-Id: I31422329f1109273909293a83913ae801eb1fe52
2020-01-23 00:12:02 +00:00
Ryan Savitski
cdebef1d2b Merge "init: add builtin check for perf_event LSM hooks" 2020-01-21 20:40:50 +00:00
Satoshi Niwa
1eb300dca5 init: Fix a bug in MountDir
mkdir always returns -1 for any types of errors.
errno should be checked for actual error type.

Test: m
Change-Id: I1b56d48ba48992a2f9629dc09d795c277b5b774d
2020-01-20 18:00:49 +09:00
Oli Lan
90c523b30b Give x permission on apex data directories.
This gives search (x) permission on the parent apex data
directory /data/misc/apexdata so that directories below it
may be opened. It also gives that permission on the apex
data directories themselves.

Bug: 147848983
Test: Build & flash, check perms are correct
Change-Id: I27c4ea01602002c89d0771a144265e3879d9041a
2020-01-17 11:41:04 +00:00
Howard Chen
62f35129d4 Merge "Refine the first stage mount for DSU" 2020-01-16 05:33:09 +00:00
Ryan Savitski
f0f7e70186 init: add builtin check for perf_event LSM hooks
Historically, the syscall was controlled by a system-wide
perf_event_paranoid sysctl, which is not flexible enough to allow only
specific processes to use the syscall. However, SELinux support for the
syscall has been upstreamed recently[1] (and is being backported to
Android R release common kernels).
[1] da97e18458

As the presence of these hooks is not guaranteed on all Android R
platforms (since we support upgrades while keeping an older kernel), we
need to test for the feature dynamically. The LSM hooks themselves have
no way of being detected directly, so we instead test for their effects,
so we perform several syscalls, and look for a specific success/failure
combination, corresponding to the platform's SELinux policy.

If hooks are detected, perf_event_paranoid is set to -1 (unrestricted),
as the SELinux policy is then sufficient to control access.

This is done within init for several reasons:
* CAP_SYS_ADMIN side-steps perf_event_paranoid, so the tests can be done
  if non-root users aren't allowed to use the syscall (the default).
* init is already the setter of the paranoid value (see init.rc), which
  is also a privileged operation.
* the test itself is simple (couple of syscalls), so having a dedicated
  test binary/domain felt excessive.

I decided to go through a new sysprop (set by a builtin test in
second-stage init), and keeping the actuation in init.rc. We can change
it to an immediate write to the paranoid value if a use-case comes up
that requires the decision to be made earlier in the init sequence.

Bug: 137092007
Change-Id: Ib13a31fee896f17a28910d993df57168a83a4b3d
2020-01-15 20:58:15 +00:00
Nikita Ioffe
05506f05b6 Don't reboot into recovery during userspace reboot
In case one of the cryptfs calls to vdc fails, first try a normal
reboot.

Test: manual
Bug: 135984674
Bug: 143970043
Change-Id: I5706d9cd6c3a08fa06329ffb7d141de632620e3d
2020-01-15 16:27:39 +00:00
Nikita Ioffe
60ddf3a29a Merge "Change scope of ro.init.userspace_reboot.is_supported to public" 2020-01-15 14:14:08 +00:00
Nikita Ioffe
10cdc17283 Change scope of ro.init.userspace_reboot.is_supported to public
Test: atest CtsUserspaceRebootHostSideTestCases
Test: m checkbuild
Bug: 135984674
Change-Id: Ie11c6720ee21afef99b4b53415da00d8c1e446ca
2020-01-14 12:42:48 +00:00
Treehugger Robot
b7c68f777b Merge "init: document interface_* commands and ctl.* actions" 2020-01-13 22:41:44 +00:00
Tom Cherry
504eb85f9d init: document interface_* commands and ctl.* actions
Test: n/a
Change-Id: Ided7e16a00142e7235edeef3be2eddb6bb751bfc
2020-01-13 09:45:08 -08:00
Treehugger Robot
644d6a1e2e Merge "init: Bind mount /mnt/installer early for scoped storage." 2020-01-13 08:27:44 +00:00
Martijn Coenen
c70c0665fc init: Bind mount /mnt/installer early for scoped storage.
Scoped storage has some unique requirements that are hard to implement
with the two mount namespaces, because the daemon that does the mounting
(vold) lives in a different namespace than the processes using those
mounts.

In particular, /mnt/installer is a special bind mount that should
receive mount events under /mnt/user, but at the same time only
only propagate mount events under /mnt/installer to /mnt/installer in
the other namespace. More details in the code.

Bug: 134706060
Test: /mnt/installer shows up and is setup correctly.
Change-Id: I6dab5ace5a345d9d684a9f1ae94c833fc294d49e
2020-01-11 15:07:21 +01:00