Skip to content

Commit 7ca4b08

Browse files
Luís Henriquestytso
authored andcommitted
ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup}
If the filename casefolding fails, we'll be leaking memory from the fscrypt_name struct, namely from the 'crypto_buf.name' member. Make sure we free it in the error path on both ext4_fname_setup_filename() and ext4_fname_prepare_lookup() functions. Cc: [email protected] Fixes: 1ae98e2 ("ext4: optimize match for casefolded encrypted dirs") Signed-off-by: Luís Henriques <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 5f02a30 commit 7ca4b08

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/ext4/crypto.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname,
3333

3434
#if IS_ENABLED(CONFIG_UNICODE)
3535
err = ext4_fname_setup_ci_filename(dir, iname, fname);
36+
if (err)
37+
ext4_fname_free_filename(fname);
3638
#endif
3739
return err;
3840
}
@@ -51,6 +53,8 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry,
5153

5254
#if IS_ENABLED(CONFIG_UNICODE)
5355
err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname);
56+
if (err)
57+
ext4_fname_free_filename(fname);
5458
#endif
5559
return err;
5660
}

0 commit comments

Comments
 (0)