Re: [PATCH v3] ext4: Fix rec_len verify error
From: Stephen Zhang
Date: Tue Aug 01 2023 - 21:17:48 EST
Darrick J. Wong <djwong@xxxxxxxxxx> 于2023年8月1日周二 23:18写道:
>
>
> This is sitll missing some pieces; what about this clause at line 367:
>
> if (t->det_reserved_zero1 ||
> le16_to_cpu(t->det_rec_len) != sizeof(struct ext4_dir_entry_tail) ||
> t->det_reserved_zero2 ||
> t->det_reserved_ft != EXT4_FT_DIR_CSUM)
> return NULL;
>
Yeah...
> > @@ -445,13 +445,13 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
> > struct ext4_dir_entry *dp;
> > struct dx_root_info *root;
> > int count_offset;
> > + int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
> >
> > - if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
> > + if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == blocksize)
> > count_offset = 8;
> > - else if (le16_to_cpu(dirent->rec_len) == 12) {
> > + else if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == 12) {
>
> Why not lift this ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ to a
> local variable? @dirent doesn't change, right?
>
Will do.
> > dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
> > - if (le16_to_cpu(dp->rec_len) !=
> > - EXT4_BLOCK_SIZE(inode->i_sb) - 12)
> > + if (ext4_rec_len_from_disk(dp->rec_len, blocksize) != blocksize - 12)
> > return NULL;
> > root = (struct dx_root_info *)(((void *)dp + 12));
> > if (root->reserved_zero ||
>
> What about dx_make_map?
>
dx_make_map(
....
map_tail->size = le16_to_cpu(de->rec_len);
That might be a questionable one...
map_tail->size is 16 bit, while the key reason we want ext4_rec_len_from_disk
is converting 16-bit rec_len disk form to a in-memory form consisting of like 17
bits...i.e. 0x10000.
Cheers,
Shida
> Here's all the opencoded access I could find:
>
> $ git grep le16.*rec_len fs/ext4/
> fs/ext4/namei.c:356: le16_to_cpu(d->rec_len));
> fs/ext4/namei.c:367: le16_to_cpu(t->det_rec_len) != sizeof(struct ext4_dir_entry_tail) ||
> fs/ext4/namei.c:449: if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
> fs/ext4/namei.c:451: else if (le16_to_cpu(dirent->rec_len) == 12) {
> fs/ext4/namei.c:453: if (le16_to_cpu(dp->rec_len) !=
> fs/ext4/namei.c:1338: map_tail->size = le16_to_cpu(de->rec_len);
>
> --D
>
> > --
> > 2.27.0
> >