Commit graph

4209 commits

Author SHA1 Message Date
Yi-Yo Chiang
da5323e2d6 init: Use libfs_mgr kernel cmdline parser
Bug: 293695109
Test: CtsFsMgrTestCases
Change-Id: Ie2567d84cb80c392ad68aef0c438d8acc03a311e
2023-08-02 17:59:05 +08:00
Yi-Yo Chiang
79ad1e2e9b init: Unify kernel bootconfig parser with libfs_mgr
Right now there are two bootconfig parsers that gets linked into `init`.
One is from libinit itself and the other is from libfs_mgr.

The one in libinit removes all space characters between list elements,
so `key = "val1", "val2"` gets unquoted and squeezed into:
  `key=val1,val2`
The one in libfs_mgr doesn't remove spaces, it only unquotes:
  `key=val1, val2`

The libinit behavior is due to existing systems (such as sysprop)
expect the config value to be in the same format as kernel cmdline.
(aosp/1757971)
THe libfs_mgr behavior is due to the `androidboot.boot_device[s]`
format explicitly allows quoted comma appear in its list value, thus
relies on space, not comma, as the list value delimeter.

This commit merges the two parsers into libfs_mgr. Since all usages in
libfs_mgr besides `boot_device[s]` do not care about how list value are
delimited, and most usages in init expects the bootconfig value format
to be the same format as cmdline. We just special case the
`boot_device` scenario.

Also harden the test cases to cover all the different config value
format and expected result.

Note:
The format of kernel bootconfig is described here
https://docs.kernel.org/admin-guide/bootconfig.html

Bug: 293695109
Test: CtsFsMgrTestCases
Change-Id: I42b9bf626e8de38a60e8e09fac0693126b7efd91
2023-08-02 09:57:37 +00:00
Yi-Yo Chiang
0b30e34a04 Merge "init: Unify duplicated get_android_dt_dir with libfs_mgr" into main 2023-08-02 09:56:36 +00:00
Yi-Yo Chiang
ca52a5f2cb Merge "init: Unify duplicated get_android_dt_dir with libfs_mgr" into main 2023-08-02 08:35:08 +00:00
Jooyung Han
6c84b05a94 Merge "Revert "Use /bootstrap-apex for bootstrap APEXes"" into main am: deff223842 am: 2e438b3a5d am: 4c8b9529a5 am: 68c1dc5bd9 am: 25020cbaaf
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2685548

Change-Id: If05a81daac01d12daf00dcdb6107eba28dc6e99a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-01 13:25:40 +00:00
Jooyung Han
deff223842 Merge "Revert "Use /bootstrap-apex for bootstrap APEXes"" into main 2023-08-01 10:44:45 +00:00
Yi-Yo Chiang
b8c23259b1 init: Unify duplicated get_android_dt_dir with libfs_mgr
init and libfs_mgr both defines get_android_dt_dir() with subtle
differences. Merge the two implementations into libfs_mgr to reduce code
duplication (in terms of source code and code gen)

Note:
init's implementation checks the kernel cmdline first and then the
kernel bootconfig, while libfs_mgr's order is the opposite.
Realistically I don't think this order matter much though. If any, we
should prioritize bootconfig over kernel cmdline most of the time.

Bug: 293695109
Test: Presubmit
Merged-In: Ic8d2c965c62f9e873ccdaf77d67c7708f25a7b56
Change-Id: Ic8d2c965c62f9e873ccdaf77d67c7708f25a7b56
2023-08-01 10:15:05 +00:00
Yi-Yo Chiang
f4b1d698b1 init: Unify duplicated get_android_dt_dir with libfs_mgr
init and libfs_mgr both defines get_android_dt_dir() with subtle
differences. Merge the two implementations into libfs_mgr to reduce code
duplication (in terms of source code and code gen)

Note:
init's implementation checks the kernel cmdline first and then the
kernel bootconfig, while libfs_mgr's order is the opposite.
Realistically I don't think this order matter much though. If any, we
should prioritize bootconfig over kernel cmdline most of the time.

