Commit graph

2829 commits

Author SHA1 Message Date
Eric Biggers
efe209352e fs_mgr: allow FDE options in recovery mode
Unfortunately, some recovery fstabs still specify the FDE options, where
they never really did anything anyway.  Allow them for now, since it
seems preferable to restrict any breakage to the case that really
matters (devices actually configured to use FDE in their main fstab).

Bug: 191796797
Bug: 206025578
Change-Id: I85e35af8f42d2aef91f08816a67a71bbf756b211
2021-11-12 13:11:46 -08:00
Eric Biggers
9e21700282 fs_mgr: allow any argument to encryptable
There are some fstab files that specify "encryptable=footer" for
adoptable storage volumes, which contradicts the documentation which
says that it should be "encryptable=userdata".  However, the argument
was previously being ignored anyway.  To avoid unnecessarily breaking
such devices, ignore the argument to "encryptable".

Note that we continue to only allow "encryptable" in combination with
"voldmanaged".  So, fstabs that use "encryptable" for FDE (rather than
for adoptable storage) should continue to be rejected.

Bug: 191796797
Change-Id: Idc4d5f9c01098f997e12be0022bea992439cec9c
2021-11-12 12:26:10 -08:00
Eric Biggers
89ba7775af fs_mgr: remove FDE-specific FS_MGR_MNTALL codes
Remove these codes, now that neither fs_mgr nor init uses them anymore.

Bug: 191796797
Change-Id: I97451ed8b83043a4035fc8cf8bfbb95ee60afd83
2021-11-09 22:44:50 -08:00
Eric Biggers
4d0c5efac9 fs_mgr: remove crypt_footer argument from fs_mgr_do_format()
FDE is no longer supported, so there's no longer any need to ever
reserve a crypto footer.

Bug: 191796797
Change-Id: I79121188b0bcb7b00c16fda03b68b20c40c1e240
2021-11-09 22:44:50 -08:00
Eric Biggers
c953d6eb5f fs_mgr: remove FDE fields from FstabEntry
Remove the now-unused FDE fields from struct FstabEntry.

Bug: 191796797
Change-Id: Iab11a1fe86ac9d06beef68dc7e3c543f48ce0ac6
2021-11-09 22:44:50 -08:00
Eric Biggers
63fb19532c fs_mgr: remove code that handles FDE
Since Android 10, new devices have been required to use FBE instead of
FDE.  Therefore, the FDE code is no longer needed.

Bug: 191796797
Change-Id: I2f29ce5fa61c67325d6eb6cf6693787f8fa8a011
2021-11-09 22:44:50 -08:00
Eric Biggers
b662530677 fs_mgr: stop allowing the FDE fstab options
Since Android 10, new devices have been required to use FBE instead of
FDE.  Therefore, the FDE code is no longer needed.

Make fs_mgr reject fstabs where FDE is enabled.

Unfortunately, there is a quirk where the "encryptable" flag (which was
originally meant just for FDE) was overloaded to identify adoptable
storage volumes.  It appears that we have to keep supporting this use
case.  Therefore, don't reject the "encryptable" flag completely.
Instead, just reject "encryptable" when it appears without
"voldmanaged", or without "userdata" as its argument.

Here are some references for how "encryptable=userdata" is being used to
identify adoptable storage volumes:

  * https://source.android.com/devices/storage/config#adoptable_storage
  * f26c7e9b12:system/vold/main.cpp;l=269
  * f26c7e9b12:device/google/cuttlefish/shared/config/fstab.f2fs;l=17
  * f26c7e9b12:device/generic/goldfish/fstab.ranchu;l=7

[ebiggers@: modified from a WIP CL by paulcrowley@]

Bug: 191796797
Change-Id: I3c4bbbe549cc6e24607f230fad27ea0d4d35ce09
2021-11-09 22:44:50 -08:00
Yi-Yo Chiang
9ac28517a3 Merge "Make clean_scratch_files work" 2021-11-08 06:43:36 +00:00
Yi-Yo Chiang
ad0f69c5a6 Merge "libfiemap: array boundary check for fiemap.fm_extents[]" 2021-11-03 06:52:02 +00:00
Akilesh Kailash
7ad63b4c77 Revert "snapuserd: Add unit test for test merge code path"
This reverts commit 1cc9818642.

