Commit graph

233 commits

Author SHA1 Message Date
Nate Myren
32677ae8f3 Only write appcompat properties if flag is defined
Only writes the appcompat properties if the
WRITE_APPCOMPAT_OVERRIDE_SYSTEM_PROPERTIES cflag is defined

Fixes: 331307495
Test: manual
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f04f6bae4314e01111045ba231010ba7067477a0)
Merged-In: Ie99b5027a9704c0f4f7fe4d3a6a6cf49f4bb8176
Change-Id: Ie99b5027a9704c0f4f7fe4d3a6a6cf49f4bb8176
2024-04-19 19:07:52 +00:00
Jiyong Park
12c64a7586 Don't install Android-only dependencies to microdroid
init_second_stage_defaults provides properties that are common to both
Android's init and Microdroid's init. Before this CL, it included
target.product.required and target.recovery.required properties. The
required dependencies were Android-specific; the dependencies included
Android-only init.rc. Microdroid has its own init.rc (microdroid_init_rc
module).

This was problematic but so far it didn't cause an issue because those
Android-only dependencies were not installed to Microdroid due to a bug
in the build system.

As we fix the build system bug, the Android-only dependencies started
get installed to Microdroid, effectively overriding the Microdroid-only
init.rc file. This made Microdroid fail to boot.

Fixing this issue by moving the Android-only dependencies out of the
defaults module and putting them on the Android's init.

In addition to that, this CL removes the recovery variant for the
Microdroid's init because it's not used.

Bug: N/A
Test: run AVF tests
Change-Id: I09748f1123125cac74ce54fd5c360c9a3ba2f996
2024-04-17 14:36:55 +09:00
Nikita Ioffe
feb7e0ea97 Restorecon /microdroid_resources in setup_selinux
The main reason for running restorecon of /microdroid_resources during
the setup_selinux stage is to avoid granting init some weird permissions
like `allow init tmpfs:file relabelfrom;`.

Instead we add such permissions to kernel domain in which setup_selinux
runs. This feels better since kernel domain already has similar
permissions like `allow kernel rootfs:file relabelfrom;`.

Bug: 287593065
Test: run microdroid vm with vendor partition
Change-Id: I82ef5499392e90f53655f7582e887d0b6cb3a5f0
2024-04-04 13:04:52 +00:00
Jeongik Cha
6d7e83fb42 Add //visibility:any_system_partition
system image which is declared in Android.bp should include the module.

Bug: 321000103
Test: m nothing
Change-Id: I6e9d8fa4c1051211ff9ff80c7dfa4a8ee5cbd732
2024-03-23 12:31:32 +09:00
Nikita Ioffe
1e114e677b Add a step to derive microdroid vendor dice node
The derivation happens in the derive_microdroid_vendor_dice_node binary
which first_stage_init forks and execvs.

Since the derivation requires talking to the dice driver, its
initialisation is also moved to the first stage init.

The derivation happens before the microdroid vendor partition is
verified & mounted. This should be safe because the first_stage_init
will fail the boot if the verification of the microdroid vendor
partition fails.

Bug: 287593065
Test: run microdroid with and without vendor partition
Test: atest MicrodroidTests
Change-Id: I0d83772eb98a56c315617e66ec64bd03639cfde6
2024-03-13 15:24:44 +00:00
Nikita Ioffe
2384e8abfe Mount /microdroid_resources as tmpfs
This will be used to store the new dice chain generated during
first_stage_init phase in case Microdroid VM is launched with
microdroid vendor partition.

Bug: 287593065
Test: atest MicrodroidTests
Test: start Microdroid VM & check microdroid_resources exists
Change-Id: I40677376bfed14d813ad51c78db6109b2d76d1d1
2024-03-13 14:39:08 +00:00
Jooyung Han
18407b7870 init: move generated_android_ids to host_init_verifier
It's used only by host_init_verifier. This is to remove the unnecessary
dependency from clients of init_host_defaults.

Bug: 326509378
Test: mmma system/core/init
Change-Id: I983fbfe616f0bcb87940c934e19f614d3bf51030
2024-02-26 11:18:00 +09:00
Jooyung Han
39e8be43eb Add check_builtins to libinit_host
This requires a bit of refactoring: moving things around.

