Commit graph

3703 commits

Author SHA1 Message Date
Bart Van Assche
ee36ba39f9 Fix a race condition in Service::Start()
The SetTaskProfiles() call modifies cgroup attributes. Modifying cgroup
attributes can only succeed after the cgroups and cgroup attributes have
been created. Hence this patch that makes the child process wait until
the parent has finished creating cgroups and activating cgroup
controllers.

Bug: 213617178
Test: Without this patch the migration to the v2 hierarchy does not work reliably. With this patch applied, the migration to the v2 hierarchy works reliably.
Change-Id: I80a7c0a35453d8fd89ed798d077086aa8ba9ea17
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-02-15 22:31:09 +00:00
Justin Yun
d1e4f7d157 Update ro.vendor.api_level for non-GRF devices
Non-GRF devices must read only the `ro.product.first_api_level` but
not the vendor build version because `ro.product.first_api_level` is
always less than or equal to `ro.vendor.build.version.sdk` for
non-GRF devices.

Bug: 218610653
Test: getprop ro.vendor.api_level
Change-Id: Ib98c33ae052daa949208c43bd441f98cf442da49
2022-02-11 09:44:31 +09:00
Treehugger Robot
eb710bfa72 Merge "Revert "Revert "Use Apex sepolicy if it's available""" 2022-02-08 14:47:43 +00:00
Jeffrey Vander Stoep
baeece6d0c Revert "Revert "Use Apex sepolicy if it's available""
This reverts commit 5638fcc22b.

Reason for revert: Root cause of b/217252559 fixed.

Change-Id: I8d2fbf0cab23a56dbea1f422608097c48d9288c0
2022-02-08 12:42:33 +00:00
Treehugger Robot
c75044d639 Merge changes from topic "system_dlkm_dynamic"
* changes:
  system_dlkm: Fix flag for mount point guard
  system_dlkm: load property for dynamic partition
2022-02-02 06:04:07 +00:00
Ramji Jiyani
8431328d96 system_dlkm: load property for dynamic partition
Load from: /system_dlkm/etc/build.prop

Bug: 200082547
Test: TH
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
Change-Id: I9c34c44fc969107b215c05ed9b0ed779683a30b6
2022-02-02 02:34:46 +00:00
Jeffrey Vander Stoep
2e7bc19fc2 Merge "Revert "Use Apex sepolicy if it's available"" 2022-02-01 12:42:11 +00:00
Jeffrey Vander Stoep
5638fcc22b Revert "Use Apex sepolicy if it's available"
Revert "Build precompiled_sepolicy.apex_sepolicy.sha256"

Revert submission 1965099-precompiled-apex-sepolicy

Reason for revert: Boot regression b/217252559
Reverted Changes:
I2dbe43e32:Use Apex sepolicy if it's available
Bug: 217252559

Change-Id: I1cca3a1ae833c21619de26b2610736170ec5463c
2022-02-01 11:21:38 +00:00
Treehugger Robot
d15b09f187 Merge "init: remove debug logging." 2022-01-31 23:54:48 +00:00
Elliott Hughes
0305cf0f19 init: remove debug logging.
I think this was left in by accident?

Test: treehugger
Change-Id: Ie954efe33f1f811f58c9df4934d50caf0f79e0ea
2022-01-31 13:03:29 -08:00
Treehugger Robot
1412fee4a8 Merge "Use Apex sepolicy if it's available" 2022-01-31 09:11:05 +00:00
Jeff Vander Stoep
2e4b3ffa75 Use Apex sepolicy if it's available
[reland aosp/1910032]

Updatable sepolicy is shipped within an zip within an APEX. Because
it needs to be available before Apexes are mounted, apexd copies
the zip from the APEX and stores it in /metadata/sepolicy. If there is
not updatable sepolicy in /metadata/sepolicy, then updatable policy is
loaded from /system/etc/selinux/apex. Init performs the following
steps on boot:

