Commit graph

1434 commits

Author SHA1 Message Date
Wonsik Kim
3428d0c2c0 Merge "Revert "init: use read_file and write_file to implement do_copy builtin"" 2017-03-31 00:22:00 +00:00
Wonsik Kim
395e29472f Revert "init: use read_file and write_file to implement do_copy builtin"
This reverts commit 82bac0de6d.

Change-Id: Ibfdf453bd85ba4fcd1948b78bd22e639a883653e
2017-03-31 00:18:13 +00:00
James Hawkins
e78ea77f69 bootstat: Refactor init/utils/boot_clock into base/chrono_utils.
Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.

This is a reland of aosp/338325 with a stubbed implementation for Darwin.

This change also has clang_format fixes (automatic).

Bug: 34352037
Test: chrono_utils_test
Change-Id: I72a62a3ca1ccfc0a4ccc6294ff1776c263144686
2017-03-30 14:24:12 -07:00
Treehugger Robot
9ead7c4a74 Merge "send SIGTERM only once" 2017-03-30 04:10:41 +00:00
Janis Danisevskis
9cc51728af Make init builtin command installkey respect property updates
init used to block on installkey such that it was unable to
process property events. This lead to a deadlock by which
the Keymaster HAL would wait indefinitely for the
hwservicemanager.ready=true. 

This fixes the issue by implementing the builtin in terms of 
do_exec, which allows init to stay responsive to properties 
while waiting for the child to terminate.

Bug: 36278706
Test: Add a 3s delay into hwservicemanager before it sets the property
      hwservicemanager.ready and the device still boots.

Change-Id: Iaefd31156ca01f3a44b4f85a8bf78beee8dfe224
2017-03-30 00:11:48 +00:00
Keun-young Park
acd55b39fe send SIGTERM only once
- Processes capturing SIGTERM signal will not terminate and
  killProcessGroup will timeout after retry. This gives 200ms
  of waiting per such process. Change it to retry only once as
  SIGTERM will keep failing for such process.

bug: 36696408
Test: check time spent in SIGTERM for reboot
Change-Id: I9b0843614598dd3f97a50b21352046297ed70b6b
2017-03-29 16:33:25 -07:00
Sandeep Patil
7ef60b4ed4 init: consolidate restorecon after selinux initialization in single function
Test: Boot sailfish
Change-Id: I423028f12a84c4e0c12c9bdde52b6d795d45b620
(cherry picked from commit 74df5bab16)
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-03-29 16:01:31 -07:00
Keun-young Park
c4ffa5c47d set zero shutdown timeout for eng build
- still it will take time to kill services, < 3 secs in tested device.

bug: 36678028
Test: reboot
Change-Id: I3f3eb83aede8cd950da12e3fcc259eeaf8517c3b
2017-03-29 12:25:33 -07:00
Treehugger Robot
8772b3686e Merge changes from topic 'exec-start-update-verifier'
* changes:
  init.rc: launch update_verifier with exec_start
  init: add exec_start command
2017-03-29 18:39:32 +00:00
Tom Cherry
ccf23537ee init: replace property_get with its android::base equivalent
Slowly try to decouple property_service.cpp from the rest of init.

Test: Boot bullhead
Change-Id: I267ae0b057bca0bf657b97cb8bfbb18199282729
2017-03-29 10:07:54 -07:00
Treehugger Robot
20e43a2f2c Merge "init: remove unused cutils includes" 2017-03-29 01:27:19 +00:00
Tom Cherry
1ec1bd918c init: remove unused cutils includes
Test: Boot bullhead
Change-Id: I629f9c3863f00fa38f87a68442c2380d28764718
2017-03-28 16:22:33 -07:00
Treehugger Robot
8678872a00 Merge "init: add class_restart" 2017-03-28 04:22:47 +00:00
Treehugger Robot
deb23ba2c1 Merge "init: remove superfluous forward definitions" 2017-03-28 02:22:51 +00:00
Treehugger Robot
88d6b4af16 Merge "init: Fix README.md for writepid" 2017-03-28 01:07:50 +00:00
Tom Cherry
46b6c43b7c init: remove superfluous forward definitions
Test: Boot bullhead
Change-Id: I4a005616a825529bc2ad1b413e51b501f6407cbd
2017-03-27 17:55:37 -07:00
Tom Cherry
b27004aa05 init: add exec_start command
Exec services may also want to set other service flags such as
priority.  Instead of expanding the exec syntax to handle this, create
a new command, exec_start, that will treat an existing service
definition as an exec service.  The new exec_start command will start
the service then halt init from executing further commands until the
service has exited.

This change additionally encapsulates the waiting_for_exec logic into
ServiceManager and removes the ambiguous 'bool' return value from
Reap() which previously indicated if a Reaped service was an exec
service or not.

Bug: 36511808
Bug: 36102163
Test: Bullhead boots, services run with exec_start as they do exec.

Change-Id: I44f775cf1c1dd81d5c715f44fdc150c651a2c80a
2017-03-27 17:41:27 -07:00
Treehugger Robot
3c1568aa13 Merge "init: add support of multiple class names" 2017-03-28 00:39:09 +00:00
Keun-young Park
59cebb6e6f Merge "update shutdown sequence and use shutdown_timeout to cover all wait" 2017-03-27 22:27:30 +00:00
Wei Wang
641ff0a4d8 init: add support of multiple class names
Add support of multiple class names in service, so that related services
can be grouped together. By doing this, we can start/stop some services
for special purpose. For example, early zygote, early boot animation
and etc.