Reason for revert: Failing build - There is a dependency with https://r.android.com/c/1843772/3

Change-Id: Iccac56cf4c7012d8732b4338eb7055e1b2451e3b
2021-11-03 02:19:00 +00:00
Akilesh Kailash
1cc9818642 snapuserd: Add unit test for test merge code path
Most of the test cases are similar to dm-snapshot-merge.

Additional test cases have been added primarily to test
I/O's in parallel with merge.

Bug: 193863397
Test: snapuserd_test
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: If7fede1be6d678c8665e1f9369fd3c69f5d3c4df
2021-11-03 01:54:53 +00:00
Yi-Yo Chiang
6455f27e1b Make clean_scratch_files work
clean_scratch_files.rc seems to never work as intended due to
missing domain transition rules.
Add a 'remount' domain to the platform policies to allow
remount-related operations, including clean_scratch_files.
Merge remount and clean_scratch_files binary to simplify the added
policies.

Bug: 204836146
Test: 1. Use a VAB device, for example bramble-userdebug
  2. adb remount system
  3. adb reboot fastboot && fastboot flash system system.img
  4. recovery (fastbootd) should mark the remount scratch as disabled
  5. fastboot reboot && adb shell mount | grep scratch => nothing
  6. adb logcat | grep 'clean_scratch_files|gsid' => shows that
    disabled image "scratch" is removed during boot
Change-Id: I18d543868d1f37d43b483eae7517b707e46df1bd
2021-11-02 22:10:46 +08:00
Akilesh Kailash
2ba8eea489 snapuserd: Sort REPLACE ops for batch merge
Since we will be iterating forward for user-space
merge, we need to sort the blocks in increasing order
so that blocks can be batch merged if contiguous.

For dm-snapshot merging, we will continue to sort
in decreasing order.

Bug: 193863397
Test: Snapuserd_test
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I25fb5fce054f716a2ad0dddc0d0c3afef18bc7ad
2021-11-02 08:09:38 +00:00
Akilesh Kailash
b94353cae0 snapuserd: API to query snapshot and merge status
Add new API to query the snapshot and merge status.
This will be used by libsnapshot.

Bug: 193863443
Test: Full OTA on CF
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I86cffff6a979e2e2bf1d8d1a1770e209eeb4a47d
2021-11-02 07:34:36 +00:00
Akilesh Kailash
ff590a806c snapuserd: Wire up API's for Initiating and tracking Merge
Add new client API's for initiating and tracking merge.
These API's will be used by libsnapshot.

Track the merge completion in the server by walking through
all the partitions. Each worker thread will update the
merge completion as and when number of COW operations
are completed. Server will gather all the completions
of each partition and average it out. This is in sync
with the current merge completion tracking for dm-snapshot.

As a side effect, move the snapuserd_server.h/cpp files to
dm-snapshot-merge directory as it will only be a maintaining
code.

Bug: 193863443
Test: Snapuserd_test
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I031eb1a11b0f426aafbed3d39d85b0c22b9030fb
2021-11-02 07:32:09 +00:00
Akilesh Kailash
8abe050eb5 snapuserd: I/O requests which are not block aligned.
If the I/O request is for a sector which is not block
aligned, then we will not find the mapping directly
to a COW op as each op is block aligned. Thus, we
handle them by chopping the I/O request and processing
the unaligned data. Furthermore, if the request
doesn't map to any of the COW ops, then route the
I/O to the base device.

Bug: 196929997
Test: Full OTA on CF - during boot up, we get an I/O request
to read superblock on system partition which is not block aligned.

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ie40633c0c6bc0c87b681c051c74c0ac787e34d9c
2021-11-02 07:17:23 +00:00
Akilesh Kailash
be46ca7ff3 snapuserd: Service I/O requests from dm-user
Now that merging is done in user-space and
partitions are mounted off dm-user directly,
daemon will have to serve every I/O request.

Daemon has to handle this wherein we need to
check if the given I/O request block has been
modified in the OTA. Furthermore, if merge is
in-progress, we will have to synchronize with
the merge thread before servicing the I/O.

If the I/O request maps to a REPLACE or ZERO op,
we will just read the data from COW device.

If the I/O request maps to a COPY or XOR op,
the worker thread will have to synchronize
with the merge thread and if the merge is
in progress, fetch the data directly from RA buffer.

This patch handles I/O requests only if the
sectors are 4k aligned.

