Commit Graph

1907 Commits

Author SHA1 Message Date
Yifan Hong 1dc4e19f2a Merge changes from topic "libsnapshot_fuzzer_test"
* changes:
  libsnapshot_fuzzer: Properly unmap images
  Reland "libsnapshot_fuzzer: Add tests"
2020-05-18 20:18:07 +00:00
Steve Muckle a90bfdd874 add API to get hash descriptor
The GKI verification VTS test will need to examine the boot partition's
hash descriptor, so add support to access this descriptor.

Bug: 148800209
Test: atest AvbTest#Boot
Change-Id: I92e32f61a265671ae0940c44147391f73776e66a
2020-05-17 17:06:59 -07:00
Yifan Hong 3013e6efcc libsnapshot_fuzzer: Properly unmap images
Instead of unsetting gsid.mapped_images.* directly, properly unmap
them through image manager. This also avoids interference between
different fuzzer runs because the gsid.mapped_images.* properties
are not destroyed in SoftReset.

Test: libsnapshot_fuzzer_test then reboot, device can come up
Fixes: 156689792
Bug: 156380383
Change-Id: I7a198312f63b4b17d8ea96c7df2dd112a910d004
2020-05-15 17:05:26 -07:00
Yifan Hong 8cef7c7d70 Reland "libsnapshot_fuzzer: Add tests"
This reverts commit 254b9046f7.

Reason for revert: test fixed

Bug: 156689792
Test: run it then reboot

Change-Id: I33603e87b8f6b06fed2d18066ee5f00cdf45a52e
2020-05-15 14:34:01 -07:00
Neil Fuller 254b9046f7 Revert "libsnapshot_fuzzer: Add tests"
This reverts commit 51bfe08d84.

Reason for revert: Investigating possible connection to http://b/156689792

