Commit graph

3883 commits

Author SHA1 Message Date
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
Treehugger Robot
c113dc3a95 Merge "Upgrade MTE to SYNC after ASYNC crash." 2022-09-06 21:29:14 +00:00
Florian Mayer
2ef47f8f6d Upgrade MTE to SYNC after ASYNC crash.
Bug: 169277947
Test: atest mte_ugprade_test on emulator.
Test: ASSUMPTION_FAILED on non-MTE
Test: ASSUMPTION_FAILED on HWASan
Change-Id: I5328d094ffb106abaa548feb76058c9ebd11d745
2022-09-06 20:10:57 +00:00
Jooyung Han
93c24d7e65 Only run Service::Start() under root
Tests using Service::Start() should run under root. Otherwise tests fail
to start services from the test binary due to lack of permission.

Bug: 244748231
Test: CtsInitTestCases
Change-Id: Ia4eb8457cfad7d44da6b171e44f64238e08af9f7
2022-09-06 10:03:47 +09:00
Jiyong Park
a5dfe700b8 Merge "init: remove unnecessary semicolon" 2022-09-02 11:39:05 +00:00
Jooyung Han
c69bcd4a6d Merge "Removed property init.apex.<apex-name>.load/unload." 2022-09-02 06:46:54 +00:00
Deyao Ren
259b63d71c Removed property init.apex.<apex-name>.load/unload.
Bug: 240533726
Test: atest CtsInitTestCases ApexTestCases
Change-Id: I7ed149f24dc4b116865320c85389ffe7bae6ae0d
2022-09-01 16:14:00 +00:00
Deyao Ren
e37c15e9b0 Merge changes from topic "vapex_stop_service"
* changes:
  Remove and add service and action during apex load and unload
  Stop services when unload an apex
2022-08-31 16:09:43 +00:00
Deyao Ren
238e909349 Remove and add service and action during apex load and unload
Bug: 232114573
Test: atest CtsInitTestCases ApexTestCases
Change-Id: I1f91ada1d44ac2380e2faf8fc25e0a521cc1a826
2022-08-30 17:31:00 +00:00
Treehugger Robot
85d69af38e Merge "Validate persistent properties file" 2022-08-30 08:42:09 +00:00
Bart Van Assche
fcf047113f init: Apply the NormalIoProfile when creating a service
Prepare for migration of the blkio controller to the v2 cgroup hierarchy
by applying the NormalIoProfile when starting a service. While the
NormalIoProfile is automatically applied when the blkio controller is
mounted in the v1 hierarchy, this is not the case for the v2 hierarchy.

Bug: 213617178
Change-Id: I3cad288a31aa2692e10c778ae1e5fdd04acd66d7
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-08-25 14:01:01 -07:00
Paul Crowley
f7c74694d7 Validate persistent properties file
Before loading persistent properties, init now checks if there are any
invalid properties (not starting with "persist.").

Bug: 243723877
Test: atest persistent_properties
Change-Id: Ieb4ddce05916f193388af6b658e1904004ffa473
2022-08-25 11:40:18 -07:00
Sandro
956ce287f3 Add SeamendcHostTest to selinux.cpp TEST_MAPPING
SeamendcHostTest should run when making changes to selinux.cpp, to
ensure the test logic is updated to match the logic selinux.cpp follows
when it decides to compile the SELinux policy in the OpenSplitPolicy
method.

Bug: 238394904
Test: atest --test-mapping system/core/init/TEST_MAPPING:presubmit
Change-Id: Iaf0ec2356a894b071e6875dd41bcf9e842126e42
2022-08-25 09:26:24 +00:00
Deyao Ren
07595e198c Stop services when unload an apex
Bug: 238854102
Test: atest CtsInitTestCases ApexTestCases
Change-Id: I3b9df9424f7841c42bd1bde27cd0e0750615bd6c
2022-08-24 06:22:57 +00:00
kunal rai
803b5f4230 Added init_ueventHandler_fuzzer
Test: ./init_ueventHandler_fuzzer
Bug: 218631398

Change-Id: I264d0891f14cc5836e45d08578347737c94a168f
2022-08-19 11:48:30 +05:30
Akshata Kadam
2ae767105d Added init_property_fuzzer
Test: ./init_property_fuzzer
Bug: 218631398

Change-Id: I1af733e7f82bef2979fc308b0109094b0ebe1e28
2022-08-19 11:48:19 +05:30
Devendra Singhi
d29be4aaa0 Added init_parser_fuzzer
Test: ./init_parser_fuzzer
Bug: 218631398

Change-Id: Iae344c1e174fb5e07a0fb6813744fa1ae78eff6a
2022-08-19 11:48:07 +05:30
Xin Li
4f74d4542d Merge "DO NOT MERGE - Merge Android 13" 2022-08-16 19:08:18 +00:00
Trevor Radcliffe
fcfd725a5c Point directly to generated c sysprop_library
Bug: 226199990
Test: m
Change-Id: I0ea65714f9a27093b37034abde7d59f1951a5cb6
2022-08-12 18:23:40 +00:00
Deyao Ren
aebf88191b Merge "Add apex name to service" am: ec73481e58
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2155014

Change-Id: I3c44c321568173fa11588c2d6c69a43ad48c63f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-22 23:09:19 +00:00
Jooyung Han
07316159c3 Merge "Respect namespace mnt" am: ba1fbaf50c
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2163903

Change-Id: I67d5c5d93109b97b376fb97b01618893aba8af13
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-22 23:08:56 +00:00
Deyao Ren
ec73481e58 Merge "Add apex name to service" 2022-07-22 23:03:45 +00:00
Jooyung Han
5eb441caca Respect namespace mnt
This fixes the regression of aosp/2153354.
SwitchToMountNamespaceIfNeeded() is supposed to switch between "default"
mount namespace and "bootstrap" mount namespace. But it shouldn't affect
services with its own mount namespace.

Bug: 239882455
Test: make a hal service start in a separate mount namespace
    using 'namespace mnt' in its definition.
    see the mount namespace of the service process
    $ cat /proc/$(pgrep -f myservice)/ns/mnt
Change-Id: I8c80eaec723241c405f48980b9e88640123c43ad
2022-07-23 01:41:18 +09:00
Deyao Ren
df40ed1be1 Add apex name to service
Passed apex file name to service. The file name will be parsed
to determine 1) whether the service is from an apex; 2) apex name

Bug: 236090201

Change-Id: I2c292c0c067f4bf44bb25b1f80e4f972b94f7258
2022-07-22 04:00:30 +00:00
Yi-yo Chiang
a367bdbc4c Merge "Revert "first_stage_mount: Bind mount /system after switch root"" am: e321b113d6
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2159462

Change-Id: Ie9afb0754d73a7bdcf735c8dc6d1c0fec4a514db
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-20 03:57:26 +00:00
Yi-yo Chiang
e321b113d6 Merge "Revert "first_stage_mount: Bind mount /system after switch root"" 2022-07-20 03:49:59 +00:00