* [PATCH] ext4: fix memory leak in ext4_fname_setup_filename() error path
@ 2023-08-01 14:41 Luís Henriques
2023-08-02 4:23 ` Eric Biggers
0 siblings, 1 reply; 3+ messages in thread
From: Luís Henriques @ 2023-08-01 14:41 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger
Cc: linux-ext4, linux-kernel, Luís Henriques
If casefolding the filename fails, we'll be leaking fscrypt_buf name.
Make sure we free it in the error path.
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
fs/ext4/crypto.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index e20ac0654b3f..9e4503b051c4 100644
--- a/fs/ext4/crypto.c
+++ b/fs/ext4/crypto.c
@@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
#if IS_ENABLED(CONFIG_UNICODE)
err = ext4_fname_setup_ci_filename(dir, iname, fname);
+ if (err)
+ fscrypt_free_filename(&name);
#endif
return err;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: fix memory leak in ext4_fname_setup_filename() error path
2023-08-01 14:41 [PATCH] ext4: fix memory leak in ext4_fname_setup_filename() error path Luís Henriques
@ 2023-08-02 4:23 ` Eric Biggers
2023-08-02 8:12 ` Luís Henriques
0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2023-08-02 4:23 UTC (permalink / raw)
To: Luís Henriques
Cc: Theodore Ts'o, Andreas Dilger, linux-ext4, linux-kernel
On Tue, Aug 01, 2023 at 03:41:36PM +0100, Luís Henriques wrote:
> If casefolding the filename fails, we'll be leaking fscrypt_buf name.
> Make sure we free it in the error path.
>
> Signed-off-by: Luís Henriques <lhenriques@suse.de>
> ---
> fs/ext4/crypto.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
> index e20ac0654b3f..9e4503b051c4 100644
> --- a/fs/ext4/crypto.c
> +++ b/fs/ext4/crypto.c
> @@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
>
> #if IS_ENABLED(CONFIG_UNICODE)
> err = ext4_fname_setup_ci_filename(dir, iname, fname);
> + if (err)
> + fscrypt_free_filename(&name);
> #endif
> return err;
> }
Doesn't ext4_fname_prepare_lookup() have the same bug?
Also, please include a Fixes tag.
- Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: fix memory leak in ext4_fname_setup_filename() error path
2023-08-02 4:23 ` Eric Biggers
@ 2023-08-02 8:12 ` Luís Henriques
0 siblings, 0 replies; 3+ messages in thread
From: Luís Henriques @ 2023-08-02 8:12 UTC (permalink / raw)
To: Eric Biggers; +Cc: Theodore Ts'o, Andreas Dilger, linux-ext4, linux-kernel
Eric Biggers <ebiggers@kernel.org> writes:
> On Tue, Aug 01, 2023 at 03:41:36PM +0100, Luís Henriques wrote:
>> If casefolding the filename fails, we'll be leaking fscrypt_buf name.
>> Make sure we free it in the error path.
>>
>> Signed-off-by: Luís Henriques <lhenriques@suse.de>
>> ---
>> fs/ext4/crypto.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
>> index e20ac0654b3f..9e4503b051c4 100644
>> --- a/fs/ext4/crypto.c
>> +++ b/fs/ext4/crypto.c
>> @@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
>>
>> #if IS_ENABLED(CONFIG_UNICODE)
>> err = ext4_fname_setup_ci_filename(dir, iname, fname);
>> + if (err)
>> + fscrypt_free_filename(&name);
>> #endif
>> return err;
>> }
>
> Doesn't ext4_fname_prepare_lookup() have the same bug?
Doh! I looked into that function too and then completely forgot about it.
It may also call fscrypt_setup_filename(), so it has to do the free in the
error path as well. I'll send out v2 to include that fix too.
> Also, please include a Fixes tag.
Ok, makes sense. Thanks!
Cheers,
--
Luís
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-02 8:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-01 14:41 [PATCH] ext4: fix memory leak in ext4_fname_setup_filename() error path Luís Henriques
2023-08-02 4:23 ` Eric Biggers
2023-08-02 8:12 ` Luís Henriques
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).