2019-08-20 05:17:54

by Wenwen Wang

[permalink] [raw]
Subject: [PATCH] ecryptfs: fix a memory leak bug

In parse_tag_1_packet(), if tag 1 packet contains a key larger than
ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES, no cleanup is executed, leading to a
memory leak on the allocated 'auth_tok_list_item'. To fix this issue, go to
the label 'out_free' to perform the cleanup work.

Signed-off-by: Wenwen Wang <[email protected]>
---
fs/ecryptfs/keystore.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
index 216fbe6..4dc0963 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -1304,7 +1304,7 @@ parse_tag_1_packet(struct ecryptfs_crypt_stat *crypt_stat,
printk(KERN_WARNING "Tag 1 packet contains key larger "
"than ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES\n");
rc = -EINVAL;
- goto out;
+ goto out_free;
}
memcpy((*new_auth_tok)->session_key.encrypted_key,
&data[(*packet_size)], (body_size - (ECRYPTFS_SIG_SIZE + 2)));
--
2.7.4


2019-08-20 07:12:57

by Tyler Hicks

[permalink] [raw]
Subject: Re: [PATCH] ecryptfs: fix a memory leak bug

On 2019-08-20 00:16:40, Wenwen Wang wrote:
> In parse_tag_1_packet(), if tag 1 packet contains a key larger than
> ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES, no cleanup is executed, leading to a
> memory leak on the allocated 'auth_tok_list_item'. To fix this issue, go to
> the label 'out_free' to perform the cleanup work.
>
> Signed-off-by: Wenwen Wang <[email protected]>

Thanks for the patch!

I added the following tags to the commit message:

Cc: [email protected]
Fixes: dddfa461fc89 ("[PATCH] eCryptfs: Public key; packet management")

I also added the function name to the commit subject so that it was
unique from your other fix.

I've pushed the fix to the eCryptfs next branch and I'll submit a pull
request for inclusion soon.

Tyler

> ---
> fs/ecryptfs/keystore.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
> index 216fbe6..4dc0963 100644
> --- a/fs/ecryptfs/keystore.c
> +++ b/fs/ecryptfs/keystore.c
> @@ -1304,7 +1304,7 @@ parse_tag_1_packet(struct ecryptfs_crypt_stat *crypt_stat,
> printk(KERN_WARNING "Tag 1 packet contains key larger "
> "than ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES\n");
> rc = -EINVAL;
> - goto out;
> + goto out_free;
> }
> memcpy((*new_auth_tok)->session_key.encrypted_key,
> &data[(*packet_size)], (body_size - (ECRYPTFS_SIG_SIZE + 2)));
> --
> 2.7.4
>