Commit graph

971 commits

Author SHA1 Message Date
Jeff Sharkey
1635afe83d Only restorecon CE storage after unlocked.
On FBE devices, the filenames inside credential-encrypted directories
are mangled until the key is installed.  This means the initial
restorecon at boot needs to skip these directories until the keys
are installed.

This CL changes the implementation of the "restorecon_recursive"
built-in command to use the new SKIPCE flag to avoid labeling files
in CE directories.  vold will request a restorecon when the keys
are actually installed.

Bug: 30126557
Change-Id: I320584574a4d712c493b5bbd8a79b56c0c04aa58
2016-07-15 16:21:42 -06:00
Mark Salyzyn
109d7d23c5 init: Add support for ${x.y:-default} expansion
commit 00ede7d262 (init: do
expand_props before calling the builtins) broke logpersist

Bug: 28120456
Bug: 22654233
Bug: 28788401
Change-Id: Ib4d8231665b26ac083b02243177493fab41c8978
2016-07-13 23:55:34 +00:00
Tom Cherry
b79e076e5e init: expand arguments of services when they start
Arguments of commands are expanded based on properties if they contain
${property.name}, however this is not currently done for arguments of
services.

This patch makes it that arguments of services are expanded each time
that the service starts at the point immediately before execve().

Bug: 28788401
Change-Id: Iba581a8377e25a6478d4d2ec2e8b29e181d8640c
2016-07-13 23:54:42 +00:00
Yabin Cui
ca4cf4e4af Merge "init: use libbootloader_message." into nyc-mr1-dev 2016-06-30 21:08:30 +00:00
Yabin Cui
0b1252cca0 init: use libbootloader_message.
Bug: 29582118
Change-Id: I6285b29774a11d6dda8496c7c73e4c1d17a672bd
2016-06-29 16:44:02 -07:00
Alex Light
68ab20febd Add umount call to init to unmount a filesystem
Bug: 29278988
Change-Id: Ia14ab1bcad9513688df97f7b4d9162a9ab282480
2016-06-29 17:36:13 +00:00
Paul Crowley
af8be58ca2 Wipe device on policy error
If we fail to set a crypto policy on a system-DE directory, this is a
serious and unrecoverable condition; the only way forward is to erase
the entire device. In a future commit we will also allow users the
option of booting again.

Bug: 28318405
Change-Id: Iff1e52c5bbee1beed29dc4b609d24bfeb7d138da
2016-05-10 11:04:39 -07:00
Nick Kralevich
f2049163a4 init/builtins.cpp: Switch to finit_module
Switch insmod from using init_module to finit_module. From
"man finit_module":

  The finit_module() system call is like init_module(), but reads the
  module to be loaded from the file descriptor fd. It is useful when the
  authenticity of a kernel module can be determined from its location in
  the file system; in cases where that is possible, the overhead of
  using cryptographically signed modules to determine the authenticity
  of a module can be avoided.

finit_module is preferred over init_module because it allows LSMs, such
as SELinux, to perform a permission check on kernel module loads based on
the file from which the module is loaded. This functionality is not yet
implemented in the Linux kernel, but is on the SEAndroid TODO list.
See https://bitbucket.org/seandroid/wiki/wiki/ToDo

Bug: 27824855

(cherry picked from commit 124a9c97e9)

Change-Id: I5e87de1a7b8c3d8849bf757c71b08e81c378b021
2016-05-04 07:01:46 -07:00
Mihai Serban
721c9ce4a5 ueventd: relabel block devices nodes when processing subsequent add events
There is a race in ueventd's coldboot procedure that permits creation
of device block nodes before platform devices are registered. This happens
when the kernel sends events for adding block devices during ueventd's
coldboot /sys walk.
In this case the device node links used to compute the SELinux context
are not known and the node is created under the generic context:
u:object_r:block_device:s0.
A second add event for block device nodes is triggered after the platform
devices are handled by ueventd and the SELinux context is correctly computed
but the mknod call fails because the node already exists. This patch handles
this error case and updates the node's security context.

The race is introduced by the uevent sent from the sdcard device probe
function. The issue appears when this uevent is triggered during ueventd's
coldboot procedure but before the /sys/devices recursive walk reached the
corresponding sdcard platform device path.
The backtrace looks something like:
1. ueventd_main()
2. device_init()
3. coldboot("/sys/devices");
4. do_coldboot()
5. handle_device_fd()
6. handle_device_event()
6.1 handle_block_device_event()
6.2 handle_platform_device_event()