Bug: 36535312
Test: marlin boots with defined classes
Change-Id: Ifeaaf034fd836816e24f3775bece53ea83faada6
2017-03-27 20:59:05 +00:00
Steven Moreland
2b63d54af8 init: add class_restart
Bug: 34093663
Test: hwservicemanager `onrestart class_restart hal` works
Change-Id: Ie1e4daab2b7b4c6c714d4e3d05afa2d86d6233df
2017-03-27 13:52:47 -07:00
Keun-young Park
3ee0df9bdf update shutdown sequence and use shutdown_timeout to cover all wait
- Use ro.build.shutdown_timeout to cover the total time for shutdown.
  Limit wait time for termination only to half of shutdown_timeout
  with max of 3 secs as process not terminating by that time
  will not terminate anyway. It is better to move to the next
  stage quickly. fsck time for user shutdown is excluded from timeout.
- Change last detach to kill, sync, and umount. Last detach did not
  work in many tests.
- add sync after emulated partitions umount as it can trigger
  change in /data.

bug: 36551393
Test: many reboots
Change-Id: Ib75dc19af79b8326b02ccef6b16a8817ae7f8b0e
2017-03-27 13:44:50 -07:00
Treehugger Robot
784c851785 Merge "Move selinux policy build decisions to sepolicy Makefile" 2017-03-27 20:03:04 +00:00
Tom Cherry
e564dac2b3 init: Fix README.md for writepid
writepid takes a list of space delimited files.  Make this clear in
the documentation, following the format for repeated fields used in
the rest of the file.

Test: N/A
Change-Id: I5bbe453fcb54f060d3cc5a82e9b38d3091a1ece3
2017-03-27 12:55:33 -07:00
Jeff Vander Stoep
7ef28f4e4f Move selinux policy build decisions to sepolicy Makefile
Test: Test build/boot Marlin with split policy
Test: Test build/boot Bullhead with combined policy
Bug: 36138508
Change-Id: I84654d19c4d8e9fe9086fde742ee80cd043dfbe1
2017-03-26 07:56:29 -07:00
Treehugger Robot
dd26e1a28c Merge "add kill all for shutdown_timeout of 0" 2017-03-24 05:15:20 +00:00
Treehugger Robot
7f0d15a6f2 Merge "init: use read_file and write_file to implement do_copy builtin" 2017-03-24 02:26:14 +00:00
Treehugger Robot
c1ca1a8328 Merge "init: Prevent spin loop while waiting for exec or property" 2017-03-24 01:52:37 +00:00
Treehugger Robot
186edb1aef Merge "init: Remove superfluous error check" 2017-03-24 01:51:31 +00:00
Keun-young Park
aa08ea458a add kill all for shutdown_timeout of 0
- If it is explicitly set to 0, active processes can block
  umount completely. Safe to kill all processes and umount.
- also add additional sync after emulated partition umount
  as that can change /data partition files

bug: 36004738
Test: many reboots

Change-Id: I6c9b07b6fdece44b9caec4e45ecf26a20d0eb96e
2017-03-23 18:01:24 -07:00
Yongqin Liu
82bac0de6d init: use read_file and write_file to implement do_copy builtin
this will make the implementation more cleaner,
and has error message output when failed on some operations

also add the O_TRUNC flag explicitly for the open function
called in write_file.

And add more test on read_file and write_file functions

Test: manual with hikey

Change-Id: Ifc1086a20e85db6980b497b1150a8a7952e672d6
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2017-03-24 08:34:25 +08:00
Tom Cherry
77ddcd5a3f init: Prevent spin loop while waiting for exec or property
Currently, when we are waiting for an exec service or a property, if
there are either any services to be restarted or any more commands to
be run, we set the epoll_timeout to handle these events.  However, we
don't actually restart and processes or execute any commands while
waiting, so this essentially turns this waiting into a spin loop,
particularly in the common case of having more commands to execute,
where epoll_timeout is set to 0.

The change only sets epoll_timeout if we're not waiting.

Note that the only way to stop waiting for an exec service or a
property is for a signal or property to be delivered to init, which
happens through the epoll fds, so it's safe to indefinitely wait for
epoll to return.

Test: Boot bullhead
Change-Id: Iae3b217eb28182038b464fd39df8e7d27b5e23ff
2017-03-23 17:17:54 -07:00
Keun-young Park
3cd8c6f912 add clear log for reboot start / end
- hard to tell if reboot itself is problem or not.

bug: 36004738
Test: reboot and check last kmsg
Change-Id: I0de0e10eac9ac336cc352ddee22a4a1d9e46cb79
2017-03-23 16:55:24 -07:00
Tom Cherry
9bdddd713a init: Remove superfluous error check
new doesn't return nullptr in C++, so there is no need to check for
it.

Test: Boot bullhead
Change-Id: I666afb1ba7082dd8d5b9911605b7e20a5561b49e
2017-03-23 16:44:42 -07:00
Keun-young Park
8d01f63f50 remove emergency shutdown and improve init's reboot logic
- Emergency shutdown just marks the fs as clean while leaving fs
  in the middle of any state. Do not use it anymore.

- Changed android_reboot to set sys.powerctl property so that
  all shutdown can be done by init.

- Normal reboot sequence changed to
    1. Terminate processes (give time to clean up). And wait for
      completion based on ro.build.shutdown_timeout.
        Default value (when not set) is changed to 3 secs. If it is 0, do not
        terminate processes.
    2. Kill all remaining services except critical services for shutdown.
    3. Shutdown vold using "vdc volume shutdown"
    4. umount all emulated partitions. If it fails, just detach.
       Wait in step 5 can handle it.
    5. Try umounting R/W block devices for up to max timeout.
      If it fails, try DETACH.
      If umount fails to complete before reboot, it can be detected when
      system reboots.
    6. Reboot

