Re: [PATCH v2 1/2] adfs: reject disc records smaller than one filesystem block
From: Samuel Moelius
Date: Mon Jun 29 2026 - 07:12:09 EST
On Sun, Jun 28, 2026 at 7:17 PM Russell King <linux@xxxxxxxxxxxxxxx> wrote:
>
> On Sun, Jun 28, 2026 at 10:01:25PM +0000, Samuel Moelius wrote:
> > ADFS uses the on-disk disc size to report statfs block counts. The disc
> > record validator checks the sector size, id length, high disc-size bits,
> > map zone count, and reserved bytes, but it accepts a declared disc size
> > smaller than one filesystem block.
> >
> > A crafted one-zone image with log2secsize 9 and disc_size 1 can pass map
> > checksum validation and mount. A subsequent statfs then reports zero
> > f_blocks from adfs_map_statfs(), and adfs_statfs() divides by that zero
> > while deriving f_ffree.
>
> I think this is still too low.
>
> 1. The disc map is nzones sectors long, and can not be in the same
> sector as the boot block. The disc record can not share with the map.
> This means the minimum is 1 + nzones sectors to fit just the map in.
>
> 2. If the disc record was found at 0xc00 rather than 0, then that
> will add sectors to the minimum size.
>
> 3. The root directory is also necessary, which is 2048 bytes for an
> E/F format (format_version=0) or root_size for an F+ format.
>
> So, if we're really trying to avoid mounting something that isn't a
> proper image, then just checking that the disc size is at least one
> sector isn't sufficient.
I understand your points, but the intent of this patch was simply to
eliminate a divide-by-zero. Is it sufficient for that purpose?