diff options
author | Eric Biggers <ebiggers@google.com> | 2022-10-12 02:40:20 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-10-12 02:40:20 +0000 |
commit | 376be63430b2a827e769317a86252feb0ec4dded (patch) | |
tree | 34480f793bb308654d9efdcebef13d3da7da3997 | |
parent | b3c87f9cbf0293bf43b3100f8a3df71a58440a44 (diff) | |
parent | 279a1982f1c19d171fc9ed9896e4bff993f3d8f5 (diff) | |
download | vold-android11-gsi.tar.gz |
Merge "cryptfs: Update the size of dm-crypt device according to sector size" into android11-gsiandroid11-gsi
-rw-r--r-- | cryptfs.cpp | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/cryptfs.cpp b/cryptfs.cpp index 423c960d..3ba4b172 100644 --- a/cryptfs.cpp +++ b/cryptfs.cpp @@ -1045,42 +1045,28 @@ static void convert_key_to_hex_ascii(const unsigned char* master_key, unsigned i master_key_ascii[a] = '\0'; } -/* - * If the ro.crypto.fde_sector_size system property is set, append the - * parameters to make dm-crypt use the specified crypto sector size and round - * the crypto device size down to a crypto sector boundary. - */ -static int add_sector_size_param(DmTargetCrypt* target, struct crypt_mnt_ftr* ftr) { +static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned char* master_key, + const char* real_blk_name, std::string* crypto_blk_name, + const char* name, uint32_t flags) { constexpr char DM_CRYPT_SECTOR_SIZE[] = "ro.crypto.fde_sector_size"; char value[PROPERTY_VALUE_MAX]; + unsigned int sector_size = 0; if (property_get(DM_CRYPT_SECTOR_SIZE, value, "") > 0) { - unsigned int sector_size; - if (!ParseUint(value, §or_size) || sector_size < 512 || sector_size > 4096 || (sector_size & (sector_size - 1)) != 0) { SLOGE("Invalid value for %s: %s. Must be >= 512, <= 4096, and a power of 2\n", DM_CRYPT_SECTOR_SIZE, value); return -1; } + } - target->SetSectorSize(sector_size); - - // With this option, IVs will match the sector numbering, instead - // of being hard-coded to being based on 512-byte sectors. - target->SetIvLargeSectors(); - - // Round the crypto device size down to a crypto sector boundary. - ftr->fs_size &= ~((sector_size / 512) - 1); + // Round the crypto device size down to a crypto sector boundary. + if (sector_size > 0) { + crypt_ftr->fs_size &= ~((sector_size / 512) - 1); } - return 0; -} -static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned char* master_key, - const char* real_blk_name, std::string* crypto_blk_name, - const char* name, uint32_t flags) { auto& dm = DeviceMapper::Instance(); - // We need two ASCII characters to represent each byte, and need space for // the '\0' terminator. char master_key_ascii[MAX_KEY_LEN * 2 + 1]; @@ -1094,9 +1080,13 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned if (flags & CREATE_CRYPTO_BLK_DEV_FLAGS_ALLOW_ENCRYPT_OVERRIDE) { target->AllowEncryptOverride(); } - if (add_sector_size_param(target.get(), crypt_ftr)) { - SLOGE("Error processing dm-crypt sector size param\n"); - return -1; + + // Append the parameters to make dm-crypt use the specified crypto sector size. + if (sector_size > 0) { + target->SetSectorSize(sector_size); + // With this option, IVs will match the sector numbering, instead + // of being hard-coded to being based on 512-byte sectors. + target->SetIvLargeSectors(); } DmTable table; |