- Log shutdown time and umount stat to log so that it can be collected after reboot

- To umount emulated partitions, all pending writes inside kernel should
  be completed.
- To umount /data partition, all emulated partitions on top of /data should
  be umounted and all pending writes should be completed.
- umount retry will only wait up to timeout. If there are too many pending
  writes, reboot will discard them and e2fsck after reboot will fix any file system
  issues.

bug: 36004738
bug: 32246772

Test: many reboots combining reboot from UI and adb reboot. Check last_kmsg and
      fs_stat after reboot.

Change-Id: I6e74d6c68a21e76e08cc0438573d1586fd9aaee2
2017-03-22 11:23:31 -07:00
Treehugger Robot
2fdcf37af1 Merge "Add 'ro.cpuset.default' system property for default cpusets." 2017-03-21 23:46:56 +00:00
Treehugger Robot
ac8a3bd283 Merge "init: reboot to bootloader on crash for development builds" 2017-03-21 22:50:38 +00:00
Tom Cherry
663fdfc1b2 init: reboot to bootloader on crash for development builds
Currently, if init crashes, the kernel panics.  During development, we
would like to catch this crash before the kernel panics and reboot
into bootloader. This will prevent boot looping bad configurations,
particularly desired in test labs where manual intervention would
otherwise be required to reset the devices.

Keep the existing behavior for user builds, as init crashes should be
rare for production builds and rebooting the device is the correct
behavior for end users.

Bug: 34147472
Test: Boot bullhead userdebug, force init to crash, check that the
      device is in bootloader
Test: Boot bullhead user, force init to crash, check that the kernel
      panics and the device reboots as it did previously
Change-Id: Iab3d45ed0d1f82ffaad2a0835d9ca537c0516421
2017-03-21 13:42:17 -07:00
Alex Vakulenko
0828676dff Add 'ro.cpuset.default' system property for default cpusets.
Normally 'writepid' is used to add a process to a particular cpuset. However
certain systems with big/small cores might need to specify a default cpuset for
system processes which do not explicitly specify one. Add an option to use
'ro.cpuset.default' system property to specify default cpuset for system processes
which do not explicitly write to /dev/cpuset/... with 'writepid' option.

The cpuset name specified in ro.cpuset.default is just the cpuset name, e.g.
'/system-background', '/foreground', or simply '/' for the "root" cpuset.

Bug: 28550814
Test: `m -j32` succeeds for aosp_sailfish-eng. Phone boots successfully.
      Also tested manually with debug trace messages on emulator with different
      combinations of values for 'ro.cpuset.default'.
Change-Id: I501727fa5ee3f4bb7a938fa104b81a404b616633
2017-03-21 12:00:31 -07:00
Tom Cherry
40578ab91f init: Fix leaking fd and error print
read_file() does not close its fd if either stat() fails or the file
has group/world writable permissions.

Use unique_fd to ensure that all return paths close the fd and make
the same change to write_file() for consistency.

Replace PLOG() with LOG() after a simple if conditional, that does not
set errno.

Old:
init: skipping insecure file '/data/bootchart/header': No such device or address
New:
init: skipping insecure file '/data/bootchart/header'

Test: Cause an invalid file read and check the error log
Test: Ensure non-error read_file() and write_file() work
Change-Id: Ib15d94e38362e335d671d30b36aa5605254ec7ab
2017-03-20 14:40:02 -07:00
Todd Poynor
16663a2aa4 powerctl: add thermal-shutdown command
Add sys.powerctl property interface for initiating thermal shutdown.

Bug: 30994946
Test: Manual: setprop sys.powerctl thermal-shutdown
Change-Id: Iffce60bd3cb4b40a5859623d10b91bee5101f168
2017-03-17 17:16:40 -07:00
Tom Cherry
34e70410ee init: cleanup is_first_stage conditionals
A recent change to the is_first_stage conditionals created a unneeded
else { } block as both the code in the else { } block and any code
that runs after it are both in the second stage of init.  A first step
to clean this up is to remove this else block.

Secondly, given the above confusion, it makes sense to simplify the two
if (is_first_stage) conditions into one, which only now requires
duplicating one line to initialize logging and the actual "init
first/second stage started!" logs.

Lastly, there are a few commands ran at the beginning of both init
stages that do not need to be,

* boot_clock::time_point start_time = boot_clock::now();
This is only used in the first stage so keep it there

* umask(0);
umasks are preserved across execve() so it only needs to be set in the
first stage

* chmod("/proc/cmdline", 0440);
This needs to be moved until after /proc is mounted in the first
stage, but otherwise only needs to be done once

Test: Boot bullhead, check umask, check cmdline permissions, check
boot time property

Change-Id: Idb7df1d4330960ce282d9609f5c62281ee2638b9
2017-03-17 10:58:17 -07:00
Tom Cherry
f31abeb973 Merge "init: fix DumpState() logging" 2017-03-14 20:12:48 +00:00
Treehugger Robot
0b4d34e31c Merge "ueventd: support by-name symlinks for virtual block devices" 2017-03-14 19:29:35 +00:00
Tom Cherry
e3aef3dd99 Merge "init: enable C++17" 2017-03-14 17:17:40 +00:00
Tom Cherry
62a9f32344 init: Remove custom clang-format
Use a symlink to .clang-format-4 from the parent directory now that we
have it, instead of the custom .clang-format in this directory.

