From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B0A534D4E2 for ; Wed, 10 Jun 2026 20:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781123080; cv=none; b=ufaYQ5Q9Zdx1nVfib0vluC9S8PBiEmv6AjGEqCPp/xPc9PysA2HFOgTFP7dmTAiZArqQ6qvOwIPQlJxesnSMgIzxYUdqlvK2K01YuBKSbTN6mPYEDwFxpzbVcQV6cVIc4rmhj2hR+erLBrNJ0wNx8d8aGV6G4Izcs56CeitB7T4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781123080; c=relaxed/simple; bh=TmFJkoTkoyf0k+wkWh3eK5U6GFeqlSqxRGibLL171J8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i9NFnXN0vyby92cTzWFQ8BoFM9wZs4YdqrzRQQLjLJbw/CMOsiVdtTbwPjOwH0DgeMyrdaWpwsddmUf8cww6RR3xSK0GAMGhNY9atL1c99Fu3oZHIK8M0qzMzsG/ORHjMjrRit1Z+LT+gqeLL96sVDcMIl6S0yIlNm3kqPv0YHc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OP2bgjdo; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OP2bgjdo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E24CE1F00893; Wed, 10 Jun 2026 20:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781123078; bh=yYfEeQlbF4QVPNqGGtgwYlfMC6YdJnoI8HXMm/4ty/g=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=OP2bgjdomlBO9u5waL+kPu/5TFRCH/eHIDm8pOaSSragiC3H361+b+D28nQ9A0OMl CvIyvuPRcrgks/NTvjSgjXYa+4dIu5AtDAh/R5XWb3D995qwjkWj1HYlY+Dgxhm2Lu yIDABe3wcpZ3MgqhpUeC5jixRKhwSckOIu+whibRubTn19WJR86QKBMzuobTsVb6cO JaEBD0pkG1X6jnyOne3DHYCHEUYhCWD3CqTz+WUtnAnTqQyRt3pa6Ktmu/QjiMp9xj D0fPNVO9W+87LbPbVVWXLWSLvTOhUjcfiO/DhN1Mqv9FZK2CCwQ5vXZTRiwGtPQorN 6+nHfUsNE0tPw== Date: Wed, 10 Jun 2026 13:24:38 -0700 From: Kees Cook To: Samuel Moelius Cc: "Russell King (Oracle)" , Bae Yeonju , Christian Brauner , Al Viro , open list Subject: Re: [PATCH] adfs: reject disc records smaller than one filesystem block Message-ID: <202606101323.0DFB06B054@keescook> References: <20260605183738.2489977-1-sam.moelius@trailofbits.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260605183738.2489977-1-sam.moelius@trailofbits.com> On Fri, Jun 05, 2026 at 06:37:34PM +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. > > Reject disc records whose declared disc size is smaller than one > filesystem block. 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? -Kees > > Assisted-by: Codex:gpt-5.5-cyber-preview > Signed-off-by: Samuel Moelius > --- > fs/adfs/super.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/fs/adfs/super.c b/fs/adfs/super.c > index a4cd0a5159dd..cb8f3919e3bb 100644 > --- a/fs/adfs/super.c > +++ b/fs/adfs/super.c > @@ -73,6 +73,10 @@ static int adfs_checkdiscrecord(struct adfs_discrecord *dr) > if (le32_to_cpu(dr->disc_size_high) >> dr->log2secsize) > return 1; > > + /* disc size must contain at least one filesystem block */ > + if (adfs_disc_size(dr) < (1ULL << dr->log2secsize)) > + return 1; > + > /* > * Maximum idlen is limited to 16 bits for new directories by > * the three-byte storage of an indirect disc address. For > -- > 2.43.0 > -- Kees Cook