Commit Graph

2192 Commits

Author SHA1 Message Date
Tom Cherry c49719fc5d init: always expand args in subcontext
Currently init expands properties in arguments only when those
commands are run in a subcontext.  This creates a hole where
properties that should not be accessible from a given subcontext of
init can be accessed when running a command in the main init
executable (for example `start`).

This change creates a callback in subcontext init that simply expands
and returns arguments back to the main init process, to ensure that
only those properties that a subcontext can access get expanded.

Bug: 62875318
Test: boot bullhead, new unit tests
Change-Id: I2850009e70da877c08e4cc83350c727b0ea98796
2018-01-12 10:35:26 -08:00
Tom Cherry 919458c350 Create a host side checker for property info file correctness
Bug: 36001741
Test: verify a valid property info file and fail due to various failures
Change-Id: Iadd38796aa619f87ec559fe5687bbe2009df8b2d
2018-01-04 22:00:11 +00:00
Dong Jinguang bb877e273b system property: property set without time spent asleep
There is a 2s timeout for system property set that currently
uses boot_clock as its clock source. If the system goes to sleep
during a property set, it may erroneously cause the timeout to
be reached as boot_clock increments during sleep. This patch
changes from boot_clock to steady_clock to ignore time spent
asleep when determining this timeout.

bug: 71497234
Test: 1. System service process try to set a system property
      with timeout 2s
      2. At the same time, the system go into sleep mode more
      than 2s
      3. System property set will be ok.

Change-Id: I808b9af16974a0f4de60a4ca30ae64d095a13422
2018-01-04 09:35:40 +08:00
Elliott Hughes 579e682628 Add std::string StartsWith*/EndsWith* overloads.
We should have done this from the beginning. Thanks to Windows, we're not
going to be able to switch libbase over to std::string_view any time soon.

Bug: N/A
Test: ran tests
Change-Id: Iff2f56986e39de53f3ac484415378af17dacf26b
2017-12-20 09:42:22 -08:00
Tom Cherry 2ae2f606f8 Reland "Have property_service create a serialized property_contexts file"
This reverts commit 9822f3c6cc.

Bug: 36001741
Change-Id: I27dd391fc06a3c78e88a65c7931c84de1699f157
2017-12-14 01:58:17 +00:00
Robert Greenwalt 9822f3c6cc Revert "Have property_service create a serialized property_contexts file"
This reverts commit e8181c0f55.

Reason for revert: This is broken.

Bug: 36001741

Change-Id: I458abc23275ecdfadcabacd611b288449196efa0
2017-12-13 14:42:26 -08:00
Tom Cherry c47dd6b5c0 Merge changes from topic "property-trie"
* changes:
  Have property_service create a serialized property_contexts file
  Parse property contexts via a serialized trie
2017-12-13 01:28:36 +00:00
Tom Cherry e8181c0f55 Have property_service create a serialized property_contexts file
Instead of requiring each process to parse the property contexts files
in libc initialization, this change has property_service parse these
files one into a serialized trie, which the property code in libc can
then directly interpret for mapping property names to their associated
SELinux context.

Bug: 36001741
Test: boot bullhead, walleye, run unit tests

Change-Id: If67073d56e800b3ca667fb5322e6b993e7d810f6
2017-12-11 16:12:13 -08:00
Jaegeuk Kim ec87074542 Merge changes from topic "sload_f2fs"
* changes:
  fastboot/fs_mgr/init: add sload_f2fs
  fs_mgr: format f2fs with length=xx fstab
2017-12-08 00:57:42 +00:00
Elliott Hughes 3289b9c928 Merge "Add OWNERS." 2017-12-07 23:21:26 +00:00
Elliott Hughes 693d63f9cf Add OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ie785058c0f5eb9b4086c98ccba6e63e3ed411b65
2017-12-07 13:30:03 -08:00
Jaegeuk Kim 899ad558cd fastboot/fs_mgr/init: add sload_f2fs
Change-Id: Iab1e4037cbb835aba97f941c8840b8971caf38e7
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-12-06 22:40:08 -08:00
Alin Jerpelea 4a33cee3f8 Merge "Allow firmware loading from ODM partition"
am: 5b78366665

Change-Id: Ic7c19c97598fc4087af9a1b7fcc28d5ed0600558
2017-12-06 04:10:02 +00:00
Alin Jerpelea b398ac859c Allow firmware loading from ODM partition
ODM partition may contain firmware and we should allow
firmware loading from this partition

