Commit graph

3049 commits

Author SHA1 Message Date
Tianjie Xu
137943d31b Revert "init: Write the reason in BCB on "reboot recovery""
This reverts commit 4d35f2e59c.

Reason for revert: b/137523800 This breaks factory reset on all devices (and potentially rescue party and non-ab updates). Because the init code unconditionally clear the arguments like "--wipe_data" written by framework; as a result, device boots into recovery without doing wipe. 

I guess one fix is to check the content of BCB, and skip the overwrite if it already boots into recovery. Revert the cl first to unblock p1, will submit the fix separately.

Change-Id: Iccaf3dce6999005c2199490a138844d5a5d99e7f
2019-07-18 11:42:14 -07:00
Martijn Coenen
728586f5b2 Ignore class_{reset|start}_post_data on non-updatable APEX.
For devices that use FDE and don't support updatable APEXes, don't
stop and restart all processes - there is no need and it only increases
boot time for these devices.

Additionally, some daemons have never been restarted in the past, and
restarting them exposes certain issues.

Bug: 137251597
Bug: 136777273
Bug: 135627804
Test: verified manually w/ ro.updatable.apex=false
Change-Id: I9590f2c2cdfab0a49f39846896460305d44221ee
2019-07-17 08:49:44 +02:00
Treehugger Robot
a19f51eccc Merge "Reserve 'init'." 2019-07-16 02:35:29 +00:00
Treehugger Robot
100e8ffbcd Merge "Remove obsolete subdirs entry." 2019-07-16 02:02:40 +00:00
Tom Cherry
c8620ddafe Merge "init: clean up file / socket descriptor creation" 2019-07-15 23:20:13 +00:00
Steven Moreland
4c79df91a9 Remove obsolete subdirs entry.
Change-Id: I3327df74179d2ba1ffd66da59e5196f34dfe3974
Bugs: me
Test: N/A
2019-07-15 15:14:34 -07:00
Steven Moreland
ceb36d08f4 Reserve 'init'.
This makes `pathmod init` and `gomod init` work, and it also reserves
the 'init' for potential future usage.

Change-Id: I6990bf421211b93d58d978d84d46474ff243e808
Bugs: me
Test: pathmod init; gomod init
2019-07-15 15:12:56 -07:00
Tom Cherry
2e4c85f157 init: clean up file / socket descriptor creation
clang-tidy hinted that some of this code wasn't right.  Looking
deeper, there is really not much related to file and socket
descriptors, except that they're published in similar ways to the
environment.  All of the abstraction into a 'Descriptor' class takes
us further away from specifying what we really mean.

This removes that abstraction, adds stricter checks and better errors
for parsing init scripts, reports sockets and files that are unable to
be acquired before exec, and updates the README.md for the passcred
option.

Test: build, logd (uses files and sockets) works
Change-Id: I59e611e95c85bdbefa779ef69b32b9dd4ee203e2
2019-07-15 12:17:30 -07:00
David Anderson
c9b797ac25 Merge "libdm: Improve the reliability of dm device paths." 2019-07-12 23:03:41 +00:00
Tom Cherry
8a779ee959 Merge "init: fix clang-tidy performance issues" 2019-07-12 18:49:49 +00:00
Daniel Norman
4b505fe3a8 Merge "Checks the interface inheritance hierarchy in init_rc files." 2019-07-12 18:01:46 +00:00
Tom Cherry
e7a010de01 Merge "init: Write the reason in BCB on "reboot recovery"" 2019-07-12 17:39:32 +00:00
Treehugger Robot
5c296a0003 Merge "init: powerctl support and propagate longer canonical reboot reasons." 2019-07-12 17:37:25 +00:00
David Anderson
924858cd18 libdm: Improve the reliability of dm device paths.
This fixes a race condition where WaitForFile() after
GetDmDevicePathByName appears to succeed, but a subsequent operation on
the path fails. This can happen when CreateDevice() is called
immediately after a call to DeleteDevice (from any process), and the
path is re-used, enqueuing udev events to remove and re-add the block
device.

The fix for this is to introduce a new variant of CreateDevice() that
has a timeout parameter. When the timeout is positive, CreateDevice()
will wait for a /dev/block/mapper/by-uuid symlink to be created, which
signals that ueventd has finished processing the operation.

ueventd will now create these by-uuid symlinks for device-mapper nodes.
Unfortunately, the uuid is only available during "change" events, so we
have to special case device-mapper symlink creation. And since the uuid
is not available during "remove" events, we simply find matching links
to remove them.

This ensures that callers of CreateDevice() can use the device path
knowing that no asynchronous removals are pending. Code that uses the
old CreateDevice+WaitForFile pattern will be transitioned to the new
method.

Note that it is safe to ignore the timeout, or to use the "unsafe"
CreateDevice, if the caller ensures the path by other means. For example
first-stage init has no device removal, and regenerates uevents until
it has acquired all the paths it needs.

Finally, since libdm now inspects sysfs unconditionally, libdm consumers
need r_dir_file perms for sysfs_dm in their sepolicy. Additionally
linking to libdm now requires linking to libext2_uuid.

Bug: 135771280
Test: libdm_test
      device flashes, boots
Change-Id: If5a7383ea38f32a7fbbcf24842dce6a668050a70
2019-07-11 15:39:52 -07:00
Daniel Norman
3f42a767cd Checks the interface inheritance hierarchy in init_rc files.
Bug: 118016875
Test: Added 'interface' lines to an init_rc file and observed errors
when misspelled or missing entire inheritance hierarchy.
Change-Id: I681420f15539742d8415808b2a0dcbf0bf6faaf1
2019-07-11 14:43:11 -07:00
Steven Moreland
4280165ae0 Merge "Remove binder dependency in init." 2019-07-11 20:56:12 +00:00
Sam Protsenko
4d35f2e59c init: Write the reason in BCB on "reboot recovery"
Without this change "adb reboot recovery" leads to normal boot.

Change-Id: I361d0a1f6f6f2c57f3dc80102c21970b462c9b9c
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
2019-07-11 11:25:28 +00:00
Mark Salyzyn
d7931f1149 init: powerctl support and propagate longer canonical reboot reasons.
init: Received sys.powerctl='reboot,userrequested,recovery,ui' ... (/system/bin/recovery)
init: powerctl: unrecognized command 'reboot,userrequested,recovery,ui'

Test: manual & boot_reason_test.sh
Bug: 63736262
Bug: 135078366
Bug: 133326470
Change-Id: I931daf8dc4b74db5ee114c59ee215b1ba54bc31d
2019-07-10 13:06:57 -07:00
Tom Cherry
7c1d87e490 init: fix clang-tidy performance issues
Test: boot, init unit tests
Change-Id: Iccf34d2fedfa543dd9f29e010cbb6d8fe9cf5983
2019-07-10 12:59:02 -07:00
Steven Moreland
4ee27039e0 Remove binder dependency in init.
- unused
- using binder requires twoway calls (since getting a service from
    servicemanager requires two calls)

Bug: 135768100
Test: N/A
Change-Id: Idc41f487bad2d8343e99ded98812f3a84e2b8e37
2019-07-10 17:01:31 +00:00
Justin Yun
7eaf9b58ec Rename product_services to system_ext
Update ld.config.txt and init.

Bug: 134359158
Test: make && check boot and ld.config.txt file
Change-Id: Ie1dce42e690414fb45b26759506ea7f64d06740d
2019-07-09 23:34:17 +00:00
Tom Cherry
247ffbf314 Fix a few clang-tidy issues and add NOLINT for others
android-base:
* Add NOLINT for expanding namespace std for std::string* ostream
  overload

libdm:
* Fix missing parentesis around macro parameters

init:
* Fix missing CLOEXEC usage and add NOLINT for the intended
  usages.
* Fix missing parentesis around macro parameters
* Fix erase() / remove_if() idiom
* Correctly specific unsigned char when intended
* 'namespace flags' should be signed, since 'flags' it signed for
  clone()
* Add clear to property restore vector<string> to empty after move
* Explicit comparison against 0 for strcmp

Test: build
Change-Id: I8c31dafda2c43ebc5aa50124cbbd6e23ed2c4101
2019-07-09 16:17:36 +00:00
Treehugger Robot
3d3f24bc22 Merge "init: fix to avoid loading apex *.rc files twice" 2019-07-09 00:37:31 +00:00
Steve Muckle
d75f30a4f0 first_stage_init: add console
Start and wait on a console if androidboot.first_stage_console=1 is
present on the kernel command line. This only works on eng and
userdebug builds.

Change-Id: I978e9390a89509431b399ea58b284736b27eeb1b
2019-07-08 09:33:24 -07:00
Jooyung Han
9c4fa66706 init: fix to avoid loading apex *.rc files twice
Test: adb shell dmesg | grep "init: Parsing file /apex"
 shows a single entry for each APEX'es *rc file

Change-Id: I9006cc3d0cb7bdfe7532279f29d8095b7d16a807
2019-07-05 11:22:18 +09:00
Daniel Norman
3df8dc58b2 Checks each interface in an init_rc file is a known hidl_interface.
Test: Adding a misspelling to an init_rc's interface line and observing
build failure.
Bug: 77646540
Change-Id: I58f66d73f0bd9b4203e8259161843b56ad428d73
2019-06-28 13:31:54 -07:00
Tom Cherry
3f1bce870b init: switch host_init_verifier to getopt()
Test: host init verifier works

Change-Id: Ia0fe5994079e6e182a64b14a15fdb36328080168
2019-06-27 10:09:12 -07:00
Tom Cherry
f1a044bac4 init: clean up host_init_stubs a bit
In retrospect, these always should have been header only.  We don't
need setgroups() anymore either, since we have the right symbols now.

Test: build
Change-Id: If6fbf6f8ee288ed261576207d90a7ec5674853f9
2019-06-26 15:38:47 -07:00
Tom Cherry
172c83f972 init: remove last init.cpp global
By moving it into builtins.cpp..., but that's less bad than it is
now, especially since this is defunct in code targeting Q+.  Remove
the guards that init.h isn't being included by other files too as it's
not useful anymore.

Test: build
Change-Id: Ic564fcff9e8716ec924098b07a8c9d94ca25f960
2019-06-26 14:46:58 -07:00
Tom Cherry
ff88e30126 init: remove console_init_action
There's no fundamental reason to store this aside.  That property can
only be written by init, so it's not likely that we're going to
corrupt it.

Test: boot and use serial console
Change-Id: I9248fbaf959ea913d09add829d4cb509af99d570
2019-06-26 14:20:53 -07:00
Tom Cherry
b1ffb1ded5 Move actual parsing from Service to ServiceParser
This is how this should have been done since the beginning.

Test: build, boot
Change-Id: Ifd795776c71a2e666da7fab90cbb3f356af93d4f
2019-06-26 14:03:16 -07:00
Tom Cherry
2aeb1addee Split out ServiceList and ServiceParser from service.cpp/.h
These always should have been in their own files.

Test: build
Change-Id: I201109b5ee63016e78901bbfd404846d45e1d4e6
2019-06-26 13:45:07 -07:00
Tom Cherry
84fc269b6e Merge "init: Handle properties in the background of calling fs_mgr" 2019-06-24 22:46:09 +00:00
Tom Cherry
71bdf2820e init: Handle properties in the background of calling fs_mgr
It's been a long standing problem that init calls fs_mgr functions
synchronously and therefore stops handling properties, which causes
deadlocks if either fs_mgr, or vdc, or vold attempt to set
properties.

Previous work, b/21904461, shows that there is a large performance
penalty for adding any amount of locking to properties, so moving
property service into its own thread generically is not a viable
option.  However, we can be sure that init is not setting properties
while the fs_mgr functions are running, so we can poll the property
socket in a thread while we call these functions.

The other alternative would have been to separate the fs_mgr functions
into smaller pieces and revisit the main init loop between each
piece.  Unfortunately, this would be difficult, since
fs_mgr_mount_all() calls out to different processes via logwrapper,
which synchronously polls on a logging FD from the child, among other
complexities that would make this strategy much more difficult than it
would be worth.

Bug: 21904461
Test: device boots, including when setting property in
      fs_mgr_mount_all()

Change-Id: Ib0b7123024035884f9d90f9b489c1e2f5a2e1707
2019-06-24 13:23:49 -07:00
Tom Cherry
af274fd086 Merge "init: use a property instead of file to communicate cold boot done" 2019-06-24 19:39:03 +00:00
Treehugger Robot
411fb88506 Merge "Qualifies the mention of lazily starting services from 'interface'." 2019-06-19 03:03:00 +00:00
Daniel Norman
d6d09c646a Qualifies the mention of lazily starting services from 'interface'.
The 'interface' option is not always used by services that support lazy
startup.

Test: None
Change-Id: I6bfb095d4ecb932933d56cd1859a5eff6df2edbd
2019-06-18 17:03:05 -07:00
Steve Muckle
18b981ea7c create libmodprobe, integrate into first_stage_init
Modprobe functionality is required both within first stage init and also
as a standalone binary. Create a library for this using and extending
the logic in modalias_handler.cpp.

First stage init will attempt to load modules from /lib/modules.

Bug: 129780532
Change-Id: Ie3582358fd839c2f64e1b386b30ed551a86aef5d
2019-06-18 13:24:56 -07:00
Tom Cherry
f4db2aad57 init: use Errorf() now that we have it
Init had some pretty horrid Error() << StringPrintf(...) calls that
are all much better replaced by Errorf(...) now.

Test: build, check that keyword_map errors look correct
Change-Id: I572588c7541b928c72ae1bf140b814acdef1cd60
2019-06-14 22:07:32 +00:00
Dongcheol Shin
a87c0f99ad Support importing property file with expanded name
This change is to support importing property file with its path
variations.

By substitute its filename with another, it can be used to handle
runtime varying filename within single binary.

Here's an example of usage in property defined file.
    import /odm/build_${ro.boot.product.hardware.sku}.prop

Bug: 132592551
Test: boot a device and checks above example import statement in
    "/odm/build.prop" loading expanded filename correctly

Change-Id: If3fdcf620a5d717e0930b1e4e58261bc8f79ec24
2019-06-13 23:40:23 +00:00
Treehugger Robot
b3093ff21a Merge "Read *.rc files from flattened APEX" 2019-06-11 12:11:11 +00:00
Tom Cherry
39fafedc5a init: use a property instead of file to communicate cold boot done
Ueventd can't set properties currently, but this is an artificial
limitation, since ueventd communicates to init that it has finished
cold boot via a file, and init polls this file instead of returning to
the epoll loop, where properties are handled.

This change replaces that file with a property and thus frees ueventd
to be able to set properties.

Bug: 62301678
Test: boot, check that properties are set
Change-Id: I985688e9299456efcb2dfeef9b92668991aa9c05
2019-06-10 18:08:01 -07:00
Tom Cherry
bbcbc2ffb3 init: replace Result<Success> with Result<void>
Now that Result<T> is actually expected<T, ...>, and the expected
proposal states expected<void, ...> as the way to indicate an expected
object that returns either successfully with no object or an error,
let's move init's Result<Success> to the preferred Result<void>.

