From: "Theodore Ts'o" <tytso@mit.edu>
To: "Luís Henriques" <lhenriques@suse.de>
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: Tue, 11 Oct 2022 20:57:07 -0400 [thread overview]
Message-ID: <Y0YQ42Z/XPuHZRS8@mit.edu> (raw)
In-Reply-To: <20221011155745.15264-1-lhenriques@suse.de>
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.
- Ted
next prev parent reply other threads:[~2022-10-12 0:57 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 [this message]
2022-10-12 9:03 ` 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=Y0YQ42Z/XPuHZRS8@mit.edu \
--to=tytso@mit.edu \
--cc=adilger.kernel@dilger.ca \
--cc=lhenriques@suse.de \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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