Bug: 293695109
Test: Presubmit
Change-Id: Ic8d2c965c62f9e873ccdaf77d67c7708f25a7b56
(cherry picked from https://android-review.googlesource.com/q/commit:d7c67b40a9b6a5e72d54adf37da22238381182f7)
Ignore-AOSP-First: Fix merge conflict
2023-08-01 09:27:25 +00:00
Jooyung Han
840691be71 Revert "Use /bootstrap-apex for bootstrap APEXes"
Revert submission 2666915-share-bootstrap

Reason for revert: b/293949266 vold_prepare_subdirs fails to create apexdata directories.

Reverted changes: /q/submissionid:2666915-share-bootstrap

Change-Id: I3e97e8511755844de4b54f51ff20afc154bd8e74
2023-08-01 09:06:47 +00:00
Jooyung Han
e2c091a772 Merge "Use /bootstrap-apex for bootstrap APEXes" into main am: 58ba0b44c2 am: 6b0c2c3cc6 am: 3249f9ff35 am: b47809dd10 am: dd90936be1
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2666915

Change-Id: I4eec4f989dad5dff76ee77f9da429ed469e313f7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-01 01:18:27 +00:00
Jooyung Han
389348d0e1 Merge "init: move MarkServicesUpdate later" into main am: e90d93ab6e am: ae91cd0dd6 am: 83a2197c80 am: 85d9528574 am: 27288f97f1
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2680615

Change-Id: If75033d40151025d8db4e18dca0183afdecd8915
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-01 01:18:06 +00:00
Jooyung Han
58ba0b44c2 Merge "Use /bootstrap-apex for bootstrap APEXes" into main 2023-07-31 21:53:57 +00:00
Jooyung Han
201801ce8e Use /bootstrap-apex for bootstrap APEXes
This new directory is bind-mounted to /apex in the bootstrap mount
namespace so that apexd-bootstrap mounts bootstrap APEXes there via
/apex.

The directory is detached from /apex in the default mount namespace but
still visible in case bootstrap APEXes are needed.

However, there are (mostly, virtual) devices which don't need two mount
namespaces. Those devices don't need to make /bootstrap-apex directory
at all.

Bug: 290148078
Test: atest VendorApexHostTestCases
Test: atest MicrodroidTests
Change-Id: I541cec71d9970b14971d46e01e4808b23590dbed
2023-07-31 18:16:46 +09:00
Jooyung Han
5ffd88f26f init: move MarkServicesUpdate later
MarkServicesUpdate() starts delayed services which are mostly for
APEXes. (e.g. start a service from APEX). But before
"DefaultNamespaceReady", services are started in "bootstrap" mount
namespace, which makes services from non-bootstrap APEXes fail to start.

This is a quick fix for the problem before coming up with better
solution in the future.

Bug: 293535323
Test: add 'start adbd' before 'perform_apex_config' in init.rc
      adbd starts successfully.
Change-Id: I846689f7c38cdca83c1f7faec0106b8174527e09
2023-07-28 17:28:27 +09:00
Yi-Yo Chiang
9859eed09a Merge "init_first_stage: Disable ThinLTO" into main am: 6b57c885d3 am: fe0b2355fc am: 6e6b357d4e am: 01d9118143 am: 2518f622ca
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2667055

Change-Id: Ic88795fb5a907e7f47b75d7a75f761e94d1999fb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-21 08:35:52 +00:00
Yi-Yo Chiang
6b57c885d3 Merge "init_first_stage: Disable ThinLTO" into main 2023-07-21 05:08:13 +00:00
Jakob Vukalović
58ce74c55d Merge "ueventd: Fix creation of VFIO dev nodes" into main am: 998c3b4fbe am: fcd6f0fb11 am: 1fae39537b am: a87a4a1c73 am: b4e0fbcef1
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2664635

Change-Id: Ic2f51817a3f307b394e936f4cef7e702a076b042
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-20 12:24:37 +00:00
Yi-Yo Chiang
4d6fa8ccaf init_first_stage: Disable ThinLTO
Static executables + x86 target build + ThinLTO produces bug behavior.
Global variables are not constructor initialized, resulting in faulty
runtime behavior.

Bug: 169004486
Bug: 291033685
Test: Treehugger
Change-Id: I777016cceb4851f2b432a37bc4d29aed56c23804
2023-07-20 18:47:16 +08:00
Treehugger Robot
11e2ebbc53 Merge "Listen on property_service_for_system socket for powerctl messages" into main 2023-07-19 22:18:07 +00:00
Jakob Vukalovic
e377432924 ueventd: Fix creation of VFIO dev nodes
VFIO nodes, both the container (`vfio`) node and group (numbered)
nodes, should be located in `/dev/vfio`. This change prevents
ueventd from flattening that structure.

Test: Bind a device to VFIO driver to create a VFIO group
Change-Id: I635e9febe6bb52718df263e735479f361eacad4c
2023-07-19 10:03:10 +01:00
Paul Lawrence
689adfad37 Listen on property_service_for_system socket for powerctl messages
It is easy to dos the property_service socket, since it will wait for a
complete data packet from one command before moving on to the next one.

To prevent low privilege apps interfering with system and root apps,
add a second property_service socket that only they can use.

However, since writes to properties are not thread-safe, limit use of
this second socket to just sys.powerctl messages. These are the messages
that this security issue is concerned about, and they do not actually
write to the properties, rather they are acted upon immediately.

Bug: 262208935
Test: Builds, boots
Ignore-AOSP-First: Security fix
Change-Id: I32835de31bb42c91b6479051ddf4b26b5c0b163f
2023-07-18 08:48:52 -07:00
Eric Biggers
53ed745e3f init: avoid ERROR log due to missing SEPolicy.zip
One of the first ERROR messages in logcat of a normal boot of Cuttlefish
is from failure to open SEPolicy.zip.  This condition is expected.
Therefore don't try to load SEPolicy.zip when it doesn't exist.  This
replaces the following log messages:

0     0 I init    : Error: Apex SEPolicy failed signature check
0     0 I init    : Loading APEX Sepolicy from /system/etc/selinux/apex/SEPolicy.zip
0     0 E init    : Failed to open package /system/etc/selinux/apex/SEPolicy.zip: No such file or directory

... with just:

0     0 I init    : No APEX Sepolicy found

Change-Id: If3a77407c35130165df5782b9ef91912e8374dbf
2023-07-17 20:45:44 +00:00
Eric Biggers
53e35f410d init: remove unfinished fsverity signature support for APEX sepolicy am: 0b2c5cde1f
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2647684

Change-Id: If2a1b17f033a7d53617db9826db8a51664241cb1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-17 20:39:17 +00:00
Eric Biggers
42164ff920 Merge changes from topic "fsverity-init-cleanup" into main
* changes:
  init.rc: stop using fsverity_init --lock
  init: remove unfinished fsverity signature support for APEX sepolicy
2023-07-17 20:10:28 +00:00
Eric Biggers
ab74dbb197 init: simplify queue_fs_event()
Combine some cases that are handled identically, and remove the
'userdata_remount' parameter which is unused.  No change in behavior.

Test: presubmit
Change-Id: I0567e47d02942af7865c155dab76e6d0e9d71a1f
2023-07-10 17:58:36 +00:00
Nikita Ioffe
df0e96e962 Only allow debuggable Microdroid VMs to mount /vendor
Until the verification of the /vendor partition we restrict the usage of
the feature to only debuggable VMs. If a non-debuggable Microdroid VM
is requested to mount /vendor, first_stage_init will crash and the VM
won't boot.

Bug: 285855436
Test: vm run-microdroid --debug none --vendor test_vendor.img
Change-Id: I9d44ad5c1d971bac1a9173c291ce61b628f2f8e9
2023-07-07 14:46:23 +01:00
Nikita Ioffe
440354afa0 Support for conditionally mounting /vendor partition in Microdroid
first_stage_init will only mount the /vendor partition in Microdroid if
the androidboot.microdroid.mount_vendor=1 is provided in the kernel
cmdline.

Bug: 285855433
Test: atest MicrodroidTestApp
Change-Id: I5b840b5474bc52ec2696a0ba6ead0476acddfb1a
2023-07-07 14:45:58 +01:00
Nikita Ioffe
f17079ff58 Small refactoring in first_stage_mount
The existing approach in first_stage_init/first_stage_mount makes it
harder to add conditional logic that should only be applied for
Microdroid. Additionally, it forces the FirstStageMount object to be
created twice.

This change refactors the control flow to make first_stage_init take the
ownership of the FirstStageMount object. It will help with the follow up
change (which will add logic to conditionally mount /vendor partition
while booting Microdroid). As a nice side effect, this refactoring also
fixes the problem of the FirstStageMount being created twice.

This change also merges the FirstStageMount and FirstStageMountVBootV2
in a single class, since nobody actually uses FirstStageMount.

Bug: 285855433
Test: device boots
Test: atest MicrodroidTestApp
Change-Id: I38a72c0f20e7c1ac70031498aeeca22b091fa827
2023-07-07 14:45:01 +01:00
Eric Biggers
0b2c5cde1f init: remove unfinished fsverity signature support for APEX sepolicy
The APEX sepolicy feature has unfinished support for verifying the
sepolicy file using fsverity with a builtin signature.  However, this
was never finished and doesn't really make sense, since the
already-implemented scheme that uses a full-file hash combined with a
userspace signature check is better suited to the problem.  Therefore,
remove this unfinished code.

Bug: 290064770
Test: presubmit and booting Cuttlefish
Change-Id: I3403a3303bcea32c7340642b843cd1541fe1fd2f
2023-07-06 18:39:01 +00:00
Jooyung Han
c288e14001 Merge "No need to read ro.apex.updatable now" 2023-06-27 00:55:25 +00:00
Nikita Ioffe
a66adf45aa init selinux.cpp: use a better way to detect if we run in Microdroid
We are now conditionally compiling init binaries & libinit for
Microdroid (adding -DMICRODROID=1 cflag), so instead of checking for the
presence of the /system/etc/selinux/microdroid_precompiled_sepolicy we
can check if the code is compiled for Microdroid.

In a follow-up changes we can split the sepolicy loading logic into 2
separate headers (one for Android and one for Microdroid) and include
the necessary one depending on the target we compile for.

Bug: 287206497
Test: atest MicrodroidTestApp
Change-Id: Id9c837d03a96ff9564688d33955ec85094eee487
2023-06-26 16:43:16 +01:00
Jooyung Han
918971c69e No need to read ro.apex.updatable now
Bug: 288202251
Test: m
Test: device boots
Change-Id: I97a3c2fab69489cdfbb5103b148194d7e2ee4d1a
2023-06-23 14:22:44 +09:00
Steven Moreland
14e7b76dcf init_kill_services_test: wait 120s for apexd
This is likely waiting for the Java garbage collector to run,
and due to the lockless implementation of BinderProxyNativeData
and BpBinder, it's very difficult to efficiently force this
object to be deleted.

Change-Id: I4df667b9b47327967a43d75664fb506b8704f905
Fixes: 285458033
Test: N/A
2023-06-22 18:56:09 +00:00
Nikita Ioffe
55dd32538f Introduce microdroid variants of init_first_stage and init_second_stage
These variants will compile with -DMICRODROID flag, which will allow us
to exclude init features that are not needed for Microdroid, and
introduce features that only work in Microdroid.

Bug: 287206497
Test: build com.android.virt APEX
Change-Id: Ib9af0cfcdf06c70fc39e6e6ac8ef07bb69982969
2023-06-21 16:44:40 +01:00
Nikita Ioffe
448b70a268 Merge "Reland "Treat Microdroid as OS with monolithic sepolicy"" 2023-06-15 10:27:39 +00:00
Treehugger Robot
642929f8f8 Merge "init_kill_services_test: binder logs on apexd fail" 2023-06-15 01:57:30 +00:00
Steven Moreland
1501b0c344 init_kill_services_test: binder logs on apexd fail
Print logs necessary to understand why apexd isn't shutting
down when this test fails, due to a rare flake.

Bug: 285458033
Test: init_kill_services_test (and cause this error to be hit)
Change-Id: Ic9cbf7b2b9fa89504e4a53597065e94c32233e12
2023-06-15 00:44:31 +00:00
Nikita Ioffe
fa33f85f52 Reland "Treat Microdroid as OS with monolithic sepolicy"
Bug: 285855150
Test: presubmit
Change-Id: I477e1ef7268ac8e7d0fdae7ffcc611a69bb9d4fe
2023-06-14 20:31:17 +00:00
Pawan Wagh
85f52dd1ac Revert "Treat Microdroid as OS with monolithic sepolicy"
Revert submission 2625691

Reason for revert: b/287283650

Reverted changes: /q/submissionid:2625691

Change-Id: Ie62bbb4d4f1af528f42aafde79407b151bab46f9
2023-06-14 18:28:19 +00:00
Nikita Ioffe
94ef7122d6 Treat Microdroid as OS with monolithic sepolicy
Bug: 285855150
Test: atest MicrodroidTestApp
Change-Id: Idfda3044716a021888017adef801ef67775a3eda
2023-06-14 13:28:05 +01:00
Jiyong Park
acfc93f924 Merge "init: non-crashing service can restart immediately" 2023-06-12 01:02:34 +00:00
Jiyong Park
0d277d777f init: non-crashing service can restart immediately
This CL allows restart_period to be set to a value shorter than 5s.
Previously this was prohibited to rate limit crashing services. That
behavior is considered to be a bit too conservative because some
services don't crash, but exit deliverately.

adbd is the motivating example. When adb root or adb unroot is
requested, it changes its mode of operation (via sysprop), exits itself,
and restarts (by init) to enter into the mode. However, due to the 5s
delay, the mode change can complete no earlier than 5 seconds after adbd
was started last time. This can slow the mode change when it is
requested right after the boot.

With this CL, restart_period can be set to a value smaller than 5. And
services like adbd can make use of it. However, in ordef to rate limit
crashing service, the default is enforced if the service was crashed
last time. In addition, such intended restart is not counted as crashes
when monitoring successive crashes during booting.

Bug: 286061817
Test: /packages/modules/Virtualization/vm/vm_shell.sh start-microdroid \
 --auto-connect -- --protected
* with this change: within 2s
* without this change: over 6s

Change-Id: I1b3f0c92d349e8c8760821cf50fb69997b67b242
2023-06-09 13:06:06 +09:00
David Anderson
07533c520c init: Fix ramdump when enabling shutdown animations.
Fix a bug where services weren't stopped properly if shutdown animations
were enabled.

Bug: 285241485
Test: Pixel w/ ro.init.shutdown_animation=true
Change-Id: I7f35572b5223f03f3f5a341fa7b5e90c01d56ce3
2023-06-05 12:59:54 -07:00
Treehugger Robot
852e22d7c3 Merge "ueventd: Wait for runtime apex before running external firmware handler" 2023-05-25 01:40:10 +00:00
Steven Moreland
89a4db46f5 Merge "init_kill_services_test: special case apexd" 2023-05-23 18:18:02 +00:00
Steven Moreland
4350592133 init_kill_services_test: special case apexd
apexd restarts the device, so it causes flakes here,
especially in presubmit.

Bug: 280514080
Test: init_kill_services_test

Change-Id: I4455704795961f3ae94e29bdf098eca739130973
2023-05-23 18:17:57 +00:00
David Anderson
2fb1c671d5 Merge "ueventd: Fix a race condition in handling device-mapper events." 2023-05-19 19:43:21 +00:00
Steven Moreland
159bd29580 Merge "init_kill_services_test: log state" 2023-05-18 17:08:39 +00:00
Steven Moreland
16e08075ba init_kill_services_test: log state
It can be difficult to figure out where this test
is while it's executing, so I've added logs.

Bug: 280514080
Test: init_kill_services_test (w/o tradefed to avoid reboot), then:
:) adb logcat -d | grep init_kill_services_test
... I init_kill_services_test: hello lmkd!
... I init_kill_services_test: okay, now goodbye lmkd
... I init_kill_services_test: I said goodbye lmkd!
... I init_kill_services_test: are you still there lmkd?
... I init_kill_services_test: I'm done with lmkd
... I init_kill_services_test: hello ueventd!
... I init_kill_services_test: okay, now goodbye ueventd
... I init_kill_services_test: I said goodbye ueventd!
... I init_kill_services_test: are you still there ueventd?
... I init_kill_services_test: I'm done with ueventd
... I init_kill_services_test: hello hwservicemanager!
... I init_kill_services_test: okay, now goodbye hwservicemanager
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: I said goodbye hwservicemanager!
... I init_kill_services_test: are you still there hwservicemanager?
... I init_kill_services_test: I'm done with hwservicemanager
... I init_kill_services_test: hello servicemanager!
... I init_kill_services_test: okay, now goodbye servicemanager
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: I said goodbye servicemanager!
... I init_kill_services_test: are you still there servicemanager?
... I init_kill_services_test: I'm done with servicemanager

