ntfs3.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>
Cc: syzbot <syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com>,
	syzkaller-bugs@googlegroups.com, ntfs3@lists.linux.dev,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] fs/ntfs3: fix negative shift size in true_sectors_per_clst()
Date: Wed, 21 Sep 2022 00:59:27 +0900	[thread overview]
Message-ID: <4b37f037-3b10-b4e4-0644-73441c8fa0af@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <000000000000f8b5ef05dd25b963@google.com>

syzbot is reporting shift-out-of-bounds in true_sectors_per_clst() [1], for
commit a3b774342fa752a5 ("fs/ntfs3: validate BOOT sectors_per_clusters")
did not address that (0 - boot->sectors_per_clusters) < 0 because "u8" was
chosen for type of boot->sectors_per_clusters because 0x80 needs to be
positive in order to support 64K clusters. Use "s8" cast in order to make
sure that (0 - (s8) boot->sectors_per_clusters) > 0.

Link: https://syzkaller.appspot.com/bug?extid=1631f09646bc214d2e76 [1]
Reported-by: syzbot <syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: syzbot <syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com>
Fixes: a3b774342fa752a5 ("fs/ntfs3: validate BOOT sectors_per_clusters")

diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 47012c9bf505..c7ffd21fb255 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -672,7 +672,7 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
 	if (boot->sectors_per_clusters <= 0x80)
 		return boot->sectors_per_clusters;
 	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
-		return 1U << (0 - boot->sectors_per_clusters);
+		return 1U << (0 - (s8) boot->sectors_per_clusters);
 	return -EINVAL;
 }
 
-- 
2.18.4


  parent reply	other threads:[~2022-09-20 16:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21  8:16 [syzbot] UBSAN: shift-out-of-bounds in ntfs_fill_super syzbot
2022-04-21  8:37 ` syzbot
2022-04-21 12:29 ` syzbot
2022-09-20 15:59 ` Tetsuo Handa [this message]
2022-09-23  0:38   ` [PATCH] fs/ntfs3: fix negative shift size in true_sectors_per_clst() Randy Dunlap
2022-09-23  0:47     ` Joe Perches
2022-09-23  1:14       ` Randy Dunlap
2022-09-23  9:59       ` Dan Carpenter
2022-09-23  1:25     ` Tetsuo Handa
2022-09-23 11:58       ` Aleksandr Nogikh
2022-09-23 14:35         ` Tetsuo Handa
2022-09-24 11:58           ` Aleksandr Nogikh
2022-09-24 12:03             ` Aleksandr Nogikh
2022-09-23 11:58     ` Konstantin Komarov
2022-09-23 16:07       ` Randy Dunlap
2022-09-30 16:34   ` Konstantin Komarov

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=4b37f037-3b10-b4e4-0644-73441c8fa0af@I-love.SAKURA.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=akpm@linux-foundation.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=rdunlap@infradead.org \
    --cc=syzbot+1631f09646bc214d2e76@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;
as well as URLs for NNTP newsgroup(s).