Because handle_device_fd() reads all events from the netlink socket it may
handle the add events for the sdcard partition nodes send occasionally by the
kernel during coldboot /sys walk procedure.
If handle_device_event() continues with handle_block_device_event()
before handle_platform_device_event() registers the sdcard platform device then
handle_block_device_event() will create device nodes without knowing all block
device symlinks (get_block_device_symlinks()):
1. handle_device(path=/dev/block/mmcblk0p3, links = NULL)
2. make_device(path=/dev/block/mmcblk0p3, links = NULL)
3. selabel_lookup_best_match(path=/dev/block/mmcblk0p3, links = NULL)
  returns the default context (u:object_r:block_device:s0) for
  /dev/block/mmcblk0p3 instead of more specific context like:
  u:object_r:boot_block_device:s0
4. setfscreatecon(u:object_r:block_device:s0)
5. mknod(/dev/block/mmcblk0p3)

So the node is create with the wrong context. Afterwards the coldboot /sys walk
continues and make_device() will be called with correct path and links.
But even if the secontext is computed correctly this time it will not be
applied to the device node because mknod() fails.
I see this issue randomly appearing (one time in 10 reboots) on a Minnoboard
Turbot with external sdcard as the boot device.

BUG=28388946

Signed-off-by: Mihai Serban <mihai.serban@intel.com>

(cherry picked from commit 24a3cbfa73)

Change-Id: I2d217f1c8d48553eb4a37457dbf27fff54051cf9
2016-04-28 06:27:39 -07:00
Paul Lawrence
1f99218612 Don't start defaultcrypto twice
The old way (using triggers) starts defaultcrypto twice because
queue_property_triggers_action retriggers the action.

Bug: 27452459
Change-Id: I48c844836f551673d0dbfed6c33bd8ee1e035f40
2016-04-18 15:37:31 -07:00
Elliott Hughes
a3cc602630 Remove undocumented functionality from init.
Bug: http://b/28151340
Change-Id: I5360502c79d9113a13055bf017b39c099033e947
2016-04-12 15:38:51 -07:00
Yabin Cui
46e037980b init: write bootloader message directly.
Bug: 27176738
Change-Id: I8c95a193f3436c0893d5103760b700f3052888db
2016-04-08 11:05:56 -07:00
Mark Salyzyn
402fb79d43 init: turn off backlight when performing shutdown cleanup
(cherry pick from commit a98cc9c202)

Try writing a "0" into:

- /sys/class/leds/lcd-backlight/brightness
- /sys/class/backlight/*/brightness

to turn off the backlight during shutdown cleanup.

Bug: 27506425
Change-Id: Ic8a44dc8909b303f24e14f71cfb43292df60efde
2016-04-05 16:20:59 -07:00
Mark Salyzyn
0fcc2ee4e4 init: watchdog restarted during shutdown fsck
(cherry pick from commit ad575e04a1)

Bug: 27506425
Change-Id: I40967068d18ce1a8cbaf0b750e7a7af6eab3e4e8
2016-04-05 12:44:24 -07:00
dcashman
9261ad13ed init: Fix typo.
Bug: 27681085
Change-Id: I4308435a5b58189852c991d1bec65ed11933566a
2016-03-22 16:04:26 -07:00
dcashman
69022e03d8 Temporarily add set_mmap_rnd_bits brillo exception
Bug: 27794137
Change-Id: Idc6fc1e208bdb19556173d40215feb66e235c6d6
2016-03-22 15:18:29 -07:00
dcashman
5d36813dc8 Set mmap_rnd_bits to maximum value.
Also make sure it is above a minimum threshold, else abort.

Bug: 27681085
Change-Id: Id03ede491e5e013a2a7a090abb306d00cb74f901
2016-03-22 12:11:51 -07:00
Paul Lawrence
1098aacde4 Distinguish between unencrypted and unencryptable
Set ro.crypto.state flag to unencrypted and unsupported accordingly

Bug: 18002358
Change-Id: I1f88ce9704c5505d7b63256e2ebe5f8441c79ad0
2016-03-04 15:52:33 -08:00
Nick Kralevich
ab5629c197 init: harden socket creation against symlinks
Instead of using chown, use the symlink safe lchown.

Instead of using chmod, use the symlink safe fchmodat
with AT_SYMLINK_NOFOLLOW.

Fix a bug where the SELinux filesystem creation context may
not be restored, and some memory not freed, if bind() fails.

Check the return values from the chown/chmod calls and unlink
the files if it ever fails.

Bug: 27337831
Change-Id: I3343786f5a4eefda7bbb8317f2eca16bd21003c0
2016-02-24 15:50:52 -08:00
Jeff Sharkey
c895f11cf1 Merge "User 0 directories are created by vold now." 2016-02-05 21:01:21 +00:00
Elliott Hughes
be49484810 Merge "init: fix writepid wrong pid written in file(s)" am: 718625010d
am: 880200c9bb

* commit '880200c9bbf8b283b0f6351c1c052bc00d69697d':
  init: fix writepid wrong pid written in file(s)
2016-02-05 19:06:37 +00:00
Anestis Bechtsoudis
b702b46f68 init: fix writepid wrong pid written in file(s)
When child (pid==0) executes fork branch 'pid_str'
will always be 0 writting wrong value to file(s).
Fix by utilizing getpid() to obtain correct pid.

Tracker link provides some insight on why use cases
aren't broken.

Bug: https://code.google.com/p/android/issues/detail?id=200392

Change-Id: I29989365a8bac94502c090918fa30e5cc88eb1ea
Signed-off-by: Anestis Bechtsoudis <anestis@census-labs.com>
2016-02-05 16:49:28 +02:00
Jeff Sharkey
3b9c83a0f6 User 0 directories are created by vold now.
This ensures that all users on device follow a consistent path for
setup and validation of encryption policy.

Also add remaining user-specific directories and fix linking order.

Bug: 25796509
Change-Id: I8c2e42a78569817f7f5ea03f54b743a6661fdb9c
2016-02-04 15:26:23 -07:00
Paul Lawrence
1446f0f318 Merge "Remove code to handle non-default file encryption" 2016-02-02 23:16:02 +00:00
Elliott Hughes
edbc3af294 Merge "init: Fix load_firmware error" am: f330e5462d
am: de0af89c82

* commit 'de0af89c8253ecda179c35cb8c62c592b91e46ae':
  init: Fix load_firmware error
2016-02-02 22:54:32 +00:00
Paul Lawrence
69080180ce Remove code to handle non-default file encryption
Change-Id: I6d986853929c0237c0d958329b8e9aab47907a00
2016-02-02 10:34:40 -08:00
Paul Crowley
5949745534 On FDE devices, initialize user 0
Fix ugly special cases for user 0: initialize them explicitly.

Bug: 26704408
Change-Id: I1b8536b9e5e87ea98b4009a309f2e22c56006651
2016-02-01 16:44:46 +00:00
Biao Lu
dc848566a1 init: Fix load_firmware error
In function 'load_firmware', parameter 'buf' passed to 'write'
is wrong. To fix it, use android::base::WriteFully to replace.

Change-Id: I13f79bdc9be9e5eb669f6bd975535b1dce965ef0
Signed-off-by: Biao Lu <biao.lu@intel.com>
2016-02-01 10:10:28 +08:00
Tom Cherry
6ddde53e8e Merge "init: Update readme.txt to reflect recent changes to init" am: d401eba04c
am: 9262e5fdcd

* commit '9262e5fdcd77e296bd71dbc1c9448a347a851789':
  init: Update readme.txt to reflect recent changes to init
2016-01-25 18:22:24 +00:00
Tom Cherry
1fb20b8377 init: Update readme.txt to reflect recent changes to init
Best practice for services that reside on the system, vendor, and odm
partitions is to have a corresponding init .rc file in the
/{system,vendor,odm}/etc/init directory, which contains its service
entry and any related actions.

Change-Id: I26204f9a0f09ce8069f3791ccd9ee61d164a048f
2016-01-23 05:23:39 +00:00
Paul Crowley
65f54a8e19 Merge "Remove no-longer-needed crypto init builtins" 2016-01-21 11:16:33 +00:00
Hung-ying Tyan
25778dcf5e Merge "Allow paths of .rc files to be specified at mount_all" am: e7f9779886
am: 436a8aa9de

* commit '436a8aa9de9c90a8ee95e02e97bf65e50c80d4f4':
  Allow paths of .rc files to be specified at mount_all
2016-01-21 05:05:09 +00:00
Hung-ying Tyan
e7f9779886 Merge "Allow paths of .rc files to be specified at mount_all" 2016-01-21 04:12:23 +00:00
Hung-ying Tyan
dc738eaf15 Allow paths of .rc files to be specified at mount_all
In current implementation, the mount_all command imports all .rc files
under /{system,vendor,odm}/etc/init/ after mouting filesystems is complete.
There's a need from ODMs to import different .rc files under different boot
modes (e.g., factory mode). Without this support, they will have to fiddle
around the init implementation.

This commit makes mount_all import the .rc files/directories specified
as additional arguments. If no path is given, the original ones are applied
the same way as the current implementation.

BUG: 26549689
Change-Id: Ie67ce13dde4c440ff8bf534826bc392c882a433f
2016-01-21 09:35:43 +08:00
Paul Crowley
558d8f4364 Remove no-longer-needed crypto init builtins
Changes to the way FBE works to support lifecycles mean that these
commands aren't needed any more.

Bug: 22358539
Change-Id: Id73339e0aa8070dd688f35b5d59de75236961395
2016-01-20 11:20:23 +00:00
Nick Kralevich
974bf66088 Merge "logging: avoid unnecessary printfs" am: 542a511f87
am: 5644112b7e

* commit '5644112b7e05372fcda105fa621630c12ec29a6e':
  logging: avoid unnecessary printfs
2016-01-19 18:10:37 +00:00
Nick Kralevich
5db8d6aafa logging: avoid unnecessary printfs
Don't spend CPU cycles formatting a bunch of strings if we're
just going to throw them away later. Maybe make booting faster.

Change-Id: I4d8eb99fb3fa873ca91cf776933d0ad01988abf5
2016-01-16 16:20:24 -08:00
Tom Cherry
363d7cc205 Merge "Remove special case handling of "ro." properties permissions" am: b45f8179be
am: 44e06f5f00

* commit '44e06f5f00c3e0412c85ee5f515ccd0f83abbbc2':
  Remove special case handling of "ro." properties permissions
2016-01-13 18:52:19 +00:00
Tom Cherry
c787cf291a Remove special case handling of "ro." properties permissions
Currently, properties that begin with "ro." are special cased to skip
over the "ro." part of the prefix before matching with entries in
property_contexts.  This is not strictly needed however and it is
causing complications with the separated prop files work from Bug
21852512, so it is now removed.

Bug 26425619

Change-Id: I3cd14fa2176f96b3931e5f6a50c4a7bcd3af3da6
2016-01-11 14:00:40 -08:00
Colin Cross
51aaecea35 Merge "libinit: depend on libselinux" am: 710056efb8
am: f97f11f8c1

* commit 'f97f11f8c14e3efbd3e3840ba8ba1ea8c027e8f7':
  libinit: depend on libselinux
2016-01-08 20:57:18 +00:00
Bertrand Simonnet
530c8c75e2 Merge "init: Allows shutting down cleanly." am: f9f4ee8b72
am: a8c931b7f5

* commit 'a8c931b7f57c8ce74f520d591e99bb367f91dc81':
  init: Allows shutting down cleanly.
2016-01-08 20:54:11 +00:00
Colin Cross
710056efb8 Merge "libinit: depend on libselinux" 2016-01-08 20:49:42 +00:00
Bertrand SIMONNET
b7e03e82b8 init: Allows shutting down cleanly.
When ro.build.shutdown_timeout is set, init will send a SIGTERM signal to
all services on reboot. The normal shutdown process will continue once
all services have exited or after the shutdown timeout
(ro.build.shutdown_timeout).

If ro.build.shutdown_timeout is not set, we assume a 0s timeout.

Bug: 26216447
Test: manual: Ask to reboot. All services exit cleanly.

Change-Id: If921f6e8d87211e500ac9fa86f3e1eabe02d18cf
2016-01-08 11:12:15 -08:00
Colin Cross
c1caf88f25 libinit: depend on libselinux
libinit uses headers from libselinux, add a LOCAL_STATIC_LIBRARIES
dependency.

Change-Id: I6b0a3183058c8593ef40e58abbf2d72bcce59e95
2015-12-21 16:14:08 -08:00
Tom Cherry
bcac4a98d4 Merge "Update init documentation to reflect fs_config changes" am: b11afd7741
am: 80625ed1c3

* commit '80625ed1c3674ab8abf56a7bacd5151215215020':
  Update init documentation to reflect fs_config changes
2015-12-11 14:19:10 -08:00
Tom Cherry
dbddb40c95 Update init documentation to reflect fs_config changes
Change-Id: I00296d90c44af369a51ecb5cbb667567328f0053
2015-12-11 13:20:38 -08:00
Sami Tolvanen
6401e61a6a Merge "Set up dm-verity in EIO mode instead of logging mode" am: 0d1214c68e
am: 42a86f8d1e

* commit '42a86f8d1e918356e86d4eb3fb2444a8c42d25ff':
  Set up dm-verity in EIO mode instead of logging mode
2015-12-10 15:43:02 -08:00
Sami Tolvanen
0d1214c68e Merge "Set up dm-verity in EIO mode instead of logging mode" 2015-12-10 20:12:49 +00:00
Paul Lawrence
c5733cfadb Add createuserkey
Needed so we can make the user0 key on first boot

Change-Id: I4699dbf2efdec44bb09bc4cfa7eeb59e56cb93ab
2015-12-09 15:34:18 -08:00
Sami Tolvanen
9e9efcadc5 init: set ro.boot.flash.locked from ro.boot.verifiedbootstate
If ro.oem_unlock_supported is specified for the device and it supports
verified boot, export lock status in ro.boot.flash.locked.

Bug: 26039090
Change-Id: Ie7844aeb458c97944c72d46ea962b9cfb0a7875d
2015-12-09 10:09:11 +00:00