Bug: 132145659
Test: boot, init unit tests
Change-Id: Ib2f98396d8e6e274f95a496fcdfd8341f77585ee
2019-06-10 12:39:18 -07:00
Jiyong Park
d2217b5167 Read *.rc files from flattened APEX
This change fixes a bug that *.rc files in APEXes are not read when the
APEXes are flattened. This was because init used "/apex/*@*/etc/*.rc"
glob pattern to find the files, which gives 0 result with flattened
APEXes; with flattend APEXes /system/apex is just bind-mounted to /apex,
and therefore, the name@version directories don't exist.

Fixing the issue by globing /apex/*/etc/*.rc and filter-out the paths
with @ to avoid double parsing the *.rc files in case of non-flattend
APEXes.

Bug: 134067086
Test: revert I75ec6b69cca1cef071b50fac9a4cf8b8ceddb142
build sdk_gphone_x86_64 and record a video in the camera app.
The recording works. `ps -A | grep media.swcodec` shows media.swcodec process.
`atest CtsStatsdHostTestCases:android.cts.statsd.atom.UidAtomTests#testAudioState` passes
Test: build sdk_phone_x86_64 and do the same.

Change-Id: I00af1910a8e8a330addc4c6903e5f3695aeb6865
2019-06-10 13:06:39 +09:00
Jiyong Park
8fd64c8af1 Move result.h from init to libbase
The Result, Error, ErrnoError are quite generic. Moving them from init
to libbase so that they can be used from other places.

Bug: 132145659
Test: libbase_test
Change-Id: Id774a587f74380fadd7a0fc88c0aa892c3d9a489
2019-06-06 08:58:55 +09:00
Vic Yang
e01ca4da2d init: Refactor service.h/cpp
Factors out utility functions into service_utils.h/cpp, so that they
can be reused by the upcoming native zygote.

Bug: 133443795
Test: Build and boot cuttlefish.
Change-Id: I0531b6f17561119c8cc33dd9ba375b351747fcfe
2019-05-30 14:24:03 -07:00
Vic Yang
92c236e41b init: Refactor selinux.h/cpp
This change factors out functions that handle selabels from
selinux.h/cpp into selabel.h/cpp.  This allows util.cpp to be used by
the upcoming native zygote without a bunch of define flags that are
required for selinux.cpp.

Bug: 133443795
Test: Build and boot cuttlefish.
Change-Id: Ie238a96c6407c6698a605dd8803c1727abfaae7b
2019-05-29 15:09:39 -07:00
Tom Cherry
e20f357f4f Merge changes I16ea9e32,Ib53b5d3e
* changes:
  init: make fatal reboot target configurable
  init: dump stack when aborting
2019-05-29 21:40:12 +00:00
Tom Cherry
75e13baf32 init: make fatal reboot target configurable
Currently, if init encounters a fatal issues it reboots to fastboot
but this may be not desirable in all cases, especially the case of
critical services crashing.  Therefore this change adds the ability
for vendors to customize the reboot target via the
androidboot.init_fatal_reboot_target= kernel command line.

This applies to all LOG(FATAL) messages as well as fatal signals in
userdebug/eng builds, except for signals before logging is enabled in
first stage init.

Bug: 121006328
Test: device reboots to configurable target with LOG(FATAL)
Test: device reboots to configurable target after a segfault in the
      various stages of init
Test: device reboots to fastboot without a configured target
Change-Id: I16ea9e32e2fee08dece3d33b697d7a08191d607b
2019-05-29 09:14:17 -07:00
Tom Cherry
59656fb377 init: dump stack when aborting
Dump init stacks when aborting either due to LOG(FATAL) or in
userdebug/eng builds due to signals, including signals from
sanitizers.

Doesn't work for static first stage init yet, b/133450393 tracks
that.

Also, ensure that LOG(FATAL) in child processes calls abort() in all
stages of init, not just 2nd stage init.

Bug: 131747478
Test: abort init in various ways and see stacks
Test: hang or crash in backtrace handler and see child reboot
Change-Id: Ib53b5d3e7e814244203f875de016ada9900dfce8
2019-05-29 08:58:29 -07:00
Jiyong Park
d7f7c208da Don't use apexd when TARGET_FLATTEN_APEX == true
When TARGET_FLATTEN_APEX is true (= ro.apex.updatable is unset or set to
false), apexd is not used to activate the built-in flattened APEXes.
Init simply bind-mounts /system/apex to /apex.

However, there is a special case here. The runtime APEX is installed as
either /system/apex/com.android.runtime.debug or
/system/apex/com.android.runtime.release, whereas it should be activated
on /apex/com.android.runtime - without the .debug or .release suffix.
To handle that case, the build system creates an empty directory
/system/apex/com.android.runtime and the .debug or .release directory
is bind-mounted to the empty directory by init at runtime.

This change also fixes a minor bug that native watchdog is triggered
for all post-apexd processes regardless of whether ro.apex.updatable
is true or not. Since apexd is expected to shutdown itself when ro.apex
.updatable is false, we don't trigger the watchdog in that case.

Bug: 132413565
Bug: 133305381
Test: marlin and sdk_gphone are bootable
Merged-In: I219465b8b81decb960e2c5f46bab6e0768b31317
Change-Id: I219465b8b81decb960e2c5f46bab6e0768b31317
(cherry picked from commit f93088ba2b)
2019-05-29 07:04:27 +09:00
Treehugger Robot
7d1f11759a Merge "init: replace Result<> with expected<>" 2019-05-27 04:35:26 +00:00
Treehugger Robot
1c144d5a51 Merge "ueventd: add more logging when firmware loading fails" 2019-05-27 03:06:26 +00:00
Tom Cherry
d38aafd20b ueventd: add more logging when firmware loading fails
Bug: 130131892
Test: boots
Change-Id: I82ce0f72341bb44590177cedaa2e3a7990456c1d
2019-05-23 16:27:33 -07:00
Wei Wang
5f01d3af77 init: add error handling in control message
Bug: 133432022
Test: boot
Test: setprop ctl.interface_restart android.hardware.power@1.0::IPower/default success
Test: setprop ctl.interface_restart android.hardware.power@1.0::IPower/abc fail
Change-Id: I66342b2723eb01022fb4e0d98f0b6ffc2752bcac
2019-05-23 12:43:09 -07:00
Tom Cherry
cbe0876f8b Merge "init: don't import rc files during mount_all after Q" 2019-05-23 18:46:51 +00:00
Treehugger Robot
5436843246 Merge "Moving /odm/build.prop to /odm/etc/buid.prop" 2019-05-23 09:16:34 +00:00
Tom Cherry
9949ec5f56 init: replace Result<> with expected<>
Android-base has an implementation of the future std::expected<>.
This provides the same baseline functionality as Result<>, so use it
instead of our own version.

Bug: 132145659
Test: boot, init unit tests
Change-Id: I11e61bcb5719b262a6420483ed51a762826a9e23
2019-05-22 15:23:01 -07:00
Bowgo Tsai
9fc8dcf517 Moving /odm/build.prop to /odm/etc/buid.prop
In device root directory, we have the following symlinks:
  - /odm/app -> /vendor/odm/app
  - /odm/bin -> /vendor/odm/bin
  - /odm/etc -> /vendor/odm/etc
  ...

This allows the Generic System Image (GSI) to be used on both devices:
  1) Has a physical odm partition, where those symlink will be hidden
     when /odm is used as the mount point
  2) Has no physical odm partition and fallback to /vendor/odm/.

We can't just have the symlink /odm -> /vendor/odm, because the former
devices won't have /vendor/odm directory, which leads to mount failure
when the mount point /odm is resolved to /vendor/odm.

The existing /vendor/odm/build.prop won't be loaded in the latter
devices, because there is no symlink
    - /odm/build.prop -> /vendor/odm/build.prop.

Note that init blocks reading through direct symlinks (O_NOFOLLOW) so
the above symlink won't work either. This CL moves the odm build.prop
to /odm/etc/build.prop for init to load it (symlinks in earlier
components of the path will still be followed by O_NOFOLLOW).

Bug: 132128501
Test: boot a device and checks /odm/etc/build.prop is loaded
Change-Id: I0733c277baa67c549bb45599abb70aba13fbdbcf
Merged-In: I0733c277baa67c549bb45599abb70aba13fbdbcf
2019-05-22 06:03:34 +00:00
Tom Cherry
3041a5100b init: don't import rc files during mount_all after Q
Importing rc files during mount_all was at best a stop gap until
Treble's first stage mount and at worst a bad idea.  It doesn't have a
reason to exist now that first stage mount exists and is required, and
always had edge cases where init could not handle loading some aspects
of scripts after it had started processing actions.

This change removes this functionality for devices launching after Q.

Test: devices boot
Change-Id: I3181289572968637b884e150d36651f453d40362
2019-05-21 17:48:33 -07:00
Peter Collingbourne
f6ce7d0de0 Stop adding the bootstrap directory to rpath.
This is no longer necessary now that the bootstrap linker does this
automatically.

Change-Id: Ifd8177cc9cf5f2dc2a18c467ddb0147f8182fc4c
2019-05-16 19:36:27 -07:00
Tom Cherry
8a3630e327 Merge "init: always initialize device-mapper" 2019-05-16 15:09:16 +00:00
Martijn Coenen
acc45aa0a1 class_start_post_data also starts disabled services.
This keyword was introduced to support restarting services on devices
using APEX and FDE. The current implementation is not a restart, but
rather a 'reset' followed by a 'start', because the real /data must be
mounted in-between those two actions. But we effectively want this to be
a restart, which means that we also want to start 'disabled' services
that were running at the time we called 'class_reset_post_data'.

To implement this, keep track of whether a service was running when its
class was reset at post-data, and start all those services.

Bug: 132592548
Test: manual testing on FDE Taimen
Change-Id: I1e81e2c8e0ab2782150073d74e50e4cd734af7b9
Merged-In: I1e81e2c8e0ab2782150073d74e50e4cd734af7b9
2019-05-16 09:30:35 +02:00
Tom Cherry
eef2a703ad init: always initialize device-mapper
Device-mapper is required already, so drop the conditionals for trying to
load it.  GetRootEntry() was depending on its existance, so this adds the
required dependency.

Bug: 131747478
Test: boot without any verity/avb/dm-linear devices.
Change-Id: Ifc89d3b338e2c2b8faaf1c24e2792c1eeb5bbbde
2019-05-15 16:35:43 -07:00
Mark Salyzyn
44505ecdd9 init: move "started at" environment var names to headers
Move "FIRST_STAGE_STARTED_AT" to env_first_stage_started_at variable
in first_stage_init.h.  Move "SELINUX_STARTED_AT" to
env_selinux_started_at variable in selinux.h.

Test: build
Bug: 124491153
Bug: 129780532
Change-Id: I512d1835dcee5a3d034ac453b27b0709eed23cff
2019-05-08 13:50:21 -07:00
Mark Salyzyn
10377df9f8 init: ro.boottime.init.first_stage
Add a property ro.boottime.init.first_stage to provide us a
first stage init duration from start to exec completed in
nanoseconds.

For consistency, report nanoseconds duration for
ro.boottime.init.selinux as well instead of milliseconds.
Now also report consistently from start to exec completed
instead of just the selinux load time.

SideEffects: ro.boottime.init.selinux is reported to TRON and
             may alarm with the millionfold increase in precision.
             ro.boottime.init is now also consistent with ns
             precision.

Test: inspect
Bug: 124491153
Bug: 129780532
Change-Id: Iff4f1a3a1ab7ff0a309c278724c92da0832b9a69
2019-05-08 16:07:10 +00:00
Martijn Coenen
fc78be2935 Merge "Support for stopping/starting post-data-mount class subsets." 2019-05-07 06:41:01 +00:00
Tom Cherry
1cd30df584 Merge "Vboot1.0: remove code to read verity state in userspace" 2019-05-06 23:41:47 +00:00
Jeff Vander Stoep
0ac51cfc01 Load selinux compat file if it exists
This addresses Treble backwards compat issues introduced in
aosp/793958 and aosp/783669.

Bug: 122874820
Test: build/flash blueline with pi-dev vendor and generic_ab system
    images.
Test: adb pull /sys/fs/selinux/policy;
    sesearch policy --allowx -s vendordomain -t dev_type

Change-Id: I9123aa02cf4bf07d72d1ea086dde0d1cf1b30db4
2019-05-02 14:25:06 -07:00
Zimuzo
88de80fc53 Attempt native rollback for frequent crashes before boot completed
Before, if updatable processes crash 4 times in 4mins, a native
rollback will be attempted. This behavior does not detect
system_server early boot deadlocks because the system server requires
at least a min to detect a deadlock, and crash itself. The crashes
don't happen frequently enough for init to detect.

After, this cl, the old behavior exists and additionally, init detects
*any* 4 crashes of updatable processes before boot completed,
regardless of if they happen within 4mins or not.

Test: Manually tested by adding artificial sleep in system_server so
deadlock is triggered before boot. system_server crashes 4 times in
over 4mins and the ro.init.updatable_crashing prop is set to 1.
Bug: 129597207

Change-Id: Ie6fb5693ff4be105bcbe139c22850fb076e40260
2019-04-30 11:19:19 +00:00
Martijn Coenen
70788f93ba Support for stopping/starting post-data-mount class subsets.
On devices that use FDE and APEX at the same time, we need to bring up a
minimal framework to be able to mount the /data partition. During this
period, a tmpfs /data filesystem is created, which doesn't contain any
of the updated APEXEs. As a consequence, all those processes will be
using the APEXes from the /system partition.

This is obviously not desired, as APEXes in /system may be old and/or
contain security issues. Additionally, it would create a difference
between FBE and FDE devices at runtime.

Ideally, we restart all processes that have started after we created the
tmpfs /data. We can't (re)start based on class names alone, because some
classes (eg 'hal') contain services that are required to start apexd
itself and that shouldn't be killed (eg the graphics HAL).

To address this, keep track of which processes are started after /data
is mounted, with a new 'mark_post_data' keyword. Additionally, create
'class_reset_post_data', which resets all services in the class that
were created after the initial /data mount, and 'class_start_post_data',
which starts all services in the class that were started after /data was
mounted.

On a device with FBE, these keywords wouldn't be used; on a device with
FDE, we'd use them to bring down the right processes after the user has
entered the correct secret, and restart them.

Bug: 118485723
Test: manually verified process list
Change-Id: I16adb776dacf1dd1feeaff9e60639b99899905eb
2019-04-26 14:04:59 +02:00
Joseph Jang
67231474fe Merge "init: Add reboot timeout handler" 2019-04-26 08:23:06 +00:00
josephjang
aaddf282ec init: Add reboot timeout handler
In order to prevent device stuck at reboot, we try to create shutdownt
monitor thread with a timeout (default 30s). It will dump init process
and blocked tasks call trace in last kmsg then trigger kernel panic to
reboot device.

Test: reboot device

bug: 128561401
Change-Id: Ieb400ab9fbd983544b61241a4f4b8aa2f4baa863
2019-04-26 06:02:09 +08:00
Tom Cherry
7a03b5d314 Merge "init: simplify async restorecon" 2019-04-24 19:14:28 +00:00
Tom Cherry
fe8154175c init: simplify async restorecon
In the future, property service may run in its own thread or process,
which means that PropertyChildReap() needs to be refactored to not run
as part of the init signal handler.

The new method spawns a new thread that handles the queue of paths
that require restorecon. It then communicates back to property service
via android::base::SetProperty(). Property service distinguishes the
thread from other callers of SetProperty() by checking the pid in the
credentials for the socket connection, thus avoiding dependencies on
the rest of init.

The new method also drops the genericness, since restorecon is the
only function that we should ever need to run asynchronously

Test: async restorecon works, including with queued requests
Change-Id: I2ca00459969e77b1820776dac23d0a0d974e330b
2019-04-24 08:50:10 -07:00
Treehugger Robot
74d84224ae Merge "Remove the mount points defined in skip_mount.cfg from ReadDefaultFstab()" 2019-04-24 02:53:53 +00:00
Tom Cherry
87882c0a00 Merge "init: handle getpeercon() errors" 2019-04-23 16:06:40 +00:00
Tom Cherry
4bc16589df Merge "init: set up SelinuxAuditCallback() earlier" 2019-04-23 16:04:35 +00:00
SzuWei Lin
77c28476f1 Remove the mount points defined in skip_mount.cfg from ReadDefaultFstab()
The first stage init skips mounting the mount points defined in
skip_mount.cfg, but these mount points still return from
ReadDefaultFstab(). The behavior causes some error logic which
try to access the partition which had been skipped.

After applying the patch. ReadDefaultFstab() will not contain the
skipped mount points.

Bug: 128961335
Test: `fastboot delete-logical-partition product_a`
Test: `fastboot flash system aosp_arm64-userdebug`
Test: `fastboot -w reboot` and boot to home screen
Change-Id: I3156260b5d37647dbecf98ca90601a089bea5c46
2019-04-23 17:42:40 +08:00
Treehugger Robot
2ddb8df2ef Merge "Adding adb_debug.prop into debug ramdisk" 2019-04-23 02:01:36 +00:00
Tom Cherry
7f160af142 init: handle getpeercon() errors
Though unlikely, it is possible for getpeercon() to fail.  This change
adds code to handle this case gracefully.

Bug: 130209483
Test: boots, properties are set
Change-Id: I3b3fb76b2312a5cbc87c0da2a044be3ddf8aa400
2019-04-22 13:32:24 -07:00
Tom Cherry
2f113ad1e1 init: set up SelinuxAuditCallback() earlier
The setup of SelinuxAuditCallback() was happening after property files
are loaded, and now that these property files can trigger audits, the
audit messages did not contain all of the correct information.  This
change moves the setup of SelinuxAuditCallback() to immediately before
the property area is initialized, to ensure that this can not happen
again.

Bug: 130979265
Test: audits work early
Change-Id: I9eb43269317c74e041626ee7b2bb7fea49250e09
2019-04-22 12:41:39 -07:00
Bowgo Tsai
05f07d89a6 Adding adb_debug.prop into debug ramdisk
The debug ramdisk can only be used if the device is unlocked.
When it's used, init will load adb_debug.prop and the userdebug
sepolicy from the debug ramdisk, to allow adb root on a user build.

Bug: 126493225
Test: 'make' and checks the file is installed
Change-Id: Id6962414197fc8f47f7c07818e8fb16107dc17a3
2019-04-20 06:08:51 +00:00
Treehugger Robot
72d8d2f2c6 Merge "Copying debug ramdisk files to /debug_ramdisk/*" 2019-04-19 23:54:53 +00:00
Tom Cherry
f7545cea34 Vboot1.0: remove code to read verity state in userspace
The code to read verity state in userspace is deprecated in favor of
having the bootloader read and report the state, so this change
removes this now unused code.

Bug: 73456517
Test: boot
Change-Id: Ib626fd61850bce3016179ca92a9831c2ac29c032
2019-04-19 16:53:33 -07:00
Treehugger Robot
9b33cbc0cb Merge "init: small header clean up" 2019-04-19 04:23:24 +00:00
Treehugger Robot
a7c103eb8e Merge "init: set oom_adj early before fork vendor_init" 2019-04-19 02:17:50 +00:00
Bowgo Tsai
30afda71c0 Copying debug ramdisk files to /debug_ramdisk/*
In previous implementation, userdebug sepoilcy and property files are
loaded from the system.img. This CL changes this to:

  - first-stage init copies userdebug files from ramdisk to /debug_ramisk/*
  - second-stage init loads files from /debug_ramdisk/*.

Note: same as before, the above can only be triggered, if the device
is UNLOCKED

With this, we don't have to put userdebug related files into the USER
system.img.

Bug: 126493225
Test: boot device with a ramdisk with /force_debuggable, checks related
      files are loaded
Change-Id: I63f5f846e82ba78427062bf7615c26173878d8f3
2019-04-19 09:56:14 +08:00
Wei Wang
45d8174fe7 init: set oom_adj early before fork vendor_init
right now vendor_init is forked before we set oom_adj for init which
leaves a chance vendor_init could be killed in heavy memory pressure.

this CL set the oom_adj before forking everything to ensure all native
have correct oom_adj settings.

Fixes: 130824864
Test: procrank -o
Change-Id: I8af129076c3efa29f7b781459449f8f2dc853c98
2019-04-18 16:14:08 -07:00
Tom Cherry
030ef18580 init: small header clean up
Remove an unimplemented function from the header and clean up some
slight syntax mistakes.

Test: build
Change-Id: Ia82c6aee24fa0889a7595aabc564bef970a0863b
2019-04-18 14:18:36 -07:00
Tom Cherry
990483d409 init: do not fork before doing (u)mount_all()
A fork() was historically added in case of fs_mgr crashing or leaking
memory, but this should not be the case with fs_mgr, and a fork() only
hides any such problem, instead of allowing us to address it
directly.

Test: boot
Change-Id: If7ee4807757048258a6ea9a79a24cebbacc530cc
2019-04-17 12:55:50 -07:00
Yifan Hong
e438843ead Merge "init: add umount_all builtin." 2019-04-16 22:46:52 +00:00
Treehugger Robot
6aa0d7eaf8 Merge "init: fix loglevel docs." 2019-04-16 07:32:47 +00:00
Yifan Hong
402633d605 init: add umount_all builtin.
umount_all is the cleanup step for mount_all.

In particular, the mount_all builtin creates a verity device,
'postinstall-verity', for the following line:

system /postinstall ... ... slotselect_other,logical,avb_keys=...

cppreopt umounts /postinstall but doesn't destroy the postinstall-verity
device, causing OTA to fail (because it cannot destroy the
system_[other] device). umount_all also destroy the verity device.

Note that mount_all does not map system_[other]; it is mapped by
first stage init. Hence, umount_all doesn't destroy it either. The OTA
client is reponsible for unmapping the device itself.

Bug: 129988285
Test: flash, boot, then check `dmctl list devices`, then OTA

Change-Id: Id3ab65b3860b6ea6cfec310ab13652009c81f415
Merged-In: Id3ab65b3860b6ea6cfec310ab13652009c81f415
2019-04-15 15:11:28 -07:00
Elliott Hughes
8457f52ba9 init: fix loglevel docs.
Bug: http://b/129989984
Test: N/A
Change-Id: Ie7b320fd47dec839ad79d677eb90050cfbcf50c3
2019-04-15 12:17:22 -07:00
Bowgo Tsai
a0f8b05d91 first-stage mount: support using other avb_keys
This change allows specifying additional avb keys to verify a fstab
entry. It can be used together with the original 'avb' flag. When both
'avb' and 'avb_keys' are present, it will try to use avb_keys to verify
this partition and extract the AVB descriptor from the end of it first.
When avb_key fails, it falls back to searching the AVB descriptor in the
built-in /vbmeta (and its chained partitions) with the matched partition
name.

An example of a fstab file:

system  /system  ext4  ro,barrier=1  wait,slotselect,avb=vbmeta,logical,first_stage_mount,avb_keys=/avb/gsi.avbpubkey
vendor  /vendor  ext4  ro,barrier=1  wait,slotselect,avb,logical,first_stage_mount

The overhead of adding an additional 'avb_keys' should not be significant,
as the typical size of a AVB Hashtree descriptor for /system is usually
less than 1000 bytes. e.g., on crosshatch, it's about 600 bytes, which
takes less than 1 millisecond for the following call to return failure.

   auto avb_standalone_handle = AvbHandle::LoadAndVerifyVbmeta(*fstab_entry);

We also checked the time spent on init's first stage on crosshatch, with the
following CL to set ro.boottime.init.first_stage. The testing result
shows no significant difference between them as well.

https://android-review.googlesource.com/c/platform/system/core/+/934536

With an additional avb_keys entry for /system
    [ro.boottime.init.first_stage]: [728]
    [ro.boottime.init.first_stage]: [720]
    [ro.boottime.init.first_stage]: [722]

Without an additional avb_keys entry for /system
    [ro.boottime.init.first_stage]: [730]
    [ro.boottime.init.first_stage]: [728]
    [ro.boottime.init.first_stage]: [725]

Bug: 124491153
Test: boot a device with above fstab settings

Change-Id: I0c81f816efb0dd40c93da2df304f2e215df9d105
2019-04-09 13:38:05 +00:00
Mark Salyzyn
b833d17de2 init: fixes to README.mk
Corrected a few technical, spelling and grammar errors.

Test: none
Bug: 129780532
Change-Id: Ia05f44c782d94a3bb4224fc6929ac325852e0c41
2019-04-08 10:06:49 -07:00
Nick Kralevich
9ca898fff8 Avoid leaking property values into logs on error
The purpose of having fine grain read/write control over the property
space is to help ensure the confidentiality of data stored in
properties. Leaking property values into the dmesg buffer on errors
exposes the value outside of the access control rules specified by
policy.

(arguably this is also true for the property name, not just the value.
However, property names are exposed in other places now, so the
incentive to fix this is lower. It would also take away a valuable
debugging tool.)

Test: compiles
Change-Id: I4a0634b8b5e4fd2edf718eaf7343940df627366d
2019-04-04 10:15:25 -07:00
Yifan Hong
25d42eeaa6 Merge changes from topic "libprocessgroup_rc"
* changes:
  CgroupSetupCgroups -> CgroupSetup
  Add libcgrouprc to ld.config.*.txt.
  libprocessgroup: use libcgrouprc to read cgroup.rc
  libprocessgroup_setup: use libcgrouprc_format
  libprocessgroup: Move CgroupSetupCgroups() to libprocessgroup_setup
  libprocessgroup: Add libcgrouprc
  libprocessgroup: Add libcgrouprc_format
2019-04-03 19:08:51 +00:00
Yifan Hong
9d7b89abea CgroupSetupCgroups -> CgroupSetup
Test: builds
Bug: 123664216
Change-Id: I47c46ca9ba5c1fbf3f9f7a1b185dc48b058b1e32
Merged-In: I47c46ca9ba5c1fbf3f9f7a1b185dc48b058b1e32
2019-04-02 22:31:57 -07:00
Yifan Hong
d8ce1fb1d1 libprocessgroup_setup: use libcgrouprc_format
Use CgroupController definition from libcgrouprc_format, not
libprocessgroup, because the wire format will be removed
from libprocessgroup later.

Bug: 123664216
Test: builds
Change-Id: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
Merged-In: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
2019-04-02 22:31:57 -07:00
Yifan Hong
6f9ce2e548 libprocessgroup: Move CgroupSetupCgroups() to libprocessgroup_setup
Only init uses SetupCgroups. This functionality is
moved from libprocessgroup to its own library, and only
init links to it.

Also, merge CgroupSetupCgroups() with CgroupMap::SetupCgroups()
because the former is just an alias of the latter, and
CgroupMap does not belong to libcgrouprc_setup.

Test: boots
Bug: 123664216
Change-Id: I941dc0c415e2b22ae663d43e30dc7a464687325e
Merged-In: I941dc0c415e2b22ae663d43e30dc7a464687325e
2019-04-02 22:31:57 -07:00
Mark Salyzyn
e419a79329 ueventd: populate /dev/block/mapper link
Since DM_NAME= is not sent (delete bug) or interpreted with ueventd
message, instead probe /sys/devices/virtual/block/dm-X/dm/name when
instantiating.  Cache the value for later delete.

By creating the /dev/block/mapper/<name> nodes, this will give
selabel_lookup_best_match an alias to hang its hat on so that the
associated /dev/block/dm-X nodes will be suitably labelled and
differentiated.

NB: For Android, the deletion of the nodes will only happen in the
    context of fastbootd, update_engine and gsid; otherwise the links
    and properties created can be considered set-once and persistent.

Test: manual inspect /dev/block/mapper/ links
Bug: 124072565
Change-Id: I6d9e467970dfdad7b67754ad61084964251eb05f
2019-04-02 19:28:47 +00:00
Treehugger Robot
0a887aa14c Merge "Disallow operator!() on unique_fd" 2019-03-29 03:52:46 +00:00
Treehugger Robot
a896e2aee5 Merge "init: mount_handler: system-as-root (legacy)" 2019-03-28 18:25:27 +00:00
Suren Baghdasaryan
81cfeb54fc Merge "libprocessgroup: restrict SetupCgroups to one-time usage and only by init" 2019-03-28 17:13:09 +00:00
David Anderson
5aa37dc3dc Merge "init: Support booting off GSIs installed to non-userdata block devices." 2019-03-28 09:46:44 +00:00
Bernie Innocenti
7cb72c96b4 Disallow operator!() on unique_fd
This catches a common mistake where client code checks for errors using
the common idiom that works for std::iostream and other file-like
classes:

  unique_fd fd = open(...);
  if (!fd) {
  }

Test: atest libbase_test
Test: m droid
Change-Id: I9629a7795537ecb3b57be9c741c06f80967e4cc2
2019-03-28 15:56:07 +09:00
Suren Baghdasaryan
5b53573671 libprocessgroup: restrict SetupCgroups to one-time usage and only by init
SetupCgroups is called by init process during early-init stage and is not
supposed to be called again by anyone else. Ensure that the caller is the
init process, make sure cgroup.rc file is written only one time, keep the
file descriptor to cgroup.rc file open by the init process to ensure all
its further mappings stay valid even if the file is deleted.

Bug: 124774415
Test: build, run, verify no errors or warning in the logcat

Change-Id: Ib8822cf0112db7744e28d442182d54dcf06f46f2
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-03-28 01:25:22 +00:00
Mark Salyzyn
793f4b503e init: mount_handler: system-as-root (legacy)
On marlin, dev.mnt.blk.root is empty.  Issue is shared for all
devices that are system-as-root.

/dev/root /proc/mounts entry exists before the associated block device
is instantiated by ueventd.  As a result when the device shows up the
root mount is updated late when the next mount inotify trigger occurs,
delay which we will accept.  But the property entries are added before
removed in the loop which causes the ultimate property entry for root
to report empty. Add /dev/block/dm-0, remove /dev/root, for property
dev.mnt.blk.root.

Fix is to change to Remove before Adding.  Remove /dev/root, then add
/dev/block/dm-0.

On system-as-root as well, can not just use fstab.  Determine if a
dm-verity reference is wrapped around system and use that instead.

Add some additional filtration of loop and APEX mounts to reduce
property noise.

Fix issue with creating the std:string line holder from getline(3).

Test: manual on marlin
Bug: 124072565
Change-Id: Ief2e1a6f559cbcbc87273fc2db35c675bb972f43
2019-03-27 20:50:39 +00:00
Yifan Hong
f959fffc1c Merge changes from topic "lpdumpd"
* changes:
  libbase: realpath is wrapped with TEMP_FAILURE_RETRY
  liblp: Replace open with GetControlFileOrOpen
  init: expand prop in 'file'
  libcutils: android_get_control_file uses realpath.
2019-03-26 20:35:36 +00:00
Yifan Hong
567f1874fd init: expand prop in 'file'
Allow having properties in 'file' option of a service.

Test: boots (sanity)
Test: lpdumpd
Bug: 126233777
Change-Id: I55158b81e3829b393a9725fd8f09200690d0230f
2019-03-21 16:00:00 -07:00
Vic Yang
87215c2530 Fix parse_apex_configs doc in README.md
Test: None
Change-Id: I0871e640cfcab706a5396e3824a1f75239c29840
2019-03-21 11:59:29 -07:00
David Anderson
ee725f610f init: Support booting off GSIs installed to non-userdata block devices.
Bug: 126230649
Bug: 127953521
Test: GSI boots when installed to sdcard on hikey960
      GSI boots when installed to /data/gsi
Change-Id: Id59926ebe363939c8c5745bb1bf5bd13722dae7e
2019-03-20 18:22:00 -07:00
Jeff Vander Stoep
402e4a6615 init: make sepolicy dependency optional
Test: make system/core/init
Change-Id: Ie2e7ba57fe885baf017ef12334aea7f2f9f8f0c1
2019-03-19 17:01:09 -07:00
Jeffrey Vander Stoep
e21d07fbab Merge "selinux: use the policy version defined in sepolicy" 2019-03-19 21:44:59 +00:00
Mark Salyzyn
cdb825e461 Check if we need to Poll for devices after RegenerateUevents
If the required_devices_partition_names is cleared, no need to Poll.

Test: manual check boot time, and adb-remount-test.sh
Bug: 128834849
Change-Id: I044ee2752a7f32b084ff6e88b4b586accdfb78f0
2019-03-18 10:29:48 -07:00
Mark Salyzyn
a73ed22cb7 init: add MountHandler property handler
Set properties dev.mnt.blk.<mount_point>=<device_block_class> for mount
and umount operations by setting up an Epoll handler to catch
EPOLLERR or EPOLLPRI signals when /proc/mounts is changed.  Only
update properties associated with block devices.  For the mount
point of /, use the designation of /root instead.

Can use the properties in init rc expansion like:

on property dev.mnt.blk.root=*
    write /sys/block/${dev.mnt.blk.root}/queue/read_ahead_kb ${boot_read_ahead_kb:-2048}

on property dev.mnt.blk.data=*
    write /sys/block/${dev.mnt.blk.data}/queue/read_ahead_kb ${boot_read_ahead_kb:-2048}

on late-fs
    setprop boot_read_ahead_kb 128
    write /sys/block/${dev.mnt.blk.root}/queue/read_ahead_kb ${boot_read_ahead_kb}
    write /sys/block/${dev.mnt.blk.data}/queue/read_ahead_kb ${boot_read_ahead_kb}

Test: boot and inspect getprop results.
Bug: 124072565
Change-Id: I1b8aff44f922ba372cd926de2919c215c40ee874
2019-03-15 11:54:38 -07:00
Treehugger Robot
4cd0914048 Merge changes from topic "apex_earlymount_no_bionic_bindmount"
* changes:
  /bionic path is gone
  Revert "Handle adb sync with Bionic under /bionic"
  Don't bind-mount bionic files
2019-03-15 09:02:18 +00:00
Bowgo Tsai
1dacd42ae1 Allow overriding ro.debuggable to 1 on USER builds
When init found "/force_debuggable" in the first-stage ramdisk, it will
do the following if the device is unlocked:
  1. load /system/etc/adb_debug.prop (with ro.debuggable=1)
  2 .load userdebug_plat_sepolicy.cil instead of original plat_sepolicy.cil from
    /system/etc/selinux/.

This make it possible to run VTS on a USER build GSI, by using a special
ramdisk containing "/force_debuggable".

Bug: 126493225
Test: unlock a USER build device, check 'adb root' can work
Change-Id: I9b4317bac1ce92f2c0baa67c83d4b12deba62c92
2019-03-15 06:12:00 +08:00
Mark Salyzyn
37bbf800fa init: epoll: add events argument to RegisterHandler
Allow caller to specify events other than EPOLLIN default.

Test: boot
Bug: 124072565
Change-Id: Id4e582a6abc74c5fdb26fea7dcbd3ba2150dadd6
2019-03-13 16:51:31 -07:00
Jiyong Park
7b4801a921 Don't bind-mount bionic files
Bind-mounting of the bionic files on /bionic/* paths no longer required
as there are direct symlinks from bionic files in /system partition to
the corresponding bionic files in the runtime APEX. e.g.,

/system/lib/libc.so -> /apex/com.android.runtime/lib/bionic/libc.so

Bug: 125549215
Test: m; devices boots
Change-Id: I4a43101c3e3e2e14a81001d6d65a8a4b727df385
2019-03-14 07:35:54 +09:00
Elliott Hughes
076305e4fb init: use PLOG rather than strerror.
Test: builds
Change-Id: Ifdba8e7fa4cd5c852946bb0f398382f2d64674cd
2019-03-08 12:34:53 -08:00
Jiyong Park
e5dc674a95 Make /apex on ramdisk
Bug: 127576519
Bug: 127653919
Test: build hikey, check ramdisk has /apex directory
Change-Id: I4e844caa032c0717bd36d323675852ce3681fb01
2019-03-07 11:17:44 +09:00
Jiyong Park
8502ed308d Access apex sysprops via the generated API
Bug: 125549215
Test: m
Change-Id: Ie9b0aa5eec5931da3512d77613b034e5bd760f3e
2019-03-05 16:22:55 +09:00
Jiyong Park
dcbaf9f41b Activate system APEXes early
Summary: Boot sequence around apexd is changed to make it possible for
pre-apexd processes to use libraries from APEXes. They no longer need to
wait for the apexd to finish activating APEXes, which again can be
done only after /data/ is mounted. This improves overall boot
performance.

Detail: This change fixes the problem that processes that are started
before apexd (so called pre-apexd processes) can't access libraries
that are provided only by the APEXes but are not found in the system
partition (e.g. libdexfile_external.so, etc.). Main idea is to activate
system APEXes (/system/apex/*.apex) before /data is mounted and then
activate the updated APEXes (/data/apex/*.apex) after the /data mount.

Detailed boot sequence is as follows.

1) init prepares the bootstrap and default mount namespaces. A tmpfs is
mounted on /apex and the propagation type of the mountpoint is set to
private.

2) before any other process is started, apexd is started in bootstrap
mode. When executed in the mode, apexd only activates APEXes under
/system/apex. Note that APEXes activated in this phase are mounted in
the bootstrap mount namespace only.

3) other pre-apexd processes are started. They are in the bootstrap
mount namespace and thus are provided with the libraries from the system
APEXes.

4) /data is mounted. init switches into the default mount namespace and
starts apexd as a daemon as usual.

5) apexd scans both /data/apex and /system/apex, and activate latest
APEXes from the directories. Note that APEXes activated in this phase
are mounted in the default namespaces only and thus are not visible to
the pre-apexd processes.

Bug: 125549215
Test: m; device boots
Change-Id: I21c60d0ebe188fa4f24d6e6861f85ca204843069
2019-03-05 09:47:49 +09:00
Jiyong Park
4ba548d845 mount /apex during first_stage init
/apex is not mounted via init.rc but directly by the first_stage init
before the mount namespaces are configured.

This allows us to change the propagation type for /apex mount point to
private to isolate APEX activatesions across post- and pre-apexd
processes.

Bug: 125549215
Test: m; device boots to the UI

Change-Id: I10e056cd30d64cb702b6c237acd8dab326162884
2019-03-04 16:22:41 +09:00
Bowgo Tsai
f3e28e1682 libfs_avb: support key rotation for standalone partitions
The FstabEntry.avb_key is renamed to FstabEntry.avb_keys, to
allow specifying multiple avb keys, separated by ':'
(because ',' is already used by fstab parsing).

Bug: 124013032
Test: boot live GSI with multiple allowed AVB keys
Change-Id: Iacd3472a1d5a659dfecf09ea6074d622658f4d0b
2019-02-27 04:13:21 +00:00
Jeff Vander Stoep
724eda5503 selinux: use the policy version defined in sepolicy
In the current setup, init uses the highest policy version supported
by the kernel, instead of the policy version defined in policy. This
results in inconsistency between precompiled (version 30) and
on-device compiled policy (version 30 or 31). Make these consistent.

Bug: 124499219
Test: build and boot a device. Try both precompiled and on-device
compiled policy.

Change-Id: I0ce181916f43db17244c4d80f5cf5a91bbb58d3a
2019-02-25 10:47:29 -08:00
Treehugger Robot
084d3b9124 Merge "libfs_avb: support rollback protection for Live GSI" 2019-02-22 16:28:23 +00:00
David Anderson
1cdd96cb10 Merge "init: Set a property indicating that we're booting into a GSI." 2019-02-21 14:40:48 +00:00
Bowgo Tsai
918668a2cd libfs_avb: support rollback protection for Live GSI
This commit extracts the security patch level (SPL), e.g.,
com.android.build.system.security_patch = 2019-04-05 from AVB property
descriptors when attempting to mount a standalone image (e.g., live
GSI). Then compares the SPL between the old system.img and the new live
system.img for rollback protection.

Bug: 122705329
Test: boot an old Live GSI, checks rollback is detected
Change-Id: I7aae58c0b2062a3ff57ed932ad58e7b604453fed
2019-02-21 10:32:18 +08:00
Tom Cherry
86f38d56b8 Merge "init: Ignore "ro." restrictions when reading prop files" 2019-02-20 16:59:39 +00:00
Tom Cherry
be0489281f init: Ignore "ro." restrictions when reading prop files
"ro." properties do not make sense for prop files, especially with the
way that the system/product and vendor/odm partitions are meant to
override each other.  To fix this, we ignore the fact that "ro."
properties are "write once" when first loading in property files.

We then adjust the order of property file loading, such that we read
partitions from least to most specific, reading in order: system,
vendor, odm, product, product_services.

Bug: 122864654
Test: ro. properties can override when reading build props with
      appropriate permissions
Test: ro. properties do not override when lacking permissions to
      be set by a given partition
Change-Id: Ib9a5f77e95d9df647cdde7a5c937bb3425c066fa
2019-02-19 13:02:58 -08:00
Jinguang Dong
f42e08d878 load selinux property_contexts in /odm and /product
Commit I27dd391fc06a3c78e88a65c7931c84de1699f157  make property_service no longer
load selinux property_contexts by function selinux_android_prop_context_handle,
So we should config /odm and /product property_contexts loading path in
property_service.cpp but not in libselinux.

Test: property_service can load property_contexts in /odm and /product
Change-Id: Ifa94b87180c4867ecbe8dea347ad02bb37958043
2019-02-15 17:56:45 +08:00
David Anderson
372278c86d init: Set a property indicating that we're booting into a GSI.
Bug: 123777418
Test: gsid.image_running is set after booting into GSI
Change-Id: I8ec79fa58b41b04676de0c8909fcd520c28c05ab
2019-02-14 13:23:28 -08:00
Bowgo Tsai
fffe43974d Skip enabling dm-verity for live GSI when needed
Currently the dm-verity for live GSI is always enabled, even if the
disable bit in the top-level /vbmeta is set. We should skip setting up
dm-verity on live system.img when adb disable-verity is ever set.

Bug: 124291583
Test: adb disable-verity, then boot live GSI
Test: fastboot flash --disable-verification vbmeta vbmeta.img,
      then boot live GSI

Change-Id: Id52d20d0b2e56dfa7de8f866dcc989b82a96c879
2019-02-13 22:12:09 +08:00
Tom Cherry
5272f9b017 Merge "Refactor fs_mgr_update_verity_state()" 2019-02-12 17:22:09 +00:00
Steven Laver
944e6f1d17 Merge "Allow properties to be derived from partition-specific properties during init" 2019-02-12 16:44:57 +00:00
Tom Cherry
cf80b6d6e5 Refactor fs_mgr_update_verity_state()
fs_mgr_update_verity_state() has two callers with generally different
intentions.  One caller loops through all entries in the default fstab
to set partition.<mount_point>.verified properties.  The other caller
is only interested in whether or a specific mount point has verity
enabled.

Given this, we refactor fs_mgr_update_verity_state() to
fs_mgr_get_verity_mount_point() which takes a single FstabEntry and
returns the mount point used for the dm-verity device or an empty
option if verity is not enabled on that mount point.

Test: adb-remount-test.sh test on blueline
Change-Id: Ic7dd8390509e95b2931b21e544c919a544138864
2019-02-11 12:50:22 -08:00
Tom Cherry
6576e13995 Remove logic to fake /system in overlayfs
It is better to guarantee that a /system or / entry will be present in
first stage mount than it is to maintain the code to fake an entry if
its not present in the input fstab.

Test: adb-remount-test.sh on blueline
Change-Id: I8aa3e704903b8abf06b1c63be071913a9de58eb3
2019-02-08 16:25:24 -08:00
Steven Laver
57a740eca2 Allow properties to be derived from partition-specific properties during init
If not present, ro.product.[brand|device|manufacturer|model|name] and
ro.build.fingerprint will be resolved during init from
partition-specific properties.

Test: booted system image, verified properties
Test: booted recovery image, verified properties
Bug: 120123525
Change-Id: I7fe2793a7d9eb65645d92ceb408f1f050acf9a81
2019-02-07 16:15:55 -08:00
Tom Cherry
500b6c0e86 Merge "init: allow services to have no capabilities set" 2019-02-06 23:48:36 +00:00
Tom Cherry
1cd082d421 init: allow services to have no capabilities set
In particular, this allows services running as the root user to have
capabilities removed instead of always having full capabilities.

Test: boot device with a root service with an empty capabilities
      option in init showing no capabilities in /proc/<pid>/status
Change-Id: I569a5573ed4bc5fab0eb37ce9224ab708e980451
2019-02-06 11:25:18 -08:00
Treehugger Robot
54f7e57bac Merge "init: print property/value for wait_for_property" 2019-02-06 07:28:00 +00:00
Wei Wang
c9352bb383 init: print property/value for wait_for_property
Bug: 123772265
Bug: 123788098
Test: Build
Change-Id: Ice130d7efab1f227a2f9021136621ad08f84fd23
2019-02-06 01:03:53 +00:00
Treehugger Robot
54ef09c88e Merge "Reland: "Identify post-apexd crashing processes"" 2019-02-05 03:16:30 +00:00
Zimuzo Ezeozue
23aa17ba42 Reland: "Identify post-apexd crashing processes"
This reverts commit 60b89aee4c.

Reason for revert: Blocking change merged, Icdfbdcc1efca540ac854d4df79e07ee61fca559f

Change-Id: Iec7f0b28ca3326d1dc1d86304751eee5e941235e
2019-02-04 21:41:12 +00:00
Suren Baghdasaryan
e01ae8deca init: Replace cgroup hardcoded path with detected one
Remove hardcoded cpuset path usage and replace it with a request to
get the path using new API.

Exempt-From-Owner-Approval: already approved in internal master

Bug: 111307099
Test: builds, boots

Change-Id: I211d093c24a682e2d1992c08e4c1d980379711a4
Merged-In: I211d093c24a682e2d1992c08e4c1d980379711a4
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-03 16:49:08 +00:00
Suren Baghdasaryan
82b72a5667 libprocessgroup: Add support for task profiles
Abstract usage of cgroups into task profiles that allows for changes
in cgroup hierarchy and version without affecting framework codebase.
Rework current processgroup and sched_policy API function implementations
to use task profiles instead of hardcoded paths and attributes.
Mount cgroups using information from cgroups.json rather than from init.rc

Exempt-From-Owner-Approval: already approved in internal master

Bug: 111307099
Test: builds, boots

Change-Id: If5532d6dc570add825cebd5b5148e00c7d688e32
Merged-In: If5532d6dc570add825cebd5b5148e00c7d688e32
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-03 16:48:35 +00:00
Tom Cherry
54ea49ba05 Merge "Add android::fs_mgr namespace for new Fstab code" 2019-01-31 19:35:54 +00:00
Treehugger Robot
a15f385821 Merge changes from topic "move_bionic_to_apex3"
* changes:
  Handle adb sync with Bionic under /bionic
  Proper mount namespace configuration for bionic
2019-01-31 04:46:49 +00:00
Tom Cherry
a3530e6366 Add android::fs_mgr namespace for new Fstab code
Should have been done a while ago, but better late than never.

Test: treehugger
Change-Id: I0ea6e8d459cd3f3b3ce2d00a7a6a9786d52c52dd
2019-01-30 20:20:05 -08:00
Bowgo Tsai
ee6114fb1d Enable AVB for dynamic GSI (f.k.a. Live Image)
Bug: 117960205
Test: Use the dynamic Android to start GSI, checks verity is enabled.
Change-Id: I93b321808ba278b162fec5e231bff7229cac3937
2019-01-31 07:06:14 +08:00
Jiyong Park
6866041ff0 Proper mount namespace configuration for bionic
This CL fixes the design problem of the previous mechanism for providing
the bootstrap bionic and the runtime bionic to the same path.

Previously, bootstrap bionic was self-bind-mounted; i.e.
/system/bin/libc.so is bind-mounted to itself. And the runtime bionic
was bind-mounted on top of the bootstrap bionic. This has not only caused
problems like `adb sync` not working(b/122737045), but also is quite
difficult to understand due to the double-and-self mounting.

This is the new design:

Most importantly, these four are all distinct:
1) bootstrap bionic (/system/lib/bootstrap/libc.so)
2) runtime bionic (/apex/com.android.runtime/lib/bionic/libc.so)
3) mount point for 1) and 2) (/bionic/lib/libc.so)
4) symlink for 3) (/system/lib/libc.so -> /bionic/lib/libc.so)

Inside the mount namespace of the pre-apexd processes, 1) is
bind-mounted to 3). Likewise, inside the mount namespace of the
post-apexd processes, 2) is bind-mounted to 3). In other words, there is
no self-mount, and no double-mount.

Another change is that mount points are under /bionic and the legacy
paths become symlinks to the mount points. This is to make sure that
there is no bind mounts under /system, which is breaking some apps.

Finally, code for creating mount namespaces, mounting bionic, etc are
refactored to mount_namespace.cpp

Bug: 120266448
Bug: 123275379
Test: m, device boots, adb sync/push/pull works,
especially with following paths:
/bionic/lib64/libc.so
/bionic/bin/linker64
/system/lib64/bootstrap/libc.so
/system/bin/bootstrap/linker64
Change-Id: Icdfbdcc1efca540ac854d4df79e07ee61fca559f
2019-01-30 19:18:22 +09:00
Tom Cherry
d6c2feb9fa init: delete code that sets ro.recovery_id
It looks like this code is dead currently.  From history, this was
meant to be used as a way to check that the recovery image is what was
expected during runtime, but that effort never completed, and we have
full verification of the recovery image when booting into recovery
anyway.

The code is functionally dead as is too, since /recovery doesn't
actually exist in any fstab, since recovery is either mounted as a
ramdisk during recovery or not mounted during normal boot.

Test: boot
Change-Id: I48cd324ef0d5a163db2df2648f6042174b83f10e
2019-01-29 21:17:53 +00:00
Tri Vo
9ffdf5945d Merge "selinux: account for /product hash" 2019-01-25 00:04:34 +00:00
LongPing Wei
9f2e84e507 Do SetUpDmVerity only once for the same mount point
SetUpDmVerity won't return true twice for the same partition and it will
leads to failure when verify-boot is enabled on multi-fstab-lines.

Test: make
Change-Id: I5ce35e9c6b2d47fd0f599e36046e1ad2b0a35ffa
2019-01-23 23:30:13 +00:00
Tri Vo
c8137f93f7 selinux: account for /product hash
We need to be able to tell if /product was updated independently
/system.  Otherwise, the device might accidentally load the
precompiled_policy after a /product sepolicy update.

Bug: 119305624
Test: boot aosp_taimen, precompiled policy is loaded
Test: If either of these hashes
/system/etc/selinux/plat_sepolicy_and_mapping.sha256
/product/etc/selinux/product_sepolicy_and_mapping.sha256
are removed, then init falls back to compiling sepolicy at boot time.
Change-Id: I3d658335cf66bcb7123109de701309039b1ae5ba
2019-01-23 09:23:22 -08:00
Tri Vo
7ca2c565b0 Merge "init: load /product selinux mapping file" 2019-01-22 18:49:21 +00:00
Tom Cherry
5d7439ff5b Merge "Revert "do not start shutdown animation from init"" 2019-01-22 17:16:32 +00:00
Treehugger Robot
60fc999722 Merge "init: Remove the obsolete restorecon for /sbin files." 2019-01-18 19:35:26 +00:00
Jiyong Park
60b89aee4c Revert "Identify post-apexd crashing processes"
This reverts commit c661b660fe.
Reason: Breaks some 3p apps.

Bug: 122920047
Test: run the app, login.
Change-Id: Ie56ea5516887b885579764929e82e4fe684a7dcf
2019-01-18 12:30:54 +09:00
Jiyong Park
8b73dfc0a4 Revert "Bionic libs and the dynamic linker are bind mounted"
This reverts commit 2599088ff6.
Reason: Breaks some 3p apps.

Bug: 122920047
Test: run the app, login.
Change-Id: Idea332b1f91e9d2ac6ebd3879da7820c8ba2284f
2019-01-18 12:30:51 +09:00
Jiyong Park
80aec3f0f0 Revert "Don't create separate mount namespaces for pre-apexd processes"
This reverts commit 5ab1300481.

Reason: Breaks some 3p apps.

Bug: 122920047
Test: run the app, login.
Change-Id: Iec3347d7f35fbb6f32fd1192135a0cf87dc123a7
2019-01-18 12:30:39 +09:00
Treehugger Robot
9c334367fd Merge "Re-enable asan on /init." 2019-01-18 01:56:43 +00:00
Tao Bao
a68d8c9ea3 init: Remove the obsolete restorecon for /sbin files.
These files, including their building rules, have been removed in favor
of their dynamically linked versions; we no longer need to explicitly
restorecon the actual files either, for the same reason as in commit
05f96a2561. When doing normal boot, these
files come from system.img, which have been labeled at build time; when
booting recovery, they don't need dedicated labels to be functional.

Test: Build and boot crosshatch.
Test: Factory reset under recovery on taimen (mke2fs).
Test: Factory reset under recovery on crosshatch (make_f2fs).
Change-Id: Icbcd24aad8be1e7f4ba7d379acd5855d256ae106
2019-01-17 14:52:29 -08:00
Treehugger Robot
1945fbef10 Merge "init: dump less debug logs when unmount timeout" 2019-01-17 22:06:50 +00:00
Evgenii Stepanov
dd02fa162d Re-enable asan on /init.
Fixed in the new toolchain.

Bug: 120561310
Test: asan build boots
Change-Id: I722c98467ed0ac5e18441cb659f26cd8a803eee0
2019-01-17 14:05:22 -08:00
Jaegeuk Kim
2fdbdfddac Merge "zram: support zram_writeback" 2019-01-17 21:03:15 +00:00
Jonglin Lee
28a2c9213b init: dump less debug logs when unmount timeout
Dump only uninterruptible tasks instead of all tasks when
unmount timeout. Also dump current CPU stack traces.

Bug: 122858312
Test: Reboot with and without timeout
Change-Id: I1412ace022b6d78e25fbe1337d1082d4be9c19c0
2019-01-17 19:14:46 +00:00
David Anderson
b43440ba79 Merge "init: Add support for GSI installations in first-stage mount." 2019-01-17 18:42:58 +00:00
David Anderson
0e330f12bc init: Add support for GSI installations in first-stage mount.
Bug: 121209697
Test: gsi boots
Change-Id: I69db0f8e999da366e46728b1008602f543cd79f6
2019-01-16 17:45:07 -08:00
Tri Vo
503f1852ba init: load /product selinux mapping file
/system/etc/selinux/mapping/V.v.cil is being split into /system and
/product parts.

Change init to account for /product/etc/selinux/mapping/V.v.cil mapping
file when merging SELinux policies.

Bug: 119305624
Test: boot taimen
Test: "cnd" type is declared in /vendor; "dataservice_app" type is
declared in /product. This permission is preserved
"allow cnd dataservice_app:binder { transfer call };"
Change-Id: I65995a75041044ae71c148d655a70c5efd3b84cc
2019-01-16 12:54:32 -08:00
Randall Huang
df2faa4238 reboot: only run fsck when detecting filesystem inconsistency
Running fsck when filesystem is in clean state is unnecessary
and causes long shutdown duration.

Bug: 120575926
Test: shutdown
Change-Id: I0562bdad4ac2fb2dd3c9617f96ca3d6279876bd8
Signed-off-by: Randall Huang <huangrandall@google.com>
2019-01-16 16:19:24 +08:00
Jaegeuk Kim
2aedc82f02 zram: support zram_writeback
This patch supports zram_writeback enabled by fstab in two ways.

e.g.,
/dev/block/zram0 none swap defaults
    zramsize=1073741824,max_comp_streams=8,zram_loopback_path=/data/unencrypted/zram_swap

==> loopback size is 512MB by default.

Or,
/dev/block/zram0 none swap defaults
    zramsize=1073741824,max_comp_streams=8,zram_loopback_path=/data/unencrypted/zram_swap,zram_loopback_size=1G

==> loopback size can be specified by "zram_loopback_size=%s" with "GB" or "MB".

Or,
/dev/block/zram0 none swap defaults
    zramsize=1073741824,max_comp_streams=8,zram_backing_dev_path=/dev/block/partition

Bug: 74582279
Bug: 122659265
Change-Id: I66a2e6953b4743a34cf732dd0f5b5256c901f247
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2019-01-15 16:07:59 +00:00
Jiyong Park
3b316ee201 Load build sysprops early
*/build.prop files are now loaded much earlier than before; from 'on
post-fs' to the time when the property service is started which is
before init starts the action loop.

This ensures that all processes that are launched by init have a
consistent view of system properties. Previously, the processes that
started before 'on post-fs' were initially with the small number of
sysprops loaded from */default.prop and then suddenly get additional
sysprops from */build.prop while they are executing.

Bug: 122714998
Test: device boots

Change-Id: Ic07528421dfbe8d4f43673cea41175d33cfbf298
2019-01-15 22:40:49 +09:00
Zimuzo Ezeozue
91fa140312 Merge "Identify post-apexd crashing processes" 2019-01-15 10:05:41 +00:00
Steven Moreland
ebae0d3ad9 Merge "Init: error on oneway calls." 2019-01-14 20:50:12 +00:00
Zimuzo
c661b660fe Identify post-apexd crashing processes
I7d47ea1223f7792a834981c729694242ab3f28c9 tried to identify processes that crash
after apexd is ready by introducing an 'updatable' class. However, after
I7ca67755dc0656c0f0c834ba94bf23ba9b1aca68 we now have a pre_apexd_ field we can
reuse instead of introducing a new class type.

Bug: 120598832
Test: Killing a !pre_apexd_ process 4 times in 4mins sets the
ro.init.updatable.crashing prop while killing a pre_apexd_ process reboots
into the bootloader

Change-Id: Icb9f405b9b54d11546bbf6d3bc28212936a78b0e
2019-01-14 16:22:10 +00:00
Steven Moreland
dc1f24777a Init: error on oneway calls.
Before, this process had no threadpool, so it could make blocking
calls, but if it did, they would block forever. Now when this
happens, an error is logged so that we can easily see this happen.