Bug: 196929997
Test: snapuserd_test

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I08562b8927e1c22dd9d9ef160e873280854eac99
2021-11-02 07:08:30 +00:00
Yi-Yo Chiang
0f62506139 libfiemap: array boundary check for fiemap.fm_extents[]
Ensure we have at least one element before we try to access the last
element. Else the array index of the last element may underflow,
0ull - 1 == ~0ull == UINT64_MAX.

Bug: 204536075
Test: atest fiemap_writer_test
Change-Id: Ic390d108bf789cfe136fb5dfe2983f3c7d6f7e48
2021-11-02 11:38:31 +08:00
Shaju Mathew
cab12f8ae2 Merge "Addressing error-code propagation for remount service." 2021-11-02 02:11:57 +00:00
Shaju Mathew
7e5451a6ab Addressing error-code propagation for remount service.
Bug: 201596822

Test: Local test (isolated to host)

$ adb -s 8BDAY00CM6 root
adbd is already running as root
$ adb -s 8BDAY00CM6 remount
Disabling verity for /system
Using overlayfs for /system
Disabling verity for /system_ext
Using overlayfs for /system_ext
Disabling verity for /vendor
Using overlayfs for /vendor
Disabling verity for /product
Using overlayfs for /product
remount succeeded.. now reboot device for settings refresh
$ echo $?
0
$ adb -s 8BDAY00CM6 unroot
restarting adbd as non root
$ adb -s 8BDAY00CM6 remount
Not running as root. Try "adb root" first.
remount failed
$ echo $?
3

Signed-off-by: Shaju Mathew <shaju@google.com>
Change-Id: I8e6d0735d2da0ed58cae867db2e4736abb86d351
2021-11-01 18:05:45 -07:00
David Anderson
de2ec0b427 libfiemap: Only call FS_IOC_FIEMAP once.
The kernel can return different compatible ranges on each call, depending on
how it decides to merge contiguous extents in the results. To avoid the
complexity of requerying the ioctl, just do one query up to the maximum
allowed extent size.

Bug: 204536075
Test: install DSU on cuttlefish
      fiemap_test
Change-Id: I4d569e3e6feed14c91a5f500296623888060dcad
2021-11-01 13:44:56 -07:00
Yi-Yo Chiang
fb62a719a2 Fix ubsan error path found by libfstab_fuzzer
Fix: 204255714
Bug: 204056804
Test: Rerun the fuzzer
Change-Id: Ief4cd12c414033fc0a0c2891433a16c35c7a6e79
2021-10-27 12:06:41 +00:00
Yi-Yo Chiang
a68b83fd60 Merge "libfstab_fuzzer: Add dictionary to guide the fuzzer" 2021-10-26 20:34:47 +00:00
Treehugger Robot
8d4993316b Merge "Add a bug component for test vts_libsnapshot_test." 2021-10-26 19:15:21 +00:00
Yi-Yo Chiang
ed72e37c4a libfstab_fuzzer: Add dictionary to guide the fuzzer
This is probably an overkill, but still, add a collection of
interesting keywords that may appear in a fstab file.

Also add myself to the "CC" list of this fuzz target.

BYPASS_INCLUSIVE_LANGUAGE_REASON="slave" or MS_SLAVE is a mount flag

Bug: 204056804
Test: adb shell /data/fuzz/x86_64/libfstab_fuzzer/libfstab_fuzzer \
  -dict=/data/fuzz/x86_64/libfstab_fuzzer/fstab.dict
Change-Id: Ife55837212a711dcbeed4f00d97da0cb022c7156
2021-10-26 23:03:33 +08:00
Yi-Yo Chiang
b398a0bc73 Add libfstab_fuzzer that fuzzes ReadFstabFile()
Just a modest initial implementation. Uses the fuzz data as the fstab
file content directly.

Bug: 204056804
Test: lunch aosp_cf_x86_64_phone-userdebug
  SANITIZE_TARGET=address m libfstab_fuzzer
  adb sync data
  adb shell /data/fuzz/x86_64/libfstab_fuzzer/libfstab_fuzzer
