Commit graph

219 commits

Author SHA1 Message Date
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
Santiago Seifert
f60946a242 Merge "Revert "Add /system_ext/etc/selinux/ to the debug policy search ..."" am: 2b324f5642
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1834618

Change-Id: I8b3e938430736bbe1a42c173d167d66c397f88de
2021-09-23 13:33:47 +00:00
Santiago Seifert
be09a1e643 Revert "Add /system_ext/etc/selinux/ to the debug policy search ..."
Revert "Add a copy of debug policy to GSI system image"

Revert "Add PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT"

Revert "Add system_ext_userdebug_plat_sepolicy.cil for GSI"

Revert submission 1824717-gsi_debug_policy

Reason for revert: Breaks the build (see b/200933187).
Reverted Changes:
I37ef02628:Add a copy of debug policy to GSI system image
I9c3dad8bb:Add PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT
I43adc6ada:Add system_ext_userdebug_plat_sepolicy.cil for GSI...
I4d6235c73:Add /system_ext/etc/selinux/ to the debug policy s...

Change-Id: I2eb3b00abb981c25514b75b2e7b4b7b203653390
2021-09-23 13:07:25 +00:00
Yi-Yo Chiang
1e27e4b5da Merge "Add /system_ext/etc/selinux/ to the debug policy search path for GSI" am: d7f8cf483b
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1824634

Change-Id: I6107412518294026723339a5de215593c1e6a1e7
2021-09-23 10:15:17 +00:00
Yi-Yo Chiang
650b29d234 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: I4d6235c73472e4d97619b2230292e6a0bc4b3e05
2021-09-18 20:21:25 +08:00
Suren Baghdasaryan
5cdaecf693 init: Add extra_free_kbytes.sh script to adjust watermark_scale_factor am: 642048d969
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1780972

Change-Id: I0e818f411b580cbe37288f0fe9ac77c4e2f5d75a
2021-08-17 19:24:24 +00:00
Suren Baghdasaryan
642048d969 init: Add extra_free_kbytes.sh script to adjust watermark_scale_factor
Android uses an out-of-tree /proc/sys/vm/extra_free_kbytes kernel knob
to increase low watermark. A similar /proc/sys/vm/watermark_scale_factor
knob supported in upstream kernel can be used for the same purpose.
The script implements conversion from desired extra_free_kbytes value
to watermark_scale_factor value and sets watermark_scale_factor according
to the value for extra_free_kbytes provided as a parameter.
Note that watermark_scale_factor affects high watermark differently
from extra_free_kbytes. While extra_free_kbytes increases low and high
watermarks by the same amount, watermark_scale_factor affects high
watermark 2x times. Therefore it is expected that replacing the usage
extra_free_kbytes with watermark_scale_factor will keep the same low
watermark but high watermark will be higher than before.

Usage:
    extra_free_kbytes.sh <extra_free_kbytes value>

Bug: 109664768
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Id8949be731da77be884cdeec3a765ea291dbc2f0
2021-08-17 17:02:18 +00:00
Yi-Yo Chiang
dc28bef023 Merge "init: Separate the required modules of core and recovery variants" am: 81dad902f6 am: feb6ff1ef9
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1739813

Change-Id: I2b460230b3a5bbcd260bd0ac17bd328bd51f5ca6
2021-07-30 18:35:26 +00:00
Yi-Yo Chiang
9ba6a5b8a2 init: Separate the required modules of core and recovery variants
So that init_second_stage (core) depends on core variant tools and rc
files, and init_second_stage.recovery depends on recovery variant tools
and recovery specific rc files.

Bug: 191369319
Test: Presubmit
Test: Check the ninja graph, init_second_stage.recovery no longer depend
  on core variation modules
Test: Check out/soong/Android-${PRODUCT}.mk
Change-Id: I03f0cf6af10617fe2e7de677e9dde1aecb2afc74
2021-07-24 22:51:55 +08:00
Treehugger Robot
a7ac810749 Merge "Revert "Re-land removing RECOVERY_AS_BOOT check for init_first_stage"" am: d939aa2405 am: eafdcd0b27
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1765788

Change-Id: I0b54cb36881d6e31233d83e4a81e0aab04a41fa8
2021-07-15 09:29:40 +00:00
Bowgo Tsai
ab079af28f Revert "Re-land removing RECOVERY_AS_BOOT check for init_first_stage"
This reverts commit 4818f74888.

The previous commit might introduce a build break on legacy
devices that with a smaller /boot partition size, because it
outputs the first-stage init and the second-stage init binaries
in the following locations, respectively (when
BOARD_USES_RECOVERY_AS_BOOT is true).

    * $OUT/recovery/root/first_stage_ramdisk/init
    * $OUT/recovery/root/system/bin/init

The first one is not needed because there is already a symlink
under $OUT/recovery/root:  init -> /system/bin/init.

Bug: 193565271
Test: `lunch aosp_flame-userdebug`, `make bootimage_debug` then
      checks the output under $OUT/debug_ramdisk/.
Test: Performs the same check for `lunch aosp_bramble-userdebug`.
Change-Id: I6277a6c4c0980bd976cc35db6ca99eafc6bf3f5a
2021-07-14 19:21:40 +08:00
Treehugger Robot
8df4eb971e Merge "Re-land removing RECOVERY_AS_BOOT check for init_first_stage" am: 662729bc2e am: 852981c0c3
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1762146

Change-Id: Id70e6e4bf858e026e6d88ff9fc8e05f274126b67
2021-07-13 02:01:07 +00:00
Inseob Kim
4818f74888 Re-land removing RECOVERY_AS_BOOT check for init_first_stage
This has kept adb_debug.prop from being installed for
legacy devices with BOARD_USES_RECOVERY_AS_BOOT set to
true.

Bug: 192432810
Bug: 193291885
Test: `lunch aosp_flame-userdebug` and checks `get_build_var
      BOARD_USES_RECOVERY_AS_BOOT` is true.
Test: `make bootimage_debug` then checks
      $OUT/debug_ramdisk/adb_debug.prop exists
Test: build/soong/build_test.bash --dist --incremental

Change-Id: I28e2c082512791407167b610843f18731ed6d673
2021-07-10 23:42:53 +08:00
Inseob Kim
9fa041c9a4 Revert "Remove RECOVERY_AS_BOOT check for init_first_stage"
This reverts commit 94c2593ea0.

Reason for revert: build breakage

Change-Id: I270a56bb33d19a2747298c69f6ec1b24746d97bf
2021-07-01 02:33:53 +00:00
Inseob Kim
94c2593ea0 Remove RECOVERY_AS_BOOT check for init_first_stage
This has kept adb_debug.prop from being installed.

Ignore-AOSP-First: fixes sc-release test breakage

Bug: 192432810
Test: build ramdisk-debug.img and see contents
Change-Id: I254579d2c6427213f40e9ae8e50d046e19390ba5
2021-06-30 11:35:21 +00:00