The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Russell King <linux@armlinux.org.uk>
To: Samuel Moelius <sam.moelius@trailofbits.com>
Cc: kees@kernel.org, brauner@kernel.org, iwasbaeyz@gmail.com,
	linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk
Subject: Re: [PATCH v2 1/2] adfs: reject disc records smaller than one filesystem block
Date: Mon, 29 Jun 2026 13:07:44 +0100	[thread overview]
Message-ID: <akJgENpDfHQ5RQxE@shell.armlinux.org.uk> (raw)
In-Reply-To: <CAE+C+DYY1KChjsGiCwr3Y6C+NaHsE6HujkqHJ=gjeXzOTR6L=Q@mail.gmail.com>

On Mon, Jun 29, 2026 at 07:45:21AM -0400, Samuel Moelius wrote:
> On Mon, Jun 29, 2026 at 7:34 AM Russell King <linux@armlinux.org.uk> wrote:
> >
> > On Mon, Jun 29, 2026 at 07:07:57AM -0400, Samuel Moelius wrote:
> > > On Sun, Jun 28, 2026 at 7:17 PM Russell King <linux@armlinux.org.uk> 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?
> >
> > While it is, you are also introducing selftests that rely on your
> > behaviour, where you merge the disc record with the map for both
> > of your test cases. This should also be rejected, because the bytes
> > in the disc record will be interpreted as the disc map.
> >
> > Have you checked what happens if you attempt to access such a bad
> > image, or are you purely focussed on what an AI bot told you was
> > a problem, rather than looking at the bigger picture?
> 
> I have not attempted to access the bad image. And to be clear, the
> selftest was an attempt to address Kees Cook's request here:
> https://lore.kernel.org/all/202606101323.0DFB06B054@keescook/
> 
> > Can you create a tools/testing/selftests/ script that will generate a
> > good and bad image and attempt to mount both, validating the filesystem
> > checking logic you're adding here?
> 
> Would another approach be better?

So, in essence,

- a bug was found (divide by zero) caused by an invalid image,
  presumably by AI.
- a patch was generated to address _just_ that issue without looking
  at the bigger picture.
- Kees requested a selftest for it
- A selftest was created which _itself_ generates two filesystem
  images, both of which are technically invalid, but tests that one
  mounts but the other doesn't, and the kernel doesn't have the
  divide by zero.
- No check whether the mounted "good" filesystem doesn't cause other
  issues.
- Author resists suggestions from filesystem maintainer to improve
  the check.

Fixing the bigger picture will result in the selftest failing, because
the invalid "good" image is still invalid, and that makes patch 2
incorrect.

Sorry, but no.

While I'm here, another thing that should be checked - that the disc
size specified in the disc record isn't larger than the block device
being mounted.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  reply	other threads:[~2026-06-29 12:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 18:37 [PATCH] adfs: reject disc records smaller than one filesystem block Samuel Moelius
2026-06-10 20:24 ` Kees Cook
2026-06-28 22:01   ` [PATCH v2 0/2] " Samuel Moelius
2026-06-28 22:01     ` [PATCH v2 1/2] " Samuel Moelius
2026-06-28 23:16       ` Russell King
2026-06-29 11:07         ` Samuel Moelius
2026-06-29 11:34           ` Russell King
2026-06-29 11:45             ` Samuel Moelius
2026-06-29 12:07               ` Russell King [this message]
2026-06-28 22:01     ` [PATCH v2 2/2] selftests: filesystems: add ADFS mount validation test Samuel Moelius

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=akJgENpDfHQ5RQxE@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=brauner@kernel.org \
    --cc=iwasbaeyz@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam.moelius@trailofbits.com \
    --cc=viro@zeniv.linux.org.uk \
    /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