fs: crypto: Fix memory leak while allocating blk crypto key

In case of legaacy data encryption mode, block crypto key allocated
for file encryption was not freed when inode is evicted or destroyed
as crypto data do not own the key. So free the blk crpto key
explicitly in case legacy data encryption mode is used.

Change-Id: Ia860edc7c67516bf8fa47b6e3241ce068a09492b
Signed-off-by: Neeraj Soni <neersoni@codeaurora.org>
This commit is contained in:
Neeraj Soni 2020-07-27 12:30:13 +05:30
parent e3e20132c3
commit 0c7cfe4998
2 changed files with 12 additions and 3 deletions

View file

@ -477,9 +477,17 @@ static void put_crypt_info(struct fscrypt_info *ci)
if (ci->ci_direct_key)
fscrypt_put_direct_key(ci->ci_direct_key);
else if (ci->ci_owns_key)
fscrypt_destroy_prepared_key(&ci->ci_key);
else if (ci->ci_owns_key) {
if (fscrypt_policy_contents_mode(&ci->ci_policy) !=
FSCRYPT_MODE_PRIVATE) {
fscrypt_destroy_prepared_key(&ci->ci_key);
} else {
#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
if (ci->ci_key.blk_key)
kzfree(ci->ci_key.blk_key);
#endif
}
}
key = ci->ci_master_key;
if (key) {
struct fscrypt_master_key *mk = key->payload.data[0];

View file

@ -279,6 +279,7 @@ static int setup_v1_file_key_derived(struct fscrypt_info *ci,
if ((fscrypt_policy_contents_mode(&ci->ci_policy) ==
FSCRYPT_MODE_PRIVATE) &&
fscrypt_using_inline_encryption(ci)) {
ci->ci_owns_key = true;
memcpy(key_new.bytes, raw_master_key, ci->ci_mode->keysize);
for (i = 0; i < ARRAY_SIZE(key_new.words); i++)