Commit graph

3987 commits

Author SHA1 Message Date
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