1. Validates the zip by checking its signature against a public key
that is stored in /system/etc/selinux.
2. Extracts files from zip and stores them in /dev/selinux.
3. Checks if the apex_sepolicy.sha256 matches the sha256 of
precompiled_sepolicy. if so, the precompiled sepolicy is used.
Otherwise, an on-device compile of the policy is used. This is the
same flow as on-device compilation of policy for Treble.
4. Cleans up files in /dev/selinux which are no longer needed.
5. Restorecons the remaining files in /dev/selinux.
6. Sets selinux into enforcing mode and continues normal booting.

Bug: 199914227
Test: adb root
adb shell cp /apex/com.android.sepolicy.apex/etc/SEPolicy-33.zip \
/metadata/sepolicy/SEPolicy.zip
adb shell cp /apex/com.android.sepolicy.apex/etc/SEPolicy-33.zip.sig \
/metadata/sepolicy/SEPolicy.apk.sig
adb shell cp /apex/com.android.sepolicy.apex/etc/SEPolicy-33.zip.fsv_sig \
/metadata/sepolicy/SEPolicy.zip.fsv_sig
adb reboot
ls -laZ /dev/selinux/
Verify that files exist and that the labels are expected.

Change-Id: I2dbe43e329e91f46abedc7e44f7d24b220e19173
2022-01-28 13:47:24 +01:00
Jeffrey Vander Stoep
acd4121dbc Merge "Revert "Use Apex sepolicy if it's available"" 2022-01-27 18:04:28 +00:00
Jeffrey Vander Stoep
9759e248d1 Revert "Use Apex sepolicy if it's available"
This reverts commit 97ff3ab852.

Reason for revert: b/216491364 boot time regression

Bug: 216491364
Change-Id: I6c9af0887affa130cc61edf70506e79453dbd228
2022-01-27 17:49:40 +00:00
Treehugger Robot
71f3bfab23 Merge "Use Apex sepolicy if it's available" 2022-01-26 08:53:08 +00:00
Jeff Vander Stoep
97ff3ab852 Use Apex sepolicy if it's available
Updatable sepolicy is shipped within an zip within an APEX. Because
it needs to be available before Apexes are mounted, apexd copies
the zip from the APEX and stores it in /metadata/sepolicy. If there is
not updatable sepolicy in /metadata/sepolicy, then updatable policy is
loaded from /system/etc/selinux/apex. Init performs the following
steps on boot:

1. Validates the zip by checking its signature against a public key
that is stored in /system/etc/selinux.
2. Extracts files from zip and stores them in /dev/selinux.
3. Checks if the apex_sepolicy.sha256 matches the sha256 of
precompiled_sepolicy. if so, the precompiled sepolicy is used.
Otherwise, an on-device compile of the policy is used. This is the
same flow as on-device compilation of policy for Treble.
4. Cleans up files in /dev/selinux which are no longer needed.
5. Restorecons the remaining files in /dev/selinux.
6. Sets selinux into enforcing mode and continues normal booting.

Bug: 199914227
Test: adb root
adb shell cp /apex/com.android.sepolicy.apex/etc/SEPolicy-33.zip \
/metadata/sepolicy/SEPolicy.zip
adb shell cp /apex/com.android.sepolicy.apex/etc/SEPolicy-33.zip.sig \
/metadata/sepolicy/SEPolicy.apk.sig
adb shell cp /apex/com.android.sepolicy.apex/etc/SEPolicy-33.zip.fsv_sig \
/metadata/sepolicy/SEPolicy.zip.fsv_sig
adb reboot
ls -laZ /dev/selinux/
Verify that files exist and that the labels are expected.

Change-Id: I614e8d84892693ecc663b17eebd204096367693d
2022-01-25 10:27:00 +01:00
Akilesh Kailash
fd5562b0a5 init: Wait for snapuserd before starting second stage
This is a race between init process and bionic libc initialization of
snapuserd.

