Commit graph

91 commits

Author SHA1 Message Date
Treehugger Robot
100e8ffbcd Merge "Remove obsolete subdirs entry." 2019-07-16 02:02:40 +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
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
Daniel Norman
4b505fe3a8 Merge "Checks the interface inheritance hierarchy in init_rc files." 2019-07-12 18:01:46 +00: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
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
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
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
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
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
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
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
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
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
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
Jeffrey Vander Stoep
e21d07fbab Merge "selinux: use the policy version defined in sepolicy" 2019-03-19 21:44:59 +00: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
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
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
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
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
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
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
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
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
Treehugger Robot
044e02764d Merge "Run BoringSSL self test during startup" 2018-11-29 16:56:19 +00: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
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
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
Martijn Coenen
62e985a954 init: Allow restricted use of binder.
Allow init to use binder, but in a restricted way:
- No binder threadpool
- Other processes can't initiate calls to init
- No death recipients

This change adds libbinder/libutils and calls into ProcessState,
which also calls into the kernel driver and sets up state there.
No other binder calls are made, so that we can let this soak for
a while to see if there any bad side effects of just loading
these libraries and initializing the kernel driver.

This introduces about 120kB of additional memory usage (PSS),
mostly due to pulling in libbinder and libutils and the private
state they have.

We also don't include these libraries in the recovery version of
init, because space on the recovery partition is limited.

Bug: 112684055
Test: device still boots, /d/binder/proc/1 shows init state
Change-Id: I972b1eebdb16337f52e20d1f614e3a0dce0f06d2
2018-09-07 15:47:21 +02:00
Tao Bao
a3d36a8ce7 init: Build init_tests only for the first arch.
Not all the dependent shared libs are installed on device with both
arches. For example, we don't have 32-bit `libfs_mgr.so` or
`libbootloader_message.so` on marlin, which would cause 32-bit
`init_tests` to fail.

Bug: 112494634
Test: Run (64-bit) init_tests on marlin.
Test: `m -j continuous_native_tests` with aosp_marlin-userdebug. Check
      that only 64-bit init_tests is included in
      `continuous_native_tests.zip`.
Change-Id: I999d58750d48c34df7dbabccf8863a6ccaf0b83c
2018-08-24 11:28:54 -07:00
Tao Bao
66209ca9bf init: init_defaults uses more shared libraries.
This CL switches init_defaults and thus init_second_stage to depend on
commonly used shared libraries. In particular, use the following shared
libs that have been available on device (under both of normal boot and
recovery):
 - libbootloader_message
 - libext4_utils
 - libfs_mgr
 - libhidl-gen-utils
 - libkeyutils
 - liblogwrap

The following transitive dependencies have been dropped. They were only
needed when including the above libs statically. Dropping them doesn't
further affect the size though.
 - libfec
 - libfec_rs
 - libsquashfs_utils

With the change, the second stage init size has been reduced from
1094328 to 627992 bytes (aosp_taimen-userdebug), with no new shared libs
installed.

Also evaluated the impact of using `libprotobuf-cpp-lite.so` and
`libseccomp_policy.so`. It doesn't look beneficial -- at least not right
now with `init` as the singler user.
 - statically linked them both: 627992-byte
 - with libprotobuf-cpp-lite.so: 605880 (init) + 262624 (.so)
 - with libseccomp_policy.so: 605848 (init) + 32208 (.so)

Bug: 112494634
Test: `mmma -j system/core/init` with aosp_marlin-userdebug
Test: Flash the marlin build on device. Run init_test.
Test: Boot into recovery successfully.
Change-Id: I49debe9066ff36dfda55b08266862e29e2bfc96b
2018-08-24 10:54:24 -07:00
Tom Cherry
31438489c0 split first stage init into a separate executable
In the future, systems with dm-linear will require a ramdisk to set up
the mount for system.  In this world, first stage init will be a part
of this ramdisk and handle setting up dm-linear, mounting the
necessary partitions, then pivoting to the system image, which will
become the root partition.

This also enables previous devices without system-as-root, to be
unified with system-as-root devices for all aspects of boot after the
pivot_root.

Bug: 79758715
Test: boot hikey
Test: boot sailfish, boot sailfish into recovery
Change-Id: Iefa88a3ec5994e7989aa9f26f2de0351ffa5468b
2018-08-06 10:36:43 -07:00
Tom Cherry
44aceed016 Split init's source files init first stage and second stage
This is a baseline for splitting init first and second stage into
their own executables.