Change-Id: I2466f574fc06cdf1b01db82f89649f39b0f34345
2023-05-17 23:20:53 +00:00
David Anderson
59abbfe647 ueventd: Fix a race condition in handling device-mapper events.
We've had flake in libdm_test for a long time, with no clear cause.
Lately however it has become particularly reproducible when running
the UeventAfterLoadTable test in isolation, and thus we've identified
the root cause.

uevents for device-mapper are fired when the sysfs node is added, but at
that time, the "dm" subnode has not yet been added. The root node and dm
node are added very close together, so usually it works, but sometimes
ueventd is too fast.

Instead of relying on sysfs, query the uuid/name node directly from
device-mapper.

Bug: 270183812
Test: libdm_test
Change-Id: I258de5de05d813c3cb7f129e82e56dbfe8bf3117
2023-05-17 15:52:16 -07:00
Treehugger Robot
9f6e88567b Merge "Support ZSTD in userspace COW" 2023-05-16 19:02:57 +00:00
Kelvin Zhang
32dcac7851 Support ZSTD in userspace COW
Perf:
Lz4:
Update took 429 seconds
merge time 35.4s
cow size: 3.18GB

ZSTD:
Update took 676 seconds
merge time 49.4s
cow size: 2.62GB

Gz:
Update took 1057 seconds
merge time: 50.0s
cow size: 2.55GB

In summary, ZSTD is a middle point between LZ4 and GZ.

Speed: LZ4 > ZSTD > GZ
Space: LZ4 > ZSTD > GZ

Bug: 274129758

Change-Id: I203bf088b7c2a9ce429f75478799da0e7126febf
2023-05-16 10:13:52 -07:00
JW Wang
a37c4d2796 Export active dsu slot to system prop
The prop can be consumed by init scripts to do customized setup:

on property:ro.gsid.dsu_slot=oemtest
    # Do setup for test
on property:ro.gsid.dsu_slot=oemdemo
    # Do setup for demo

Bug: 277691885
Test: m
Change-Id: I7bd78b9ba31021b27d57c6f092dad5d7ebf6e59b
2023-05-15 09:48:59 +08:00
Isaac J. Manjarres
6f742376bc Add support for reading modules.load.charger when booting into charger mode
When booting up, Android can boot into one of three modes: normal,
recovery, and charger mode. The set of modules that should be loaded
during first stage init in each mode can differ, which is why init
reads the list of modules to load from modules.load.recovery when
booting into recovery, and modules.load otherwise.

This means that init will read the list of modules to load during first
stage init from modules.load even when booting into charger mode. This
is not ideal, as it causes modules that need to be loaded during
first stage init only when booting into charger mode to also be loaded
during first stage init of normal boot, which can degrade boot time.

Thus, add support for reading modules.load.charger, which contains the
list of modules that need to be loaded during first stage init when
booting into charger mode.

Bug: 266752750
Change-Id: Ib9178bdfe5a6aac57b86b6d453b03625e95d5b48
Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
2023-05-12 16:26:35 -07:00
tangjie1
2b26bdf973 init: automatically add a new loop device when there are no idle loop devices
Signed-off-by: tangjie1 <tangjie1@xiaomi.com>
Change-Id: I5fe6df9b733c4932334097aff6b7781dcb34027e
2023-05-09 22:15:33 +08:00
Steven Moreland
e5349196b2 init: V devices need to specify user
This also specifies user on an adbd service
declaration which was missing before. It seems
that certain services are declared mulitple
times.

Fixes: 276813155
Test: boot (on CF, the only V device in the tree)
Test: remove 'user' specification and see error

Change-Id: I138f3ace72d46f221551ad61e75ba4c01632da59
2023-05-03 01:06:38 +00:00
Steven Moreland
5ca6c9888e Merge "init: log when 'user' is unspecified" 2023-04-24 17:28:09 +00:00
Steven Moreland
f5d22ef7cd init: log when 'user' is unspecified
NOTE: in master, but should be submitted in AOSP.
Waiting to hear from security folks. Also might
need cleanup.

Not currently done. Seems errorprone.

Bug: 276813155
Test: boot, check logs
Change-Id: I7cbc39b282889dd582f06a8eedc38ae637c8edec
2023-04-17 20:18:00 +00:00
Steven Moreland
f0578771ea Merge "Explicit init .rc user." 2023-04-14 21:43:38 +00:00
Steven Moreland
2fccf5ead3 Explicit init .rc user.
Set the user explicitly.

For boringssl self-test, changed to 'nobody' since
this test doesn't require permissions.

Bug: 276813155
Test: boot, check can 'nobody' can still write to kmesg.
Change-Id: I32f7134e83183bd054bffbb22d412d7a2dc0ad09
2023-04-14 21:43:25 +00:00
Daniel Rosenberg
76607e5b07 Merge "Require root for StartConsole Test" 2023-04-11 01:14:17 +00:00
Daniel Rosenberg
b8baa8dd34 Require root for StartConsole Test
This test requires root to run. Skip if not root.

Bug: 270052268
Test: CtsInitTestCases init#StartConsole
Change-Id: I8b54acf97cda4bc2cfa15d0e34c678ec2b13f83e
2023-04-07 13:18:53 -07:00
Mateus Azis
1a2f73d76a Improve the formatting for init's README.
Make sure the arguments to "mkdir" show up in the same block.

Before: c3a119caa3/init/README.md
After: https://android.googlesource.com/platform/system/core/+/refs/changes/60/2528060/1/init/README.md

Test: N/A
Change-Id: I88b4931e70e2793566cce53c38c0295168463971
2023-04-06 13:46:35 -07:00
Thiébaud Weksteen
f03dde8549 Skip newlines for SELinux logs
libselinux log messages usually end with a new line character. Android
log system does not require the new line character and will include the
character as-is in the log buffer.

This trimming was already implemented when the message is typed as
SELINUX_AVC (see SelinuxAvcLog). Move the truncation one level up so it
is occurring for all types of logs.

Test: boot & adb logcat & inspect SELinux logs
Change-Id: I360359c1b178ef24d555dd41f8d4a18b293a175c
2023-04-05 09:32:18 +10:00
Jingwen Chen
095374cde7 Merge "Make the host_init_verifier init.rc parser follow symlinks." 2023-03-17 06:42:04 +00:00
Jingwen Chen
f643b354fe Make the host_init_verifier init.rc parser follow symlinks.
Bazel's intermediates/inputs are symlinks in its execution root, unlike Soong.

e.g.

$ file $(readlink -f out/bazel/output/execroot/__main__/packages/modules/adb/apex/adbd.rc)
/usr/local/google/home/jingwen/aosp/master-with-phones/packages/modules/adb/apex/adbd.rc:
ASCII text

Test: presubmits
Change-Id: I3977a37ee989e07bee56abb019a21055b8cef567
2023-03-17 02:47:21 +00:00
Steven Moreland
bc21816d5b Merge "init_kill_services_test: clearer logs" 2023-03-15 23:59:10 +00:00
Steven Moreland
d9d4034d0b init_kill_services_test: clearer logs
Don't continue with a specific run if a service
is already dead.

Bug: 272618190
Test: init_kill_services_test
Change-Id: I1b1c0b4e87fd7a5200bd6e6e6af2eb9686d7367d
2023-03-15 21:47:38 +00:00
Treehugger Robot
89d8fdf3ed Merge "init tests: libhidl-gen-utils static" 2023-03-15 21:16:50 +00:00
Steven Moreland
973aadeff5 init tests: libhidl-gen-utils static
No longer installed on device, so we need to include
it as a static lib. This library was actually specified
as a dependency on vts_ibase_test in two places, so this
is the second CL doing the same thing but in another
project.

