Commit graph

4095 commits

Author SHA1 Message Date
T.J. Mercier
ef9e7f8572 Merge "libprocessgroup: Remove max_processes from KillProcessGroup API" into main 2023-11-06 21:43:59 +00:00
Treehugger Robot
6c7dca816f Merge "Update fmtlib to 10.1.1" into main 2023-11-05 03:36:11 +00:00
Bart Van Assche
63d52783de Merge changes I3c882c36,I930c668d,I29e2d51d into main
* changes:
  init: Fix a bug in the WaitToBeReaped() logging code
  init/host_init_verifier: Fix a compiler warning
  init: Fix a compiler warning
2023-11-03 00:55:57 +00:00
Bart Van Assche
7ce6453aa8 init: Fix a bug in the WaitToBeReaped() logging code
Only report status information for the processes that are still running.
Additionally, make the logging output look better by starting the
process information from /proc start on a new line.

Fixes: ea595ba2a0 ("init: Log more information if stopping times out")
Change-Id: I3c882c364f11278087a78efb7a8e8fee8e582417
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-02 13:06:23 -07:00
Bart Van Assche
4844092066 init/host_init_verifier: Fix a compiler warning
Fix the following compiler warning:

//system/core/init:host_init_verifier clang++ host_init_verifier.cp
system/core/init/host_init_verifier.cpp:112:9: warning: ISO C++ requires field designators to be specified in declaration order; field 'pw_shell' will be initialized after field 'pw_uid' [-Wreorder-init-list]
        .pw_uid = 0,
        ^~~~~~~~~~~
system/core/init/host_init_verifier.cpp:111:21: note: previous initialization for field 'pw_shell' is here
        .pw_shell = static_shell,
                    ^~~~~~~~~~~~

Change-Id: I930c668d7fb1d12ebe9307b1549776da71a9a95a
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-02 13:06:23 -07:00
Bart Van Assche
ac8b5bd0bc init: Fix a compiler warning
Fix the following compiler warning:

system/core/init/init.cpp:754:57: warning: ISO C++ requires field designators to be specified in declaration order; field '' will be initialized after field 'sa_flags' [-Wreorder-init-list]
    const struct sigaction act { .sa_handler = SIG_DFL, .sa_flags = SA_NOCLDSTOP };
                                                        ^~~~~~~~~~~~~~~~~~~~~~~~
system/core/init/init.cpp:754:34: note: previous initialization for field '' is here
    const struct sigaction act { .sa_handler = SIG_DFL, .sa_flags = SA_NOCLDSTOP };
                                 ^~~~~~~~~~~~~~~~~~~~~

Change-Id: I29e2d51dfdff85212a33eebfd51b241268cdfe9a
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-02 13:06:22 -07:00
Dennis Shen
fa21f12e3b Merge "Move staging value application logic to persistent_properties and add unit tests" into main 2023-11-02 17:00:44 +00:00
Dennis Shen
79283ef377 Move staging value application logic to persistent_properties and add
unit tests

1, Previous implementation has the staged prop application done in
property_service, which caused a number of unnecessary changes which
including exposing apis like AddPersistentProperty. In addition, it made
the property_service logic complicated. A better design is to have the
staged value application done while reading the persistent properties
from file. This way, no change to property service. In addition, unit
test is much cleaner and efficient.

2, add a unit test to lock down the behavior. Specifically, it locks down that when a prop is staged, it should be applied the next time when the persistent prop is loaded. In addition, it should lock down that other persistent props are not overwritten.

Bug: b/307752841, b/300111812, b/306062513

Change-Id: I43c603efbb803195065dda3f0bc2145716302bbc
2023-11-02 14:17:33 +00:00
Henri Chataing
6bdb5f86cd Update fmtlib to 10.1.1
Test: m
Change-Id: I1f23ea1a07c792c3b4974414aef9aeb9ae8f11d7
2023-11-01 17:25:37 +00:00
T.J. Mercier
599d979126 libprocessgroup: Remove max_processes from KillProcessGroup API
The max_processes calculation is incorrect for KillProcessGroup because
the set of processes in cgroup.procs can differ between the multiple
reads in the implementation. Luckily the exact value isn't very
important because it's just logged. Remove max_processes from the API
and remove the warning about the new behavior in Android 11.

Note that we still always LOG(INFO) that any cgroup is being killed.

Bug: 301871933
Change-Id: I8e449f5089d4a48dbc1797b6d979539e87026f43
2023-10-31 16:31:44 +00:00
Treehugger Robot
1f5e877185 Merge "Initialize the appcompat system property folder" into main 2023-10-31 02:29:56 +00:00
Jiyong Park
c7230a1eb1 Don't overwrite persistent property files
This fixes a bug introduced by I81b6bd984aad8f7ddec93ce74f4543e4f71be508

