From: "Luís Henriques" <lhenriques@suse.de>
To: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Daniel Rosenberg <drosen@google.com>,
Eric Biggers <ebiggers@kernel.org>
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
"Luís Henriques" <lhenriques@suse.de>
Subject: [PATCH v3] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup}
Date: Thu, 3 Aug 2023 10:17:13 +0100 [thread overview]
Message-ID: <20230803091713.13239-1-lhenriques@suse.de> (raw)
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.
Fixes: 1ae98e295fa2 ("ext4: optimize match for casefolded encrypted dirs")
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
Changes since v2:
- Rephrased commit log to (hopefully!) make it more clear.
- Use ext4_fname_free_filename() instead of fscrypt_free_filename().
Although not strictly needed, it cleans up the fname struct, removing a
dangling pointer to freed memory.
Changes since v1:
- Include fix to ext4_fname_prepare_lookup() as well
- Add 'Fixes:' tag
fs/ext4/crypto.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index e20ac0654b3f..453d4da5de52 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)
+ ext4_fname_free_filename(fname);
#endif
return err;
}
@@ -51,6 +53,8 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry,
#if IS_ENABLED(CONFIG_UNICODE)
err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname);
+ if (err)
+ ext4_fname_free_filename(fname);
#endif
return err;
}
next reply other threads:[~2023-08-03 9:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 9:17 Luís Henriques [this message]
2023-08-04 4:06 ` [PATCH v3] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} Eric Biggers
2023-08-05 12:20 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230803091713.13239-1-lhenriques@suse.de \
--to=lhenriques@suse.de \
--cc=adilger.kernel@dilger.ca \
--cc=drosen@google.com \
--cc=ebiggers@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox