Commit graph

3173 commits

Author SHA1 Message Date
Nathan Huckleberry
997d738dda Expose system property for dm-verity check_at_most_once
Allow us to check if check_at_most_once is set for any partitions.

This property should be false for any device with a reasonable amount of
RAM and a modern CPU. Enabling check_at_most_once violates AVB best
practices, it should only be allowed on performance limited devices.

Bug: 253033920
Test: Ensure that avbHashtreeNotUsingSha1 CTS test still passes
    and that partition.system.verified.check_at_most_once is set.
Change-Id: I8174adf81111cc0df547ea01f81b0dfaca32631f
Signed-off-by: Nathan Huckleberry <nhuck@google.com>
2022-10-25 21:12:52 +00:00
Treehugger Robot
c052460659 Merge "fs_mgr_overlayfs: Fallback to allocate scratch on super if /data failed" 2022-10-25 20:56:59 +00:00
Yi-Yo Chiang
1c76ccb554 fs_mgr_overlayfs: Fallback to allocate scratch on super if /data failed
b/255593675 showed that gsid can fail to allocate scratch on /data on
some device configurations. Before we can locate the root cause,
gracefully fallback to previous "scratch-on-super" logic in case of
error.

Bug: 255593675
Test: Presubmit
Test: manual test
Change-Id: I229ab51f11fa354a6f231c4d083dd6329d6a9579
2022-10-26 03:17:37 +08:00
Akilesh Kailash
b71b32dc83 libsnapshot: Do not store CowOperations in memory during writes
The only use case of storing COW operations in memory
was to calculate SHA256 sum during Finalize() - However,
we haven't been doing that since day one of libsnapshot_cow library.

This consumes peak memory ~14mb on an incremental OTA which has 700k+
COW operations writes on one partition.

We can rather use this memory for Async operations where we will have
to cache the buffers.

Bug: 254188450
Test: Incremental OTA
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I2165ed95ff26a9dfb465dc3120df61bb02eee27b
2022-10-25 06:59:36 +00:00
David Anderson
9d8637289b Merge "snapshotctl: Add a test-blank-ota command for development." 2022-10-24 20:36:58 +00:00
David Anderson
d62bdd2974 snapshotctl: Add a test-blank-ota command for development.
The test-blank-ota command is for iterating on changes to snapuserd or
the Virtual A/B boot flow, which is normally very time consuming to
test.

It works by creating a partial OTA outside of update_engine, purely
through SnapshotManager calls. Every partition except system is
preserved. system is "updated" entirely with copy operations. The entire
"OTA" takes about ten seconds.

Tested on cuttlefish, but a physical device should work as long as
physical partitions are flashed to both slots beforehand.

The big limitation is that since update_engine does not run, there is no
merge action on reboot. This can be done manually with "snapshotctl
merge" however.

This type of tool could be easily used in the future for quickly testing
specific bugs or performance ideas in snapuserd.

Bug: N/A
Test: launch_cvd
      adb wait-for-device root
      adb shell snapshotctl test-blank-ota
      adb reboot
      adb wait-for-device root
      adb shell snapshotctl dump
Change-Id: I5911440cbe14ee909905a0b0fc17da95ba4c5d68
2022-10-24 11:49:25 -07:00
Treehugger Robot
882c1681df Merge "libfstab_fuzzer: fuzz TransformFstabForDsu() and skip mount logic" 2022-10-24 09:48:05 +00:00
Yi-Yo Chiang
40a8223d34 libfstab_fuzzer: fuzz TransformFstabForDsu() and skip mount logic
These functions contain complex logic and parse user input. It shall be
valuable to fuzz these functions to prevent regression.

Bug: 254832225
Test: Build and run the fuzzer
Change-Id: I21099c3fc1c226f95a0f8f996bb751030e0c59bc
2022-10-21 19:51:25 +08:00
Yi-yo Chiang
cc7ddc04f9 Merge "Revert "fs_mgr_overlayfs: Revert to use /data only if VAB"" 2022-10-20 08:11:57 +00:00
Akilesh Kailash
b23bf16efc libsnapshot: Changes to AddCopy() API
If the copy blocks are contiguous, add a third
argument which takes the number of blocks
which are contiguous. With this, update engine
can call the API in one shot for all the
contiguous COPY operations.