Bug: 36424585
Test: boot
Change-Id: I7d2fa12b6d5a243bdde13ce4d974a444133749f7
2019-01-11 14:41:34 -08:00
Jiyong Park
5ab1300481 Don't create separate mount namespaces for pre-apexd processes
It is causing problem to the sdcardfs. Specifically, re-mounting events
for /mnt/runtime/{runtime|write} done by the vold process (which is a
pre-apexd process) are not being propagated to other mount namespaces.
As a result, SDCard access isn't working.

The propagation problem is a bug in sdcardfs which is fixed by [1].
However, we can't make all Android devices to have the patch at the same
time. Therefore, by default the separate mount namespace is not created
and will be created only for the devices where the kernel patches are in and
ro.apex.bionic_updatable sysprop is set to true.

[1]
d73d07673edbdbe78e1a7d00e7827ba9bfd86a59 ("ANDROID: mnt: Fix next_descendent")
b5858221c1c4f4bdc9ef67eb75ecf22580368820 ("ANDROID: mnt: remount should propagate to slaves of slaves")

Bug: 122559956
Test: m
Test: device boots
Test: sdcard works (e.g. camera can take pictures)
Test: atest android.appsecurity.cts.ExternalStorageHostTest
Change-Id: I7a309bab46356ee5782f34c5963d1760963c0b14
2019-01-11 15:17:04 +09:00
Jiyong Park
2599088ff6 Bionic libs and the dynamic linker are bind mounted
This change makes the bionic libs and the dynamic linker from the
runtime APEX (com.android.runtime) available to all processes started
after apexd finishes activating APEXes.

