From a7635718c459b95c45a09c409460570e564037dc Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Tue, 15 Dec 2020 08:46:44 -0800 Subject: [PATCH] Pass wiped and fs_type to vold to format encrypted partition Bug: 172378121 Signed-off-by: Jaegeuk Kim Change-Id: I358380fc47fe9d4d75337323c772ca1af122d2c6 --- fs_mgr/fs_mgr.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index 4c9fd9b08..2876094be 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -1324,6 +1324,7 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { int error_count = 0; CheckpointManager checkpoint_manager; AvbUniquePtr avb_handle(nullptr); + bool wiped = false; bool userdata_mounted = false; if (fstab->empty()) { @@ -1457,7 +1458,8 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { encryptable = status; if (status == FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION) { if (!call_vdc({"cryptfs", "encryptFstab", attempted_entry.blk_device, - attempted_entry.mount_point}, + attempted_entry.mount_point, wiped ? "true" : "false", + attempted_entry.fs_type}, nullptr)) { LERROR << "Encryption failed"; set_type_property(encryptable); @@ -1474,7 +1476,7 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { } // Mounting failed, understand why and retry. - bool wiped = partition_wiped(current_entry.blk_device.c_str()); + wiped = partition_wiped(current_entry.blk_device.c_str()); bool crypt_footer = false; if (mount_errno != EBUSY && mount_errno != EACCES && current_entry.fs_mgr_flags.formattable && wiped) { @@ -1499,6 +1501,27 @@ MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) { } else if (current_entry.is_encryptable() && current_entry.key_loc == KEY_IN_FOOTER) { crypt_footer = true; } + + // EncryptInplace will be used when vdc gives an error or needs to format partitions + // other than /data + if (should_use_metadata_encryption(current_entry) && + current_entry.mount_point == "/data") { + + // vdc->Format requires "ro.crypto.type" to set an encryption flag + encryptable = FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED; + set_type_property(encryptable); + + if (!call_vdc({"cryptfs", "encryptFstab", current_entry.blk_device, + current_entry.mount_point, "true" /* shouldFormat */, + current_entry.fs_type}, + nullptr)) { + LERROR << "Encryption failed"; + } else { + userdata_mounted = true; + continue; + } + } + if (fs_mgr_do_format(current_entry, crypt_footer) == 0) { // Let's replay the mount actions. i = top_idx - 1;