This is required for batching the I/O
for async writes.

This should still continue to support the existing
API where we pass one COPY block at a time.

Bug: 254188450
Test: Incremental OTA from A->B with new API changes in A
      Incremental OTA from A->B with plain VAB
      cow_api_test
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I7edc52a152e02de28a44ef1dc2c88b76a28c4109
2022-10-19 17:55:52 +00:00
Akilesh Kailash
63190d2e3a Merge changes I7681e9a4,If84ff730
* changes:
  libsnapshot: Refactor compress function
  libsnapshot: Refactor code
2022-10-18 21:58:16 +00:00
Akilesh Kailash
1119e8e018 libsnapshot: Refactor compress function
Move compress() function to a dedicated file.
This is in preparation for variable block size
compression and async writes.

No change in functional logic.

Bug: 254188450
Test: Full OTA Pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I7681e9a4d884eac1ccbf8adeb1fc6bd1a9fedfa6
2022-10-18 16:49:02 +00:00
Akilesh Kailash
e8f6a126fb libsnapshot: Refactor code
Move all files related to libsnapshot_cow library to
a seperate directory. Libsnapshot directory is getting
crowded and we will be adding more files to this library
with async writes.

No changes to any logic.

Bug: 254188450
Test: Full OTA on Pixel
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: If84ff730d477c85a8ef57864d2185f2f897cf8e0
2022-10-18 16:48:33 +00:00
Yi-yo Chiang
956a45485a Revert "fs_mgr_overlayfs: Revert to use /data only if VAB"
This reverts commit c540ab9bf8.

Reason for revert: root cause is fixed

Bug: 253207748
Test: TH run g3-app-compat-main
Change-Id: I44c2535508a5718a823cdd61ad1938bba739c2a0
2022-10-18 09:43:20 +00:00
Yi-yo Chiang
eb88e7b677 Use ro.product.vendor.device to determine if running on Cuttlefish
Similar reasoning as aosp/2255456. ro.product.device could be overridden
by GSI if system.img was replaced with GSI.
Use ro.product.vendor.device, which comes from the vendor.img, to
determine the "device" type.

Bug: 243116800
Test: adb-remount-test on cuttlefish
Change-Id: Ib4a956047ef46d8e4837b27334f8d58162d4fa2a
2022-10-18 07:34:45 +00:00
Yi-yo Chiang
e7f5532e0a Merge "fs_mgr_overlayfs: Add scratch size override system property" 2022-10-18 06:56:24 +00:00
Jaegeuk Kim
c114177985 overlayfs: use overlayfs for f2fs readonly mode
F2FS doesn't allow remount,rw for RO partition, so that it caused adb remount.
Fix it.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Ia4410d08e8be344d79292c16a335a7e5be7a48bb
2022-10-17 11:38:45 -07:00
Kelvin Zhang
7e05c04432 Fix bug in WriteStringToFileAtomic
According to https://www.slideshare.net/nan1nan1/eat-my-data ,
rename() without an fsync() is not safe, and cannot guarantee data
integrity in case of powerloss of OS failure.

Test: partner verification, th
Bug: 238702018
Change-Id: I5809770062ed7bfa47df81de418a2d8f7cbc6620
2022-10-13 09:43:44 -07:00
Yi-Yo Chiang
15f94436b3 fs_mgr_overlayfs: Add scratch size override system property
Bug: 253207748
Test: Treehugger
Change-Id: I7140044d127e7db99d86decbe818be3680d26995
2022-10-12 20:23:19 +08:00
yi.sun
301adfcc07 Replacing fs_mgr_dir_is_writable(work) with fs_mgr_rw_access(work) to
check whether the scratch partition is writable.

Delate fs_mgr_dir_is_writable, as it may cause remount to fail.