Test: firmware is loaded succesfully
Change-Id: I7d327bc79a04d1a2dee0fd47407eb53f9d391665
Signed-off-by: Alin Jerpelea <alin.jerpelea@sonymobile.com>
2017-12-04 16:22:15 +01:00
Bowgo Tsai 43da9ee604 Merge "init/selinux: renames nonplat_declaration.cil to plat_pub_versioned.cil"
am: d06a0c035b

Change-Id: I9d5f5c441dc3669417787f69116f6e332807d337
2017-12-01 05:06:43 +00:00
Treehugger Robot d06a0c035b Merge "init/selinux: renames nonplat_declaration.cil to plat_pub_versioned.cil" 2017-12-01 05:02:47 +00:00
Joel Galenson 80d2fdcac7 Merge "Run restorecon after init creates a symlink or writes to a file."
am: c02b92a923

Change-Id: I06d9c5cdefa732ae2094d389678980e597a89c4c
2017-11-30 17:34:25 +00:00
Treehugger Robot c02b92a923 Merge "Run restorecon after init creates a symlink or writes to a file." 2017-11-30 17:30:17 +00:00
Joel Galenson 4b591f1851 Run restorecon after init creates a symlink or writes to a file.
Init currently sets the SELinux context on a mkdir but not on
other operations.  This patch modifies it to do so when creating
symlinks, writing to a file, or copying a file.

Test: Built, flashed, and booted.  Added fake init entries and
verified that they received the proper SELinux context.

Change-Id: I836b570fef81d74f3b6c8e7ce0274e94ca7b12d3
2017-11-29 15:29:49 -08:00
Bowgo Tsai 069ab5bd1a init/selinux: renames nonplat_declaration.cil to plat_pub_versioned.cil
The content of nonplat_declaration.cil in /vendor is a versioned public
sepolicy exported from ${AOSP}/system/sepolicy/public. Renames it to
better reflect the fact.

Bug: 64240127
Test: boot sailfish normally without odm
Test: boot another device having odm
Change-Id: I654f5bbde2f2d666a2a5c7ed8561ccd93c983a6e
2017-11-29 18:13:10 +08:00
Tom Cherry a3f19e0261 Merge "Revert "init: use ro.init.subcontexts_enabled to enable subcontexts""
am: f71a3d66b3

Change-Id: I79914c7f7757caa24b024cb33a6d454275704548
2017-11-27 23:00:22 +00:00
Tom Cherry f71a3d66b3 Merge "Revert "init: use ro.init.subcontexts_enabled to enable subcontexts"" 2017-11-27 22:54:45 +00:00
Luis Hector Chavez 289c1f3468 Merge "init: Drop inheritable capabilities when switching uids"
am: a227804015

Change-Id: I2d720e330e7043434e198ef455a8f340dd57b95d
2017-11-27 21:37:16 +00:00
Tom Cherry 193e43494f Revert "init: use ro.init.subcontexts_enabled to enable subcontexts"
This reverts commit 79193a42e7.

Bug: 62875318
Test: boot walleye, sailfish without SELinux audits
Change-Id: I019b66a3130acba2c07e984e4bc352228f09d7f5
2017-11-27 09:03:28 -08:00
Luis Hector Chavez 94fb5b0bef init: Drop inheritable capabilities when switching uids
This change explicitly drops all inheritable capabilities (and, by
extension, ambient capabilities) when there are no explicit capabilities
being set by a service and the user is changed. This prevents Android
running in a container from accidentally granting extra capabilities to
services.

Bug: 69320306
Test: aosp_sailfish still boots
Test: sailfish:/ $ grep Cap /proc/`pidof android.hardware.audio@2.0-service`/status
      CapInh: 0000000000000000
      CapPrm: 0000000000000000
      CapEff: 0000000000000000
      CapBnd: 0000003fffffffff
      CapAmb: 0000000000000000
Test: sailfish:/ $ grep Cap /proc/`pidof logd`/status
      CapInh: 0000000000000000
      CapPrm: 0000000440000000
      CapEff: 0000000440000000
      CapBnd: 0000003fffffffff
      CapAmb: 0000000000000000
Test: Android in Chrome OS still boots
Test: localhost ~ # grep Cap /proc/`pidof android.hardware.audio@2.0-service`/status
      CapInh: 0000000000000000
      CapPrm: 0000000000000000
      CapEff: 0000000000000000
      CapBnd: 000000006daefdff
      CapAmb: 0000000000000000
