From: "Luís Henriques" <lhenriques@suse.de>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] ext4: fix BUG_ON() when a directory entry has an invalid rec_len
Date: Wed, 12 Oct 2022 10:03:03 +0100 [thread overview]
Message-ID: <Y0aCx45PBQrde4IC@suse.de> (raw)
In-Reply-To: <Y0YQ42Z/XPuHZRS8@mit.edu>
On Tue, Oct 11, 2022 at 08:57:07PM -0400, Theodore Ts'o wrote:
> On Tue, Oct 11, 2022 at 04:57:45PM +0100, Luís Henriques wrote:
> > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> > index 3a31b662f661..06803292e394 100644
> > --- a/fs/ext4/namei.c
> > +++ b/fs/ext4/namei.c
> > @@ -2254,8 +2254,18 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
> > memset(de, 0, len); /* wipe old data */
> > de = (struct ext4_dir_entry_2 *) data2;
> > top = data2 + len;
> > - while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top)
> > + while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top) {
> > + if (de->rec_len & 3) {
>
> As the kernel test bot as flaged, de->rec_len needs to be byte swapped
> on big endian machines. Also, for block sizes larger than 64k the low
> 2 bits are used to encode rec_len sizes 256k-4. All of this is
> encoded in ext4_rec_len_from_disk().
>
> However, I think a better thing to do is instead of doing this one
> check on rec len, that instead we call ext4_check_dir_entry(), which
> will do this check, and many more besides. It will also avoid some
> code duplication, since it will take care of calling EXT4_ERROR_INODE
> with the appropriate explanatory message.
Awesome, thanks for the explanation, Ted. I'll work on a v2 of the patch
that'll use ext4_check_dir_entry() and send it after running some tests
with it. Thanks for the suggestion!
Cheers,
--
Luís
prev parent reply other threads:[~2022-10-12 9:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-11 15:57 [PATCH] ext4: fix BUG_ON() when a directory entry has an invalid rec_len Luís Henriques
2022-10-11 21:21 ` kernel test robot
2022-10-12 0:57 ` Theodore Ts'o
2022-10-12 9:03 ` Luís Henriques [this message]
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=Y0aCx45PBQrde4IC@suse.de \
--to=lhenriques@suse.de \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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).