Change-Id: Idd779815940e3835bc0b86103ef016141d48ce7f
2020-05-15 10:37:56 +00:00
Yifan Hong 51bfe08d84 libsnapshot_fuzzer: Add tests
Add tests for the fuzzer itself. The test ensures that the
initial corpus is a good run on SnapshotManager (in the sense
that not only it doesn't crash, but also it executes as expected).

Also changed fuzz_utils so that impl functions return the
invocation result too, so that the test can check its values.

Test: run it
Bug: 154633114

Change-Id: I31ab7830f8c20a0575aaadabd038632d10f33962
2020-05-06 17:10:34 -07:00
Yifan Hong b2e939599a libsnapshot_fuzzer: add initial corpus
Transform some of the tests in vts_libsnapshot_test
to corpus and use them as initial corpus to
libsnapshot_fuzzer.

The corpus alone gives us 50% of line coverage in snapshot.cpp.

Test: run it
Bug: 154633114
Change-Id: I8f3bf1d76ef64d710224e24c913990692481b65e
2020-05-06 17:10:34 -07:00
Yifan Hong 50c52c223b libsnapshot_fuzzer: Attempt to cleanup env before and after
Ensure a clean env as much as possible. Otherwise,
previous crashes may affect subsequent runs.

Test: crash and run it again
Bug: 154633114
Change-Id: I0db690f420bef4a95d2e937f423c21ddf916e0d5
2020-05-06 17:10:34 -07:00
Yifan Hong 4cbaf858de libsnapshot_fuzzer: add new test directive to switch slot
Add a test directive to mimic the behavior of switching
slots after rebooting. This changes the behavior of
SnapshotFuzzDeviceInfo and has nothing to do with the
API surface of ISnapshotManager. It also relies on the
fact that SnapshotManager does not record the current
slot suffix and always reads from IDeviceInfo.

Test: run with corpus
Bug: 154633114
Change-Id: I6ebb68afb8519feaa05bd3e4817f0e06596fc920
2020-05-06 17:10:34 -07:00
Yifan Hong 322ea7ae3c libsnapshot_fuzzer: mount data image
Mount a real data image and use it as the backing storage of
image manager. This is needed for ImageManager to DetermineMaximumFileSize.

Test: run with corpus
Bug: 154633114
Change-Id: I4802094d78459427f5d83102bcb716de590789e0
2020-05-06 17:10:34 -07:00
Yifan Hong 933d341b6a libsnapshot_fuzzer: also create snapshots dir
/metadata/ota/snapshots is created by init.rc at boot time.
Conditionally create it in the fuzz test

Test: run it
Bug: 154633114

Change-Id: Ice5e340b554ffd59861c4b21d9c4eb652ca60c55
2020-05-06 17:10:34 -07:00
Yifan Hong 7134ae064e libsnapshot_fuzzer: Add ZERO to operation types
Even though operation type ZERO is not used
in libsnapshot, add it so that the fuzzer has
an alternative operation type to use. Without
it, the fuzzer will only generate operations
SOURCE_COPY.

Test: pass
Bug: 154633114
Change-Id: I4fd36421b8b33ed68b94be2d739a6dd706b3829f
2020-05-06 17:10:34 -07:00
Yifan Hong 1af4a81f7d Merge "libsnapshot: fix incorrect assumption of cow images" 2020-05-06 22:06:12 +00:00
Yifan Hong e6c1a84276 libsnapshot: fix incorrect assumption of cow images
libsnapshot used to assume CoW images are always mapped
with device mapper, and call GetDeviceString directly.
However, in tests, it is possible that it is mapped as loop
devices. Fix the incorrect assumption and calls
IImageManager::GetMappedImageDevice instead.

Test: libsnapshot_fuzzer with corpus
Bug: 154633114
Change-Id: I1ec39744480e514ae7a7902643ed863e0ca0a340
2020-05-05 18:01:15 -07:00
David Anderson e3fa729dc2 libfiemap: Remove brittle tests.
libfiemap functionality is extensively tested via libsnapshot, gsid, and
fiemap_writer_test. However those tests rely on the configuration of the
device, and libfiemap has fairly different behavior based on whether FBE
or metadata encryption is in use. (The former will use loop devices, the
latter uses dm-linear).

To expand coverage, we added tests with very complicated nesting,
creating fiemaps on a rw partition mounted off a device backed by a
fiemap. Unsurprisingly, this was brittle to begin with, and now
consistently fails due to the intermediate partition not having
sepolicy.

Given the preference toward metadata encryption, and the fact that the
FBE mode will still be properly tested via VTS, let's just remove these
tests.

Bug: 148874852
Test: fiemap_image_test
Change-Id: I7be7d44dea81508505c050ed995b3b78086ad35f
2020-05-05 15:33:21 -07:00
David Anderson 42c2733d6c liblp: Add integer overflow checks when aligning.
This will prevent ubsan crashes on invalid inputs.

Bug: 155510366
Test: liblp_test gtest
Change-Id: Id6dd8badd0025d6cac3113c3f9076ea3f4d9c175
2020-05-05 11:37:53 -07:00
Yifan Hong 2e66043394 Merge "Add tests for zero snapshot size." 2020-05-05 15:23:35 +00:00
Alessio Balsini f2554ab2ad Merge "fiemap_image_test: libcrypto_utils as static lib" 2020-05-04 17:48:06 +00:00
David Anderson 5a0177d945 fastboot: Fix snapshot-update merge behavior.
When merging in recovery, the "imminent data wipe" code was used, which
made the assumption the /metadata and /data state would be zapped. This
caused future OTAs to error because the old snapshots were detected.

This CL allows OTAs to proceed even if unexpected snapshots are present.
It also forces the state to "MergeCompleted" after a merge in recovery,
so that the next normal boot can perform cleanup.

Bug: 155339165
Test: fastboot snapshot-update merge, then take another OTA
      vts_libsnapshot_test
Change-Id: Ief6dea3ba76323044e61307272dda320a4494aea
2020-05-02 16:02:07 -07:00
Yifan Hong f4cd49afa4 Merge changes from topic "snapshot_fuzz"
* changes:
  Enable automatic libsnapshot fuzzer runs
  Also log corpus when aborted through libbase.
  libsnapshot_fuzzer: Fuzz MapUpdateSnapshot.
  libsnapshot_fuzzer: construct valid super partition metadata.
  libsnapshot_fuzzer: Fuzz CreateUpdateSnapshots
  libsnapshot_fuzzer: add additional tests for more APIs
  libsnapshot_fuzzer: use protobuf
  libsnapshot_fuzzer: map super image
2020-05-02 04:46:31 +00:00
Yifan Hong e0c2e62c87 Add tests for zero snapshot size.
Test: run vts_libsnapshot_test
Test: fails without the fix patch
Bug: 155484992
Change-Id: Ia048704f427682d4f83219fbf9813ae06d05298b
2020-05-01 16:22:27 -07:00
Yifan Hong 83c690c7a6 Handle zero snapshot size appropriately.
This won't happen in practice because device size is never
zero. Hypothetically, if it is, PartitionCowCreator still
suggests that a CoW size of 8192 bytes needs to be created. In
reality, it is not necessary.

Test: libsnapshot_fuzzer
Bug: 155484992
Change-Id: I6c69f54820522d50c699384eec90c474ca3a9402
2020-05-01 18:46:44 +00:00
Yifan Hong c43f513c91 Enable automatic libsnapshot fuzzer runs
Test: none
Bug: 154633114
Change-Id: I226d88b74bd1ea6b3cb912609d7bdf10aa8208fd
2020-05-01 11:00:48 -07:00
Yifan Hong 4d5bfabfeb Also log corpus when aborted through libbase.
If a CHECK or LOG(FATAL) is hit, also attempt to log the current
corpus.

Test: pass
Bug: 154633114
Change-Id: Id0f376021011924f5d64eb5b591b5ebab6dc7dbc
2020-05-01 11:00:48 -07:00
David Anderson b827d1db0c Merge "remount: Improve messaging when a reboot is needed." 2020-05-01 17:44:18 +00:00
Alessio Balsini ce036fd7ba fiemap_image_test: libcrypto_utils as static lib
libcrypto_utils is not available as 32 bit library in 64 bit devices.
Import the library as static.

Bug: 148878078
Test: nativetest/fiemap_image_test
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I2b8cd69d06607f4216e4e2220dd8561e6eff323c
2020-05-01 12:18:39 +01:00
Yifan Hong 0d4a47b0c7 libsnapshot_fuzzer: Fuzz MapUpdateSnapshot.
Test: run it
Bug: 154633114
Change-Id: I15ea0fb28df5b0f6d32096aab808549c3855c289
2020-04-30 23:06:42 -07:00
Yifan Hong db0e62b87a libsnapshot_fuzzer: construct valid super partition metadata.
This should hopefully achieve more coverage.

Test: pass
Bug: 154633114
Change-Id: Ice575f2d8c3e22b80465c133d055e7c4368ebdfa
2020-04-30 23:06:42 -07:00
Yifan Hong 74d1fb4571 libsnapshot_fuzzer: Fuzz CreateUpdateSnapshots
Test: run it
Bug: 154633114
Change-Id: I56ed2953e85714d23a9273224a28eb8e8e47a54d
2020-04-30 23:05:36 -07:00
Yifan Hong c0df932a43 libsnapshot_fuzzer: add additional tests for more APIs
Test: run it
Bug: 154633114
Change-Id: I956cb74bfd46750137dfa73e9e040dd9d1782ce7
2020-04-30 23:05:36 -07:00
Yifan Hong 90a9393ea0 libsnapshot_fuzzer: use protobuf
Use protobuf because it already has all the fuzzing implemenetations.
Delete fuzz_utils.

Pros:
- Fuzzing protobuf is faster; it is easy to achieve 4K exec/s
- It is more guided; protobufs are fuzzed using mutators, and mutators
  should have better knowledge of the structure of the fuzz data
- No more hand-written parsing code of the fuzz data. That code in
  fuzz_utils.h is deleted.
- Corpus data can be reused even after adding new fields in the protobuf
- Corpus data is human-readable and easily manually written (it is
  the text format of the protobuf)

Cons:
- The "actions" are "declared" in protobuf definition and "defined" in
  C++, so there's more boilerplate to write. Adding a new "Action"
  requires changes in both.

Test: run libsnapshot_fuzzer
Bug: 154633114
Change-Id: Idc2a6b2c087e370e4cfef53142a244b9b275389e
2020-04-30 23:05:36 -07:00
Yifan Hong 5eb2d6fa27 libsnapshot_fuzzer: map super image
... instead of operating on the image file directly.
Test: run it
Bug: 154633114

Change-Id: Id04c0d15d0d52483647716f8bfb0b8ee1a2876d9
2020-04-30 23:05:36 -07:00
Alessio Balsini 75672f8be5 snapshot_test: Fix overflow in statvfs arithmetics
Operations on (unsigned long) f_bsize and f_bfree are correctly handled
on 64 bit architectures, but when switching to 32 bit, the
multiplication between the two could result in an overflow, causing the
test to crash.
Fix by using a uint64_t operand, hinting the compiler to handle the
whole multiplication with 64 bit operands.

Bug: 154355449
Bug: 148889015
Test: vts_libsnapshot_test (32 bit)
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: Ief5c03ff7954c4a3e8597ef6e7df467f59428877
2020-04-30 21:02:26 +01:00
David Anderson 45253ae5c6 remount: Improve messaging when a reboot is needed.
Bug: 149665201
Test: adb remount
Change-Id: I990ce80f14795669d4bbf05789910c5b15ee53cf
2020-04-29 22:04:58 -07:00
David Anderson b954b13613 Merge "libfiemap: Ignore userdata requirements in fiemap_writer_test when running a DSU." 2020-04-28 22:09:25 +00:00
Treehugger Robot 3124175854 Merge "Moves some shared_libs to static_libs for vts_libsnapshot_test." 2020-04-28 18:49:52 +00:00
Treehugger Robot fdabad8d53 Merge "Add fuzz test for libsnapshot" 2020-04-28 08:28:53 +00:00
David Anderson dde0c28089 Merge "liblp: Remove alignment_offset handling." 2020-04-28 04:30:23 +00:00
Daniel Norman 2f8eb83f52 Moves some shared_libs to static_libs for vts_libsnapshot_test.
These shared_libs are missing from /system/lib/ on 64-bit devices.

Test: Build, install, and run 32bit vts_libsnapshot_test.
Bug: 154115505
Change-Id: Iaf2014748546a055d35e4fe0e24969eef13db7fa
2020-04-27 15:39:35 -07:00
David Anderson cc2bf6b9d3 libfiemap: Ignore userdata requirements in fiemap_writer_test when running a DSU.
The test is guaranteed to fail because userdata is itself a fiemap-backed device.

Bug: 154447105
Test: fiemap_writer_test on DSU
Change-Id: Ied35da0eb7aba3daca7ed430f006bf1e90e21dca
2020-04-27 21:46:53 +00:00
Yifan Hong 1b0893ea5e Add fuzz test for libsnapshot
Bug: 154633114
Test: source fuzz.sh && run_snapshot_fuzz_all -runs=100000

Change-Id: I5cd9e3f088ca283d3a49959c38aa74a483931f2c
2020-04-27 12:37:40 -07:00
Mark Salyzyn 93c1233f12 fs_mgr: overlayfs: replace adb reboot -R with adb remount -R
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Test: none
Change-Id: Ie718e264b41763d904e59db74d4e7c9d4b8787f3
2020-04-27 07:41:17 -07:00
David Anderson 171681caf9 liblp: Remove alignment_offset handling.
This code is complex and alignment_offset is not useful for
optimization. Remove it, and add another test that misaligned extents do
not cause overlapping partitions.

Bug: 154646936
Test: liblp_test gtests
Change-Id: I563122282e940e07a7ece97ed1a9846ad1f3253c
2020-04-22 23:44:03 -07:00
David Anderson 9c66e53a82 liblp: Fix tests for linear extent overlap.
The "OwnsSector" tests did not work if one range fit completely inside
another range. The new OverlapsWith() methods address this case.

Bug: 154277287
Bug: 154646936
Test: liblp_test gtests
Change-Id: I1a59069db4ffe4f13c45963c4847cff7b3dd3dfc
2020-04-21 15:43:59 -07:00
Nikita Ioffe bcaeb70d80 PrepareZramBackingDevice: use loop_control.h
loop_control.h already provides loop device management APIs that we need
here. In addition, this change fixes a subtle race condition between
uevented creating a loop device node in userspace and
PrepareZramBackingDevice accessing it without waiting for it to be
created.

Test: device boots
Test: adb reboot userspace
Bug: 154500256
Change-Id: If80f18c8c337210030a6caf2aec6f7a47472b6fb
Merged-In: If80f18c8c337210030a6caf2aec6f7a47472b6fb
(cherry picked from commit c8313adf88)
2020-04-20 21:08:25 +01:00
Yifan Hong 96174857f2 Merge changes from topics "sm_mock", "sm_stub"
* changes:
  libsnapshot: Add MockSnapshotManager and MockDeviceInfo.
  libsnapshot: Add GetSnapshotMergeStatsInstance
  libsnapshot: Add SnapshotManagerStub.
  libsnapshot: Add ISnapshotManager.
2020-04-20 18:50:01 +00:00
Alessio Balsini 0c27fb8c5d Fix liblp imported both as static and dynamic lib
In vts_libsnapshot_test, liblp was explicitly imported as static
library, but due to the importing of libsnapshot_defaults, it also
inherited the shared importing.
The import in libsnapshot_default, is not required, drop it.

Test: manual inspection with ldd
Bug: 148889015
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I12ba0516a482dc917848b5f34cccc659a60a4803
2020-04-19 18:34:32 +00:00
Yifan Hong 2dcca52457 libsnapshot: Add MockSnapshotManager and MockDeviceInfo.
For testing.

Bug: 153555889
Test: vts_libsnapshot_test
Test: update_engine_unittests
Change-Id: Id92f7372ef408625f2ef1120c99d0b4058ed488c
2020-04-16 13:12:41 -07:00
Yifan Hong 66f0115b05 libsnapshot clients: Add missing dep.
libsnapshot* uses update_metadata-protos. This
used to be optimized out, but now that SnapshotManager is
virtual, CreateUpdateSnapshots can no longer be optimized out.

Bug: 148956645
Test: compiles
Change-Id: Ib67cafd156308bf5a477996ec32eb786f8e896db
2020-04-16 13:12:41 -07:00
Yifan Hong ee5032a436 libsnapshot: Add GetSnapshotMergeStatsInstance
This is preferred over SnapshotMergeStats::GetInstance because
the latter needs a concrete SnapshotManager, not the ISnapshotManager
interface.

SnapshotManagerStub::GetSnapshotMergeStatsInstance returns
a SnapshotMergeStatsStub instance.

Test: vts_libsnapshot_test
Bug: 148956645
Change-Id: Ife0ad6d3ce85333cbf395d07f74dedc9ca3fe675
2020-04-16 13:12:41 -07:00