]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/ntfs3: Fix possible null-pointer dereference in hdr_find_e()
authorZiqi Zhao <astrajoan@yahoo.com>
Wed, 9 Aug 2023 19:11:18 +0000 (12:11 -0700)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 28 Sep 2023 12:04:05 +0000 (15:04 +0300)
Upon investigation of the C reproducer provided by Syzbot, it seemed
the reproducer was trying to mount a corrupted NTFS filesystem, then
issue a rename syscall to some nodes in the filesystem. This can be
shown by modifying the reproducer to only include the mount syscall,
and investigating the filesystem by e.g. `ls` and `rm` commands. As a
result, during the problematic call to `hdr_fine_e`, the `inode` being
supplied did not go through `indx_init`, hence the `cmp` function
pointer was never set.

The fix is simply to check whether `cmp` is not set, and return NULL
if that's the case, in order to be consistent with other error
scenarios of the `hdr_find_e` method. The rationale behind this patch
is that:

- We should prevent crashing the kernel even if the mounted filesystem
  is corrupted. Any syscalls made on the filesystem could return
  invalid, but the kernel should be able to sustain these calls.

- Only very specific corruption would lead to this bug, so it would be
  a pretty rare case in actual usage anyways. Therefore, introducing a
  check to specifically protect against this bug seems appropriate.
  Because of its rarity, an `unlikely` clause is used to wrap around
  this nullity check.

Reported-by: syzbot+60cf892fc31d1f4358fc@syzkaller.appspotmail.com
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/index.c

index 124c6e822623feaff048f3b15354702944092de8..cf92b2433f7a750aeb86383eb7440c730ad7dc95 100644 (file)
@@ -729,6 +729,9 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,
        u32 total = le32_to_cpu(hdr->total);
        u16 offs[128];
 
+       if (unlikely(!cmp))
+               return NULL;
+
 fill_table:
        if (end > total)
                return NULL;