In the original CL, setting a sysprop `next_boot.<name>` and then
rebooting the device could remove all the persistent properties stored
in /data/property/persistent_properties. It happened because the
function `WritePersistentProperty` is called with a properties set which
is initialized as an empty set and then added with the properties which
had the next_boot prefix.

As a result...

Before the boot:
* persist.a = 1
* next_boot.b = 2
* next_boot.persist.c = 3

After the reboot:
* b = 2
* persist.c = 3

persist.a gets lost.

This change fixes the issue by populating properties set from the memory
and then save it to the file.

Bug: 306062513
Bug: 300111812
Test: do the following.
$ adb root
$ adb shell setprop persist.a 1
$ adb shell setprop next_boot.b 1
$ adb shell setprop next_boot.persist.c 1

$ adb reboot
$ adb shell getprop persist.a
1    // was (none) before this change
$ adb shell getprop b
1
$ adb shell getprop persist.c
1

$ adb reboot
$ adb shell getprop persist.a
1    // was (none) before this change
$ adb shell getprop b
     // (none) because b isn't persisted. WAI.
$ adb shell getprop persist.c
1

Change-Id: I85d3777f9b32523b010e49b8ca53f4319dd2ce05
2023-10-20 21:20:50 +09:00
Nate Myren
c25abe4739 Initialize the appcompat system property folder
Certain applications may have their system properties overlaid with the
contents overlaid for appcompat purposes. Init must initialize the
appcompat folder, same as it does the standard folder.

Bug: 291814949
Test: manual
Change-Id: I6d239e0a10a1c81a05d4121e5fc2c41da5b3dbc4
Merged-In: I0c6a0f66dc543c6e861bc86a417e4feb5ecd7789
2023-10-19 20:17:55 +00:00
Thiébaud Weksteen
b010393fe5 Remove write to /sys/fs/selinux/checkreqprot
This SELinux option has been deprecated in the kernel since v5.7. In
v6.4, commit a7e4676e made any write to this file a no-op.

Since v4.4, the default value of 0 is set by the kernel. Skip the
setting of this value since we only support kernel >= 4.14.

Test: presubmit
Change-Id: Ied5945532e10b156dc0d9996b2a41a99d04e750b
2023-10-19 11:39:42 +11:00
Elliott Hughes
3aee719660 Merge "init: don't use magic numbers for RLIMIT_ constants." into main 2023-10-17 15:34:56 +00:00
Elliott Hughes
7a19bf8e0d init: don't use magic numbers for RLIMIT_ constants.
Also, why are we accepting the completely made-up "RLIM_AS" but not the
real "RLIMIT_AS" in .rc files?

Bug: http://b/293894041
Test: treehugger
Change-Id: I18b10b6dd77265a9a14b88bfdf1cc0b474800a94
2023-10-16 22:29:47 +00:00
Dennis Shen
f307ee0767 Merge "apply staged property value when loading persistent props" into main 2023-10-13 18:22:56 +00:00
Dennis Shen
678d268848 apply staged property value when loading persistent props
Bug: b/300111812
Change-Id: I81b6bd984aad8f7ddec93ce74f4543e4f71be508
Merged-In: I81b6bd984aad8f7ddec93ce74f4543e4f71be508
2023-10-13 13:18:50 +00:00
Yi-Yo Chiang
c519d1dde2 Merge "Revert "init_first_stage: Disable ThinLTO"" into main 2023-10-12 10:33:54 +00:00
Yi-Yo Chiang
1a3dd7eb4b Revert "init_first_stage: Disable ThinLTO"
This reverts commit 4d6fa8ccaf.

Reason for revert: b/295944813 is fixed

Bug: 304290959
Change-Id: I2d6f5216800d6ee26b25623898836dc216c8be18
Test: adb-remount-test.sh
2023-10-11 02:06:26 +00:00
David Anderson
d8a9a0c81c init: Remove arbitrary delay in async persist writes.
Bug: 297093092
Test: manual test
Change-Id: Ia80b33d2fe87aa5da64b4f156fefeb474e68dc93
2023-10-06 14:52:08 -07:00
Elliott Hughes
7d46c3fd7a Remove obsolete <linux/capabilities.h> workarounds.
We've updated the glibc header (and musl will just use the bionic uapi
headers), so this is obsolete (and getting in the way of someone trying
to use the PERFMON capability).