Test: localhost ~ # grep Cap /proc/`pidof logd`/status
      CapInh: 0000000000000000
      CapPrm: 0000000040000000
      CapEff: 0000000040000000
      CapBnd: 000000006daefdff
      CapAmb: 0000000000000000

Change-Id: I9218f2e27ff4fb4d91d50f9a98c0fdb4e272952c
2017-11-17 09:11:37 -08:00
Steven Moreland 864a1baa0f Merge changes from topic "b69050941"
am: 37eb97d911

Change-Id: Icdfc3e160b2ae1d2dc63c1d86c1a75a199fdf1c0
2017-11-15 21:49:19 +00:00
Steven Moreland 6f5333a4a9 Allow a service to override another.
For instance, on vendor.img:
service foo /vendor/bin/nfc
    ...

And then on odm.img:
service foo /odm/bin/super-nfc
    override

Allows a service on ODM to override a HAL on vendor.

Bug: 69050941
Test: boot, init_tests
Change-Id: I4e908fb66e89fc6e021799fe1fa6603d3072d62a
2017-11-15 10:39:29 -08:00
Steven Moreland 5e1bea30b9 Move service name duplication lookup to EndSection
This is paving the way to allow an "override" tag
in init services. This also means that errors for
part of a service definition in its section will
be shown in addition to the fact that the service
is duplicated.

Bug: 69050941
Test: boot, init_tests
Change-Id: Ic1ea8597789f45ead1083451b3e933db1524bdc9
2017-11-15 10:39:29 -08:00
Steven Moreland 7d0a5c3656 EndSection returns Result<Success>
Allow it to fail. When there is an error for a section ending,
print the error pointing to the line where the section starts.

Bug: 69050941
Test: boot, init_tests
Change-Id: I1d8ed25f4b74cc9ac24d38b8075751c7d606aea8
2017-11-15 10:39:29 -08:00
Steven Moreland b480d441ac Fix out of date SectionParser comment.
It has since been refactored with different
return types.

Bug: 69050941
Test: boot, init_tests
Change-Id: I54c0e6745640136f060ba1876b2f26d95bddc9d6
2017-11-14 13:47:59 -08:00
Xin Li 23e27db576 Merge commit 'a63ccea6abc7ea02e2d98e41c80793ca97237bd3' from
oc-mr1-dev-plus-aosp into stage-aosp-master

Change-Id: Ia33311cd1fd26dfaea59a69317b306fb91203c40
Merged-In: I03d06b10807e8a313c9654c2e1db36bfb59e3f99
2017-11-14 13:19:45 -08:00
Bowgo Tsai ec19cf6306 first stage mount: abort when failed to parse fstab in device-tree
The client of FirstStageMount class should check the existence of fstab
in device-tree prior to using it. So raising a FATAL error inside
FirstStageMount when failed to parsing the fstab, in order to expose
more accurate error messages.

Also fixing a comment in fs_mgr, where it might happen in either
non-A/B or A/B.

Bug: 69102431
Test: boot sailfish
Change-Id: Ifb525beaa3423b118644778bfe0f84bff9465303
2017-11-10 12:53:46 +08:00
Chih-Hung Hsieh 122352d983 Use -Werror in system/core
* Move -Wall -Werror from cppflags to cflags.
* Fix/suppress warning on unused variables.

Bug: 66996870
Test: build with WITH_TIDY=1
Change-Id: I1e05e96a1d0bcb2ccef1ce456504b3af57167cc5
2017-11-01 11:32:55 -07:00
Tao Wu ee14225e0d Merge "Fix race condition between restart and stop/reset." 2017-10-27 21:32:51 +00:00
Tao Wu 84b856d901 Fix race condition between restart and stop/reset.
If there is a restart follow a stop/reset immediately or vice versa,
clear previous flag bits.

Test: manual - trigger restart after stop immediately to check if
service get started.

Change-Id: I4503177d7cb5ed054dbcf50cd8e09728415404d4
2017-10-27 11:31:42 -07:00
Tao Wu 876b13d0ec Merge "Fix one race condition between start and stop." 2017-10-26 22:48:51 +00:00
Tao Wu 990d43cb82 Fix one race condition between start and stop.
For a oneshot service, if start happens immediately after stop,
the service could be still in stopping status and then start
won't do anything. This fix this race condition.