Fixes: 270497432
Test: readelf -d $ANDROID_BUILD_TOP/out/target/product/vsoc_x86_64/data/nativetest/vts_ibase_test/vts_ibase_test
  no longer shows libhidl-gen-utils
Change-Id: Icf427085e3978906e82231c8faacb7bdbcbf4569
2023-03-15 19:40:56 +00:00
Alistair Delva
f9bfe0d16d Stop respawning serial console if disabled
After introducing ro.boot.serialconsole=0, the console will no longer be
spawned, but a step was missed to disable the service to prevent
respawns.

Bug: 266982931
Bug: 223797063
Bug: 267428635
Change-Id: I12b159eaa1999781aec31c05ce431b55e2ba4017
2023-03-13 16:09:36 -07:00
Bart Van Assche
071dbc1729 init: Combine the CheckShutdown() and set_do_shutdown() methods
Let the CheckShutdown() method clear the do_shutdown_ member instead of
clearing that member separately from calling CheckShutdown().

Bug: 266255006
Change-Id: Ifc1cff2be92a45db7f91be2fdb812930d2fd1ad5
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-03-03 13:27:17 -08:00
Bart Van Assche
b4b1b75a35 init: Remove the DebugRebootLogging() function
The DebugRebootLogging() function was introduced to help with
root-causing b/150863651. Remove this function since this logging
functionality is no longer needed. Also remove the functions and methods
that are only used by DebugRebootLogging().

Change-Id: Ia150604c6cd70f42b13d655ba43b95445a55b6e2
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-03-03 13:26:58 -08:00
Bart Van Assche
1fdbf8d0f8 init: Combine two if-statements
Combine two if-statements. This change is fine because:
* The code between the two if-statements does not queue actions.
* If an action is queued from another thread then WakeMainInitThread()
  is called after the action has been queued.

Bug: 266255006
Change-Id: Id4b9565ff4fdb3ee2a2bbca316c8c78e0f2d38dd
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-03-03 13:26:58 -08:00
Treehugger Robot
8dab2ef586 Merge "Use ro.boot.serialconsole to disable console services" 2023-03-02 20:04:33 +00:00
Steven Moreland
8e25d9c5b0 init: add log w/ service PID
We could combine this with the existing log, but I
wouldn't want to make that appear later.

Ironically, adding this log to try to reduce logs.

Bug: 36785118
Test: :) adb logcat -d | grep "started service" | wc -l
131

Change-Id: I38f4e9740871aa256eef0c62e897038eb46871a5
2023-02-28 01:42:24 +00:00
Bart Van Assche
3dfb8bc889 init: Simplify struct BuiltinArguments
Make the code that creates BuiltinArguments instances easier to read by
using initializer lists instead of constructor calls. Remove the
BuiltinArguments constructors.

Change-Id: I6cf215a81d298cf7e524e22fb75db820e0225c9a
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-23 16:06:42 +00:00
Jiyong Park
8437b9a082 Merge "Fix failure on mounting system_ext partition" 2023-02-23 03:56:40 +00:00
Alistair Delva
5591f12834 Use ro.boot.serialconsole to disable console services
For many years, services declaring "console" would only be started if the
console device specified by androidboot.console= was present under /dev.
However, they would also be started if the /dev/console node existed.

This fallback causes problems with newer GKI kernel images which now
hard-code "console=ttynull" via CONFIG_CMDLINE, which essentially means
/dev/console always exists, even though this console points nowhere.

It also causes problems on devices where the androidboot.console was not
the same as the kernel dmesg console ("console="), such as cuttlefish,
because those platforms could not simultaneously enable kernel logging
but disable the interactive serial console feature. The framework just
assumed both would be muxed on the same serial port. Cuttlefish had a
workaround, to use "androidboot.console=invalid" to avoid the fallback,
but this doesn't work on devices which still want to mux the kernel logs
and interactive serial console.

This change resolves the issue in a better way, by introducing a new
boolean property called "androidboot.serialconsole". Setting this to "0"
will disable the console services, regardless of whether the
/dev/console or /dev/${ro.boot.console} devices exist. Older kernels
and bootloaders don't need to set this and can rely on the old behavior
in init, but bootloaders booting newer kernels must set it to avoid the
"performance is impacted" message due to console services being started.

Bug: 266982931
Bug: 223797063
Bug: 267428635
Test: "launch_cvd" with "androidboot.console=invalid" removed;
      See the "performance is impacted" message.
Test: "launch_cvd" with "androidboot.serialconsole=0";
      The "performance is impacted" message is gone.
Change-Id: Iaad4d27ffe4df74ed49606d3cabe83483c350df4
2023-02-22 14:31:24 -08:00
Lianjun Huang
ccd094cd4e Fix failure on mounting system_ext partition
There can be more than one fstab entry of system partition.
For example, the filesystem of one entry is ext4 and another is erofs.

system /system ext4 ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey
system /system erofs ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey

If both filesystems of system and system_ext paritions are erofs,
only the ext4 fstab entry will be returned by GetEntryForMountPoint,
and system_ext cann't be mounted.

So we need to return both of the fstab entries and try all of them.

Signed-off-by: Lianjun Huang <huanglianjun@xiaomi.com>
Change-Id: I407553d48b1749cd0554f057a6bfd38daa96fdcb
Signed-off-by: Lianjun Huang <huanglianjun@xiaomi.corp-partner.google.com>
2023-02-20 16:50:03 +08:00
Bart Van Assche
b6b7ccc24f init: Document the locking strategy used in class PropWaiterState
Let the compiler verify that lock_ is held when any of the data members
are accessed.

Bug: 266255006
Change-Id: I71b341815d84ab530627d934ad4d4681b652b9d8
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-17 13:55:11 -08:00
Bart Van Assche
68a59e1c72 init: Document the locking strategy in class ShutdownState
Let the compiler verify that shutdown_command_lock_ is held when
shutdown_command_ is accessed.

Bug: 266255006
Change-Id: Ibd05137ab65e20f247f35bbb2bb1865e05f51f41
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-17 13:55:11 -08:00
Bart Van Assche
468067a204 init_test: Close all file descriptors before calling execv()
This change improves test reliability.

Change-Id: Ib9a6b75bbd81968eb7e2fd90ea567155bc8355f7
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-15 09:27:32 -08:00
Bart Van Assche
878560dae0 init_test: Fix a race condition
Wait until strace has attached to the service instead of assuming that
it has attached after one second.

Change-Id: Ifb71fa2419563e1334d8500ea867ec92121395e0
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-15 09:27:32 -08:00
Bart Van Assche
947d75f0b8 init_test: Simplify the gentle_kill test
Remove the ConvertToArgv() function. Do not cast the std::string::find()
result. Make the strace path absolute.

Change-Id: If329e91275c834ba375863e40901f6be07a5f347
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-15 09:27:32 -08:00
Daniel Rosenberg
2f0508686e Only run GentleKill test as root
Without root, Service::Start() fails due to lack of permissions.

Bug: 267559075
Test: run cts -m CtsInitTestCases -t init#GentleKill
      atest init#GentleKill
      Will skip under cts, pass under atest
Change-Id: I69e8be7000718bdba1c2acd9675b5645c0891afc
2023-02-08 17:31:49 -08:00
Treehugger Robot
d019150a00 Merge "Add bug component id to OWNERS" 2023-02-07 02:44:56 +00:00
Jiyong Park
078cc15b00 Add bug component id to OWNERS
Bug: 261015504
Test: N/A
Change-Id: I07d951e0bc551f2e642ffc2ee1aaeca2b7e77626
2023-02-06 07:39:56 +00:00
Bart Van Assche
dcc208f38a Fix a spelling error
Fixes: 2e4b3ffa75 ("Use Apex sepolicy if it's available")
Change-Id: Ib937fa8384658f05ff435024f7834c5df12f0d22
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-02 22:31:51 +00:00
Alex Hong
057b94215a Reland "Set the log callback earlier for showing system property set denials"
PropertyInit loads the build.prop files and set the system properties.
Set the SELinux log callback before that to show the avc denials for debugging.

Test: $ make init_system
      Push this module and ensure system property set denials are shown during boot
Bug: 185920634
Bug: 211547922
Change-Id: If9f34d469d3da2ebdfe64bb611de85a3ca37e000
2023-01-31 22:11:16 +08:00
David Anderson
298f6c033b Merge "Disable multilib for CtsInitTestCases." 2023-01-17 23:15:47 +00:00
Treehugger Robot
b9e1821201 Merge "Find a zoned partition automatically" 2023-01-17 22:22:26 +00:00
Jaegeuk Kim
b92e5b5c48 Find a zoned partition automatically
Since we cannot create a gpt table on zoned LU, we cannot make a generic symlink
from it. Instead, let's make it by uevent, "/dev/block/by-name/zoned_device".
Note that, we support only one zoned device in the system.

Bug: 265180564
Change-Id: Ie62b0fd68b77e3e43cf0f5c5cad9503150174271
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2023-01-14 10:29:31 -08:00
Akilesh Kailash
545870e53a Merge "init: Wait for daemon to fully spin up all threads" 2023-01-13 06:35:33 +00:00
David Anderson
9b9924b412 Merge "init: Allow persistent properties to be written asynchronously." 2023-01-12 21:50:42 +00:00
Treehugger Robot
e8d42e65c8 Merge changes I169b52cf,Ieb0e4e24
* changes:
  init: Add test for gentle_kill
  init: Add gentle_kill service property