Steps to reproduce:
1.adb root
2.adb remount
3.adb reboot
4.adb remount
5.push files to the system partition until the scratch partition is full
6.check that the Available of /mnt/scratch is zero through the df command
7.reboot
8.adb root
9.adb remount
Now, overlayfs failed to mount.

But I want to continue to view the files that were previously pushed to
the system partition.
Mounting of overlayfs should not be blocked when there is not enough space.
It seems reasonable to use fs_mgr_rw_access(work) to check whether
the partition is writable.
We should allow mount even if scratch is full, because this allows
the user to delete previously pushed files to free up space.

Bug: 240635368
Change-Id: I726ccd064cfabfab29789e7c690ea8cb574a6344
Signed-off-by: yi.sun <yi.sun@unisoc.com>
2022-10-12 03:06:22 +00:00
Akilesh Kailash
889b446810 Merge "init: Detach daemon only after sepolicy is loaded" 2022-10-11 21:04:42 +00:00
Yi-yo Chiang
c540ab9bf8 fs_mgr_overlayfs: Revert to use /data only if VAB
Partial revert of aosp/2240456 to fix b/251472189

Bug: 251472189
Test: Treehugger
Test: adb-remount-test
Test: g3-app-compat-main
Change-Id: Ifbd608a249fdc599954c34a134ef8497fdf24b46
2022-10-11 05:27:44 +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
Yi-Yo Chiang
ce2dbd009f remount: Remove AVB 1.0 code & opaque exit code
* Remove AVB 1.0 (fec).
* Assert device is bootloader unlocked in main().
* Since error is already logged to stderr and logd, there is no need to
  return an opaque enum value as error code. Just return 1 if main()
  encounters any error.

Bug: 241688845
Test: Presubmit
Test: adb-remount-test
Change-Id: I06df6f92a3d4adaca77061920736056c9051c112
2022-10-06 18:54:19 +08:00
Yi-yo Chiang
5653687caf Merge changes I8b5e08a3,Iccfe06f9
* changes:
  fs_mgr_overlayfs: Remove support for physical scratch
  fs_mgr_overlayfs: Refactor scratch mounting code
2022-10-06 06:19:12 +00:00
Yi-yo Chiang
27cf51e71c Merge "fs_mgr_overlayfs: Cleanup -user build stubs" 2022-10-05 09:19:45 +00:00
Yi-Yo Chiang
9032c00869 fs_mgr_overlayfs: Remove support for physical scratch
Deprecate physical scratch path, support only dynamic partition scratch
and scratch on /cache.

Bug: 243116800
Test: adb-remount-test
Change-Id: I8b5e08a38e323139b56b169865dcaf1a6620cf20
2022-10-05 01:13:32 +08:00
Yi-Yo Chiang
ea2f32a438 fs_mgr_overlayfs: Refactor scratch mounting code
Make the control flow less chaotic and rename to cpp style function
name.

Bug: 243116800
Test: adb-remount-test
Change-Id: Iccfe06f9cb9659b7b0bad085250422e298cc4f27
2022-10-05 01:11:18 +08:00
Yi-yo Chiang
7214c98d2e Merge "remount: Remove errno test & improve messaging of fs_mgr_overlayfs_mount_all" 2022-10-04 06:27:27 +00:00
Akilesh Kailash
2e780402e2 snapuserd: Set taskprofile OtaProfiles
Since update-engine already has this profile set,
it is better to have similar profile for the daemon
so that threads don't run at high priority.

Additionally, lower the nice value for worker
threads.

No change in the OTA install time observed.

Bug: 237490659
Test: Full OTA on Pixel
Change-Id: I53ec8c647eb781965792683b04621e6fec5eb5f2
Signed-off-by: Akilesh Kailash <akailash@google.com>
2022-09-27 19:36:49 +00:00
Yi-Yo Chiang
ad06b405ee fs_mgr_overlayfs: Cleanup -user build stubs
* Categorize functions in fs_mgr_overlayfs.h into three classes:
  - Type 1: common and non-critical utilities.
  - Type 2: internal routines for facilitating remount.
  - Type 3: external entry points for users of fs_mgr_overlayfs, like
            fs_mgr_overlayfs_mount_all().