Change-Id: I7976a6ee124e9b5da59cfa7f4bae9699be3f1474
2021-10-26 14:22:36 +08:00
Yiming Pan
ac84a8ded6 Add a bug component for test vts_libsnapshot_test.
Test: Tree Hugger
Bug: 143903671
Change-Id: Ifaa406f6c7a94c4eb615ddc146119c12359ad198
2021-10-18 16:30:57 -07:00
David Anderson
a5df9e5db1 Merge "Add a test for bug 198265278." 2021-10-08 19:29:16 +00:00
Akilesh Kailash
71c680226d Merge changes from topic "vabc-merge-phase-1"
* changes:
  snapuserd: Refactor buffer allocation code
  snapuserd: Implement snapshot merge
  snapuserd: Move dm-snapshot-merge related code
2021-10-08 06:45:38 +00:00
David Anderson
af09c15049 Merge "adds LO_FLAGS_AUTOCLEAR for loop device of zram backing device" 2021-10-07 15:49:18 +00:00
Akilesh Kailash
fb964a1fbe snapuserd: Refactor buffer allocation code
Since there is no change in the buffer allocation
code with respect to snapshots in user-space, refactor
it so that we have a common code base.

Bug: 193863397
Test: Build
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I3a7b3d319f6d1532b1bb63af9884b64e1346bb50
2021-10-07 07:18:45 +00:00
Akilesh Kailash
228f6a099c snapuserd: Implement snapshot merge
Implement snapshot merge in the daemon. Following
are the important changes:

1: Spin up merge thread which does merging in user-space.
2: For ordered ops (COPY and XOR), read-ahead thread is used.
3: Read-ahead thread will read a fixed set of COW ops and cache
them in memory. Furthermore data is saved in scratch space buffer
in COW device.
4: No change in scratch space buffer - default 2MB buffer is allocated.
5: Merge thread and Read-ahead thread will work in lock step for merging
ordered ops.
6: Once the ordered ops are merged, REPLACE and XOR operations are
merged.
7: If there is a crash during merge, COW header tracks the number of
operations merged. No change in this code path.
8: Merge thread requires Base device for merging as opposed to using
the source device. Hence, while initializng the merge threads,
libsnapshot will have to pass the "Base" device to the daemon. This
is the same "Base" device which is passed to dm-snapshot during
snapshot creation.

Patch does not handle any communication with dm-user yet.

Bug: 193863397
Bug: 193863280
Bug: 193862712
Test: snapuserd_test on CF
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I14aab6eaa07ac68f2a3a23516ed9ba6567a35734
2021-10-07 07:09:28 +00:00
Akilesh Kailash
46e15bd18b snapuserd: Move dm-snapshot-merge related code
Move all the snapuserd files related to dm-snapshot/dm-snapshot-merge
to a seperate directory. We will have a logical seperation
to maintain user-space merge code.

No code changes other than moving files around.

Bug: 193863397
Test: Build
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ide0d824bb19f9d870ec32699d0a37de0e5d6ce81
2021-10-07 07:08:45 +00:00
Akilesh Kailash
ba097d2cd2 Merge "Revert "snapuserd: Handle real time signal 36"" 2021-09-30 16:52:10 +00:00
Akilesh Kailash
fec60563c4 Revert "snapuserd: Handle real time signal 36"
This reverts commit 8d3b31fe68.

Reason for revert: With https://r.android.com/1840754, bionic will handle the real time signal for statically linked binaries.

Change-Id: I81f0892f1734c7ecfb604820a8894506df8618b3
2021-09-30 07:24:11 +00:00
Treehugger Robot
19dc4d413f Merge "Add OWNERS for VTS module vts_libdm_test" 2021-09-30 03:46:00 +00:00
Yiming Pan
47af156ee0 Add OWNERS for VTS module vts_libdm_test
Each VTS module is required to have OWNERS file. The ownership is based on
go/vts-owners. For more information about ownership policy, please visit
go/xts-owners-policy.

Test: Tree Hugger
Bug: 143903671
Change-Id: Id2911fd62841bf5622607f9deeb50c7cf1413b1b
2021-09-29 14:46:24 -07:00
Akilesh Kailash
7ec205920c Merge "snapuserd: Handle real time signal 36" 2021-09-29 21:04:41 +00:00
Yifan Hong
d6fc145473 Merge "libsnapshot_fuzzer: allow ENXIO." 2021-09-29 20:58:10 +00:00
Treehugger Robot
3ad79c8ff7 Merge "Add VerifyMergeOps to ISnapshotWriter" 2021-09-29 20:06:40 +00:00
Akilesh Kailash
8d3b31fe68 snapuserd: Handle real time signal 36
Add a signal handler for real time signal 36 which
is primarily used by profilers. Default action is to
terminate the daemon if there is no signal handler. We
don't want daemon to get terminated, hence just capture
the signal and ignore it.