2023-01-11 23:16:55 +00:00
Akilesh Kailash
717ee9120a Merge "init: Avoid killing all processes during reboot if update is in progress" 2023-01-11 20:52:13 +00:00
Akilesh Kailash
5140f3ad47 init: Wait for daemon to fully spin up all threads
During selinux transition, daemon will notify `init` process
by writing to file "/metadata/ota/daemon-alive-indicator".

Init will wait until daemon notifies it. Furthermore, daemon
will only write to that file once all threads are spin up
and attached to dm-user misc devices.

Once snapshot-merge is completed, this file will be removed.
Additionally, during boot, init will also ensure that
there are no stale files and will try to remove just
before selinux transition.

Bug: 262407519
Test: OTA on Pixel - Verify new file exits and init waits until daemon
is fully up.
Change-Id: Iabef58ad282d80a7afa493e9df9468ae41a13e44
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-01-11 19:24:56 +00:00
Treehugger Robot
7fcaa14e27 Merge "Add comment about out-of-bounds being on purpose" 2023-01-11 18:55:18 +00:00
Jooyung Han
6b88d1684c Parser::ParseConfigFile returns Result<void>
ParseApexConfigs() uses Parser::ParseConfigFile() to parse .rc files in
the target apex. ParseConfigFile() returning bool (with logging on
error) doesn't propagate the error message back to the callers
(including apexd or PackageManager).

We'd better to migrate other Parse*() methods of Parser class to return
Result<T>. But this change focuses on plumbing error progagation for
APEX configs.

Bug: 238820991
Test: atest CtsInitTestCases
Change-Id: Ifad97635dbb53a70053ec73a7a5b7e742466daf6
2023-01-11 17:20:16 +09:00
Akilesh Kailash
2c52d09078 init: Avoid killing all processes during reboot if update is in progress
Bug: 262321167
Test: Reboot device post OTA reboot
Change-Id: I5d13844e4e157d24a414dce668163bb1915bf65e
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-01-11 06:00:34 +00:00
Daniel Rosenberg
ed8178c8cc init: Add test for gentle_kill
Tests that a service marked as gentle_kill terminiated with SIGTERM

Bug: 249043036
Test: atest CtsInitTestCases:init#GentleKill
Change-Id: I169b52cfd74f07b4d2439761ea315117323b3fcb
2023-01-10 18:29:46 -08:00
Daniel Rosenberg
de76688e40 init: Add gentle_kill service property
If a service specifies gentle_kill, attempt to stop it will send SIGTERM
instead of SIGKILL. After 200ms, it will issue a SIGKILL.

Bug: 249043036
Test: atest CtsInitTestCases:init#GentleKill
      Added in next patch
Change-Id: Ieb0e4e24d31780aca1cf291f9d21d49cee181cf2
2023-01-10 18:29:46 -08:00
David Anderson
0af9ab3308 init: Allow persistent properties to be written asynchronously.
Persistent properties are flushed with fsync which can cause the
non-persistent property write path to block.

Bug: 250125146
Test: manual test with ro.property_service.async_persist_write = true
Change-Id: Id123bfc7de948b76c51b4d98d00c8cb4a0850bf1
2023-01-09 16:41:56 -08:00
Florian Mayer
04fb2c838d Add comment about out-of-bounds being on purpose
Change-Id: I97e334f0555cce80eeab6567905054d807af3c91
2023-01-09 21:46:10 +00:00
Carlos Galo
1447120f78 Set memlock rlimit to 64KB
Defaulting Android to limit memlock to 64KB. This will help preventing
pages from being swapped until the app is killed it's memory will stay
resident. CTS test is enforced only in U+ devies.

Bug: 201797650
Test: Added new test to verify we are memlock at or under 64KB
Change-Id: I5a9e9da12f6df5a056ee47d0593c13e9c779e054
2023-01-05 16:29:59 +00:00
Bart Van Assche
f85317fb43 Make an error message more informative
From
https://android-build.googleplex.com/builds/tests/view?testResultId=TR66328435937757440&invocationId=I00700010119503421:

system/core/init/init_test.cpp:219: Failure
Failed
Value of: service-&gt;Start()
  Actual: createProcessGroup(0, 15611) failed for service 'console'
  Expected: is ok

The above error message does not contain enough information to
root-cause the test failure. Hence this CL that makes an error message
more informative.

Bug: 262090304
Change-Id: I09929b2f2aabf1eec4d90ec93234a9e968888da4
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-31 23:41:29 +00:00
Nikita Ioffe
24d1c238ce Revert "host_init_verifier: add check for root services and linux capabilities"
This reverts commit f1e3bfff40.

Reason for revert: Breaks builds

Bug: 263874232
Change-Id: Iabe5cd01114bf4a3731ace4345da8009e6b86f74
2022-12-28 16:18:20 +00:00
Nikita Ioffe
f1e3bfff40 host_init_verifier: add check for root services and linux capabilities
If a service that runs under root doesn't have the capabilities field in
it's definition, then it will inherit all the capabilities that init
has.

This change adds a linter to detect such services and ask developers to
explicitly specify capabilities that their service needs. If service
doesn't require any capabilities then empty capabilities fields should
be added in the service definition.

The actual access control list on what capabilities a process can use is
controlled by the SELinux, so inheriting all the init capabilities is
not a security issue here. However, asking services to explicitly
specify the capabilities they need is a good defense-in-depth mechanism.

So far this linter only checks the services on /system partition.

All currently offending services are added to the exempt list. I will
work on fixing some of them in the follow-up changes.

Bug: 249796710
Test: m dist
Change-Id: I2db06af165ae320a9c5086756067dceef20cd28d
2022-12-22 22:08:49 +00:00
Jiyong Park
3e951a7758 Merge "Skip StartConsole test on user builds." 2022-12-20 07:08:23 +00:00
Jiyong Park
5b7a51a59a Skip StartConsole test on user builds.
It runs a service with root privilege which can't be done on user
builds. Until the issue is resolved, skip the test on user builds.

Bug: 262090304
Test: N/A
Change-Id: I690ffbd7fdaef688a0c862e0c653e9b21e281ece
2022-12-20 10:46:31 +09:00
Treehugger Robot
fd98382506 Merge "Run the console test with /dev/null" 2022-12-16 01:54:14 +00:00
Nikita Ioffe
cc0e90a964 Update docs around capabilities and root processes
Current documentation is misleading: if a service runs as root and
doesn't specify any capabilities, then it will start with all the
capabilities (note that whether it can use them is controlled by
selinux).

Test: n/a
Bug: 249796710
Change-Id: I0d6a884127c6a6c5b651c1222fcf48322065daae
2022-12-15 18:04:21 +00:00
Jiyong Park
ae412804ca Run the console test with /dev/null
The availability of /dev/console varies across different devices and
even across different build variants (ex: userdebug/user). Instead of
relying on the device-specific condition, use the /dev/null as the
console device for the test.

Bug: 262090304
Test: atest CtsInitTestCases on raven-user
Change-Id: I3b12d66e94609328dfdd6f640d1adb88a773fa38
2022-12-15 16:32:38 +09:00
Jiyong Park
717ece7397 Merge "Clarify the behavior about event and property triggers" 2022-12-14 15:16:31 +00:00
Steven Moreland
bb1ee3c689 Merge "ignore error -> log" 2022-12-14 01:29:20 +00:00
Steven Moreland
507209ba55 ignore error -> log
Current code ignores an error, which is a code
rot risk.

Bug: 261700511
Change-Id: I04ca7046dc42d761ecaaf56f6100c96cc8298ec5
Test: N/A
2022-12-13 22:43:58 +00:00
David Anderson
95cfb31bd2 Merge "Support sysfs changes in the Linux 5.15 kernel." 2022-12-12 18:38:04 +00:00
Treehugger Robot
5c3e24816d Merge "Kill services even when cgroups is disabled" 2022-12-12 01:20:45 +00:00
Inseob Kim
a049a9928b Kill services even when cgroups is disabled
process_cgroup_empty_ is used to indicate that a service is already
killed or not. If cgroup support lacks, services cannot be killed
because process_cgroup_empty_ is always true.

This change fixes it by not assigning process_cgroup_empty_ as true.
Instead, make KillProcessGroup send signals even when cgroup is
disabled. Also DoKillProcessGroupOnce() is updated so it returns a number of killed processes, excluding already dead processes. This behavior agrees with its name (DoKillProcessOnce), and it prevents regression upon missing cgroups, because kill(-pgid) will always
"succeed" so KillProcessGroup will loop even when all processes are
already dead.

Bug: 257264124
Test: boot microdroid, see services are terminated
Change-Id: I19abf19ff1b70c666cd6f12d0a12956765174aaa
2022-12-12 01:19:26 +00:00
David Anderson
d6bf86b8cf Support sysfs changes in the Linux 5.15 kernel.
DM_DEV_CREATE no longer creates sysfs nodes. Note this in ueventd and
add some helper APIs to libdm, so devices can be created with a
placeholder table.

This also fixes a bug in dmctl where the detailed info on suspended
devices was wrong.

