public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
From: Ziqi Zhao <astrajoan@yahoo.com>
To: syzbot+60cf892fc31d1f4358fc@syzkaller.appspotmail.com,
	almaz.alexandrovich@paragon-software.com, ntfs3@lists.linux.dev,
	skhan@linuxfoundation.org, ivan.orlov0322@gmail.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzkaller-bugs@googlegroups.com, Ziqi Zhao <astrajoan@yahoo.com>
Subject: [PATCH] fs/ntfs3: Fix possible null-pointer dereference in hdr_find_e()
Date: Wed,  9 Aug 2023 12:14:09 -0700	[thread overview]
Message-ID: <20230809191409.30786-1-astrajoan@yahoo.com> (raw)
In-Reply-To: <0000000000009531dc0602016bb0@google.com>

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>
---
 fs/ntfs3/index.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index 124c6e822623..cf92b2433f7a 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -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;
-- 
2.34.1


  parent reply	other threads:[~2023-08-09 19:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  9:29 [syzbot] [ntfs3?] BUG: unable to handle kernel NULL pointer dereference in hdr_find_e (2) syzbot
2023-08-09 19:11 ` [PATCH] fs/ntfs3: Fix possible null-pointer dereference in hdr_find_e() Ziqi Zhao
2023-08-09 20:49   ` [syzbot] [ntfs3?] BUG: unable to handle kernel NULL pointer dereference in hdr_find_e (2) syzbot
2023-08-09 19:14 ` Ziqi Zhao [this message]
2023-08-31  0:31 ` syzbot

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=20230809191409.30786-1-astrajoan@yahoo.com \
    --to=astrajoan@yahoo.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=ivan.orlov0322@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=syzbot+60cf892fc31d1f4358fc@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /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