The changes between these files are,
Old:
ConstructorInitializerAllOnOneLineOrOnePerLine: false
TabWidth: 8
New:
ConstructorInitializerAllOnOneLineOrOnePerLine: true
TabWidth: 4

There is no reason to keep a custom .clang-format for these two
changes, and setting ConstructorInitializerAllOnOneLineOrOnePerLine to
true will be beneficial.

Test: Run clang-format and see that its output is sane
Change-Id: I5b357949eb02a60577cf57a783c0a80997b24e75
2017-03-13 16:23:20 -07:00
Tom Cherry
d8a7257b14 init: fix DumpState() logging
Fix two formatting issues in Action::DumpState(),

Old:
on ro.crypto.state=encrypted ro.crypto.type=file zygote-start
New:
on ro.crypto.state=encrypted && ro.crypto.type=file && zygote-start

Old:
on boot
  %sifup lo
  %shostname localhost
  %sdomainname localdomain
  %swrite /proc/sys/vm/overcommit_memory 1
New:
on boot
  ifup lo
  hostname localhost
  domainname localdomain
  write /proc/sys/vm/overcommit_memory 1

Also, now that we're importing many small rc files, it no longer makes
sense to call Parser::DumpState() after each import.  Therefore, move
the conditional to call Parser::DumpState() to after /init.rc and its
imports are parsed and after the late imports are parsed.

Test: Boot bullhead with DumpState() enabled and check the output
Change-Id: I0b81305b8938aa1a7133d7dd2055f34f47609cf9
2017-03-13 12:24:49 -07:00
Tom Cherry
2bc00140be init: enable C++17
Test: Boot bullhead
Change-Id: I40961ff765461e8aef211d27158ffb7c4be76493
2017-03-13 11:58:58 -07:00
Treehugger Robot
2d03e64b95 Merge "Build split file_contexts on TREBLE builds" 2017-03-10 23:54:18 +00:00
Treehugger Robot
ac13718d0a Merge changes from topic 'fstab_relocation'
* changes:
  init: replacing fs_mgr_read_fstab() with fs_mgr_read_fstab_default()
  fs_mgr: support reading fstab file from /odm or /vendor partition
  fs_mgr: add fs_mgr_read_fstab_with_dt() API
2017-03-10 02:07:34 +00:00
Alex Klyubin
a71dfec4c2 Remove hard-coded policy version from secilc step
This change makes init's SELinux policy compilation step target the
highest SELinux policy language version supported by the kernel.
Prior to this change the version was simply hard-coded in init.

P. S. clang-format (part of presubmit for this change) is being
counter-productive trying to format the section with secilc
parameters. The resulting layout is harder to read. This commit thus
disables clang-format for this section of code and formats the code
for improved readability.

Test: Remove precompiled policy, device boots up, no new denials.
      Added log statement to print out the policy version passed
      into secilc -- it printed 30, as expected.
Bug: 31363362

Change-Id: I151017b5211712861bafb662525e794a44026dd2
2017-03-09 11:11:23 -08:00
Bowgo Tsai
c9a1842d31 init: replacing fs_mgr_read_fstab() with fs_mgr_read_fstab_default()
The original default /fstab.{ro.hardware} might be moved to
/vendor/etc/. or /odm/etc/. Use the new API to get the default
fstab instead of using the hard-coded /fstab.{ro.hardware}.

Bug: 35811655
Test: boot marlin with /vendor/etc/fstab.marlin

Change-Id: I8a9c70eda7f68b174ec355910d0fa1eb18a46e21
2017-03-09 23:26:31 +08:00
Jeff Vander Stoep
0cbbb8381e Build split file_contexts on TREBLE builds
Build file_contexts.bin on legacy builds.
Test: Marlin and Bullhead build and boot with no new denials.
Test: Marlin and Bullhead recovery boots with no new denials.
Test: Bullhead boots with file_contexts.bin in /
Test: Marlin boot with /system/etc/selinux/plat_file_contexts and
      /vendor/etc/selinux/nonplat_file_contexts.
Bug: 36002414

Change-Id: I66f138fc3ad808df0480e0467cee03fd40177f31
2017-03-08 15:28:06 -08:00
Alex Klyubin
2d19aeb13a Use precompiled sepolicy when available
NOTE: This change affects only devices which use SELinux kernel policy
split over system and vendor directories/partitions.

Prior to this change, init compiled sepolicy from *.cil files on every
boot, thus slowing boot down by about 400 ms. This change enables init
to skip the step compilation and thus avoid spending the 400 ms. The
skipping occurs only if the device's vendor partition includes an
acceptable precompiled policy file. If no acceptable policy is found,
the compilation step takes place same as before.

Because such devices support updating system and vendor partitions
independently of each other, the vendor partition's precompiled policy
is only used if it was compiled against the system partition's policy.
The exact mechanism is that both partitions include a file containing
the SHA-256 digest of the system partition's policy
(plat_sepolicy.cil) and the precompiled policy is considered usable
only if the two digests are identical.

Test: Device with monolithic policy boots up just fine
Test: Device with split policy and with matching precompiled policy
      boots up just fine and getprop ro.boottime.init.selinux returns
      a number below 100 ms. No "Compiling SELinux policy" message in
      dmesg.
Test: Device with split policy and with non-matching precompiled
      policy boots up just fine and getpropr ro.boottime.init.selinux
      returns a number above 400 ms. There is a "Compiling SELinux
      policy" message in dmesg. The non-matching policy was obtained
      by adding an allow rule to system/sepolicy, building a new
      system image using make systemimage and then flashing it onto
      the device.
