From: Eric Biggers <ebiggers@kernel.org>
To: "Luís Henriques" <lhenriques@suse.de>
Cc: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Daniel Rosenberg <drosen@google.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup}
Date: Wed, 2 Aug 2023 21:19:18 -0700 [thread overview]
Message-ID: <20230803041918.GA1218@sol.localdomain> (raw)
In-Reply-To: <20230802094931.18215-1-lhenriques@suse.de>
On Wed, Aug 02, 2023 at 10:49:31AM +0100, Luís Henriques wrote:
> If casefolding the filename fails, we'll be leaking fscrypt_buf name.
fscrypt_buf => fscrypt_name
> diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
> index e20ac0654b3f..3c05c7f3415b 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,
> struct fscrypt_name name;
> int err;
>
> err = fscrypt_setup_filename(dir, iname, lookup, &name);
> if (err)
> return err;
>
> ext4_fname_from_fscrypt_name(fname, &name);
>
> #if IS_ENABLED(CONFIG_UNICODE)
> err = ext4_fname_setup_ci_filename(dir, iname, fname);
> + if (err)
> + fscrypt_free_filename(&name);
> #endif
> return err;
> }
> @@ -51,6 +53,8 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry,
> struct fscrypt_name name;
> int err;
>
> err = fscrypt_prepare_lookup(dir, dentry, &name);
> if (err)
> return err;
>
> ext4_fname_from_fscrypt_name(fname, &name);
>
> #if IS_ENABLED(CONFIG_UNICODE)
> err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname);
> + if (err)
> + fscrypt_free_filename(&name);
> #endif
> return err;
> }
This works, but it's a bit weird that the freeing happens on the original struct
fscrypt_name after it has already been "moved" to the struct ext4_filename by
ext4_fname_from_fscrypt_name(). That leaves a dangling pointer in the struct
ext4_filename. Maybe you should call ext4_fname_free_filename() instead, even
though it would do some unnecessary work?
- Eric
next prev parent reply other threads:[~2023-08-03 4:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 9:49 [PATCH v2] ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup} Luís Henriques
2023-08-03 4:19 ` Eric Biggers [this message]
2023-08-03 8:58 ` Luís Henriques
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=20230803041918.GA1218@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=drosen@google.com \
--cc=lhenriques@suse.de \
--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;
as well as URLs for NNTP newsgroup(s).