init->fork() ----------------> SecondStageMain() -> PropertyInit()
       |
       |
       v
      execveat ---> __libc_init_common() -> __system_properties_init()
     (snapuserd)

When init process calls PropertyInit(), /dev/__properties__ directory
is created. When bionic libc of snapuserd daemon invokes __system_properties_init
_after_ init process PropertyInit() function is invoked, libc will
try to initialize the property by reading
/system/etc/selinux/plat_property_contexts. Since any reads on /system
has to be served by snapuserd, this specific read from libc cannot be
serviced leading to deadlock.

Reproduce the race by inducing a sleep of 1500ms just before execveat()
so that init process calls PropertyInit() before bionic libc
initialization. This leads to deadlock
immediately and with additional kernel instrumentation with debug
logs confirms the failure:

======================================================
init: Relaunched snapuserd with pid: 428
ext4_file_open: SNAPUSERD: path /system/etc/selinux/plat_property_contexts - Pid: 428 comm 8
ext4_file_read_iter: SNAPUSERD for path: /system/etc/selinux/plat_property_contexts pid: 428 comm 8

[   25.418043][  T428]  ext4_file_read_iter+0x3dc/0x3e0
[   25.423000][  T428]  vfs_read+0x2e0/0x354
[   25.426986][  T428]  ksys_read+0x7c/0xec
[   25.430894][  T428]  __arm64_sys_read+0x20/0x30
[   25.435419][  T428]  el0_svc_common.llvm.17612735770287389485+0xd0/0x1e0
[   25.442095][  T428]  do_el0_svc+0x28/0xa0
[   25.446100][  T428]  el0_svc+0x14/0x24
[   25.449825][  T428]  el0_sync_handler+0x88/0xec
[   25.454343][  T428]  el0_sync+0x1c0/0x200

=====================================================

Fix:

Before starting init second stage, we will wait
for snapuserd daemon to be up and running. We do a simple probe by
reading system partition. This read will eventually be serviced by
daemon confirming that daemon is up and running. Furthermore,
we are still in the kernel domain and sepolicy has not been enforced yet.
Thus, access to these device mapper block devices are ok even though
we may see audit logs.

Note that daemon will re-initialize the __system_property_init()
as part of WaitForSocket() call. This is subtle but important; since
bionic libc initialized had failed silently, it is important
that this re-initialization is done.

Bug: 207298357
Test: Induce the failure by explicitly delaying the call of execveat().
      With fix, no issues observed.
      Tested incremental OTA on pixel ~15 times.
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I86c2de977de052bfe9dcdc002dcbd9026601d0f3
2022-01-25 08:30:08 +00:00
Kelvin Zhang
a2544adbb4 Convert perfboot.py to python3
Change-Id: I29c06888b84c2b00455884bca8e5d4dd9209057c
2022-01-21 13:53:19 -08:00
David Anderson
471643a909 init: Add diagnostics for snapuserd hangs
This patch attempts to diagnose snapuserd hangs by performing reads
immediately after entering second-stage init. This is done by spawning
two threads: one to perform the reads, and another to wait for the read
thread to finish. If any aspect of the read fails, or the read thread
does not complete in 10 seconds, then a list of snapuserd's open file
descriptors are logged.

Bug: 207298357
Test: apply working OTA, check logcat for success
      apply broken OTA, check logcat for fd map
Change-Id: I549e07b7d576fcdaca9b2d6ff33e0924c3812c07
2022-01-21 17:35:33 +00:00
Jiyong Park
e060580c31 Merge changes from topic "or_return"
* changes:
  Sort exported headers of libutils
  OR_RETURN supports status_t
2022-01-12 07:27:41 +00:00
Jiyong Park
705abe2d30 OR_RETURN supports status_t
This change provide a specialization of android::base::OkOrFail for
status_t. As a result, a statement whose type is status_t can be used
with OR_RETURN.