Specifically, the device has two sets of bionic libs and the dynamic
linker: one in the system partition for pre-apexd processes and another
in the runtime APEX for post-apexd processes. The former is referred as
the 'bootstrap' bionic and are located at
/system/lib/{libc|libdl|libm}.so and /system/bin/linker. The latter is
referred as the 'runtime' bionic and are located at
/apex/com.android.runtime/lib/bionic/{libc|libdl|libm}.so and
/apex/com.android.runtime/bin/linker.

Although the two sets are located in different directories, at runtime,
they are accessed via the same path: /system/lib/* and
/system/bin/linker ... for both pre/post-apexd processes. This is done
by bind-mounting the bootstrap or the runtime bionic to the same path.
Keeping the same path is necessary because there are many modules and
apps that explicitly or implicitly depend on the fact that bionic libs
are located in /system/lib and are loaded into the default linker
namespace (which has /system/lib in its search paths).

Before the apexd is started, init executes a built-in action
'prepare_bootstrap_bionic' that bind-mounts the bootstrap bionic to the
mount points. Processes started during this time are provided with the
bootstrap bionic. Then after the apexd is finished, init executes
another built-in action 'setup_runtime_bionic' which again mounts the
runtime bionic to the same mount points, thus hiding the previous mounts
that target the bootstrap bionic. The mounting of the runtime bionic
(which is only for post-apexd processes) is hidden from pre-apexd
processes by changing propagation type of the mount points to 'private'
and execute the pre-apexd processes with a new mount namespace using
unshare(2). If a pre-apexd process crashes and re-launched after the
apexd is on, the process still gets the bootstrap bionic by unmounting
the runtime bionic which effectively un-hides the previous bind-mounts
targeting the bootstrap bionic.

Bug: 120266448
Test: device boots
Test: cat /proc/`pidof zygote`/mountinfo shows that
/system/lib/{libc|libdl|libm}.so and /system/bin/linker are from the
runtime APEX
Test: cat /proc/'pidof vold`/mountinfo shows that the same mount points
are from system partition.

Change-Id: I7ca67755dc0656c0f0c834ba94bf23ba9b1aca68
2019-01-11 15:17:04 +09:00
Treehugger Robot
89e2aa94b7 Merge "Add conditional class starting" 2019-01-11 00:58:18 +00:00
Tom Cherry
82b8e518e3 Merge "Support mounting same mount points with different fstab config" 2019-01-10 23:36:16 +00:00
Tom Cherry
2f171cc69e Merge "init: remove the restriction of arguments" 2019-01-10 18:47:53 +00:00
Tri Vo
b5b7d0a777 Merge "init: don't restorecon root sepolicy files" 2019-01-10 17:38:15 +00:00
LongPing Wei
01cf85bd8e Support mounting same mount points with different fstab config
This commits allows multiple lines in a fstab have the same mount
point for first-stage mount, where the first successful mount will be
used.

This allows us to specify a common/shared fstab, with different
settings (e.g., ext4, squashfs) per line, to mount different types
of images on the same mount point. e.g., allows the device to mount
GSI (ext4) while support mounting the original squashfs system.img.

Sample fstab:
fstab in dt:
android {
    fstab {
        odm_ext4 {
            dev = "/dev/block/by-name/odm";
            mnt_point = "/odm";
            type = ext4;
            mnt_flags = "ro";
            fs_mgr_flags = "slotselect";
        };
        odm_f2fs {
            dev = "/dev/block/by-name/odm";
            mnt_point = "/odm";
            type = f2fs;
            mnt_flags = "ro";
            fs_mgr_flags = "slotselect";
        };
    };
}

fstab in file:
/dev/block/by-name/odm /odm ext4 ro slotselect
/dev/block/by-name/odm /odm f2fs ro slotselect

Test: make & boot & check /proc/mounts
Change-Id: I64892e3007b0cfd7d06dad1cfc664c45305197ee
2019-01-10 22:58:18 +08:00
Haoyu Tang
f32bc7cd29 init: remove the restriction of arguments
X86 Kernel could pass CPU capablity to init as argument. This will cause init
can't start first-stage because unknown argument. Need remove this restriction
of arguments to start init successfully.

Fixes: 122435289
Test: Android init can start successfully

Change-Id: I1d432e25553589dd7f618e42ad238b9372dbe34f
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Signed-off-by: Xihua Chen <xihua.chen@intel.com>
2019-01-10 01:02:29 +00:00
Tri Vo
05f96a2561 init: don't restorecon root sepolicy files
Removing restorecon on root sepolicy files because:
1. Under normal boot the files are properly labeled when creating the
image. Restorecon'ing them successfully would require "adb remount".
2. These restorecon's are not required for recovery to function.

Fixes: 122535196
Test: boot blueline
Change-Id: I20b127e950b16535d4bfa9fd4e626e11228925e7
2019-01-10 00:50:43 +00:00
Daniel Rosenberg
ca00b0edeb Add conditional class starting
This adds the ability to prevent a class from starting
if a certain persistent property has been set to
disallow it.

A class will only load if there is not a property named
persist.init.dont_start_class.[class name] set to 1.

Test: Set a property called persist.dont_start_class.[class]
      to 1. Verify that the given class does not start
Change-Id: I51c70ad635762ed77855d0509e630adb0aec0eb1
2019-01-09 15:18:01 -08:00
Jiyong Park
93318d496c Build init with the bootstrap bionic libs
As bionic libs are moved from /system to the runtime APEX, anything that
is outside of the runtime APEX cannot use private symbols from the
bionic libs.

init is not included in the runtime APEX but is using private bionic
APIs: __system_property_[add|area_init|update|...]. So, it was required
to publicize the private symbols for init.

However, since init is started before the runtime APEX is activated, it
actually cannot use the bionic libs from the runtime APEX, but will use
the bootstrap bionic libs left in /system/bootstrap/lib[64]. Because
init and the bootstrap libs are in the same partition, init doesn't need
to link against the stubs of bionic libs. In order to make this
possible, the new property 'bootstrap' is set to true allow init to use
the bootstrap bionic.

Bug: 120266448
Test: m with https://android-review.googlesource.com/c/platform/bionic/+/849044

Change-Id: If61f25faf9aed4968bf2922859ceb94276ba03fb
2019-01-09 20:41:41 +09:00
Tom Cherry
4f4caccefd Revert "do not start shutdown animation from init"
This reverts commit e2b04b71ae.

Conditionally reintroduce the shutdown animation as there is some
interest in retaining it.

Bug: 117854737
Test: n/a
Change-Id: I99a085bc763e230de46aa44b3488d771f7ad04ce
2019-01-08 10:39:59 -08:00
Treehugger Robot
97212d36da Merge "Set system property if 'updatable' process crashes too frequently" 2019-01-07 23:55:25 +00:00
Zimuzo
c55a8c6afb Set system property if 'updatable' process crashes too frequently
Critical processes currently cause the device to reboot into recovery when they
crash 4 times in 4mins.

We extend this feature to a new 'updatable' class of init services.
If these services crash 4 times in 4mins, instead of rebooting into bootloader,
we set ro.init.updatable_crashing to '1'. apexd and update_verifier will
listen to that property and try to abort and rollback updates, staged apex
modules and new slots respectively.

Test: Tested manually by marking zygote as updatable and killing zygote
frequently, verified that property is set.
Bug: 120598832
Change-Id: I7d47ea1223f7792a834981c729694242ab3f28c9
2019-01-07 19:26:10 +00:00
Tom Cherry
9a9a4ad84c Merge "ueventd: create a /dev/block/by-name/ symlink without a partition name" 2019-01-05 01:06:16 +00:00
Tom Cherry
a961611a99 init: document the early init boot phase
With all of the changes made to the early init boot phase, the
README.md needs updating for future referencing.

Test: none

Change-Id: Ia572577c683add449a4e091ffd4d1597682e9325
2018-12-27 12:51:32 -08:00
Tom Cherry
2c56d7cdda ueventd: create a /dev/block/by-name/ symlink without a partition name
Create /dev/block/by-name/<device> symlink for block devices that are
boot devices but do not have a partition name given.

Test: boot normally
Change-Id: I8c100b0d30dce02a2dd31aebcfea538b8eed9b19
2018-12-21 09:27:38 -08:00
David Anderson
a1bb982c01 init: Don't fail first stage mount for formattable partitions.
If a partition can be formatted by vold, then it doesn't make sense to
have first-stage mount fail if the partition hasn't been formatted yet.

Bug: 121209697
Test: device boots after fastboot flashall -w
Change-Id: I4a6c794a9912a5e0794983e9514a08f9c23e6ae9
2018-12-20 16:30:40 -08:00
Tri Vo
96b8ce7228 Merge "init: support loading /product/etc/selinux/product_sepolicy.cil" 2018-12-18 21:13:27 +00:00
Tri Vo
d3518cf4c8 init: support loading /product/etc/selinux/product_sepolicy.cil
Bug: 119305624
Test: boot aosp_taimen with product_sepolicy.cil
Change-Id: I2124275de7ffc0058c48f5d5ef16644d5d39da3b
2018-12-14 15:45:16 -08:00
Bowgo Tsai
1f4b4f99ca Allow init to skip mounting /product and /product_services
mainline-core is still in the progress of defining interfaces between
/system, /product, /product_services. Before that was completely done,
just updating /system to GSI usually couldn't boot a device.

Therefore, this CL allows GSI to specify a config file, telling init
not to mount /product and /product_services. And fallback to
/system/product and /system/product_services in the GSI.

Bug: 120208657
Test: boots a device with /system/etc/init/config/skip_mount.cfg and
      checks both /product and /product_services are not mounted.

Change-Id: Ibe2abad30b178a6e552fb21e4b30207fc3ef5523
2018-12-14 21:35:25 +08:00
Tom Cherry
de545a4bb3 Allow specifying vbmeta/parts via fstab
We want to move all information required for first stage mount into
the first stage ramdisk instead of using device tree.  A previous
change allowed reading the fstab from the first stage ramdisk, but
'vbmeta/parts' was still in device tree.  This change allows
specifying the required vbmeta/parts information in the fstab.

The new syntax is that instead of simply specifying 'avb' as an fs_mgr
option, a partition may specify 'avb=<vbmeta partition name>' and that
vbmeta partition will also be initialized by first stage init before
attempting to mount any devices.

Bug: 117933812
Test: boot crosshatch without device tree fstab
Change-Id: Ida1a6da988c10d364b3ccdaa6c5d63e5264d1b27
2018-12-12 13:58:44 -08:00
Tom Cherry
23319ebebf Start using new C++ Fstab class widely
Bug: 62292478
Test: boot
Test: adb-remount-test.sh

Change-Id: Id4715af4c1f03e2cfc67de92d3ea58e933685e51
2018-12-12 17:08:09 +00:00
Tom Cherry
ac1812ddb5 Merge "Update fs_mgr_update_verity_state() for new C++ Fstab" 2018-12-10 17:17:28 +00:00
Tom Cherry
02eff5cccd Update fs_mgr_update_verity_state() for new C++ Fstab
Bug: 62292478
Test: boot and check verity state
Change-Id: I4912a16ada9a6d72480d7ac905654b764c5d18b6
2018-12-07 14:14:54 -08:00
Tom Cherry
e29101077c ueventd: allow configuring SO_RCVBUF(FORCE) for the ueventd socket
Some configurations won't allow ueventd to have CAP_NET_ADMIN, so the
new default size of 16M is not possible for those.  Those
configurations also won't need such a large buffer size, so this
change allows devices to customize the SO_RCVBUF(FORCE) size for the
uevent socket.

This is done by adding the line 'uevent_socket_rcvbuf_size <size>' to
your device's ueventd.rc file.  <size> is specified as a byte count,
for example '16M' is 16MiB.

The last parsed uevent_socket_rcvbuf_size line is the one that is
used.

Bug: 120485624
Test: boot sailfish
Test: ueventd unit tests
Change-Id: If8123b92ca8a9b089ad50318caada2f21bc94707
2018-12-06 13:35:52 -08:00
Tom Cherry
05735591f8 Merge "init: disable asan" 2018-12-06 03:14:58 +00:00
Tom Cherry
c12e205ec5 Fix /init -> /system/bin/init symlink creation race
A symlink for TARGET_ROOT_OUT as a post install command of a package
that is also installed to TARGET_ROOT_OUT.  We hijack init.rc which
satisfies this requirement for this symlink.

Bug: 120402274
Bug: 120460755
Bug: 120509320
Bug: 120554662
Test: symlink is created
Test: make bootimage && ls -la $OUT/root/init
Change-Id: I6f1ac06ef152c36d7d7db4618d49a008338da39b
2018-12-05 23:42:07 +00:00
Tom Cherry
f8315f073f init: disable asan
Asan requires /proc to be mounted, which means it fundamentally cannot
be used with first stage init.  Given that second stage init now
contains the logic for first stage init, asan must be disabled on all
of init until this can be resolved.

Bug: 120424438
Bug: 120561310
Test: Asan builds boot
Change-Id: I24d1a0c8ecb5eb3f77435e6e36432c7b4cb97c6a
2018-12-05 13:52:42 -08:00
Tom Cherry
e1e71b9b98 Merge "init: allow first stage mount to read an fstab" 2018-12-05 20:32:08 +00:00
Alistair Strachan
5d55580fe1 Merge "Handle renamed "super" device correctly" 2018-12-05 00:06:41 +00:00
Alistair Strachan
1906d5f357 Handle renamed "super" device correctly
In the non-retrofit case, the metadata source partition will be
hardcoded as "super", but such a partition may not exist or may have
been overridden by super_partition=<something>. Make this work reliably
by plumbing the resolved metadata block device through, and using it any
time a partition called "super" is requested.

This also fixes a case in the first_stage_mount code that assumed that
detected a non-A/B, non-retrofit case by assuming the metadata source
partition would be called "super".

Bug: 113175337
Test: boot test on cuttlefish
Change-Id: I8ce1defb902e257eeb7170d697b378eba31faee3
2018-12-04 11:21:34 -08:00
Tom Cherry
e68bf85fd6 init: allow first stage mount to read an fstab
Now that we have a first stage ramdisk (or use recovery in its place),
it's possible to place a vendor specific fstab along with first stage
init, removing the need for device tree modifications to have an
fstab.

Bug: 117933812
Test: hikey boots with only an fstab in first stage ramdisk
Test: blueline mainline boots with a disabled DT fstab and an fstab in recovery
Change-Id: I4460b88851557a75ba06ff795cd842e7dfb6da46
2018-12-04 11:06:30 -08:00
Tom Cherry
bb72b808f4 Merge "Convert fs_mgr_swapon_all() to use the new Fstab struct" 2018-12-04 18:41:56 +00:00
Treehugger Robot
a7f54b1592 Merge "C++17 is the default now." 2018-12-04 07:53:24 +00:00
Treehugger Robot
307337fb40 Merge changes I6a4c3d9b,Ia5cdb797,I946eb605,Ieff3f6ea
* changes:
  init: overlay: allow fs_mgr_overlayfs_required_devices to report partitions
  fastboot: call fs_mgr_overlayfs_teardown() in UpdateSuper
  fs_mgr: overlay: disable overrides in recovery or fastbootd.
  fs_mgr: overlay: umount scratch more aggressively
2018-12-03 20:14:02 +00:00
Daniel Mentz
41aa2c3703 Increase netlink uevent rcvbuf size to 16M
Increase size of the NETLINK_KOBJECT_UEVENT socket receive buffer to
16M.  Also, use SO_RCVBUFFORCE to override any limits set by
/proc/sys/net/core/rmem_max.

We had a couple of instances, where we lost critical uevent messages due
to receive buffer overflows.

Bug: 119933843
Change-Id: I6aab183aa0194e173f9175b47c6beb0835cf6675
2018-12-03 18:39:24 +00:00
Tom Cherry
3055457a96 Convert fs_mgr_swapon_all() to use the new Fstab struct
Bug: 62292478
Test: build
Change-Id: Ifbde514bf73d3ce2f321326291daa025b6afac46
2018-12-03 09:41:01 -08:00
Elliott Hughes
3c59cb8420 C++17 is the default now.
Test: builds
Change-Id: I6814455e9ad2cdcf99ad66de38a3ad0bfb440d80
2018-12-03 09:02:18 -08:00
Mark Salyzyn
acf56c297f init: overlay: allow fs_mgr_overlayfs_required_devices to report partitions
init add support for picking up partitions if specified by
fs_mgr_overlayfs_required_devices() as /dev/block/by-name/<partition>

Test: adb-remount-test.sh
Bug: 119885423
Change-Id: I6a4c3d9b5c2b406178f0acf0a86c52ab17209537
2018-12-03 07:33:38 -08:00
Treehugger Robot
e43c146eb4 Merge "fs_mgr: move AVB related source into libfs_avb" 2018-11-30 06:59:38 +00:00
Tom Cherry
ac3c7740ad Merge "init: always create a symlink from /init to /system/bin/init" 2018-11-29 23:22:58 +00:00
Tom Cherry
9843007327 init: always create a symlink from /init to /system/bin/init
Even though it isn't strictly needed when not system-as-root, for
backwards compatibility, it is desired to keep this symlink.

Bug: 119851742
Test: tree-hugger
Change-Id: I47bc25ab257336f56ef09b5db6ebaf6b17daad35
2018-11-29 09:39:30 -08:00
Treehugger Robot
044e02764d Merge "Run BoringSSL self test during startup" 2018-11-29 16:56:19 +00:00
Tom Cherry
3ecaf2e7f5 Merge "init: clean up the 1st/2nd stage init split" 2018-11-29 16:50:37 +00:00
Ivan Lozano
4cafb54481 Merge "Revert "Disable XOM in init."" 2018-11-29 15:58:11 +00:00
Bowgo Tsai
c1bc2813c9 fs_mgr: move AVB related source into libfs_avb
This CL also adds namespace android::fs_mgr and remove FsManager* prefix
for class names. Note that android::fs_mgr::FsManagerAvbOps will be removed
in later CLs when fs_mgr doesn't rely on libavb->avb_slot_verify() to
parse vbmeta structs.

Some lingering sources for by_name_symlink_map_ are also removed.

Bug: 112103720
Test: boot crosshatch_mainline-userdebug
Change-Id: I2d1a5cc39bcd5a699da8d5539f191d8c7737c4af
2018-11-29 22:21:33 +08:00
Branden Archer
d052118702 Run BoringSSL self test during startup
NIAP certification requires that all cryptographic functions
undergo a self-test during startup to demonstrate correct
operation. This change adds such a check.

If the check fails, it will prevent the device from booting
by rebooting into the bootloader.

Bug: 119826244
Test: Built for walleye. After device booted examined dmesg and
      observed logs from init showing that the new task did
      start. Further, when BoringSSL is built to fail its self
      check the device did stop during a normal boot and enter
      the bootloader, and did so before the boot animation stopped.

Change-Id: I07a5dc73a314502c87de566bb26f4d73499d2675
2018-11-28 20:57:00 +00:00
Ivan Lozano
741fe84d56 Revert "Disable XOM in init."
This reverts commit 055347e564.

Reason for revert:
init boots with XOM now. I think this was fixed when this boringssl patch got merged in earlier this week (init has a static dependency on libcrypto):
https://boringssl-review.googlesource.com/c/boringssl/+/33245

Change-Id: I70e15fad4a194c0d2087941bba70dfcd38abe8b5
2018-11-28 19:07:59 +00:00
Alistair Strachan
ef9835967a Merge changes I99d46a2c,I6ff460d0
* changes:
  Skip logical partitions in non-AVB2 case too
  Allow non-A/B, non-retrofit devices to override super_partition
2018-11-28 19:07:13 +00:00
Alistair Strachan
53c5c623c0 Skip logical partitions in non-AVB2 case too
Follow up to the change made for AVB2 devices in
I19371b05912240480dc50864a2c04131258a7103.

The same consideration must be made in the fall through case, which
is taken either if AVB is completely disabled, or the dm-verity / AVB1
mechanism is used.

Bug: 113175337
Test: boot test on cuttlefish
Change-Id: I99d46a2c2630c40f5f5c02279b11e423998a1e05
2018-11-28 19:06:54 +00:00
Ivan Lozano
055347e564 Disable XOM in init.
init doesn't cooperate with execute-only memory just yet, so disable it
until we can determine the root cause.

Bug: 77958880
Test: Device boots.
Change-Id: Ieb78315ba1e48c9cd0d047a42951bd3fbd36641b
2018-11-27 09:12:16 -08:00
Treehugger Robot
8995970ce3 Merge "fs_mgr: remove by_name_symlinks_map_ from AvpOps" 2018-11-19 05:56:36 +00:00
Treehugger Robot
e04aa9e03a Merge "Don't fail when no glob match" 2018-11-17 00:54:39 +00:00
Yifan Hong
0e0f818c8a logical -> dynamic partitions.
Reflect a name change.
Test: boots
Bug: 119286600

Change-Id: I076071be18be521eeee4ebae10491b9f3e8ef857
2018-11-16 12:53:18 -08:00
Jiyong Park
f169f72fba Don't fail when no glob match
There can be no match when there is no APEX installed or no APEX is
providing *.rc file. Don't fail in that case.

Bug: 117403679
Test: m apex.test; m; device is is bootable

Change-Id: Ib1c607ee2c156dc236da1df7df0c6663e8d899b2
2018-11-16 18:08:46 +09:00
Mark Salyzyn
9f1cf25332 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
2018-11-14 09:35:34 -08:00
Tom Cherry
9856460763 fs_mgr: remove by_name_symlinks_map_ from AvpOps
With the addition of the /dev/block/by-name/ symlinks created for the
boot_device, we no longer need to use a map to track the symlinks for
the partitions AVB needs to access.

This will help us in removing the requirement to specify which
partitions contain AVB metadata.

Bug: 117933812
Test: boot blueline_mainline with AVB
Change-Id: I1d46dba5b2fc16b2a14f861b34225ac0f2995b60
2018-11-13 11:37:36 -08:00
Treehugger Robot
34ffa7e074 Merge "init: error log on by-name identical replacement" 2018-11-13 15:27:27 +00:00
Tom Cherry
7bfea3d59c init: clean up the 1st/2nd stage init split
The first split of 1st/2nd stage init went a bit overboard, since it
split these even in the case of the recovery image and system-as-root,
which don't actually need the split.  This change simplifies this a
bit:

system-as-root and recovery have a single combined /system/bin/init
and a symlink from /init to it.

non-system-as-root has a separate first stage init at /init on the
first stage ramdisk and a combined /system/bin/init on system.img.

Two particular benefits from this:
1) Removal of the rsync of TARGET_RAMDISK_OUT to the recovery image
2) Decrease of overall space on the recovery image since it won't have
   a statically linked first stage init

This also unified the various entry points of init to depend entirely
on the arguments passed to it, instead of the hybrid of arguments and
environment variable used previously.

Bug: 80395578
Test: boot both system-as-root and non-system-as-root
Change-Id: Ic2f29b6f56b7defc80eaa0e7cd0c9107e978816f
2018-11-12 16:08:19 -08:00
Jiyong Park
80aa44704c Add support for updatable services
A service with 'updatable' option can be overriden by the same service
definition in APEXes.

/system/etc/init/foo.rc:

service foo /system/bin/foo
    updatable

/apex/myapex/etc/init.rc:

service foo /apex/myapex/bin/foo
    override

Overriding a non-updatable (i.e. without updatable option) service
from APEXes is prohibited.

When an updatable service is started before APEXes are all activated,
the execution is delayed until when the APEXes are all activated.

Bug: 117403679
Test: m apex.test; adb push <built_apex> /data/apex; adb reboot
adb shell, then lsof -p $(pidof surfaceflinger) shows that
the process is executing
/apex/com.android.example.apex@1/bin/surfaceflinger instead of
/system/bin/surfaceflinger

Change-Id: I8a57b8e7f6da81b4d2843e261a9a935dd279067c
2018-11-13 08:59:14 +09:00
Mark Salyzyn
3c426b65f6 init: error log on by-name identical replacement
The following message creates unnecessary alarm:

init: Partition system_a already existed in the by-name symlink map \
 with a value of \
 /dev/block/platform/soc/1d84000.ufshc/by-name/system_a, new value \
 /dev/block/platform/soc/1d84000.ufshc/by-name/system_a will be \
 ignored.

and in the code is cited as an ERROR.  The message admittedly does
point out an inefficiency by reporting multiple updates.

Test: compile
Change-Id: I388a76fa078cf9de5840930247f732d16ccb0719
2018-11-12 20:27:09 +00:00
Tom Cherry
13856a05e7 Merge "Reland: "init: chroot from recovery to /first_stage_ramdisk"" 2018-11-12 16:38:59 +00:00
Tom Cherry
866c08c0ac Reland: "init: chroot from recovery to /first_stage_ramdisk"
When using the recovery image as a trampoline to boot the system,
first chroot from the recovery image to /first_stage_ramdisk, to
minimize differences between these two boot paths.

Primary motivation is due to the fact that the basename of each mount
point is used by device-manager to name its nodes, and the previous
code that created used /system_recovery_mount as the mount point for
system.img broke AVB.  Instead of hacking around that issue, this
change unified mounting for the recovery trampoline and true first
stage ramdisk paths.

Change when relanding: the original change skipped the move mount from
/first_stage_ramdisk to / and only did a chroot instead.  This was a
mistake that resulted in the subsequent move mount of /system to / to
mount over the '/' directory instead of moving that mount.  This
change uses a bind mount of /first_stage_ramdisk to itself instead of
skipping the first move mount.

Bug: 114062208
Test: AVB works with blueline_mainline
Change-Id: I65207edfe98531892da2eafcbff19b438c9c64fe
2018-11-09 14:58:46 -08:00
Jiyong Park
c240440eec init parses *.rc files from APEXes
Init now parses *.rc files from the APEXs when the apexd notifies the
mount event via apexd.status sysprop.

Bug: 117403679
Test: m apex.test; adb root; adb push <builtfile> /data/apex; adb reboot
adb root; adb shell setprop ctl.start apex.test; dmesg shows that init
tries to start the service which doesn't exist.

[   47.979657] init: Could not ctl.start for 'apex.test': Cannot find '/apex/com.android.example.apex/bin/test': No such file or directory

Change-Id: I3f12355346eeb212eca4de85b6b73257283fa054
2018-11-10 04:18:09 +09:00
Tom Cherry
223114008c Merge "Revert "init: chroot from recovery to /first_stage_ramdisk"" 2018-11-09 18:51:14 +00:00
Tom Cherry
e087a6a3bb Revert "init: chroot from recovery to /first_stage_ramdisk"
This reverts commit 56999b41af.

Reason for revert: Something is broken here; we're not switching to /system properly.

Change-Id: I777fedcfb545c11275c9cc12f99b99a2423959a0
2018-11-09 18:47:26 +00:00
Tom Cherry
64ae77e526 Merge "init: chroot from recovery to /first_stage_ramdisk" 2018-11-09 17:01:41 +00:00
Tom Cherry
56999b41af init: chroot from recovery to /first_stage_ramdisk
When using the recovery image as a trampoline to boot the system,
first chroot from the recovery image to /first_stage_ramdisk, to
minimize differences between these two boot paths.

Primary motivation is due to the fact that the basename of each mount
point is used by device-manager to name its nodes, and the previous
code that created used /system_recovery_mount as the mount point for
system.img broke AVB.  Instead of hacking around that issue, this
change unified mounting for the recovery trampoline and true first
stage ramdisk paths.

Bug: 114062208
Test: AVB works with blueline_mainline
Change-Id: Iffb154962b6e160150917e068f1e7d0bf7cb84e7
2018-11-08 15:47:36 -08:00
Treehugger Robot
76b420f38d Merge "Fix bootchart" 2018-11-07 07:36:35 +00:00
David Anderson
f89b1df1a5 init: Regenerate uevents for dependent super partition devices.
This patch adds another uevent-regeneration pass to the first stage
mount. When the super partition spans multiple block devices, we need
/dev/block/by-name symlinks to have been created before we begin mapping
dynamic partitions.

Bug: 116802789
Test: retrofit device boots
Change-Id: I00bb277e1d81385a457c5b4205a95d8fbe365bb2
2018-11-05 17:53:49 -08:00
Treehugger Robot
82c88d9b00 Merge "ueventd: don't skip restorecon after the cold boot" 2018-11-02 22:57:27 +00:00
Oleksiy Avramchenko
dd5802a27e ueventd: don't skip restorecon after the cold boot
We need to do restorecon after the cold boot, otherwise the newly
created sysfs nodes won't be labelled.

Bug: 118861992
Test: manual - do insmod, check sysfs nodes are properly labelled
Change-Id: I4bdfb4a68206724a568d8cbb6c644ba8764b5fa7
2018-11-02 15:43:11 +00:00
Evgenii Stepanov
1f47f4add4 Do not hwasanitize init_first_stage.
Current hwasan implementation breaks when stderr (fd 2) is missing.

Bug: 118776698
Test: hwasan boots without serial console
Change-Id: Id095a87212096526a497563adab3d7f2f9fe8ab0
2018-11-01 13:43:50 -07:00
Peter Collingbourne
166ae693d4 Merge "Introduce additional service options for controlling memory cgroups." 2018-11-01 17:55:34 +00:00
Justin Yun
6bab0a9c23 Mount vendor overlay from the system partition
Using overlayfs, the system partition may provide files for older
version of vendor partitions by overlaying on the vendor partition.
Directories in /system/vendor_overlay will be overlaid on the
directories in /vendor to override existing files or provide new
files.

This feature works only if the kernel support overlayfs and has a
patch for override_creds. Otherwise, no-op.

Bug: 114679254
Test: Build and boot: nothing affected without overlayfs, or
                      vendor file is overrided with overlayfs

Change-Id: Iff3a308945299034123ba7bcb40dc787e102730e
2018-11-01 10:26:12 +09:00
Peter Collingbourne
d7157c22af Introduce additional service options for controlling memory cgroups.
The memcg.limit_percent option can be used to limit the cgroup's
max RSS to the given value as a percentage of the device's physical
memory. The memcg.limit_property option specifies the name of a
property that can be used to control the cgroup's max RSS. These
new options correspond to the arguments to the limitProcessMemory
function in frameworks/av/media/libmedia/MediaUtils.cpp; this will
allow us to add these options to the rc files for the programs that
call this function and then remove the callers in a later change.

There is also a change in semantics: the memcg.* options now have
an effect on all devices which support memory cgroups, not just
those with ro.config.low_ram or ro.config.per_app_memcg set to true.
This change also brings the semantics in line with the documentation,
so it looks like the previous semantics were unintentional.

Change-Id: I9495826de6e477b952e23866743b5fa600adcacb
Bug: 118642754
2018-10-31 17:09:59 -07:00
Victor Chang
6b15a6b1ad Fix bootchart
Found the following 2 binary is not in the path
system/core/init/grab-bootchart.sh: line 20: bootchart: command not found
system/core/init/grab-bootchart.sh: line 21: gnome-open: command not found

Use a more commonly available command to create bootchart

Test: system/core/init/grab-bootchart.sh started a bootchart
successfully

Change-Id: I6d5b4a692af2fd53ea636b768f55c697586e6898
2018-10-31 21:00:19 +00:00
Eric Biggers
82c6ba74e2 Merge "init: use libfscrypt for file-based encryption setup" 2018-10-29 17:19:39 +00:00
Tom Cherry
668f70f6ef Merge "init: fix error messages when an invalid section header is found" 2018-10-26 22:31:52 +00:00
Tom Cherry
0166fd606d init: fix error messages when an invalid section header is found
If a section header such as 'on' or 'service' has an error with it,
the rest of the commands / options are currently reported as errors
since there is no valid parser object to parse them.  For example,

service !@#$%%^&*() /system/bin/false
    user root
    group blah
    blah blah

Generates:

init: /system/etc/init/bad.rc: 2: invalid service name '!@#$%%^&*()'
init: /system/etc/init/bad.rc: 3: Invalid section keyword found
init: /system/etc/init/bad.rc: 4: Invalid section keyword found
init: /system/etc/init/bad.rc: 5: Invalid section keyword found

This change suppresses the extraneous 'Invalid section keyword found'
messages.

Test: faulty error messages are suppressed.
Change-Id: Ieeb2d5b8b7eea33e191a88ce5a0d41701686943f
2018-10-26 12:33:52 -07:00
Tom Cherry
fa79ae87f1 init: allow vendor init to action on any vendor or odm property
Partial revert of "init: if vendor_init can read a property, let it be
a trigger too" (b35f827c97).

We made a mistake when we allowed vendor init to action on any vendor
or odm property, since when a new SELinux label is created for a
vendor property, vendor_init does not automatically get read
permissions for it.

Recently, we tried to use read permissions instead of the built-in
list in init, but that broke due to the above mistaken.  Since we have
already launched with these permissions as is, we must restore them.

Bug: 118457755
Test: no denials for vendor init actionable properties on crosshatch
Change-Id: I7a9a560c9a54a177c6b83d28309e2f288f05d400
2018-10-26 08:50:45 -07:00
Eric Biggers
f05da4a4be init: use libfscrypt for file-based encryption setup
The file-based encryption setup code is being refactored into its own
library because it applies to both ext4 and f2fs, not just ext4.  Update
init to use the new location.   For fs_mgr, just remove the include of
ext4_crypt_init_extensions.h since it was unneeded.

Test: built, booted device with f2fs encryption
Change-Id: I392a763e3349f001bdbc09eb9ca975aa3451fd68
2018-10-25 17:10:15 -07:00
Tom Cherry
b35f827c97 init: if vendor_init can read a property, let it be a trigger too
There is a list of 'stable_properties' that vendor_init can use as
property triggers for Treble property compliance.  This list came about
since init parses init scripts before all partitions are mounted and
therefore before all property context files are available, such that
init cannot use the normal SELinux mechanisms for determining if a
given property is vendor_init readable.

Currently though, we require all partitions that would contain
property context files to be mounted during first stage mount, so we
can use the normal SELinux mechanisms here, so this change deprecates
the stable_properties list and moves init to use SELinux to determine
if a property can be a trigger.

Bug: 71814576
Test: vendor_init fails to use non-readable properties as a trigger
Test: vendor_init successfully uses readable properties as a trigger
Change-Id: I6a914e8c212a3418cbf4a8a07215056aad2e0162
2018-10-22 16:16:03 -07:00
Tom Cherry
5083be5d72 Merge "init: Add some ASAN helpers" 2018-10-19 20:41:24 +00:00
Tom Cherry
e0042419f8 init: Add some ASAN helpers
Init is special.

It starts early and does not pick up the Android ASAN options provided
on the environment.  Therefore we pull in /system/asan.options in
explicitly if it exists.  We provide sane defaults that will allow the
system to boot otherwise.

Logging is complicated because it needs to go to the kernel log.
So use sanitizer functions to install log functions.

Bug: 117879229
Test: m && m SANITIZE_TARGET=address
Test: init boots with ASAN enabled
Change-Id: I72c033a1f86ba5d6b2e4f943e7a3acd0d399c8bf
2018-10-19 11:18:58 -07:00
Tom Cherry
7a08c896dd Merge changes Iea270320,Ib9063185
* changes:
  init: allow properties to be used for the keycodes option
  init: use rvalues references for callees of ParseLineSection()
2018-10-19 15:43:43 +00:00
Nick Kralevich
2991949001 Add O_CLOEXEC
Prevent an FD from accidentally leaking across an exec() boundary.

Test: code compiles.
Change-Id: I90ca6e332802700403f401db016cc6c0c72b0ea3
2018-10-18 16:09:40 -07:00
Tom Cherry
791668462a init: allow properties to be used for the keycodes option
Bug: 117828597
Test: bugreport launches with a test property set to appropriate keys
Test: bugreport doesn't launch with the test property unset
Test: no errors seen in build or boot in either of the above cases
Change-Id: Iea27032080a0a7863932b1c1b573857ac66b56b5
2018-10-17 11:30:53 -07:00
Tom Cherry
018a438ff0 init: use rvalues references for callees of ParseLineSection()
ParseLineSection() provides 'args' as an rvalue reference, so its
callers can and should use it as such.  This saves some copying
overhead and cleans up the code a bit.

Test: boot
Change-Id: Ib906318583dc81de9ea585f5f09fdff35403be1b
2018-10-17 11:30:53 -07:00
Tom Cherry
89bf115a70 Merge "init: separate init packaging for mainline" 2018-10-16 20:29:47 +00:00
Tom Cherry
29e5348f18 init: separate init packaging for mainline
With system-as-root, both first and second stage init belong to
system, but without system-as-root, first stage belongs to vendor and
second stage belongs to system.  This change creates two phony
packages to achieve this correctly in the build system.

Bug: 117606184
Test: mainline builds work properly
Change-Id: I19263e76c217c2e70bc06c180be3a460e9144f18
2018-10-16 09:49:00 -07:00
Tom Cherry
ad9e7eaf2d init: clarify some text/README about 'critical' services
'Critical' services have rebooted into bootloader, like all other
catastrophic init crashes, for years now.  Update the text to match.

Test: n/a
Change-Id: Icfc41bf3e383958f14ecfaab9ca187e2c3dc7fd9
2018-10-15 17:21:48 -07:00
Steven Moreland
48aed8f02d init: clarify multiple 'interface' keyword use
This keyword can (and should) be used multiple times when multiple
services are served together. I've documented this here.

Bug: N/A
Test: N/A
Change-Id: Ie986c9cac486db346555f359e9ccbed93d8d1d22
2018-10-15 18:00:36 +00:00
Minchan Kim
d37dd4a6f0 Merge "export dumpstatez into stable_properties" 2018-10-12 07:23:23 +00:00
Tom Cherry
4c67290da6 Merge "init: add [[nodiscard]] to Result" 2018-10-11 20:34:04 +00:00
Tom Cherry
d987264625 init: add [[nodiscard]] to Result
It's better to either check these results or explicitly ignore them.
Only a few callers weren't already doing this, so it's relatively
trivial to enforce.

Test: build
Change-Id: I44cdc342e46128f66cac914aaa0b9b4559cacd8c
2018-10-11 10:39:33 -07:00
Minchan Kim
b7f6c5a1cd export dumpstatez into stable_properties
Vendor might want to pause/resume some operations while a bugreport is captured
so that we need to export dumpstatez into stable_properties.h for vendor to get
property event when dumpstatez launch.

Test: confirmed manually with "adb bugreport"
Bug: 117536084
Change-Id: Ib743c5e59ca20cc44470110c814d85e4cbb90c0c
Signed-off-by: Minchan Kim <minchan@google.com>
2018-10-11 18:02:58 +09:00
Wei Wang
b5de088262 init: increase thermal shutdown timeout to 3s
1) increase thermal shutdown timeout to 3s for process to save work
2) respect property "ro.build.shutdown_timeout" in thermal shutdown if
   it is set less than default time - "3s"

Bug: 112432890
Test: Build
Change-Id: Idc2b24dd44c1fab8f9b047fd2468de2ee45ff783
2018-10-09 12:53:30 -07:00
Tom Cherry
64990d5b45 Merge "init: move InitKernelLogging() to first stage init" 2018-10-05 20:41:23 +00:00
Tom Cherry
48e83e629f init: move InitKernelLogging() to first stage init
The kernel opens /dev/console and uses that fd for stdin/stdout/stderr
if there is a serial console enabled and no initramfs, otherwise it
does not provide any fds for stdin/stdout/stderr.  InitKernelLogging()
is used to close these existing fds if they exist and replace them
with /dev/null.

Currently, InitKernelLogging() is only called in second stage init,
which means that processes exec'ed from first stage init will inherit
the kernel provided fds if any are provided.

In the case that they are provided, the exec of second stage init
causes an SELinux denial as it does not have access to /dev/console.
In the case that they are not provided, exec of any further process is
potentially dangerous as the first fd's opened by that process will
take the stdin/stdout/stderr fileno's, which can cause issues if
printf(), etc is then used by that process.

Lastly, simply moving InitKernelLogging() to first stage init is not
enough, since first stage init still runs in kernel context and future
child processes will not have permissions to access kernel context
resources.  Therefore, it must be done for a second time in second
stage init.

Bug: 117281017
Test: no audits when booting marlin.
Change-Id: If27edab5c32b27765e24c32fbed506ef625889de
2018-10-05 10:36:38 -07:00
Chih-Hung Hsieh
747eb149d0 Add noexcept to move constructors and assignment operators.
Bug: 116614593
Test: build with WITH_TIDY=1
Change-Id: I5a7461386946ca623ab509609092aa0ac8418b80
2018-10-05 16:43:47 +00:00
Tom Cherry
5f2a21d244 Merge "init: allow customizable restart and timeout periods for services" 2018-10-05 16:15:23 +00:00
Tom Cherry
73f535e33b init: allow customizable restart and timeout periods for services
Allow services to specify a custom restart period via the
restart_period service option.  This will allow services to be run
periodically, such as a service that needs to run every hour.

Allow services to specify a timeout period via the timeout_period
service option.  This will allow services to be killed after the
timeout expires if they are still running.  This can be combined with
restart_period for creating period services.

Test: test app restarts every minute
Change-Id: Iad017820f9a602f9826104fb8cafc91bfb4b28d6
2018-10-04 19:52:37 -07:00
Mark Salyzyn
e511e3a3b1 fs_mgr: Add fs_mgr_overlayfs_required_devices()
Added fs_mgr_overlayfs_required_devices() as hint to init to make sure
the device gets created before fs_mgr_overlayfs_mount_all().

Test: manual
Bug: 109821005
Change-Id: Iab038f3e0252a357b082bb08db3679512b9badec
2018-10-04 15:15:02 -07:00
Treehugger Robot
02678f32be Merge "Don't hardcode the super partition name." 2018-10-04 19:29:34 +00:00
Treehugger Robot
29e9833e39 Merge "fs_mgr/init: use unique_ptr + CLO_EXEC for setmntent()/fopen()" 2018-10-03 21:22:50 +00:00
Tom Cherry
f274e78eeb fs_mgr/init: use unique_ptr + CLO_EXEC for setmntent()/fopen()
We ran into an issue with an fd leaking due to missing both CLO_EXEC
and fclose() in related code, so let's make sure we're safe here too.

Test: boot
Change-Id: Ief893c936859815c78fa6d7e06cb88ad34aadbac
2018-10-03 13:19:04 -07:00
Treehugger Robot
8bd7d5238f Merge "init: IsDmLinearEnabled() replace with check if logical partitions present in fstab" 2018-10-03 20:03:26 +00:00
Tom Cherry
32638a1ef6 Merge "init: clarify why we mount /mnt/... in first stage init" 2018-10-02 21:55:08 +00:00
Tom Cherry
21824dddeb init: clarify why we mount /mnt/... in first stage init
Test: n/a
Change-Id: I55974fb285c55756536d038f4e20cb45d11906ee
2018-10-02 10:21:03 -07:00
David Anderson
5cbd2e43ee Don't hardcode the super partition name.
If a device has logical partitions but does not use a partition called
"super", we will need this to be configurable. Note that the "slot"
argument is currently unused, but will be necessary for update_engine if
there are A and B super partitions.

Bug: 116608795
Test: super partition works
Change-Id: Ieb548a158faeb423f3561230f26d582325efbc6b
2018-10-01 14:13:22 -07:00
Tom Cherry
e3745bc57a Merge "init: use '/system' as the system mount point for force_normal_boot" 2018-09-27 00:35:22 +00:00
Mark Salyzyn
9b1e7a34b9 init: IsDmLinearEnabled() replace with check if logical partitions present in fstab
IsDmLinearEnabled() true if logical partitions present in fstab.

Test: boot on logical device
Bug: 109821005
Change-Id: Ic083b0b8d9f7e9511d78bdc05c9f848521f1feb5
2018-09-26 21:04:24 +00:00
Tom Cherry
c382957789 init: use '/system' as the system mount point for force_normal_boot
We need to keep the right mount points in the fstab for other
processes to access (/ for system-as-root or /system otherwise).
Force_normal_boot devices are defacto not system-as-root,
since they're booting through the recovery ramdisk and therefore must
use /system as the system mount point.

Bug: 114062208
Test: boot pixel from recovery with force_normal_boot
Change-Id: Ib0e4e4f8a29299ecdcd35e8f1415551c4c9745ad
2018-09-26 13:27:16 -07:00
Treehugger Robot
5952034c25 Merge "Set device lock status from kernel command line." 2018-09-26 02:02:13 +00:00
Hridya Valsaraju
5ed32780b4 Set device lock status from kernel command line.
Device is considered to be unlocked if
androidboot.verifiedbootstate is "orange".

Test: adb shell getprop ro.boot.flash.locked

Change-Id: Id3aeec757908ea63a37e28ad880a6c71d53083ac
2018-09-25 15:49:59 -07:00
Treehugger Robot
37d8bbdf9c Merge "fs_mgr: init: adb: add fstab argument to fs_mgr_overlayfs_mount_all" 2018-09-25 20:37:15 +00:00
Treehugger Robot
6544056d54 Merge "Support 'adb reboot fastboot' command conditionally." 2018-09-25 17:17:08 +00:00