mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: hengyul@cs.unc.edu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fat: calculate data area start without overflow
Date: Wed, 2 Sep 2026 16:39:09 +0100	[thread overview]
Message-ID: <20260902163909.15ecb746@pumpkin> (raw)
In-Reply-To: <87cxuvn9m9.fsf@mail.parknet.co.jp>

On Wed, 02 Sep 2026 21:03:26 +0900
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> wrote:

> 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?

Why do the work twice?

David

> 
> Thanks.


      reply	other threads:[~2026-09-02 15:39 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
2026-09-02 15:39   ` David Laight [this message]

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=20260902163909.15ecb746@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=hengyul@cs.unc.edu \
    --cc=hirofumi@mail.parknet.co.jp \
    --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®