The specialization also provides conversion operators to Result<T,
StatusT> where StatusT is a wrapper type for status_t. This allows
OR_RETURN macro to be used in newer functions that returns Result<T,
StatusT>.

Example usage:

\#include <utils/ErrorsMacros.h>

status_t legacy_inner();

status_t legacy_outer() {
  OR_RETURN(legacy_inner());
  return OK;
}

Result<T, StatusT> new_outer() {
  OR_RETURN(legacy_inner()); // the same macro
  return T{...};
}

Bug: 209929099
Test: atest libutils_test
Change-Id: I0def0e84ce3f0c4ff6d508c202bd51902dfc9618
2022-01-12 09:20:27 +09:00
David Anderson
58e554e7ed Merge "Remove support for AVB 1.0." 2022-01-05 03:57:20 +00:00
Jiyong Park
f5caf5b2e1 Merge "android::base::ResultError/Error are template classes" 2021-12-16 23:54:16 +00:00
Yi Kong
b4b20ae65d Fix missing comma
This is discovered by Clang's -Wstring-concatenation diagnostic.

Test: presubmit
Bug: 175068488
Change-Id: Ied97b32e6707236621387bb06993d52a662d9d83
2021-12-15 17:23:46 +08:00
Jiyong Park
d185d4a8b4 android::base::ResultError/Error are template classes
They are changed to template classes. s/Error/Error<>/g to reflect that.

In addition, the direct uses of ResultError for error reporting is
replaced with Error and Errorf.

Bug: 209929099
Test: m
Change-Id: I815526a8e6fa30e63fa3efcf5700b146bf70a507
2021-12-14 17:34:40 +09:00
David Anderson
6d7c7a2156 init: Add --only-if-running argument to restart command.
If surfaceflinger crashes before zygote starts, it will restart zygote
too early. Add this argument will allow it to only restart zygote if
it's already running.

Bug: 197224273
Test: manual test
Change-Id: I0ac8dbeaf0a002f8cfcfcc0f63d4b90d08393c5c
2021-12-03 15:49:39 -08:00
David Anderson
6cdd9bd784 Remove support for AVB 1.0.
Bug: 204598884
Test: treehugger
Change-Id: Ibfb46aa6c2f761dbb3a9b5f0b16336e510417620
2021-11-30 00:57:49 -08:00
David Anderson
36ba349e8f init: Remove first_stage_mount support for AVB 1.0.
Bug: 204598884
Test: treehugger
Change-Id: I6927198b706136de9721df86e24e5828c9f4f1c2
2021-11-30 00:57:48 -08:00
Akilesh Kailash
04eecd441c Merge changes from topic "vabc-user-snapshots"
* changes:
  snapuserd: Add unit test for test merge code path
  libsnapshot: Add vts_userspace_snapshot_test
  libsnapshot: Integrate userspace snapshots APIs
2021-11-22 20:16:06 +00:00
Akilesh Kailash
3b874456fc libsnapshot: Integrate userspace snapshots APIs
dm-user block device will be the snapshot device; thus, no
more explicit call to MapSnapshot(). Additionally, block device
name for dm-user will be the snapshot name so that mount works
seamlessly.

API's to query the snapshot status, merge progress has been
integrated. Since daemon requires base device for merge, we pass
additional parameter during initialization.

Add a new virtual a/b property flag to enable/disable
user-snapshots feature. Propagate this flag to init layer
for first stage mount during boot process.

Some minor cleanup and renaming of variables.

Bug: 193863443
Test: 1: Full OTA on CF and pixel and verify the merge completion.
Tested merge-resume path by rebooting device during merge.
2: Incremental OTA on CF and pixel

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I5088f40a55807946cd044b3987678ead3696d996
2021-11-19 23:45:43 +00:00
David Anderson
2285b528de init: Add a way to class_restart only enabled services.
class_restart accidentally restarts disabled services. Changing this
behavior is risky as it could break compatibility. Instead, add an
"--only-enabled" argument to class_restart to opt-in to the new
functionality. This syntax is backward compatible, as previously only a
1-argument form was accepted.

Bug: 190065372
Bug: 198105685
Test: add a class_restart action and a disabled service, make sure
      service is not restarted.
Change-Id: Idb08779de7ac7a21e23f8b8a3276bd5a66a43299
2021-11-12 22:31:12 +00:00
Eric Biggers
dd41635cef init: remove the class_{start,reset}_post_data commands
Remove the class_start_post_data and class_reset_post_data commands,
since they aren't used anymore.  They were only used on devices that
used FDE (Full Disk Encryption), via actions in rootdir/init.rc.  These
actions have been removed, since support for FDE has been removed.
There is no use case for these commands in vendor init scripts either.

Keep the mark_post_data command, since DoUserspaceReboot() uses the
post-data service flag even on non-FDE devices.

Bug: 191796797
Change-Id: Ibcd97543daa724feb610546b5fc2a0dd7f1e62e7
2021-11-11 14:36:47 -08:00
Eric Biggers
4aa4231a8e init: remove FDE workaround from load_persist_props
FDE is no longer supported, so this workaround is no longer needed.

Bug: 191796797
Change-Id: I059b07035b2158fe84e19544f03aab48de787e62
2021-11-09 22:44:50 -08:00
Eric Biggers
e5b5e376f3 init: stop handling FDE-specific fs_mgr return codes
These codes can't be returned anymore, so stop handling them.

Bug: 191796797
Change-Id: I9bffd43db7c2f43e5f749e04e84154165dec279e
2021-11-09 22:44:50 -08:00
Treehugger Robot
d0a4e710e9 Merge "Remove references to nonplat sepolicy" 2021-11-05 17:29:55 +00:00
Jeff Vander Stoep
5effda49e1 Remove references to nonplat sepolicy
"nonplat" was renamed to "vendor" in Android Pie, but was retained
here for Treble compatibility.

We're now outside of the compatbility window for these devices so
it can safely be removed.

While I'm here, improve accuracy of some comments and
in-code-documentation.

Test: build boot cuttlefish device. adb remount, modify
/system/etc/selinux/plat_sepolicy_and_mapping.sha256 to force
on-device policy compilation. reboot. Verify that device boots
without new selinux denials.

Change-Id: Ibe5c5fa1ea206c1b4d5ad8183433c332a8aaadbf
2021-11-05 09:13:26 +01:00
Tianjie Xu
f1c8904e95 Merge "Fix unittest that checks build id" 2021-10-29 22:15:35 +00:00
Tianjie
c8cf2a4155 Fix unittest that checks build id
Should check ro.build.id instead of the ro.boot.build.id. The former
is a component of the build fingerprint.

Bug: 204507710
Test: run CtsInitTestCases
Change-Id: Iee13b30b195685c2461255f946685a288f352e06
2021-10-28 21:51:43 -07:00
Bowgo Tsai
5998c74d7a Sets 'verity_update_state' in init.rc
This is required since Android 12, because
CtsNativeVerifiedBootTestCases will read property
"partition.${partition}.verified.hash_alg" to
check that sha1 is not used.

Also see https://r.android.com/1546980 for more details.

Bug: 175236047
Bug: 203720638
Test: build and boot a device
Change-Id: I300265f4af9c2781d40537f391bda9eaf62c27ba
2021-10-21 21:38:22 +08:00
Justin Yun
4446a85dc5 Fix the vendor api level
ro.vendor.api_level must be the minimum of ro.product.first_api_level
and ro.board.(first_)api_level.

Bug: 202919753
Test: getprop ro.vendor.api_level
Change-Id: Ie70dd64b21c01ed8cd5e43b01095e1e0d8ff4444
2021-10-14 12:16:27 +09:00
Ray Essick
35ffd69db5 Versioning for apex init.rc files
Support an "init.#rc" versioning scheme for apex init files.
chooses highest # <= current system sdk.
".rc" (aka the old init.rc) is treated as sdk 0
Document these semantics in README.md