Test: manual - see reproduce instructions in bug.
Bug: 68020256
Change-Id: I20202fa346f1949a8bda3d90deedc8b6a6d814d3
2017-10-26 22:08:56 +00:00
Treehugger Robot 03d67dd99e Merge "init: fixed issues related to forking services" 2017-10-26 18:38:23 +00:00
Joe Tanen 4bfdcb3932 init: fixed issues related to forking services
Fixed issues related to forking services into new PID + mount
namespaces.

Remounting rootfs recursively as slave when creating a service in new
PID + mount namespaces. This prevents the service from interfering with
mount points in the parent namespace.

Unmount then mount /proc instead of mounting it with MS_REMOUNT, since
MS_REMOUNT is not sufficient to update /proc to the state appropriate
for the new PID namespace. Note that the /proc mount options specified
here are not the same as those used in the default mount namespace. I
kept them consistent with those used in the code prior to this fix.

Test: Used custom sleepd service to test init 'namespace' keyword.
Tested on angler in oreo-dev - I had to add PID namespaces to the
kernel (commit ad82c662).

Change-Id: I859104525f82fef3400d5abbad465331fc3d732f
2017-10-26 09:08:11 -07:00
Treehugger Robot 0f2097c0f0 Merge "Don't use TEMP_FAILURE_RETRY on close()" 2017-10-24 19:47:20 +00:00
Nick Kralevich 3d118e72dd Don't use TEMP_FAILURE_RETRY on close()
See https://lkml.org/lkml/2005/9/10/129 for details.

Bug: 20501816
Test: code compiles and boots with no obvious problems.
Change-Id: I5a9c470156d498852cfd81fbd59ddcf267309e73
2017-10-24 10:46:34 -07:00
Wei Wang 121ff413ef Merge "init: call umount unconditionally"
am: b409e5e00b

Change-Id: I9eb45b728145301418b9d7775067ce298551f063
2017-10-24 02:13:43 +00:00
Wei Wang 25dc30f3be init: call umount unconditionally
std::all_of is using std::find_if, which means, if any element the given
predicate returns false, it stops further iteration and just returns false.
std::all_of used in Reboot.cpp will cause umount not to be called on all
block devices if some block device returns false in the middle.

Bug: 68158923
Test: reboot
Change-Id: I43ba6bd0c18018c1ed5fe2b63996552bc51cc67c
2017-10-23 16:25:31 -07:00
Tom Cherry be96bdb09d Merge "init: clean up subcontext_test"
am: 4e2a8e375e

Change-Id: I0ab7401d36d32c5e0df7dc68286117a1ac60d2f8
2017-10-20 14:40:02 +00:00
Tom Cherry 4e2a8e375e Merge "init: clean up subcontext_test" 2017-10-20 14:36:31 +00:00
Steven Moreland fea6f56069 Merge "init language extension for lazy HIDL services."
am: 0f40200577

Change-Id: I7b42d2b6af8c9d53a7adb97643d040037ab96b00
2017-10-20 06:43:34 +00:00
Treehugger Robot 0f40200577 Merge "init language extension for lazy HIDL services." 2017-10-20 06:38:42 +00:00
Steven Moreland e055d73396 init language extension for lazy HIDL services.
This associates every service with a list of HIDL services
it provides. If these are disabled, hwservicemanager will
request for the service to startup.

Bug: 64678982
Test: manual with the light service
Change-Id: Ibf8a6f1cd38312c91c798b74574fa792f23c2df4
2017-10-19 20:38:47 -07:00
Tom Cherry f0b4e4daee Merge "init: add SelabelInitialize() for subcontext"
am: cba7f57119

Change-Id: I0ea0c99c5848aeaa5fd463e347bd76c5b471b7ef
2017-10-20 00:54:39 +00:00
Tom Cherry 0d1452ee1b init: add SelabelInitialize() for subcontext
Children of init that use any of the SELinux wrapper functions,
including make_dir(), mkdir_recursive(), and plenty others, need to
first initialize the sehandle with SelabelInitialize().

I wish there were a better solution, but early init doesn't actually
want this handle initialized, so that is a valid use case.  Ueventd
needs to initialize this before fork()'ing, so lazy initialization is
not universally acceptable either.  Likely we won't have other
children that fork() then exec() init again, so this should be okay.

Bug: 62875318

Test: init unit tests
Test: sailfish creates directories with correct SELabel after wipe
Change-Id: I6de937604a060e18945427418f15b90e0b9d5c37
2017-10-19 16:25:45 -07:00