Bug: 31363362
Change-Id: Ic2e81a83051689b5cd5ef1299ba6aaa1b1df1bdc
2017-03-08 12:25:25 -08:00
Jeremy Compostella
937309d3e3 ueventd: support by-name symlinks for virtual block devices
This patch makes ueventd create by-name symlinks for virtual block
devices when Android is running as a Xen guest OS.

The symlinks will be created under /dev/block/vbd/. For example:
/dev/block/vbd/768/by-name/

Change-Id: Id45da560d13f641d7c8419511c154de9ae8a4ec9
Test: manual
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
2017-03-07 10:55:19 +01:00
Keun-young Park
0c93ab67c6 Merge "add ro.boottime.init.mount_all.* for measuring mount time" 2017-03-06 19:25:50 +00:00
Alex Klyubin
1185050767 Log stderr of secilc
This makes init log stderr of secilc invoked to compile SELinux
policy. Having an explanation for why secilc failed is very useful for
debugging boot issues.

Test: Device with PRODUCT_FULL_TREBLE boots up just fine
Test: Modified init.cpp to reference non-existent .cil file on a device
      with PRODUCT_FULL_TREBLE and confirmed that dmesg now contains the
      error message from secilc saying that the file was not found.
Bug: 31363362

Change-Id: I6a3b3576daf0d6fd09e2c79bc43ae63850f44a00
2017-03-05 14:29:16 -08:00
Keun-young Park
69fae7b3dc add ro.boottime.init.mount_all.* for measuring mount time
- three properties: .early, .default, .late
- for tracking critical early boot times

bug: 35949600
Test: manual, getprop after boot

Change-Id: I851891518428e6e21cb43a2a6f982ab7db281d4c
2017-03-03 18:57:09 -08:00
Alex Klyubin
c2a4c9ab9a Track the move of split SELinux policy CIL files
The three CIL files comprising split sepolicy are being moved from the
root directory to system and vendor directories based on whether the
file is for platform/system policy or non-platform/vendor policy.

Test: Device boots, no additional SELinux denials. This test was run
      for a device which has split policy and for a device which has
      monolithic policy.
Bug: 31363362
Change-Id: Ica49f0beae56be0f1cea7117e48bf2f6af8b848b
2017-03-03 10:35:10 -08:00
Treehugger Robot
0ab93fdf3a Merge "Include correct type of SELinux policy" 2017-03-03 03:50:49 +00:00
Keun-young Park
22cc398d76 Merge "use ro.persistent_properties.ready for persistent props ready" 2017-03-02 22:41:30 +00:00
Alex Klyubin
b51f9abf45 Include correct type of SELinux policy
This makes the build system include split SELinux policy (three CIL
files and the secilc compiler needed to compile them) if
PRODUCT_FULL_TREBLE is set to true. Otherwise, the monolitic SELinux
policy is included.

Split policy currently adds around 400 ms to boot time (measured on
marlin/sailfish and bullhead) because the policy needs to be compiled
during boot. This is the main reason why we include split policy only
on devices which require it.

Test: Device boots, no additional SELinux denials. This test is
      performed on a device with PRODUCT_FULL_TREBLE set to true, and
      on a device with PRODUCT_FULL_TREBLE set to false.
Test: Device with PRODUCT_FULL_TREBLE set to true contains secilc and
      the three *.cil files, but does not contain the sepolicy file.
      Device with PRODUCT_FULL_TREBLE set to false contains sepolicy
      file but does not contain the secilc file or any *.cil files.
Bug: 31363362

Change-Id: I419aa35bad6efbc7f936bddbdc776de5633846fc
2017-03-02 13:25:17 -08:00
Treehugger Robot
056eca201b Merge "Use split SELinux policy at boot, if available" 2017-03-02 01:02:15 +00:00
Keun-young Park
404906d59a use ro.persistent_properties.ready for persistent props ready
- for security reason, only notify ready state instead of
   passing time info to hidl clients

Bug: 35178781
Bug: 34274385
Test: reboot

Change-Id: I2d64bd6da81139945bd0224079af9376f1d90da7
2017-03-01 23:16:10 +00:00
Alex Klyubin
16696e201b Use split SELinux policy at boot, if available
This modifies init's loading of SELinux policy into the kernel to
load the split (platform/system vs non-platform/vendor) policy if it's
present. If the split policy is not present, the usual monolithic
policy is loaded into the kernel, same as before.

Split policy is loaded by first compiling it from CIL form using
secilc compiler into the conventional monolithic/compiled form which
is then loaded into the kernel.

The build system has not yet been modified to place split policy onto
devices. Thus, this commit currently has no effect. For testing split
policy, build plat_sepolicy.cil, nonplat_sepolicy.cil, and
mapping_sepolicy.cil, and place them into the root directory of the
device.

The following tests were performed for a device with monolithic policy
and for the same device with split policy.

Test: Device boots, no new denials
Test: Play Movies plays back movies
Test: Load ip6.me im Chrome
Bug: 31363362
Change-Id: I9a75a48ac88f3392abc36669f91b0803e88cd147
2017-03-01 14:07:40 -08:00
Bowgo Tsai
32232724fb init: skip early mount in recovery mode
We don't need early mount in recovery mode for security considerations,
e.g., users should explicitly select 'mount /system' from the recovery
menu. This CL checks the existence of file "/sbin/recovery" and skip
early mount when it is found.