Bug: 79758715
Test: sailfish boots
Change-Id: I549ad4502893b3a5e4c2a9886f66850f6d31b619
2018-08-03 13:40:17 -07:00
Tom Cherry
40acb379cd Move watchdogd out of init
We're moving past a world where static executables are needed,
including watchdogd, so treat this like any other executable and place
it in /system/bin.

Bug: 73660730
Test: watchdogd still runs
Change-Id: I1f7508fd55dce6e9ee72a6ab7a085011a76c0053
2018-08-02 12:25:58 -07:00
Andrew F. Davis
9963847419 ueventd: Add dynamic kernel module loading
For some platforms it is not known at build time what devices
will be attached at runtime. Building into the kernel or pre-loading
at init all the modules that could be needed would unnecessary bloat
the kernel. The solution is dynamic kernel module loading.

The kernel will generate uevents when devices are added, userspace
should monitor for these events and load the compatible modules.

The init process already monitors for uevents, add here the ability
to respond to modalias events and preform the correct action.

Adding this to init is preferred over an external program as we
can read and process the module alias and dependency files once,
instead of for each module needing to be loaded.

Test: Run on Beagle-X15, check all needed modules are loaded (lsmod)
Change-Id: I1b57d9aeb0a9770f309207183dc4bc2b7b905f14
Signed-off-by: Andrew F. Davis <afd@ti.com>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
2018-07-26 09:42:22 -05:00
Treehugger Robot
1d2b29a902 Merge "init: rename init_first_stage" 2018-07-21 02:47:36 +00:00
Tom Cherry
38a11ccdd1 init: rename init_first_stage
In preparation for splitting first stage init from the rest of the
init executable, rename these files which are specifically involved in
first stage mount operations to a more appropriate name.

Test: builds
Change-Id: I8a2d4e8c7e1deea1bab45cc8e738727bc2ceb3e5
2018-07-20 15:31:36 -07:00
Tom Cherry
74069d1734 init: clean up logging initialization
Clean up a few mistakes in logging initialization

1) Only init needs to clear stdout/stderr/stdin, so remove this from
   ueventd, watchdogd, and subcontext init
2) Only init should reboot due to FATAL errors. This was true even
   before this change due to getpid() checks, but there's no reason to
   not just use the DefaultAborter for other processes.
3) It's probably a mistake for FATAL logs in init to try to gracefully
   shutdown the system, so simply call RebootSystem() here.
4) Lastly, remove log.cpp since it's not actually shared code anymore

Test: build
Change-Id: Ic8c323393dc7ee98ed6bb9691361b51d0d915267
2018-07-20 15:30:14 -07:00
Tom Cherry
5f0198bfbb ueventd: add a test for ueventd_parser.cpp
Test: this unit test
Change-Id: Ib23f23ea5b362bb458adf8208573e5dc80ad6cf0
2018-07-17 15:28:51 -07:00
Tom Cherry
2a5a4e72f3 init: add unit tests for tokenizer.cpp
Test: this unit test
Change-Id: Iae24f3bf7850dd4b298281f6608bce195096d60a
2018-06-27 13:22:16 -07:00
Yifan Hong
16bb55cb7b Merge "Revert "init: dummy host_init_verifier for mac"" 2018-06-20 22:56:39 +00:00
Yifan Hong
3c4aa11cab Revert "init: dummy host_init_verifier for mac"
This reverts commit f567367584.

Reason for revert: mac build

Change-Id: Icd5d08206c50854d6645e07c4fb29705222bd226
2018-06-20 22:49:48 +00:00
Treehugger Robot
b0e193c609 Merge "init: dummy host_init_verifier for mac" 2018-06-20 21:19:49 +00:00
Tom Cherry
f567367584 init: dummy host_init_verifier for mac
Let's start by fixing the build, then see how possible this will be to do fully.

Bug: 110477913
Test: n/a
Change-Id: If52e15bd070781a405c5494631ede033c1067903
2018-06-20 12:29:59 -07:00
Jiyong Park
012171d3af libselinux is dynamically linked from init
init is now dynamically linked to libselinux. This gives us about 100KB
extra space, which is valuable in the recovery partition.

Bug: 63673171
Test: m -j
Test: adb reboot recovery
Change-Id: I72c4f886cbbb9ce54f8221f05547f5b9f0e1adb0
2018-06-19 16:55:05 +09:00