NetBSD Problem Report #60053

From www@netbsd.org  Tue Mar  3 21:32:10 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.netbsd.org", Issuer "R13" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id EF57E1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  3 Mar 2026 21:32:09 +0000 (UTC)
Message-Id: <20260303213209.09A6F1A923C@mollari.NetBSD.org>
Date: Tue,  3 Mar 2026 21:32:09 +0000 (UTC)
From: ssszcmawo@gmail.com
Reply-To: ssszcmawo@gmail.com
To: gnats-bugs@NetBSD.org
Subject: [PATCH] fsck_ext2fs: add sanity check for EXT2_HUGE_FILE without HUGE_FILE feature
X-Send-Pr-Version: www-1.0
X-From4GNATS: "ssszcmawo@gmail.com via gnats" <gnats-admin@NetBSD.org>

>Number:         60053
>Category:       kern
>Synopsis:       [PATCH] fsck_ext2fs: add sanity check for EXT2_HUGE_FILE without HUGE_FILE feature
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 03 21:35:01 +0000 2026
>Last-Modified:  Wed Mar 04 11:30:01 +0000 2026
>Originator:     ssszcmawo
>Release:        11.95.5
>Organization:
>Environment:
n/a
>Description:
Add consistency check in inonblock(): reject inodes that have the
EXT2_HUGE_FILE flag set without the corresponding EXT2F_ROCOMPAT_HUGE_FILE
feature in the superblock. Previously such inconsistency was silently
accepted. Also added a warning when directory entry names are truncated due to length > MAXPATHLEN.
>How-To-Repeat:

>Fix:
>From defc50de65403e684597ffd22389055eaa35cbdd Mon Sep 17 00:00:00 2001
From: ssszcmawo <belan2470@gmail.com>
Date: Tue, 3 Mar 2026 15:29:53 +0100
Subject: [PATCH] add additional check for huge files and comments

---
 sbin/fsck_ext2fs/inode.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/sbin/fsck_ext2fs/inode.c b/sbin/fsck_ext2fs/inode.c
index 97f02b84a..c12857d5b 100644
--- a/sbin/fsck_ext2fs/inode.c
+++ b/sbin/fsck_ext2fs/inode.c
@@ -600,7 +600,8 @@ findname(struct inodesc *idesc)
 	/* from utilities.c namebuf[] variable */
 	char *buf = __UNCONST(idesc->id_name);
 	if (namlen > MAXPATHLEN) {
-		/* XXX: Prevent overflow but don't fix */
+		/* XXX: Prevent overflow but don't fix */	
+		printf("entry name truncated");
 		namlen = MAXPATHLEN;
 	}

@@ -755,25 +756,34 @@ freeino(ino_t ino)
 	n_files--;
 }

+/*
+ * read the number of block from inode
+ */
 uint64_t
 inonblock(struct ext2fs_dinode *dp)
 {
 	uint64_t nblock;
-
-	/* XXX check for EXT2_HUGE_FILE without EXT2F_ROCOMPAT_HUGE_FILE? */
+	uint32_t flags;

 	nblock = fs2h32(dp->e2di_nblock);
+	flags = fs2h32(dp->e2di_flags);

-	if ((sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)) {
-		nblock |= (uint64_t)fs2h16(dp->e2di_nblock_high) << 32;
-		if (fs2h32(dp->e2di_flags) & EXT2_HUGE_FILE) {
-			nblock = EXT2_FSBTODB(&sblock, nblock);
-		}
+	if ((flags & EXT2_HUGE_FILE) &&
+		!(sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)) {
+	    pfatal("inconsistent filesystem");
 	}
+	if (sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)
+	    nblock |= (uint64_t)fs2h16(dp->e2di_nblock_high) << 32;
+
+	if (flags & EXT2_HUGE_FILE)
+	    nblock = EXT2_FSBTODB(&sblock, nblock);

 	return nblock;
 }

+/*
+ * set the number of block in an inode
+ */
 void
 inosnblock(struct ext2fs_dinode *dp, uint64_t nblock)
 {
-- 
2.47.3


>Audit-Trail:
From: ssszcmawo <ssszcmawo@gmail.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/60053
Date: Wed, 4 Mar 2026 12:30:14 +0100

 A little update on it, made error messages more specific

 >From 94b47742f640bf789de8d9c98ce1ffb80fa825ee Mon Sep 17 00:00:00 2001
 From: ssszcmawo <belan2470@gmail.com>
 Date: Tue, 3 Mar 2026 15:29:53 +0100
 Subject: [PATCH] add additional check for huge files and improve comments

 Add validation for inconsistent EXT2_HUGE_FILE usage and clarify
 related comments and error messages
 ---
  sbin/fsck_ext2fs/inode.c | 26 ++++++++++++++++++--------
  1 file changed, 18 insertions(+), 8 deletions(-)

 diff --git a/sbin/fsck_ext2fs/inode.c b/sbin/fsck_ext2fs/inode.c
 index 97f02b84a..f3d4d37f3 100644
 --- a/sbin/fsck_ext2fs/inode.c
 +++ b/sbin/fsck_ext2fs/inode.c
 @@ -600,7 +600,8 @@ findname(struct inodesc *idesc)
      /* from utilities.c namebuf[] variable */
      char *buf = __UNCONST(idesc->id_name);
      if (namlen > MAXPATHLEN) {
 -        /* XXX: Prevent overflow but don't fix */
 +        /* XXX: Prevent overflow but don't fix */
 +        printf("entry name truncated to %d characters", MAXPATHLEN);
          namlen = MAXPATHLEN;
      }

 @@ -755,25 +756,34 @@ freeino(ino_t ino)
      n_files--;
  }

 +/*
 + * read the number of block from inode
 + */
  uint64_t
  inonblock(struct ext2fs_dinode *dp)
  {
      uint64_t nblock;
 -
 -    /* XXX check for EXT2_HUGE_FILE without EXT2F_ROCOMPAT_HUGE_FILE? */
 +    uint32_t flags;

      nblock = fs2h32(dp->e2di_nblock);
 +    flags = fs2h32(dp->e2di_flags);

 -    if ((sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)) {
 -        nblock |= (uint64_t)fs2h16(dp->e2di_nblock_high) << 32;
 -        if (fs2h32(dp->e2di_flags) & EXT2_HUGE_FILE) {
 -            nblock = EXT2_FSBTODB(&sblock, nblock);
 -        }
 +    if ((flags & EXT2_HUGE_FILE) &&
 +        !(sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)) {
 +        pfatal("inode has EXT2_HUGE_FILE but ro-compat feature is not
 enabled");
      }
 +    if (sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)
 +        nblock |= (uint64_t)fs2h16(dp->e2di_nblock_high) << 32;
 +
 +    if (flags & EXT2_HUGE_FILE)
 +        nblock = EXT2_FSBTODB(&sblock, nblock);

      return nblock;
  }

 +/*
 + * set the number of block in an inode
 + */
  void
  inosnblock(struct ext2fs_dinode *dp, uint64_t nblock)
  {
 -- 
 2.47.3

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.