Bug: 35853576
Test: early mount /vendor without dm-verity on sailfish
Test: early mount not happen in recovery mode on sailfish
Change-Id: I69cc96f6fd0de6ce493082921738a958dd571115
2017-03-02 00:30:58 +08:00
Treehugger Robot
b6cb9b0457 Merge "There's no longer a limit to property names." 2017-03-01 00:03:58 +00:00
Elliott Hughes
b7788fd454 There's no longer a limit to property names.
Bug: http://b/33926793
Test: boots
Change-Id: I8554d7af74e064c114cf817f5a2ba1247fa2a2db
2017-02-28 14:12:54 -08:00
Keun-young Park
7d3202650d set ro.boottime.persistent_properties when persisted props are restored
- allows components relying on persisted props to wait for this property.

bug: 35178781
Test: reboots
Change-Id: I06cbf2a6b375654fcc277a2699fceeb23846a241
2017-02-28 11:31:54 -08:00
Treehugger Robot
f719c255fa Merge "init: early_mount: removing hard-coded paths" 2017-02-28 01:29:13 +00:00
Bowgo Tsai
d4beed22e8 init: early_mount: removing hard-coded paths
Current early mount has some hard-coded paths that are not easy to extend
when we switch verified boot to AVB (external/avb/libavb). This CL uses some
C++ containers to replace those fixed paths.

Bug: 33254008
Test: early mount /vendor with dm-verity on sailfish
Test: early mount /vendor without dm-verity on sailfish
Test: early mount /vendor with dm-verity on bullhead

Change-Id: I32a22fe486d7649e33bb23c9018ddc0428df6069
2017-02-27 13:09:06 +08:00
Jaekyun Seok
4ec72cc25f Treblize init.rc location
Treblization requires to locate partner-specific modules in its own
partition. So their own init.rc file could be located in /odm or
/vendor.
This CL is to support those locations for the init.rc.
Additionally thic CL modified import parser to support importing a
relative path.

Test: building succeeded and tested on sailfish with enabling early
mount.
Bug: 35269867

Change-Id: I1bce924a32c8a2b53fb5d981d35d758cf9ddd9a6
2017-02-25 08:06:12 +09:00
Treehugger Robot
93072f2ce3 Merge changes from topic 'early-mount-verity'
* changes:
  adb: early-mount: fix verity toggle through adb for early mount
  early_mount: fs_mgr: move all fstab logic into fs_mgr
2017-02-24 02:13:50 +00:00
Sandeep Patil
c20c0c2cdd early_mount: fs_mgr: move all fstab logic into fs_mgr
With init parsing fstab fragments from kernel separately, the fs_mgr
would completely miss the device tree entries. That leads to things like
'adb remount' to go through without warning for verity even if /system
is verified. This happens because 'verity_update_state' completely
misses the partitions passed to android through the device tree.

solution is to teach fs_mgr about device tree fstab entries and add 2
new public APIs.

1. fs_mgr_read_fstab_dt() - reads device tree and returns fstab
generated from it.

2. fs_mgr_read_fstab_default() - reads both device tree fstab and
/fstab.{ro.hardware} and returns the combined table.

This also reduces the hardcoded /fstab.{ro.hardware} occurence only to
fs_mgr and for eveyone who wants to read the "default" fstab must be
changed to call fs_mgr_read_fstab_default() instead. e.g. adb.

b/27805372

Test: Angler was used since it has 2 early mounted partitions instead of
one. 1 verified and 1 unverified.
- Boot angler successfully without early mount
- Boot angler successfully with /vendor early mount and test if 'adb
remount' warns us about verity
- Boot angler successfully with both /system and /vendor early mounted
and ensure 'adb remount' warns us about verity.
- check partitions.system.verified status after /system early mount ot
ensure it is set to VERITY_MODE_DEFAULT.
- 'adb disable-verity' with early mounted /system doesn't work due to
missing changes in adb

TODO:
change adb to use the new fs_mgr_read_fstab_default() API

Change-Id: I82038d87c7a44488e938acce2cc1082c08f6f73a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-23 16:48:43 -08:00
Tom Cherry
0506b18a36 Check setegid() return values
The clang static analyzer is complaining that we are not checking the
setegid() return value, so let's add these checks.  We should never
fail to return to AID_ROOT, so fail hard in this case.

Bug: 26962034
Test: Boot bullhead
Test: export WITH_STATIC_ANALYZER=1 and run 'mm' in the project directory
Change-Id: I62e95b045c5734305c71502871b6cf17f152edbc
2017-02-23 13:50:21 -08:00
Treehugger Robot
4bd3facbb1 Merge changes from topic 'early-mount-support'
* changes:
  fs_mgr: add a generic fs_mgr_get_boot_config internal API
  init: early_mount: create device node for verity metadata partition
  init: early_mount: disallow partitions to be verified at boot
  init: early_mount: add support to mount verity enabled partitions early
  fs_mgr: make fs_mgr_setup_verity public API
  fs_mgr: fix the fs_mgr_setup_verity param name
  init: refactor to allow successive device_init calls
  fs_mgr: add fs_mgr_do_mount_one() API
2017-02-23 07:16:18 +00:00
Elliott Hughes
b005d90816 Address property service DoS.
Bug: http://b/35166374
Test: ran new test
Change-Id: I94cf5750f0d2dc87f4a118b2c63b16255ef30fd2
2017-02-22 14:54:15 -08:00
Sandeep Patil
e9da79bd44 init: early_mount: create device node for verity metadata partition
Most devices pass the veritymode through 'androidboot.veritymode' kernel
cmdline partition. However, for those who don't, the verity state is
read from a different block device whose path it passed to "verify="
fs_mgr option in fstab.

