Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-vold: Commit

system/vold


Commit MetaInfo

Revisionb5ebd7d9c7fe8d2b4bc60d54f1f5ad70cac4e28e (tree)
Zeit2019-06-28 02:42:25
AutorPaul Lawrence <paullawrence@goog...>
CommiterPaul Lawrence

Log Message

Make ext4 userdata checkpoints work with metadata encryption

When both ext4 user data checkpoints and metadata encryption are
enabled, we are creating two stacked dm devices. This had not been
properly thought through or debugged.

Test: Enable metadata encryption on taimen (add
keydirectory=/metadata/vold/metadata_encryption to flags for userdata in
fstab.hardware)

Unfortunately metadata is not wiped by fastboot -w, so it is
necessary to rm metadata/vold -rf whenever you wipe data.
fastboot flashall -w works
fastboot reboot -w works
A normal boot works
Disable checkpoint commits with
setprop persist.vold.dont_commit_checkpoint 1
vdc checkpoint startCheckpoint 10
adb reboot
wait for device to fully boot then
adb reboot
Wait for device to fully boot then
adb logcat -d | grep Checkpoint shows the rollback in the logs
This tests encryption on top of checkpoints with commit, encryption
without checkpoints, and rollback, which seems to be the key cases.
Also ran same tests on unmodified Taimen and Blueline

Bug: 135905679
Merged-In: I8365a40298b752af4bb10d00d9ff58ce04beab1f
Change-Id: I8365a40298b752af4bb10d00d9ff58ce04beab1f

Ändern Zusammenfassung

Diff