Test: treehugger
Change-Id: Ife7ee076179e1db6246738aa41c2b82bd8546265
2023-09-29 22:45:59 +00:00
Treehugger Robot
73fcd754ee Merge "Only skip _16k/_64k kernel modules dirs on 4K builds" into main 2023-09-22 21:55:11 +00:00
Kelvin Zhang
b4987345ff Only skip _16k/_64k kernel modules dirs on 4K builds
The initramfs.img from kernel builds do not store kernel modules under
_16k directory. Currently, init is programmed to only load kernel
modules from _16k dir if running on 16K page size kernel. Relax this
restriction so that booting on custom 16K kernel would work without
going through platform rebuild.

Test: th
Bug: 293313353
Bug: 300184677

Change-Id: I9ee3c74066ad9ec5127f1e8662f7c1273445994c
2023-09-22 09:14:43 -07:00
Treehugger Robot
9c562cf82b Merge "Delete unused DATA_MNT_POINT macro" into main 2023-09-21 17:33:28 +00:00
Andrew Scull
f06e218e82 Delete unused DATA_MNT_POINT macro
The macros isn't used anywhere but was a distraction when tracking down
/data mounting behaviour.

Test: build
Change-Id: Ie23574326cbebd7f515c8409e1dcb91a00cafc6f
2023-09-21 14:50:55 +00:00
Elliott Hughes
cc8d909ccb Merge "arm64: update the "minimum maximum" comment." into main 2023-09-20 15:55:18 +00:00
Elliott Hughes
d741c23288 Merge "riscv64: minor ASLR bits changes." into main 2023-09-19 21:23:00 +00:00
Elliott Hughes
6bc53ff7dd arm64: update the "minimum maximum" comment.
Noticed while looking at riscv64. Looks like a bug, but actually nothing
we can do about it now or for the foreseeable future.

Bug: https://github.com/google/android-riscv64/issues/45
Test: treehugger
Change-Id: I2be81b2fd7095df40958a1f641d7b89cf5a8e41d
2023-09-19 20:08:41 +00:00
Elliott Hughes
b60befa806 riscv64: minor ASLR bits changes.
Improve the comment, and increase the "minimum maximum" to 24 --- we
only support 64-bit, and 64-bit never has less than 24 bits.

Bug: https://github.com/google/android-riscv64/issues/1
Test: treehugger
Change-Id: I478c7649aa19258352c908a449cabe12da94952c
2023-09-19 18:47:18 +00:00
Thiébaud Weksteen
50f03fd58e Revert "Use Apex sepolicy if it's available"
This reverts commit baeece6d0c.

Test: boot aosp_cf_x86_64_phone-userdebug
Bug: 297794885
Change-Id: I0515bc30eba42589c407deb587684b4da011aead
2023-09-06 10:52:49 +10:00
Thiébaud Weksteen
9fb6b49131 Merge "Remove SeamendcHostTest from TEST_MAPPING" into main 2023-09-05 05:10:01 +00:00
Kelvin Zhang
dba385edda Ignore 16K kernel modules when running on 4K kernel
Test: th
Bug: 293313353
Change-Id: I02ea01c8e67b9ded164c7492eea3be0aead75de1
2023-09-01 09:55:35 -07:00
Thiébaud Weksteen
18ff56d8d7 Remove SeamendcHostTest from TEST_MAPPING
Bug: 297794885
Test: TH
Change-Id: I49c6caa575ccd570085de15ddf51ea9a71abe90f
2023-08-31 14:22:48 +10:00
Yinchu Chen
3343ca2380 Increase the number of service supplementary group
OEM can add self-owned groups, but the system init cannot support if the group numbers are over than 12, relax some restrictions as appropriate.

Bug: b/296826987

Signed-off-by: Haichao Li <liuhc3@motorola.com>
Change-Id: I231d9f6c82e93c08bc97ca32df70e5b28760acbc
2023-08-25 04:24:48 +00:00
Jooyung Han
d6b65fb307 init: reset errno in do_start
do_start() ignores ENOENT intentionally to avoid logspam. It's
implemented in ErrorIgnoreEnoent. However, without resetting errno,
ErrorIgnoreEnoent will ignore unrelated errors from Service::Start() due
to the sticking errono set from other commands.

Bug: 296821716
Test: launch_cvd
Change-Id: I71d3113bdb69bdca82e2ff4f3a793301749f6c08
2023-08-22 09:59:26 +09:00
Jooyung Han
fdbf5a5eac Merge "init: clean up DelayService()" into main 2023-08-21 22:52:01 +00:00
Jooyung Han
646e001bb5 init: clean up DelayService()
ServiceList's services_update_finished flag was overlapped with the
global flag: is_default_mount_namespace_ready. Now DelayService() relies
on the is_default_mount_namespace_ready flag.