Bug: 198186200
Test: booting, lots of logcat output
Change-Id: I2d0405be73dae9bafa6f22535b29ed6b053ddbc4
2021-10-11 19:02:47 -07:00
Treehugger Robot
30b3cb13c1 Merge "init: introduce ro.kernel.version property" am: 939353e1e3
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1840075

Change-Id: I0f2dd754e0deb081550b86497bca58888dc53fa0
2021-10-01 18:24:39 +00:00
Treehugger Robot
939353e1e3 Merge "init: introduce ro.kernel.version property" 2021-10-01 18:14:34 +00:00
Alexander Potapenko
1e966fa9f1 init: introduce ro.kernel.version property
This property will hold the major.minor part of the kernel version (e.g. "5.4"), allowing init scripts to act depending on that version, enabling and disabling certain features.

Bug: 194156700
Change-Id: Icec640b8a7150b344d9aa3bc0bdbcdae050c7c45
Test: manual on a Pixel device
Signed-off-by: Alexander Potapenko <glider@google.com>
2021-10-01 16:06:02 +00:00
Treehugger Robot
69a9fb4922 Merge "Define ro.vendor.api_level" am: 0a671e24f5
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1839954

Change-Id: Ic9f2dced1b547ec2f83c5fd8c791193781473961
2021-10-01 03:32:50 +00:00
Treehugger Robot
0a671e24f5 Merge "Define ro.vendor.api_level" 2021-10-01 02:46:09 +00:00
Treehugger Robot
2d046219ee Merge changes Ie5e47d84,I3c5c9917,Ife48b163 am: 9f2c62481f
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1838534

Change-Id: I91df1e384d10566dc9fb31220681719bbfc240a9
2021-09-29 23:30:23 +00:00
Jiyong Park
3b3d87de79 Don't create vendor_init in microdroid
vendor_init is a subcontext of init which is responsible for handling
the vendor-defined services and vendor-defined actions. This is mainly
to enforce the Treble architecture in which the vendor components are
provided with a less-privileged context than the system components
because they are less-trusted.

However, in case of microdroid, both the system and the vendor
partitions are from the same entity. As VMs don't have direct access to
any of the underlying hardware, the vendor partition is targeting the
virtual platform, not the real hw platform. There really is no need for
the discrimination.

This CL disables the creation of the vendor_init subcontext when init
runs in microdroid.

Bug: 201363575
Test: atest MicrodroidHostTestCases
Change-Id: Ie5e47d84e9e245565239b4f2159e8182b457699d
2021-09-29 21:35:08 +09:00
Nikita Ioffe
0a0e4793e3 Only run RebootTest under root
This test requires running test services, which causes test to crash
(and still incorrectly be reported as passing) when running on
non-rooted device.

Ignore-AOSP-First: reboot_test is not in AOSP yet
Bug: 190958734
Test: atest CtsInitTestCases
Merged-In: I3c5c9917d0a787d66272ccf4aefc57e6573841bc
Change-Id: I3c5c9917d0a787d66272ccf4aefc57e6573841bc
2021-09-29 21:34:59 +09:00
Nikita Ioffe
86b4324a0a Add reboot_test
This test spawns several services backed by /system/bin/yes executable,
and then stops them either while SIGTERM or SIGKILL.

Ideally we want to unit test more of reboot logic, but that requires a
bigger refactoring.

Test: atest CtsInitTestCases
Bug: 170315126
Bug: 174335499
Merged-In: Ife48b1636c6ca2d0aac73f4eb6f4737343a88e7a
Change-Id: Ife48b1636c6ca2d0aac73f4eb6f4737343a88e7a
2021-09-29 20:09:18 +09:00