libinit_host is used by host_apex_verifier which needs check_builtins as
well.

Bug: 325565247
Test: atest host-apex-verifier
Test: m out/target/product/vsoc_x86_64/host_init_verifier_output.txt
Change-Id: Ifed54dd2149afbab2bf63f7e42c410c2354895fc
2024-02-16 17:36:12 +09:00
Jiyong Park
0edd5b860a Merge "Drop CtsInitTestCases from cts" into main 2024-01-31 00:58:50 +00:00
Jiyong Park
75070b37e2 Drop CtsInitTestCases from cts
The test is not eligible for CTS. Reasons:

1. The init behavior does not directly affect app compat. App interact
   with init only for the property service and that part is covered by
the Bionic test already.

2. This test doesn't run against the init binary installed on the
   device. libinit where most of the init functionalities are
implemented is statically linked to this test binary. In other words,
this test is closer to a unit test for init.

3. This test is not compatible with Trunk stable where test and DUT are
   built in different branches. The test depends on several (private)
libraries like libbase and libutils. Since the interfaces of the
libraries may have changed in the main branch, the test binary built
from the old test-dev branch may break.

This change does not remove the test. The test will still run as a unit
test during pre/post submit.

I didn't drop the `Cts` prefix from the name, because that requires
broader changes.

Bug: 320800872
Test: N/A
Change-Id: I1402c08b79b57ad6daa7948fe37f14fbbe36f1d6
2024-01-30 10:24:10 +09:00
Justin Yun
6bc1bfe160 Use libvendorsupport for vendor api level calculation
Remove temporary 'vendor_api_level_of' function from init and replace
the function with the same in libvendorsupport.