* Move type 1 to common utils header fs_mgr_priv.h & fs_mgr.cpp.
* Move type 2 to new private header fs_mgr_priv_overlayfs.h.
* Keep type 3 in fs_mgr_overlayfs.h.
* Move set-verity-state.cpp under fs_mgr so it can include
  fs_mgr_priv_overlayfs.h. File is reformatted as a result. We should
  eventually merge and dedup set-verity-state and fs_mgr_remount.
* Add myself to OWNERS for remount-related maintenance work.

Bug: 241179247
Bug: 241688845
Test: Full build -user and -userdebug build.
Test: Presubmit
Test: Treehugger run v2/android-gki/adb_remount
Change-Id: Id5fd0e2b12c693939d712a586dd553cc4d8bfeb1
2022-09-26 16:46:03 +08:00
Yi-Yo Chiang
0cba7afd67 remount: Remove errno test & improve messaging of fs_mgr_overlayfs_mount_all
* remount don't check errno after calling fs_mgr_overlayfs_mount_all()
  as we don't report error status through errno anymore.
* fs_mgr_overlayfs_mount_all() returns false if any failure.
* fs_mgr_overlayfs_mount_all() returns true if no overlayfs to mount or
  all overlayfs are either already mounted or mounted successfully.

Bug: 241179247
Bug: 248295731
Test: Treehugger
Change-Id: Ia9c7ac686f6538a9f5da7efc4cda6f28aff056f6
2022-09-26 16:37:27 +08:00
Yi-Yo Chiang
602ac4b03c overlayfs: Fix -user build break
Bug: 241179247
Fixes: 247941706
Test: Treehugger
Change-Id: I2a7683014bb7c6f23a81a6d4b1199f19a8c184b9
2022-09-21 07:08:45 +00:00
Treehugger Robot
7cad2e8654 Merge "Fix module-file name collisions" 2022-09-20 23:24:20 +00:00
Jaegeuk Kim
4ae0eb0f86 Merge "fs_mgr: remove atgc mount option for zoned device" 2022-09-20 20:02:08 +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
David Anderson
2dcde2a36a Merge "remount: Remove unused errno propagation." 2022-09-20 18:23:29 +00:00
David Anderson
eec8932c35 Merge "remount: Remove errno interaction from fs_mgr_overlayfs_teardown." 2022-09-20 18:23:19 +00:00
Jaegeuk Kim
36755637ca fs_mgr: remove atgc mount option for zoned device
F2FS gives EINVAL when trying to mount zoned device with atgc. This patch
allows to keep the single fstab to support legacy and zoned devices at the
same time.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: I47a667443e7e60cb6729553b2ca24026e21fd90d
2022-09-20 10:07:18 -07:00
David Anderson
76dd810ecf remount: Remove unused errno propagation.
This removes all remaining save/restores of errno in
fs_mgr_overlayfs.cpp.

Bug: 241179247
Test: adb-remount-test.sh
Change-Id: I8bae6eb2752fe9460763455e88f9b82ad57c10e4
2022-09-19 22:30:06 -07:00
David Anderson
0aabcbc973 remount: Remove errno interaction from fs_mgr_overlayfs_teardown.
This patch eliminates errno as part of the return contract for
fs_mgr_overlayfs_teardown().

The non-standard use of implicit errno makes it extremely difficult to
reason about how these functions can fail. As it turns out,
fs_mgr_overlayfs_teardown has been consistently failing for a long time,
but in a place where errno isn't set, which meant "enable-verity" never
saw the failure.

The failure was originating from umount2(MNT_DETACH) which guaranteed
that DeleteBackingImage would fail with EBUSY, and DeleteBackingImage is
a binder call that doesn't set errno.

This patch switches to umount() and returns a "busy" status if the
unmount fails with EBUSY. In this case it will also disable the scratch
partition. There is a long-standing existing bug where, for non-VAB
devices, it will delete the underlying scratch partition off super. This
is pretty risky with MNT_DETACH, but that path is left unchanged here.