This change add support for such a case if the partition that needs to
be mounted early requires this additional block device to load the
verity state from.

Note that, there can only be 1 partition to get the verity state
regardless of the number of partitions we enable verity for.

Bug: 27805372

Test: Test angler by removing the metdata argument in fstab when it
boots fine. Tested by adding the argument when it fails to boot as
veritymode gets set to EIO during early mount due to lack of access to
properties as expected.

TODO: fs_mgr must pull the veritymode from kernel cmdline or device tree
by itself

Change-Id: I9e62b8c1bf2c0ae0365677df697a0cbe9e5810c1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-22 11:30:35 -08:00
Sandeep Patil
05ff38ba43 init: early_mount: disallow partitions to be verified at boot
While technically possible, the verification at boot basically will
block init for as long as the entire partition is read while nothing
else is running. Disallow that as this is not going to be used anywhere.

Bug: 27805372
Test: boot angler with verifyatboot fs_mgr option for early mounted
vendor partition. That resulted in a panic() as expected.

Change-Id: I9da5caa163cae8bce6dbfb630f0ed5605ea044a0
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-22 11:22:53 -08:00
Sandeep Patil
0a3e36fbb1 init: early_mount: add support to mount verity enabled partitions early
support mounting partitions early regardless of their "verified" status.
uses the newly exported fs_mgr APIs to split verity setup and mount
operations.

b/27805372

Test:
 Angler:
 - Early mount /vendor without dm-verity
 Sailfish:
 - Early mount /vendor without dm-verity
 - Early mount /vendor with dm-verity

TODO:
 add support for metadata partition used in angler
to load dm-verity data

Change-Id: Ie2768d4d895c19d045293c573773ee7bb03fff99
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-22 11:22:53 -08:00
Sandeep Patil
971a460c5b init: refactor to allow successive device_init calls
device_init opens the uevent socket and sehandle when called.
For early_mount however, depending on the fs_mgr flags we may call this
in order to run coldboot for device mapper, dm-verity devices etc.
So the change makes sure we don't try to re-open the uevent socket,
file context handle and selinux status on successive calls to
device_init from within the same process.

b/27805372

Test: Boot saifish successfully

Change-Id: Ifa0e665403211684183efb9be66e4e8d0d86a206
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-22 11:22:49 -08:00
Treehugger Robot
a20c678d45 Merge "init: minor fix to READEME.md" 2017-02-22 00:22:28 +00:00
Bin Chen
a08f002c23 init: minor fix to READEME.md
Change-Id: I149c2a8f2053ac4dcc61bea6fa8c57f4c7b73c9e
Signed-off-by: Bin Chen <bin.chen@linaro.org>
2017-02-22 09:38:25 +11:00
bowgotsai
763512795d Set libavb version into system property for Treble OTA
Treble allows framework-only (system.img) OTA. To libavb statically
linked in init/fs_mgr cannot parse the AVB metadata of system.img, add
this property for the Treble OTA match process.

Bug: 35236019
Test: Normal boots, use 'adb shell getprop' to check the property is set.
Test: Recovery boots, press 'Mount system' and use 'adb shell getprop'
      to check the property is set

Change-Id: I552be229c4efd45088d93252ac67176606f75d4d
2017-02-16 05:18:12 +00:00
Treehugger Robot
1549257ff5 Merge changes from topic 'pre-early-mount'
* changes:
  init: fstab: add support to read fstab entries from device tree
  init: early_mount: add support to mount non-verity partitions early
  init: remove the existing early_mount code
  init: refactor: add support for doing early coldboot
  ueventd: make selinux labeling optional for device creation
2017-02-14 20:34:35 +00:00
James Hawkins
c8ac067773 Revert "bootstat: Refactor init/utils/boot_clock into base/chrono_utils."
This reverts commit 7c92e48450.

Mac sdk still broken (despite testing locally).

Change-Id: I7d9206e15997cd0efe081bd3fa17d53d2b20ec32
2017-02-14 19:20:20 +00:00
James Hawkins
7c92e48450 bootstat: Refactor init/utils/boot_clock into base/chrono_utils.
Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.

This is a reland of aosp/332854 with a fix for Darwin.

Bug: 34352037
Test: chrono_utils_test
Change-Id: Ib2567d8df0e460ab59753ac1c053dd7f9f1008a7
2017-02-13 15:47:21 -08:00
Sandeep Patil
fc86f2442f init: fstab: add support to read fstab entries from device tree
for early mount, we need a way to tell init where to find vendor,
odm partitions (also system in case of non-A/B devices). Also, that
needs to be independent of kernel cmdline since the cmdline will likely
exceed its limit.

The change adds support for parse and create fstab entries that can be
directly sent to the fs_mgr for mounting partitions early in init first
stage.

Sample DT entry to mount vendor partition early on angler-

firmware {
    android {
        compatible = "android,firmware";
        fstab {
            compatible = "android,fstab";
            vendor {
                compatible = "android,vendor";
                dev = "/dev/block/platform/soc.0/f9824900.sdhci/by-name/vendor";
                type = "ext4";
                mnt_flags = "ro,barrier=1,inode_readahead_blks=8";
                fsmgr_flags = "wait";
            };
        };
    };
};

b/27805372

Test: Boot angler and sailfish with early "vendor" partition mount by
adding aforementioned DT node and enable CONFIG_PROC_DEVICETREE in kernel