Bug: 259328366
Test: dmctl with "uevents" tool
Change-Id: I822f8010e48d32841aa0ee508822f76d03a3dd85
2022-12-08 16:22:47 -08:00
David Anderson
cbd082d46d Disable multilib for CtsInitTestCases.
Bug: 260393485
Test: run cts -m CtsInitTestCases
Change-Id: I92a11b7961411b22525d4434312479878b353b55
2022-12-06 20:13:53 -08:00
Chih-hung Hsieh
48cd41324b Merge "Fix potential memory leaks" 2022-12-07 02:36:27 +00:00
Bart Van Assche
d3484c84bf Merge "init: Enable ANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION" 2022-12-06 23:05:30 +00:00
Bart Van Assche
9dbf8c32e9 Merge "init: Prevent copying of Service objects" 2022-12-06 17:32:23 +00:00
Bart Van Assche
b3f9f6f4c6 Merge "init/Android.bp: Sort cflags alphabetically" 2022-12-06 17:29:41 +00:00
Treehugger Robot
70b22e1c5b Merge "init: Make an error message more informative" 2022-12-06 03:04:16 +00:00
Treehugger Robot
ab3bc215e8 Merge "init: Convert a single-element array into a scalar" 2022-12-06 01:48:58 +00:00
Chih-Hung Hsieh
784e63c9a2 Fix potential memory leaks
Bug: 259995529
Test: make tidy-system_subset
Change-Id: I604a308caf498a854b916dc86a8e274148c21ab0
2022-12-05 23:52:58 +00:00
Bart Van Assche
0bb4757d03 init: Prevent copying of Service objects
Service objects have external state (the child process) and hence must
not be duplicated. Disable the copy constructor and the assignment
operator to prevent that these objects get duplicated accidentally.

Bug: 213617178
Change-Id: Ia5391154b94eca7f12be69eabcdf3f173fc06452
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-05 11:41:26 -08:00
Bart Van Assche
42764c4e3e init: Make an error message more informative
Make it easier to diagnose service failures.

Bug: 213617178
Change-Id: I27135cb32b6a98b2fe24ab2324dffbf5b591fdd5
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-05 11:41:10 -08:00
Bart Van Assche
c41a4826d1 init: Do not invoke the ServiceList destructor when exiting
From the Google C++ style guide: "Objects with static storage duration
are forbidden unless they are trivially destructible." Hence this CL.

Bug: 213617178
Change-Id: I4c9a51618ee1eb14ed439295a5fc0101b940a63d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-05 10:45:49 -08:00
Bart Van Assche
aee2ec8f1e init: Enable ANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION
From the unique_fd.h header file: "unique_fd's operator int is
dangerous, but we have way too much code that depends on it, so make
this opt-in at first."

From the Google C++ style guide: "Do not define implicit conversions."
See also go/cstyle#Implicit_Conversions.

Hence this CL that disables unique_fd::operator int().

Change-Id: I28d94755d5408f63e5819da8d1cbc285057f867f
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-05 09:40:06 -08:00
Bart Van Assche
91ba2197ef init/Android.bp: Sort cflags alphabetically
Sort the compiler flags alphabetically before adding a new macro
definition.

Change-Id: If919333302817406a890c9622396ec96920adf29
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-05 09:40:05 -08:00
Bart Van Assche
fdc0f89a4a init: Convert a single-element array into a scalar
Simplify PollIn() by converting a single-element array into a scalar. No
functionality is changed.

Change-Id: I3ef36b9c0daafeed3a92f90c7a7c4fe0654dd586
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-12-05 09:40:05 -08:00
Bart Van Assche
fa4926a9de Merge "Revert "init: Add more diagnostics for signalfd hangs."" 2022-12-01 17:50:27 +00:00
Jiyong Park
f477319692 Clarify the behavior about event and property triggers
See the comment threads at [1] for the rationale behind the behavior.

[1] https://android-review.git.corp.google.com/c/platform/system/core/+/161601/16/init/action.cpp#232

Bug: N/A
Test: N/A

Change-Id: I8b271073ec14ad9fa9add5df60577b34d1df3241
2022-12-01 10:38:48 +09:00
Bart Van Assche
3b21d95a0e init: Fix and re-enable the init#StartConsole test
Skip the test if /dev/console does not exist. Fix the console service
security label. Fix the getsid() test.

