From 88f993b4a85d5a8638f9c2fd369b5ce6a078c847 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 3 Nov 2020 14:11:00 -0800 Subject: [PATCH] Check return value of create_crypto_blk_dev() cryptfs_enable_internal() forgot to check the return value of create_crypto_blk_dev(), so it was continuing to cryptfs_enable_inplace() when creating the dm-crypt device failed, which doesn't make sense. Test: see I08fc8465f7962abd698904b5466f3ed080d53953 Change-Id: If9f20069d0f084150aa887a350f7c0c31a6d80f2 --- cryptfs.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cryptfs.cpp b/cryptfs.cpp index 316c763..36bd43b 100644 --- a/cryptfs.cpp +++ b/cryptfs.cpp @@ -2287,13 +2287,14 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) { } decrypt_master_key(passwd, decrypted_master_key, &crypt_ftr, 0, 0); - create_crypto_blk_dev(&crypt_ftr, decrypted_master_key, real_blkdev.c_str(), &crypto_blkdev, - CRYPTO_BLOCK_DEVICE, 0); + rc = create_crypto_blk_dev(&crypt_ftr, decrypted_master_key, real_blkdev.c_str(), + &crypto_blkdev, CRYPTO_BLOCK_DEVICE, 0); + if (!rc) { + rc = cryptfs_enable_all_volumes(&crypt_ftr, crypto_blkdev.c_str(), real_blkdev.data()); - rc = cryptfs_enable_all_volumes(&crypt_ftr, crypto_blkdev.c_str(), real_blkdev.data()); - - /* Undo the dm-crypt mapping whether we succeed or not */ - delete_crypto_blk_dev(CRYPTO_BLOCK_DEVICE); + /* Undo the dm-crypt mapping whether we succeed or not */ + delete_crypto_blk_dev(CRYPTO_BLOCK_DEVICE); + } if (!rc) { /* Success */