Add a service description with 'updatable' flag and invoke 'start
<name>' in 'on init' block (which comes before APEX activation).
See the log for "Cannot start an updatable service".

Bug: 293535323
Test: see the comment
Change-Id: I9341ba1a95d9b3b7c6081b530850d61f105f0a56
2023-08-21 18:37:23 +09:00
Kelvin Zhang
d479afa037 Load kernel modules from /lib/modules/uname -r_$(page_size) if present
To support booting from both 4k/16k kernels, init need to tell which
kernel we are currently booting and load the right modules. To resolve
this issue, we store 16K modules into /lib/modules/`uname -r`_16k
directory.

Test: th
Bug: 293313353
Change-Id: I4a8296384537a71e16cd20e76e6c5dfb9074f574
2023-08-18 17:04:39 -07:00
Kelvin Zhang
4b503b968c Fix uninitialized var compiler warnings
Test: th
Bug: 293313353
Change-Id: I87420a21a9c2ce1987179bf70767ea15b26cd5a5
2023-08-17 15:12:49 -07:00
Eric Biggers
87d6c8a1d5 Merge "Avoid two SELinux related error messages at boot time" into main 2023-08-14 17:33:15 +00:00
Eric Biggers
141c6a886c Avoid two SELinux related error messages at boot time
It is expected that /metadata/ota/rollback-indicator and /metadata/gsi
don't always exist, so don't call selinux_android_restorecon() on them
when they don't exist.  This eliminates the following error messages:

0     0 E selinux : SELinux: Could not get canonical path for /metadata/ota/rollback-indicator restorecon: No such file or directory.
0     0 E selinux : SELinux:  Could not stat /metadata/gsi: No such file or directory.

Test: Booted Cuttlefish and verified the error messages are gone
Change-Id: I94c998556c85adde5f11f134178219ba7880c2be
2023-08-11 21:12:16 +00:00
Jooyung Han
2982f09d57 Dedup apex-scanning
create_apex_data_dirs() now uses GetApexListFrom(dir) in
apex_init_util.cpp.

This is essentially a refactoring, but there are a few behavioral
changes, which I think make more sense.
- Emits no error when opendir(/apex) fails.
- Emits errors when mkdir fails for each apex.
- Does not abort `perform_apex_config` even though create_apex_data_dirs
  fails.

Bug: 293546778
Test: check /data/misc/apexdata/ after boot
Change-Id: I9d1a9710a6a626eec087c8c0fb1768667ffb036e
2023-08-11 14:14:37 +09:00
Jooyung Han
55ef3d6104 Skip bootstrap APEX RC files for the second round
Reading .rc files from bootstrap APEXes causes "double loading".
This works for services because init just ignores duplicates. But it
emits error logs, which can mislead even though there's no actual
errors. Besides, for actions, duplicates can cause a problem when
commands are not idempotent.

So, when loading RC files from APEXes for the second time, we'd better
skip those bootstrap APEXes.

Bug: 290148081
Test: VendorApexHostTestCases
Change-Id: Ia630dbd14046064b5e5c612c01ebacf57091c8d4
2023-08-11 10:02:08 +09:00
Jooyung Han
5c4217cf6e Read .rc files from bootstrap apexes
To start an early_hal service from a bootstrap vendor apex, init now
reads .rc files from bootstrap apexes as well.

In this change, perform_apex_config command is re-purposed to support
bootstrap mode. Now we have some similarity between two apexd calls:

- for bootstrap apexes (in the bootstrap mount namespace):

  exec_start apexd-bootstrap
  perform_apex_config --bootstrap

- for normal apexes (in the default mount namespace):

  restart apexd
  ...
  wait_for_prop apexd.status activated
  perform_apex_config

Note that some tasks in perform_apex_config are not needed in the
bootstrap.  For example, we don't need to create apexdata directories
for bootstrap apexes.

Bug: 290148081
Test: VendorApexHostTestCases
Change-Id: I8f683a4dcd7cd9a2466a4b1b417d84c025c37761
2023-08-10 15:40:06 +09:00
Jooyung Han
566c65239f 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 shared between two mount namespaces, hence visible
in the default mount namespace.

Bug: 290148078
Test: VendorApexHostTestCases
Change-Id: I841480e41be8def5a4c6a4aa874c4e21465a71d3
2023-08-09 17:27:39 +09:00
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
Jooyung Han
deff223842 Merge "Revert "Use /bootstrap-apex for bootstrap APEXes"" into main 2023-08-01 10:44:45 +00:00