Bug: 260104465
Test: atest 'CtsInitTestCases:init#StartConsole' on a P2023 development board
Change-Id: If2533a3f205f922a9b04a748cb558a09c5925986
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-30 13:25:47 -08:00
Bart Van Assche
29d8a42d14 Revert "init: Add more diagnostics for signalfd hangs."
Revert commit 14f9c15e05 ("init: Add more diagnostics for signalfd
hangs") because:
* That commit was intented to help with root-causing b/223076262.
* The root cause of b/223076262 has been fixed (not blocking SIGCHLD
  in all threads in the init process).

Test: Treehugger
Change-Id: I586663ec0588e74a9d58512f7f31155398cf4f52
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-30 09:17:16 -08:00
Bart Van Assche
027b275b57 init: Disable test init#StartConsole
Bug: 260104465
Change-Id: I43a19b2451bad955d101d9ebdc3c98419d83597d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-22 16:38:43 -08:00
Bart Van Assche
01e6669c66 init: Fix a race condition in KillProcessGroup()
Multiple tests in CtsInitTestCases, e.g. RebootTest#StopServicesSIGKILL,
can trigger the following race condition:
* A service is started. This involves calling fork() and also to call
  RunService() in the child process. RunService() calls setpgid().
* Service::Stop() is called and calls KillProcessGroup().
  KillProcessGroup() calls kill(-pgid, SIGKILL) before the child process
  has called setpgid(). pgid is the process ID of the child process. The
  kill() call fails because setpgid() has not yet been called.

Fix this race condition by adding a setpgid() call in the parent process
and by waiting from the parent until the child has called setsid() if a
console is attached.

Bug: 213617178
Change-Id: Ieb9e6908df725447e3695ed66bb8bd30e4e38aa9
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-21 11:42:44 -08:00
Bart Van Assche
987391656f init: Introduce RequiresConsole()
Prepare for adding more code in the parent process that depends on
whether or not a console is required.

Bug: 213617178
Change-Id: I066ede32fcd4ce09d06be23158f3c1970064a697
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-18 09:49:43 -08:00
Bart Van Assche
c8f34254b8 init: Introduce symbolic names for certain constants
Make the code easier to read by introducing symbolic names for the
constants used by Service::Start() for communication between the parent
and child processes.

Bug: 213617178
Change-Id: I3e735e149682fa9df2ed57f75eb5a67d7c68bd92
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-18 09:49:01 -08:00
Bart Van Assche
d394f74365 init: Reduce the number of system calls
Change setpgid(0, getpid()) into setpgid(0, 0). This patch removes one
system call but does not change the behavior of the code. From the
setpgid() man page: "If pgid is zero, then the PGID of the process
specified by pid is made the same as its process ID."

Bug: 213617178
Change-Id: I7031d9eb3711f526751da495c07a8927f9386d97
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-18 09:45:33 -08:00
Bart Van Assche
41787239ec Revert "init: Rename 'cgroups_activated' into 'fifo'"
Revert commit 9c61dad67e in preparation of
introducing a second interprocess communication channel.

Bug: 213617178
Change-Id: I2959a3902a1b994cca2ac99855be1fc60d63bcbb
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-18 09:42:14 -08:00
Bart Van Assche
bfcf4374ed init: Document which class Service members are not modified
It is nontrivial to derive from the implementation of class Service
which members are not modified. Hence this CL that documents this by
declaring these members 'const'.

Change-Id: I27b907a1c7044376d5c5393a29050c66cbdab7bf
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-18 09:42:14 -08:00
Bart Van Assche
5d18891e60 init: Add a unit test for the "start console" action
Treehugger starts Cuttlefish with the console disabled. Add a test that
enables the console. The purpose of this test is to trigger the code paths
in Service::Start() that are unique to processes associated with a
console.

Bug: 213617178
Change-Id: I834632ce6ec5c237c9c2c3f5b1aa7bc98c3ef260
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-18 09:42:05 -08:00
Bart Van Assche
f26e59ebba Revert "init: Fix a race condition in KillProcessGroup()"
This reverts commit 15e5ecdcd7.

Reason for revert: breaks console support.
Bug: 213617178
Bug: 258754901
Change-Id: Iffe213e2cd295461a427621f2b84933f1bebd39f
2022-11-15 00:55:45 +00:00
Bart Van Assche
15e5ecdcd7 init: Fix a race condition in KillProcessGroup()
Multiple tests in CtsInitTestCases, e.g. RebootTest#StopServicesSIGKILL,
can trigger the following race condition:
* A service is started. This involves calling fork() and also to call
  RunService() in the child process. RunService() calls setpgid().
* Service::Stop() is called and calls KillProcessGroup().
  KillProcessGroup() calls kill(-pgid, SIGKILL) before the child process
  has called setpgid(). pgid is the process ID of the child process. The
  kill() call fails because setpgid() has not yet been called.

Fix this race condition by adding a setpgid() call in the parent process
and by waiting from the parent until the child has called setsid() if a
console is attached.

Bug: 213617178
Test: Cuttlefish + atest 'CtsInitTestCases'
Change-Id: I6931cd579e607c247b4f79a5b375455ca3d52e29
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-10 09:08:21 -08:00
Inseob Kim
0fbc1d7e31 Don't unmount APEXes in microdroid
In microdroid, APEXes are passed as block devices from host, and then
mounted directly, without using /data. Unmounting APEXes on reboot is
for clean unmount of /data, so it's not needed in microdroid.

This skips unmounting in microdroid to remove unnecessary SELinux
denials.

Bug: 256793087
Test: run microdroid and reboot, see no denials happen
Change-Id: Iaf737876f5ab5de5e8f76ed8bb0963cc25d73a80
2022-11-09 12:50:14 +09:00
Bart Van Assche
9c61dad67e init: Rename 'cgroups_activated' into 'fifo'
Prepare for using the interprocess communication channel in two
directions.

Bug: 213617178
Change-Id: Ic78a3d8a2ec1f808fa5b4c4b198051655ee1b0ec
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-04 14:56:43 -07:00
Bart Van Assche
8462ceef62 Merge "Revert "init: Fix a race condition in KillProcessGroup()"" 2022-11-03 18:21:59 +00:00
Bart Van Assche
dcc378e53c Revert "init: Fix a race condition in KillProcessGroup()"
This reverts commit d8ef6f84d4.

Reason for revert: b/256874349

Change-Id: I86a1e03a0d2979db1c54abd3e78c32591fda98a1
2022-11-03 15:15:25 +00:00
Shen Lin
63ae3fdd9d init: Amend code format for DoLoadApex
Test: m init
Change-Id: I9d873cdf067ea586f75e62ff8a39cb753151f9ec
2022-11-02 11:01:04 +08:00
Treehugger Robot
c8c24a7255 Merge changes I4c55790c,I14baaa7a
* changes:
  init: Fix a race condition in KillProcessGroup()
  init: Document that ReapOneProcess() does not modify 'pid'
2022-10-27 23:17:03 +00:00
Treehugger Robot
0eaca46f48 Merge "Add mmap_rnd_bits routine for riscv64" 2022-10-27 22:28:21 +00:00
Bart Van Assche
d8ef6f84d4 init: Fix a race condition in KillProcessGroup()
Multiple tests in CtsInitTestCases, e.g. RebootTest#StopServicesSIGKILL,
can trigger the following race condition:
* A service is started. This involves calling fork() and also to call
  RunService() in the child process. RunService() calls setpgid().
* Service::Stop() is called and calls KillProcessGroup().
  KillProcessGroup() calls kill(-pgid, SIGKILL) before the child process
  has called setpgid(). pgid is the process ID of the child process. The
  kill() call fails because setpgid() has not yet been called.

Fix this race condition by adding a setpgid() call in the parent process
and by waiting from the parent until the child has called setsid() if a
console is attached.

Bug: 213617178
Test: Cuttlefish + atest 'CtsInitTestCases'
Change-Id: I4c55790c2dcde8716b860aecd57708d51a081086
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-27 14:29:35 -07:00
Bart Van Assche
c7d7ed0eae init: Document that ReapOneProcess() does not modify 'pid'
It is essential for correct operation of ReapAnyOutstandingChildren()
that ReapOneProcess() does not modify 'pid'. Make it easier to verify
for humans that ReapOneProcess() does not modify the 'pid' local
variable. Document the value of siginfo.si_signo with DCHECK_EQ()
statements.

Bug: 213617178
Change-Id: I14baaa7adbe5416b7f777f32fb76896f2ae27b4e
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-27 14:29:35 -07:00
Treehugger Robot
1b2d443626 Merge "init: Log more information if stopping times out" 2022-10-27 21:12:19 +00:00
Bart Van Assche
ea595ba2a0 init: Log more information if stopping times out
The newly logged information includes the pending signals bitmask (SigPnd).
That information allows to determine whether kill() did not deliver a
signal or whether SIGCHLD has not been processed in time. This patch is
expected to help with root-causing b/254878413.

Bug: 254878413
Change-Id: Id33d1fb724163f8e5d4b3edfeb6c4be5321c0d95
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-27 12:17:34 -07:00
Mao Han
c09eee098b Add mmap_rnd_bits routine for riscv64
Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Change-Id: Ide793f4365fee67f30e35302365c4a7a5ba1f021
2022-10-27 17:59:25 +00:00
Bart Van Assche
1a5b59386d init: Fix HandleSignalFd()
There are two bugs in HandleSignalFd():
* If the one_off argument is true and if no data is read from the
  signalfd, 'siginfo' is left uninitialized and used in the switch
  statement in HandleSignalFd().
* The PLOG() statement in the switch statement should be a LOG()
  statement since it does not report a failed system call.

This CL has been tested by changing kDiagnosticTimeout locally from 10s
into 100ms.

Change-Id: I0e488dd95bc13e1befaef770c0748d1d47f6e431
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-27 08:07:26 -07:00
Bart Van Assche
874448f4aa Merge "subcontext: Change a std::string argument into std::string_view" 2022-10-27 14:34:57 +00:00
Nathan Huckleberry
f2d93cebfd Merge changes I8174adf8,I9d252b0b
* changes:
  Expose system property for dm-verity check_at_most_once
  Fix flaky AVB test from late verity_update_state
2022-10-27 00:45:01 +00:00
Bart Van Assche
462ea55095 subcontext: Change a std::string argument into std::string_view
This change prevents that a later CL will trigger the following warning:

parameter 'test_context' is passed by value and only copied once; consider
moving it to avoid unnecessary copies

Change-Id: If5837ee6438efdf194781de041779c1089897789
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-26 09:31:59 -07:00
Nathan Huckleberry
997d738dda Expose system property for dm-verity check_at_most_once
Allow us to check if check_at_most_once is set for any partitions.

This property should be false for any device with a reasonable amount of
RAM and a modern CPU. Enabling check_at_most_once violates AVB best
practices, it should only be allowed on performance limited devices.

Bug: 253033920
Test: Ensure that avbHashtreeNotUsingSha1 CTS test still passes
    and that partition.system.verified.check_at_most_once is set.
Change-Id: I8174adf81111cc0df547ea01f81b0dfaca32631f
Signed-off-by: Nathan Huckleberry <nhuck@google.com>
2022-10-25 21:12:52 +00:00
Bart Van Assche
1693f420d4 init: Introduce class InterprocessFifo
Prepare for introducing a second interprocess communication channel by
introducing the class InterprocessFifo. Stop using std::unique_ptr<> for
holding the pipe file descriptors. Handle EOF consistently.

Bug: 213617178
Change-Id: Ic0cf18d3d8ea61b8ee17e64de8a9df2736e26728
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-25 06:56:50 -07:00
Nikita Ioffe
537ab23872 Merge "init: skip cgroup/task_profiles configuration if cgroups are disabled" 2022-10-24 07:14:12 +00:00
Bart Van Assche
77f3fe5e68 init: Fix the implementation of the task_profiles keyword
The documentation added by commit c9c0bbac53 ("init: Add task_profiles
init command") mentions that the task_profiles keyword sets process
attributes. Make the implementation of that keyword match the
documentation.

Change-Id: Ia080132f16bfc2488f8c25176d6aed37a2c42780
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-21 15:34:19 -07:00
Bart Van Assche
4029b05b04 Add __ANDROID_API_[STU]__ definitions
Bring the host_init_stubs.h header file in sync with the
<android/api-level.h> header file.

Change-Id: I0d344b5f89f909e5315a0075773efd0b725a72a4
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-21 15:33:09 -07:00
Nikita Ioffe
c2b1654c11 init: skip cgroup/task_profiles configuration if cgroups are disabled
We are planning to remove cgroups from the Micrdroid kernel, since the
entire VM belongs exclusively to a single owner, and is in the control
of the cgroups on the host side.

This patch expoxes CgroupAvailable API from libprocessgroup, and changes
init to query the CgroupAvailable API before doing any
cgroups/task_profiles related work.

Bug: 239367015
Test: run MicrodroidDemoApp
Test: atest --test-mapping packages/modules/Virtualization:avf-presubmit
Change-Id: I82787141cd2a7f9309a4e9b24acbd92ca21c145b
2022-10-21 13:14:23 +01:00
Bart Van Assche
dcd23dfc58 init/epoll: Stop using smart pointers
Change the type of 'handler' from std::shared_ptr<Handler> into Handler.
This change is safe since a previous CL moved the handler calls from the
Epoll::Wait() caller into Epoll::Wait() itself.

Bug: 213617178
Change-Id: Ife79e6863536b96ee4bb3cd778f6b0b164a95fed
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-20 09:32:51 -07:00
Bart Van Assche
bc5c4a4659 init/epoll: Make Epoll::Wait() easier to use
Invoke the callback functions from inside Epoll::Wait() instead of
returning a vector with pointers to callback functions. Remove handlers
after handler invocation finished to prevent that self-removal triggers
a use-after-free.

The CL that made Epoll::Wait() return a vector is available at
https://android-review.googlesource.com/c/platform/system/core/+/1112042.

Bug: 213617178
Change-Id: I52c6ade5746a911510746f83802684f2d9cfb429
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-20 09:32:51 -07:00
Bart Van Assche
a1c8a622b2 init/epoll: Switch to aggregate initialization
Make it easier to verify for humans that all data structure members are
initialized. No functionality is changed.

Bug: 213617178
Change-Id: I1ce2af566dba51f2032f2e7518576a67e666d12e
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-20 09:32:51 -07:00
Bart Van Assche
4842650043 init: Improve readability of the code in SecondStageMain()
Change the type of epoll_timeout from
std::optional<std::chrono:milliseconds> into std::chrono::milliseconds.
No functionality is changed.

Bug: 213617178
Change-Id: Ieb150e0aeabdb79c8da4649875ea3ed59297343b
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-20 09:32:51 -07:00
Bart Van Assche
b0177a0828 init/epoll: Fix a potential use-after-free
If UnregisterHandler() is called from inside a handler for an event that
has not yet been processed then that will result in a use-after-free.
Fix this by passing file descriptors to epoll_ctl() instead of pointers
to map elements.

Bug: 213617178
Change-Id: Ie62e3a299af964271ec24cd8fc2e794042b77ee6
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-18 16:34:12 -07:00
Bart Van Assche
a2c160449b init: Introduce Epoll::SetFirstCallback()
Prepare for optimizing Epoll::Wait() by moving the
ReapAnyOutstandingChildren() call into Epoll::Wait(). No functionality
is changed.

Bug: 213617178
Change-Id: I280ea0069ed29cf323e4177ec500b30b900f7c8d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-18 09:17:55 -07:00
Bart Van Assche
20954a8e34 init/epoll_test: Improve this test
Add a move constructor in the CatchDtor class. Check the .emplace()
result. Simplify the destructor. Initialize handler_invoked. Explain the
purpose of this test.

Bug: 213617178
Change-Id: I4d6f97dbb2705a2f2dd78e449ae8de74e90b102f
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-18 09:17:55 -07:00
Akilesh Kailash
889b446810 Merge "init: Detach daemon only after sepolicy is loaded" 2022-10-11 21:04:42 +00:00
Yi-yo Chiang
9b123de886 Merge "Remove deprecated BOARD_BUILD_SYSTEM_ROOT_IMAGE" 2022-10-11 10:31:19 +00:00
Akilesh Kailash
035e557fd3 init: Detach daemon only after sepolicy is loaded
The new sequence of operation would be:

1: Load sepolicy - Daemon will continue to be alive and serve any I/O request

2: After sepolicy loading is complete - Switch the device-mapper tables.

3: Kill the block device daemon launched in the first-stage init.

4: Re-launch the daemon with the correct selinux labels set.

5: Enforce the sepolicy

Bug: 240321741
Test: Full OTA on pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Idd392f0f0aae7d93e546c0ec0762e6c07b6263e4
2022-10-10 21:58:52 +00:00
Sayanna Chandula
5754b5ab10 init: Support reboot reason with thermal warmreset
Thermal shutdown could be due to tskin temperature or
battery temperature. Pass reason while rebooting the
system to reflect properly in boot.reason

Bug: 238464124
Test: Build and boot on device. Check reboot reason
for thermal shutdown and battery thermal shutdown with
thermal warmreset enabled.

Change-Id: I192562fed48ae7da7843e383362cd22a76ce479f
2022-10-07 14:11:25 -07:00
Yi-Yo Chiang
ddc9763ee2 Remove deprecated BOARD_BUILD_SYSTEM_ROOT_IMAGE
This variable is always false or empty now, so clean up remaining
references of the variable.

Bug: 241346584
Test: Presubmit
Change-Id: Id5c37a1391239206477fd802d364a2678692f513
2022-10-07 21:17:40 +08:00
Bob Badour
03d5052754 Add LOCAL_LICENSE_KINDS to system/core
Added SPDX-license-identifier-Apache-2.0 to:
  init/fuzzer/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Change-Id: I2db55c80799d0a8fc5935d9b07a2ddb17eb7235e
2022-10-06 19:59:07 +00:00
Treehugger Robot
71d9f3607b Merge changes I264d0891,I1af733e7,Iae344c1e
* changes:
  Added init_ueventHandler_fuzzer
  Added init_property_fuzzer
  Added init_parser_fuzzer
2022-10-06 13:59:37 +00:00
David Anderson
aaa16bbad4 Merge "init: Statically link libbootloader_message." 2022-10-04 16:32:50 +00:00
David Anderson
12e53bc350 init: Statically link libbootloader_message.
This is to resolve idiosyncracies with test packaging.

Bug: 244284630
Test: ldd -d -r CtsInitTestCases
Change-Id: Iec2c14c3ca5cd359b79d9e1f12e689c0eeffb122
2022-10-03 21:37:56 -07:00
Florian Mayer
84a30c8526 Merge "[MTE] Add device config to control upgrade time" 2022-10-03 17:47:12 +00:00
Cole Faust
7e279e97a3 Fix module-file name collisions
Bazel doesn't allow a module and file with the same name.

Bug: 198619163
Test: Presubmits
Change-Id: I345086764071ca649de1ac11804e21675cd5e59d
2022-09-20 12:33:47 -07:00
Florian Mayer
caa7a60e2d [MTE] Add device config to control upgrade time
Bug: 169277947
Change-Id: I67eb94a668e60a2970bb086f82cc69396275340a
2022-09-16 09:49:38 -07:00
Florian Mayer
565305b852 Merge "[MTE] only upgrade to SYNC mode for MTE crashes" 2022-09-14 01:22:45 +00:00
Florian Mayer
d705c2dbcd [MTE] only upgrade to SYNC mode for MTE crashes
Bug: 244471804
Test: atest mte_ugprade_test on emulator
Change-Id: Ie974cf2dec96267012f1b01b9a40dad86551b1be
2022-09-13 15:35:07 -07:00
Adam Langley
ecc14a5958 init: Add option to listen on sockets before starting service.
Review note: Original change was a p-o-c by agl in
https://r.android.com/2094350 which I think is actually
production quality.  I'm just taking it over so that he doesn't
get spammed by any review comments as that's not a good use
of his time.

Needed for the hardware entropy daemon (see bug).

Original commit message:
If one needs to create a service that synchronously starts listening on
a socket then there are currently no good options.

The traditional UNIX solution is to have the service create the socket
and then daemonise. In this situation, init could start the service with
`exec_start` and yet not block forever because the service forks and
exits. However, when the initial child process exits, init kills the
daemon process:

> init: Killed 1 additional processes from a oneshot process group for
> service 'foo'. This is new behavior, previously child processes
> would not be killed in this case.

Next, there is a `socket` option for services and (although the
documentation didn't nail this down), the socket is created
synchronously by `start`. However, init doesn't call `listen` on the
socket so, until the service starts listening on the socket itself,
clients will get ECONNREFUSED.

This this change adds a `+listen` option, similar to `+passcred` which
allows a socket service to reliably handle connections.

Bug: 243933553
Test: Started prng_seeder from init using the new listen flag
Change-Id: I91b3b2b1fd38cc3d96e19e92b76c8e95788191d5
2022-09-12 15:16:35 +01:00
Suren Baghdasaryan
633ce78b94 Merge "init: Change extra_free_kbytes.sh to add margin relative to the default watermark level" 2022-09-09 16:55:25 +00:00
Deyao Ren
2880afb77f Merge "Clean up services created after running test" 2022-09-09 16:20:31 +00:00
deyaoren@google.com
909bc47536 Clean up services created after running test
Services created during new tests weren't properly cleaned up after tests. It caused slowdown of subsequent tests as described in b/244486404.
This change kills/terminates services after test with apex services.

To provide some context, original change is at https://android-review.googlesource.com/q/topic:vapex_stop_service. The issue was discovered by android test monitor and filed as a P0 bug.

Bug: 244486404
Change-Id: Ie64e0eb1686e94ef543a457ea49d1d7aeab38c97
2022-09-09 04:15:26 +00:00
Suren Baghdasaryan
cfd8864f9a init: Change extra_free_kbytes.sh to add margin relative to the default watermark level
extra_free_kbytes.sh accepts a parameter representing the number of KB
to add to low and high watermarks. It adds this margin to the current
watermark levels, however this is not how /proc/sys/vm/extra_free_kbytes
knob that it replaces used to work. The old knob would add the margin
relative to the original and not the current level of the watermarks.
Change extra_free_kbytes.sh to add the specified margin to the original
watermark levels to act as correct replacement of the old knob.

Bug: 242837506
Fixes: 642048d969 ("init: Add extra_free_kbytes.sh script to adjust watermark_scale_factor")
Test: repeatedly run 'setprop sys.sysctl.extra_free_kbytes 30375'
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I8af603ba00bd4fb8182b80b3c0969fa96cdd7311
2022-09-08 19:34:43 +00:00
Bob Badour
9cf81ccfef [LSC] Add LOCAL_LICENSE_KINDS to system/core
Added SPDX-license-identifier-Apache-2.0 to:
  init/test_upgrade_mte/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Change-Id: I77b956ed672a2f171b78ab1e7bfddc09bd0dc158
2022-09-08 15:23:25 +00:00
Sandro
d01921034c Remove /dev/selinux directory creation from first_stage_init.cpp
Follow-up from aosp/2203897

Bug: 243923977
Test: m and manual verification
Change-Id: I9e41301d2fe4447906253a5c1249dc6c25cd5218
2022-09-07 15:04:59 +00:00
Sandro
1120f7f4a9 Create /dev/selinux folder if it was not created by first-stage-init
The /dev/selinux folder is normally created by first-stage-init
https://cs.android.com/android/platform/superproject/+/master:system/core/init/first_stage_init.cpp;l=299-300;drc=07c86bace1e7a7cc4dd975f10b077d21c3743749

However, in some cases the first-stage-init comes from a GKI prebuilt
boot.img and doess not create the required folder (see for example
b/217677967), resulting in bugs like b/244793900.

I modified the selinux.cpp code to create the /dev/selinux folder if it
does not exist already, as a safety measure.

To verify these changes for b/244793900, follow gpaste/4922166775644160

Bug: 243923977
Test: atest SeamendcHostTest, manual verification
Change-Id: I8fe798643b1aeab2b4caac837055348febf70b94
2022-09-07 11:31:47 +00:00