Some duplicated code in set-verity-state was refactored as well, since
the return value of fs_mgr_overlayfs_teardown is now more complex.

Bug: 241179247
Test: adb-remount-test.sh
Change-Id: I2ca75332b75a302622ba9b86d122a6f2accdda3e
2022-09-19 22:30:05 -07:00
biandonglei
9e7a73cf0c Some device that platform base on android12 doesn't support A/B update, it looks virtual A/B is also not mandatory. so this test case should check ro.vendor.api_level first.
test:
 run vts -m vts_ota_config_test -t VAB#Enabled

issue:
 245441425

Change-Id: I1795c931b28fd5fe28aa0f23717d4238fb352d37
2022-09-17 06:47:02 +00:00
David Anderson
0dfbdc5bdb Merge "vts_libsnapshot_test: Fix test flakiness." 2022-09-08 19:44:05 +00:00
David Anderson
7834809350 vts_libsnapshot_test: Fix test flakiness.
This patch fixes a few lingering issues in vts_libsnapshot_test.

The most important fix is a crash in snapuserd when handler deletion
races with the merge monitor thread. Since tests issue lots of
snapshot-related requests in rapid succession, this was easy to hit in
presubmit, and resulted in a null-pointer deref.

SnapuserdClient's CloseConnection does the same thing as the destructor,
but leaves SnapuserdClient in an unusable state. This method is removed
in favor of RAII.

Fix a bug in SnapshotManager where CloseConnection could be called
without zapping snapuserd_client_.

Fix a bug where POLLHUP was checked before calling recv().

Add test name logging so presubmit failures can be diagnosed via logcat
dumps.

Bug: N/A
Test: vts_libsnapshot_test on cuttlefish
Change-Id: I8f22a45e537c24a3c6d327ac47bf8b1352108706
2022-09-07 21:58:03 -07:00
Bowgo Tsai
0db62f43de Change log level in mount_with_alternatives()
mount_with_alternatives() supports mounting any of the
consecutive fstab entries. Some log messages shouldn't
be treated as error so changing log level to INFO instead.

Bug: 245468764
Test: TreeHugger
Change-Id: I94a18d4cf91ee5bb58cf5ba5f853a0e6599071d1
2022-09-07 18:45:36 +08:00
Yi-yo Chiang
9a0a9db6af Merge "adb-remount-test: Miscellaneous fixes - 2nd round" 2022-09-05 08:33:31 +00:00
Yi-yo Chiang
10b691284c Merge changes I2360314c,I51bd32c6,Icb136327,Id8425488
* changes:
  adb-remount-test: Refactor test cleanup
  adb-remount-test: Replace libc.so test with build.prop test
  adb-remount-test: Check override_creds only if overlayfs is used
  adb-remount-test: Print log timestamp & auto-detect color
2022-09-05 05:59:36 +00:00
Yi-yo Chiang
78430afca4 Merge "adb-remount-test: Refactor raw remount & remount from scratch test" 2022-09-05 03:34:56 +00:00
David Anderson
82e1fc0749 Merge "remount: Simplify fs_mgr_overlayfs_setup." 2022-09-03 00:28:13 +00:00
Yi-Yo Chiang
3ae19c3c01 adb-remount-test: Miscellaneous fixes - 2nd round
* Call adb_wait in adb_reboot, as virtually all adb_reboot callsites are
  immediately followed by adb_wait.
* Remove |data| option from skip_administrative_mounts. The |data|
  option doesn't really work anyway, because vold & init creates
  bewildering heirarchy of /data bind-mounts, so it's not feasible to
  filter /data by mountpoints. It's more sensible to filter by the /data
  device node name, which should be done by the caller.
* Untangle skip_administrative_mounts and skip_unrelated_mounts.
  I don't know why we need two separate functions that do similar
  things. Just merge them together.

Bug: 243116800
Test: adb-remount-test
Change-Id: I847f0b8cc2a952bb4c8656a43da783f312670061
2022-09-02 00:52:29 +08:00