Change-Id: I669013e3fdb157e88719436534f63989dec95d60
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-13 12:35:39 -08:00
Sandeep Patil
35403ebaf8 init: early_mount: add support to mount non-verity partitions early
This is done by parsing 'androidboot.fstab=<fstab>' kernel cmdline
option to get the fstab file that *only* specifies partitions to be
mounted early (i.e. in init's first stage).

Note that, the same fstab file may not be used as an argument to
mount_all later in the boot as that will cause fs_mgr to fail with
EBUSY.

TODO:
- Possibly add a new mount_mode so the same fstab can be used for
early_mount, 'mount_all --early/--late' etc.
- Add support for dm-verity enabled partitions to mount early.
- Add support for getting fstab arguments through DT instead of kernel
cmdline.

Bug: 27805372

Test:
Boot angler by passing a seperate fstab file using the kernel
cmdline option to mount vendor partition early, remove the vendor
partition entry from the main fstab file for the test.

Boot sailfish by passing a seperate fstab entry via device tree
to mount vendor partition early. Remove vendor partition entry from
the main fstab file for the test

Change-Id: I18785b893c54c8cee960ab44d5e8f83e5d624aa8
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-13 11:17:51 -08:00
Treehugger Robot
d7b5c7b2da Merge "Add a sample service for testing init." 2017-02-10 01:40:12 +00:00
Sandeep Patil
44a3ee2cd1 init: remove the existing early_mount code
keeps parts of the code that are still needed for the fs_mgr
+ dt based implementation

b/27805372

Test: boot angler, sailfish without regressions

Change-Id: I1b08f8b7b4f2e67118d328443a5011c0f5ead919
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-09 15:39:06 -08:00
Sandeep Patil
957e4ab0b5 init: refactor: add support for doing early coldboot
We don't want to spend time creating devices that are unncessesary
during early (init first-stage) mount. So, refactor the devices code
tha allows us to call into coldboot and has the

- ability to only create devices that are specified by the caller
- ability to stop coldboot cycle when all devices that the caller is
interested in
- ability to run coldboot for a specific syspath
- ability to run ueventd code unmodified

Test: Tested boot on angler, sailfish

Change-Id: Id8f3492380696760414eadc20d624d300c904f8e
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-09 15:30:20 -08:00
Jorge Lucangeli Obes
28e980b59c Add a sample service for testing init.
I find myself using something like this every time I add functionality
to init. I cannot possibly be the only one doing this. On the other
hand, if this hasn't been added for so long, maybe there's a reason
for that.

The advantage of using a test service versus modifying an existing
service is that the test service doesn't *require* any permissions or
privileges, so you can add and/or remove whatever you need to test
without breaking the service.

I found it useful to have the service check its own /proc/<pid>/status
from command-line arguments, so that's what the service does.

This CL also adds a .clang-format file for init.

Bug: None
Test: Service runs and exits successfully.

Change-Id: I3e7841a7283158e10c0bf55e0103c03902afb1f0
2017-02-09 18:23:09 -05:00
Treehugger Robot
d54d4c275e Merge "ueventd: source ueventd configs from vendor and odm" 2017-02-09 21:25:44 +00:00
Sandeep Patil
ea23983a9c ueventd: make selinux labeling optional for device creation
This is to setup a way for us to run coldboot during init first stage
and also at ueventd startup. We do not have all of the file context
during the first stage, so the "early" coldboot needs to proceed without
labelling the device nodes. However, the follow up in ueventd must label
these nodes. This change allows us to do both.

b/27805372

Test: Boot angler successfully and compare do before/after comparison of
      the output of 'ls -AclpqRZ /dev' to ensure there are no differences.

Change-Id: I5e88bd7da8a1d2cc41e3abba30dda463ecbde32e
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-08 14:40:18 -08:00
James Hawkins
0e3167e203 Revert "bootstat: Remove custom uptime parser in favor of elapsedRealtime."
This reverts commit 26f40c04c3.

This change broke the Darwin SDK target.

Test: none
Change-Id: Ia54fe2c31da8d8fa2825e023b035fb8321dcd457
2017-02-08 14:16:51 -08:00
Sandeep Patil
bf298e6d0c ueventd: source ueventd configs from vendor and odm
While keeping the old /ueventd.$ro.hardware.rc configuration for devices
without early mount or vendor,odm split

b/34967636

Test: Boot angler and sailfish without regressions

Change-Id: I8d671911fd23fb1c0b5624ae209bad86137c88b7
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-08 13:51:02 -08:00
James Hawkins
26f40c04c3 bootstat: Remove custom uptime parser in favor of elapsedRealtime.
Refactored init/utils/boot_clock into base/chrono_utils.

Bug: 34352037
Test: none
Change-Id: Ied0c00867336b85922369d7ff37520e3d28fc61e
2017-02-07 15:43:32 -08:00
Wei Wang
2d0fdaaafc init: clean up exec command
Add wait time log for exec service execution time
Fix memory leak when exec service failed to start

Test: on marlin
Bug: 34518530
Change-Id: I01736bd9b1429414f3dc91dd5d02d88a681f0985
2017-02-03 10:40:39 -08:00
Paul Lawrence
c4af05f8a3 Revert "Enable seccomp in init with generated policy"
This reverts commit db929bf9b7.

Seccomp is now inserted at the zygote level, not in init

Bug: 34710876
Test: Boots, seccomp policy in zygote & zygote64 but not init
Change-Id: I9075a79793171a4eaccf6228e9ff3398c791f8bd
2017-02-02 09:27:49 -08:00