--- a/Checkpoint.cpp
+++ b/Checkpoint.cpp
@@ -62,14 +62,11 @@ namespace {
6262 const std::string kMetadataCPFile = "/metadata/vold/checkpoint";
6363
6464 bool setBowState(std::string const& block_device, std::string const& state) {
65- if (block_device.substr(0, 5) != "/dev/") {
66- LOG(ERROR) << "Expected block device, got " << block_device;
67- return false;
68- }
65+ std::string bow_device = fs_mgr_find_bow_device(block_device);
66+ if (bow_device.empty()) return false;
6967
70- std::string state_filename = std::string("/sys/") + block_device.substr(5) + "/bow/state";
71- if (!android::base::WriteStringToFile(state, state_filename)) {
72- PLOG(ERROR) << "Failed to write to file " << state_filename;
68+ if (!android::base::WriteStringToFile(state, bow_device + "/bow/state")) {
69+ PLOG(ERROR) << "Failed to write to file " << bow_device + "/bow/state";
7370 return false;
7471 }
7572
@@ -279,7 +276,6 @@ const bool commit_on_full_default = true;
279276
280277 static void cp_healthDaemon(std::string mnt_pnt, std::string blk_device, bool is_fs_cp) {
281278 struct statvfs data;
282- uint64_t free_bytes = 0;
283279 uint32_t msleeptime = GetUintProperty(kSleepTimeProp, msleeptime_default, max_msleeptime);
284280 uint64_t min_free_bytes =
285281 GetUintProperty(kMinFreeBytesProp, min_free_bytes_default, (uint64_t)-1);
@@ -290,16 +286,17 @@ static void cp_healthDaemon(std::string mnt_pnt, std::string blk_device, bool is
290286 msleeptime %= 1000;
291287 req.tv_nsec = msleeptime * 1000000;
292288 while (isCheckpointing) {
289+ uint64_t free_bytes = 0;
293290 if (is_fs_cp) {
294291 statvfs(mnt_pnt.c_str(), &data);
295292 free_bytes = data.f_bavail * data.f_frsize;
296293 } else {
297- int ret;
298- std::string size_filename = std::string("/sys/") + blk_device.substr(5) + "/bow/free";
299- std::string content;
300- ret = android::base::ReadFileToString(size_filename, &content);
301- if (ret) {
302- free_bytes = std::strtoul(content.c_str(), NULL, 10);
294+ std::string bow_device = fs_mgr_find_bow_device(blk_device);
295+ if (!bow_device.empty()) {
296+ std::string content;
297+ if (android::base::ReadFileToString(bow_device + "/bow/free", &content)) {
298+ free_bytes = std::strtoul(content.c_str(), NULL, 10);
299+ }
303300 }
304301 }
305302 if (free_bytes < min_free_bytes) {
--- a/EncryptInplace.cpp
+++ b/EncryptInplace.cpp
@@ -62,7 +62,8 @@ struct encryptGroupsData {
6262 off64_t one_pct, cur_pct, new_pct;
6363 off64_t blocks_already_done, tot_numblocks;
6464 off64_t used_blocks_already_done, tot_used_blocks;
65- char *real_blkdev, *crypto_blkdev;
65+ const char* real_blkdev;
66+ const char* crypto_blkdev;
6667 int count;
6768 off64_t offset;
6869 char* buffer;
@@ -244,8 +245,8 @@ errout:
244245 return rc;
245246 }
246247
247-static int cryptfs_enable_inplace_ext4(char* crypto_blkdev, char* real_blkdev, off64_t size,
248- off64_t* size_already_done, off64_t tot_size,
248+static int cryptfs_enable_inplace_ext4(const char* crypto_blkdev, const char* real_blkdev,
249+ off64_t size, off64_t* size_already_done, off64_t tot_size,
249250 off64_t previously_encrypted_upto,
250251 bool set_progress_properties) {
251252 u32 i;
@@ -383,8 +384,8 @@ static int encrypt_one_block_f2fs(u64 pos, void* data) {
383384 return 0;
384385 }
385386
386-static int cryptfs_enable_inplace_f2fs(char* crypto_blkdev, char* real_blkdev, off64_t size,
387- off64_t* size_already_done, off64_t tot_size,
387+static int cryptfs_enable_inplace_f2fs(const char* crypto_blkdev, const char* real_blkdev,
388+ off64_t size, off64_t* size_already_done, off64_t tot_size,
388389 off64_t previously_encrypted_upto,
389390 bool set_progress_properties) {
390391 struct encryptGroupsData data;
@@ -457,8 +458,8 @@ errout:
457458 return rc;
458459 }
459460
460-static int cryptfs_enable_inplace_full(char* crypto_blkdev, char* real_blkdev, off64_t size,
461- off64_t* size_already_done, off64_t tot_size,
461+static int cryptfs_enable_inplace_full(const char* crypto_blkdev, const char* real_blkdev,
462+ off64_t size, off64_t* size_already_done, off64_t tot_size,
462463 off64_t previously_encrypted_upto,
463464 bool set_progress_properties) {
464465 int realfd, cryptofd;
@@ -570,7 +571,7 @@ errout:
570571 }
571572
572573 /* returns on of the ENABLE_INPLACE_* return codes */
573-int cryptfs_enable_inplace(char* crypto_blkdev, char* real_blkdev, off64_t size,
574+int cryptfs_enable_inplace(const char* crypto_blkdev, const char* real_blkdev, off64_t size,
574575 off64_t* size_already_done, off64_t tot_size,
575576 off64_t previously_encrypted_upto, bool set_progress_properties) {
576577 int rc_ext4, rc_f2fs, rc_full;
--- a/EncryptInplace.h
+++ b/EncryptInplace.h
@@ -24,7 +24,7 @@
2424 #define RETRY_MOUNT_ATTEMPTS 10
2525 #define RETRY_MOUNT_DELAY_SECONDS 1
2626
27-int cryptfs_enable_inplace(char* crypto_blkdev, char* real_blkdev, off64_t size,
27+int cryptfs_enable_inplace(const char* crypto_blkdev, const char* real_blkdev, off64_t size,
2828 off64_t* size_already_done, off64_t tot_size,
2929 off64_t previously_encrypted_upto, bool set_progress_properties);
3030
--- a/MetadataCrypt.cpp
+++ b/MetadataCrypt.cpp
@@ -249,7 +249,8 @@ static bool create_crypto_blk_dev(const std::string& dm_name, uint64_t nr_sec,
249249 return true;
250250 }
251251
252-bool fscrypt_mount_metadata_encrypted(const std::string& mount_point, bool needs_encrypt) {
252+bool fscrypt_mount_metadata_encrypted(const std::string& blk_device, const std::string& mount_point,
253+ bool needs_encrypt) {
253254 LOG(DEBUG) << "fscrypt_mount_metadata_encrypted: " << mount_point << " " << needs_encrypt;
254255 auto encrypted_state = android::base::GetProperty("ro.crypto.state", "");
255256 if (encrypted_state != "") {
@@ -268,13 +269,14 @@ bool fscrypt_mount_metadata_encrypted(const std::string& mount_point, bool needs
268269 if (!get_number_of_sectors(data_rec->blk_device, &nr_sec)) return false;
269270 std::string crypto_blkdev;
270271 if (!create_crypto_blk_dev(kDmNameUserdata, nr_sec, DEFAULT_KEY_TARGET_TYPE,
271- default_key_params(data_rec->blk_device, key), &crypto_blkdev))
272+ default_key_params(blk_device, key), &crypto_blkdev))
272273 return false;
274+
273275 // FIXME handle the corrupt case
274276 if (needs_encrypt) {
275277 LOG(INFO) << "Beginning inplace encryption, nr_sec: " << nr_sec;
276278 off64_t size_already_done = 0;
277- auto rc = cryptfs_enable_inplace(crypto_blkdev.data(), data_rec->blk_device.data(), nr_sec,
279+ auto rc = cryptfs_enable_inplace(crypto_blkdev.data(), blk_device.data(), nr_sec,
278280 &size_already_done, nr_sec, 0, false);
279281 if (rc != 0) {
280282 LOG(ERROR) << "Inplace crypto failed with code: " << rc;
--- a/MetadataCrypt.h
+++ b/MetadataCrypt.h
@@ -19,6 +19,7 @@
1919
2020 #include <string>
2121
22-bool fscrypt_mount_metadata_encrypted(const std::string& mount_point, bool needs_encrypt);
22+bool fscrypt_mount_metadata_encrypted(const std::string& block_device,
23+ const std::string& mount_point, bool needs_encrypt);
2324
2425 #endif
--- a/VoldNativeService.cpp
+++ b/VoldNativeService.cpp
@@ -721,18 +721,20 @@ binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
721721 return ok();
722722 }
723723
724-binder::Status VoldNativeService::mountFstab(const std::string& mountPoint) {
724+binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
725+ const std::string& mountPoint) {
725726 ENFORCE_UID(AID_SYSTEM);
726727 ACQUIRE_LOCK;
727728
728- return translateBool(fscrypt_mount_metadata_encrypted(mountPoint, false));
729+ return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false));
729730 }
730731
731-binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) {
732+binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
733+ const std::string& mountPoint) {
732734 ENFORCE_UID(AID_SYSTEM);
733735 ACQUIRE_LOCK;
734736
735- return translateBool(fscrypt_mount_metadata_encrypted(mountPoint, true));
737+ return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true));
736738 }
737739
738740 binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) {
--- a/VoldNativeService.h
+++ b/VoldNativeService.h
@@ -104,8 +104,8 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
104104 binder::Status mountDefaultEncrypted();
105105 binder::Status initUser0();
106106 binder::Status isConvertibleToFbe(bool* _aidl_return);
107- binder::Status mountFstab(const std::string& mountPoint);
108- binder::Status encryptFstab(const std::string& mountPoint);
107+ binder::Status mountFstab(const std::string& blkDevice, const std::string& mountPoint);
108+ binder::Status encryptFstab(const std::string& blkDevice, const std::string& mountPoint);
109109
110110 binder::Status createUserKey(int32_t userId, int32_t userSerial, bool ephemeral);
111111 binder::Status destroyUserKey(int32_t userId);
--- a/binder/android/os/IVold.aidl
+++ b/binder/android/os/IVold.aidl
@@ -81,8 +81,8 @@ interface IVold {
8181 void mountDefaultEncrypted();
8282 void initUser0();
8383 boolean isConvertibleToFbe();
84- void mountFstab(@utf8InCpp String mountPoint);
85- void encryptFstab(@utf8InCpp String mountPoint);
84+ void mountFstab(@utf8InCpp String blkDevice, @utf8InCpp String mountPoint);
85+ void encryptFstab(@utf8InCpp String blkDevice, @utf8InCpp String mountPoint);
8686
8787 void createUserKey(int userId, int userSerial, boolean ephemeral);
8888 void destroyUserKey(int userId);
--- a/vdc.cpp
+++ b/vdc.cpp
@@ -101,10 +101,10 @@ int main(int argc, char** argv) {
101101 checkStatus(vold->shutdown());
102102 } else if (args[0] == "cryptfs" && args[1] == "checkEncryption" && args.size() == 3) {
103103 checkStatus(vold->checkEncryption(args[2]));
104- } else if (args[0] == "cryptfs" && args[1] == "mountFstab" && args.size() == 3) {
105- checkStatus(vold->mountFstab(args[2]));
106- } else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 3) {
107- checkStatus(vold->encryptFstab(args[2]));
104+ } else if (args[0] == "cryptfs" && args[1] == "mountFstab" && args.size() == 4) {
105+ checkStatus(vold->mountFstab(args[2], args[3]));
106+ } else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 4) {
107+ checkStatus(vold->encryptFstab(args[2], args[3]));
108108 } else if (args[0] == "checkpoint" && args[1] == "supportsCheckpoint" && args.size() == 2) {
109109 bool supported = false;
110110 checkStatus(vold->supportsCheckpoint(&supported));
Show on old repository browser