From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: hengyul@cs.unc.edu
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fat: calculate data area start without overflow
Date: Wed, 02 Sep 2026 21:03:26 +0900 [thread overview]
Message-ID: <87cxuvn9m9.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20260902105716.3972118-1-hengyul@cs.unc.edu>
hengyul@cs.unc.edu writes:
> From: Hengyu Liang <hengyul@cs.unc.edu>
>
> On 32-bit architectures, sbi->fat_length, sbi->dir_start and
> sbi->data_start are unsigned long. The number of FATs is an 8-bit BPB
> field, while the FAT32 length is a 32-bit BPB field. Therefore, the
> calculation
>
> sbi->fat_start + sbi->fats * sbi->fat_length
>
> can wrap before data_start is checked against total_sectors.
[...]
> - sbi->dir_start = sbi->fat_start + sbi->fats * sbi->fat_length;
> sbi->dir_entries = bpb.fat_dir_entries;
> if (sbi->dir_entries & (sbi->dir_per_block - 1)) {
> if (!silent)
> @@ -1763,19 +1764,23 @@ int fat_fill_super(struct super_block *sb, struct fs_context *fc,
>
> rootdir_sectors = sbi->dir_entries
> * sizeof(struct msdos_dir_entry) / sb->s_blocksize;
> - sbi->data_start = sbi->dir_start + rootdir_sectors;
> + dir_start = sbi->fat_start +
> + mul_u32_u32(sbi->fats, sbi->fat_length);
> + data_start = dir_start + rootdir_sectors;
Maybe, since u32 overflow is always bigger than total_sectors, so we
should use check_*_overflow() instead, and detect early?
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
next prev parent reply other threads:[~2026-09-02 12:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 10:57 hengyul
2026-09-02 12:03 ` OGAWA Hirofumi [this message]
2026-09-02 15:39 ` David Laight
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=87cxuvn9m9.fsf@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=hengyul@cs.unc.edu \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®