Bug: 201497662
Test: cow_snapuserd_test, pkill -36 snapuserd
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ife5a8bdb7344956076bc4223c19a126b90a00706
2021-09-29 17:35:49 +00:00
Kelvin Zhang
8c77196a74 Add VerifyMergeOps to ISnapshotWriter
It turns out update_engine never gets a ICowReader instance... it only
gets a generic FileDescriptor. So bring this function all the way up to
ISnapshotWriter interface.

Test: th
Change-Id: I7d17b9537f97282c99203b5cc13892e5daa1be4c
2021-09-29 10:04:11 -07:00
Yifan Hong
10e5e5979a libsnapshot_fuzzer: allow ENXIO.
This is an accepted error code.

Fixes: 170395454
Test: run fuzzer

Change-Id: I93862c44f434878a6e1a1ed15a94c92d4a60611b
2021-09-28 19:32:55 -07:00
Treehugger Robot
2d7301d235 Merge "Replace test_min_api_level with test_options.min_shipping_api_level" 2021-09-29 00:02:04 +00:00
Justin Yun
43678b17a5 Replace test_min_api_level with test_options.min_shipping_api_level
Test options for the api levels are moved to test_options.
test_min_api_level property will be removed with this change.

Bug: 187258404
Test: build
Change-Id: Id943566de2ac693b5955bd84a8463e5013a8bb0f
2021-09-28 20:35:09 +09:00
Kelvin Zhang
f2e1f20fd7 Add VerifyMergeOps() to CowReader interface
update_engine only sees ICowReader, so in order for update_engine to
consume this API, it has to be in the base interface class.

Test: th
Change-Id: I9100b6aa1db6eb6a884752620098172bdd51f200
2021-09-27 18:26:23 -07:00
David Anderson
2374bd48ed Add a test for bug 198265278.
This test uses dependency injection to cause a failure in
QuerySnapshotStatus. We expect ProcessUpdateState to return MergeFailed.
The test also checks that if the merge is attempted again, it can
succeed.

Some duplicated code has also been factored out into the test harness.

Bug: 198265278
Test: vts_libsnapshot_test gtest
Change-Id: I6ccb434afa0e5ebf6781b2cec5277e3b7c210b77
2021-09-27 17:29:45 -07:00
Liangcai Fan
d884ba5916 adds LO_FLAGS_AUTOCLEAR for loop device of zram backing device
Userdata spaces leak when zram writeback is enable and repeatedly kill
system_server(restart android).
The reason is that per_boot‘s inode is hold by loop device
although per_boot is deleted by user which become orphan inode in system.

Adds LO_FLAGS_AUTOCLEAR for loop device of zram backing device,
so loop device can release resouce.

Bug: 200904398

Change-Id: Ifeee9c0b58b10cdf7698077fbcaf54d5faccc3b1
Signed-off-by: Liangcai Fan <liangcai.fan@unisoc.com>
Signed-off-by: Hongyu Jin <hongyu.jin@unisoc.com>
Signed-off-by: Jing Xia <jing.xia@unisoc.com>
2021-09-26 10:07:50 +08:00
Treehugger Robot
5125c62cf8 Merge "libsnapshot: Add function to verify merge sequence" 2021-09-25 00:50:49 +00:00
Daniel Rosenberg
1e3fa94657 libsnapshot: Add function to verify merge sequence
This adds a function that verifies that the merge sequence does not
attempt to use blocks that have already been overwritten. It prints the
first such conflict to the logs.

Additionally, this adds a forwards merge iterator, and the ability to
ignore current progress in a merge for the purposes of verifying the
whole sequence.

This can be accessed via the VerifyMergeOps Function in Cow Reader, or
by using inspect_cow -v [COWFILE]

Include merged ops in inspect_cow listing with -a, and view ops in merge
order with -n

Bug: 200076590
Test: cow_api_test.InvalidMergeOrderTets
Change-Id: I893b9f8a8803cb6dd53225ec34224167b9fe2fda
2021-09-24 16:03:17 -07:00