Bug: 312403948
Test: getprop ro.vendor.api_level
Change-Id: I095353e602397220571e131431e7cbd1b8511fa6
Merged-In: I095353e602397220571e131431e7cbd1b8511fa6
2024-01-10 14:06:43 +09:00
Eric Biggers
5d7c35ce20 init: remove session keyring workaround for old kernels
The android-4.14-stable and later kernels support the
FS_IOC_ADD_ENCRYPTION_KEY and FS_IOC_REMOVE_ENCRYPTION_KEY ioctls.  This
has superseded the old way of adding fscrypt keys to the kernel, which
was to use the add_key() syscall to add keys to the "session" keyring.
On kernels that support the ioctls, Android doesn't use the obsolete
way.  Since upgrading even just to Android 14 requires at minimum a
android-4.14-stable kernel (according to
https://source.android.com/docs/core/architecture/kernel/android-common#compatibility-matrix),
there is no need to support the obsolete way anymore.

Therefore, this commit removes the code from init that created a keyring
named "fscrypt" in the session keyring.  It also removes the code that
created the session keyring itself, since the only reason that Android
even created a session keyring was just to hold the "fscrypt" keyring.

Flag: N/A for the following reasons:
      - Removing obsolete code, which is fairly safe
      - Very early code, so runtime flag cannot be used
      - Even a build-time flag cannot be used, since init needs
        recovery_available, which aconfig libraries do not support

Bug: 311736104
Test: Build and boot Cuttlefish
Change-Id: Id9a184c68cf16d5c4b1d889444cf637c95a91413
2023-11-27 23:43:49 +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
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
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
6b57c885d3 Merge "init_first_stage: Disable ThinLTO" into main 2023-07-21 05:08:13 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Kelvin Zhang
5cb1b0295e Add lz4 support for VABC
Add lz4 support in CowWriter/CowReader. Lz4 should offer faster
read/write performance but slightly larger COW sizes.

Download time: Reduced from 1264s to 825s (~35% faster)
Filesystem verification time: from 69s to 59s (~15% faster)
COW Size: 2.59GB to 3.21GB, (~25% regression)
Merge time: 37046ms to 27690ms (~25% faster)
Boot time: LZ4 is 2.7% faster

Overall, LZ4 offers faster read/write performance at the cost of 25%
space regression.

Test: th
Bug: 228478555
Change-Id: Ie521852fb3c9ff8a12e55b764c1eb1838f7b2181
2022-06-29 13:10:55 -07:00
Treehugger Robot
ac9b59ed5a Merge "Added libinit_headers to Android.bp" 2022-06-03 08:57:08 +00:00
Christopher Ferris
d2bd6c5f13 Use new AndroidUnwinder object.
Replace libbacktrace with the new AndroidUnwinder object.

Bug: 120606663

Test: Ran unit tests.
Test: Added call of UnwindMainThreadStack() in DebugRebootLogging()
Test: and verified unwind data is logged properly.
Change-Id: Ia724f9485377d6d2c894283242a3c5653bf82768
2022-05-11 15:39:20 -07:00
Devendra Singhi
1df957b9be Added libinit_headers to Android.bp
Test: Builds libint_headers
Bug: 218631398

Change-Id: Ia47d3c23cd4d4be7abc618ac1d2bf698f7761446
2022-04-26 09:51:59 +05:30
Daniel Norman
f1200fb117 Adds an init host lib for use in host_apex_verifier.
Includes extracting the APEX-specific SDK version naming scheme filter
logic so it can be reused when host_apex_verifier looks at rc files
inside the APEX.

Bug: 222121216
Test: Use in host_apex_verifier
Change-Id: I0396a455f30d2de71525ccd3fa69c75576054048
2022-03-21 15:45:44 -07:00
Jeffrey Vander Stoep
baeece6d0c Revert "Revert "Use Apex sepolicy if it's available""
This reverts commit 5638fcc22b.

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

Change-Id: I8d2fbf0cab23a56dbea1f422608097c48d9288c0
2022-02-08 12:42:33 +00:00
Jeffrey Vander Stoep
5638fcc22b Revert "Use Apex sepolicy if it's available"
Revert "Build precompiled_sepolicy.apex_sepolicy.sha256"

Revert submission 1965099-precompiled-apex-sepolicy

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

Change-Id: I1cca3a1ae833c21619de26b2610736170ec5463c
2022-02-01 11:21:38 +00:00
Jeff Vander Stoep
2e4b3ffa75 Use Apex sepolicy if it's available
[reland aosp/1910032]

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

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

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

Change-Id: I2dbe43e329e91f46abedc7e44f7d24b220e19173
2022-01-28 13:47:24 +01:00
Yi-Yo Chiang
aff8d4b02c Merge "init_first_stage: Remove unused srcs & static libs" am: 15ae358c71
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1838538

Change-Id: I73b198ae080e3aa1aa35d6471905bcf8902653c7
2021-09-29 04:10:36 +00:00
Yi-Yo Chiang
bc35e823e9 init_first_stage: Remove unused srcs & static libs
Test: Build pass
Change-Id: Id79ad1cf1e66c34c9ef24776c417f40286941bc7
2021-09-28 20:22:45 +08:00
Yi-Yo Chiang
623fb83cb2 Merge "Reland: Add /system_ext/etc/selinux/ to the debug policy search path for GSI" am: 711b56e2a0
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1834756

Change-Id: I6f9544179fea2a9685d13f067df58ad2046d1acb
2021-09-24 03:25:31 +00:00
Yi-Yo Chiang
bb77c544e5 Reland: Add /system_ext/etc/selinux/ to the debug policy search path for GSI
This change only *adds* /system_ext/etc/selinux to the debug policy
search path, and does not change any preconditions to load the debug
policy. The device still needs to be bootloader-unlocked and has the
debug ramdisk flashed to be able to use the debug policy. The only thing
changed is that now the debug policy can be loaded from /system_ext or
/debug_ramdisk when system partition is compliance testing GSI.

The debug policy in the boot ramdisk may be outdated if the system
partition is flashed with a image built from a different revision.
This happens frequently when running the compliance testing VTS, where
the device is flashed with (A) GSI and (B) device vendor image & debug
boot image, and (A) and (B) are built from different git revisions.

To address this, we install a copy of the debug policy under
/system_ext, so that the version desync between (A) & (B) wouldn't be a
problem anymore because (A) no longer relies on the debug policy file
from (B).

Bug: 188067818
Test: Flash RQ2A.201207.001 bramble-user with debug ramdisk & flash
  gsi_arm64-user from master, device can boot and `adb root` works
Change-Id: Ibe17eb1ecb0e813309c9596d1f152b7455686b26
2021-09-23 14:26:27 +00:00