lkml.org 
[lkml]   [2022]   [Oct]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] ext4: fix BUG_ON() when a directory entry has an invalid rec_len
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

\
 
 \ /
  Last update: 2022-10-12 02:57    [W:2.020 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site