Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH 1/2] ext2: Reject a superblock with an invalid s_first_ino
@ 2026-11-24 11:17 Peng Hao
  2026-11-24 11:17 ` [PATCH 2/2] ext2: Set the superblock UUID Peng Hao
  2026-11-24 11:22 ` [PATCH 1/2] ext2: Reject a superblock with an invalid s_first_ino sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Peng Hao @ 2026-11-24 11:17 UTC (permalink / raw)
  To: jack; +Cc: linux-ext4

ext2_fill_super() takes s_first_ino from a revision 1 superblock without
checking it.  ext2_get_inode() and ext2_nfs_get_inode() only reject
inode numbers below EXT2_FIRST_INO(sb), so with s_first_ino == 0 an
inode number of 0 gets through, and (ino - 1) wraps around when the
block group is computed.  On such an image, opening a file handle with
inode number 0 (open_by_handle_at(), or an NFS client if the filesystem
is exported) triggers:

  block_group >= groups_count - block_group = -1, groups_count = 2
  WARNING: balloc.c:51 at ext2_get_group_desc+0x5b/0x90 [ext2]
   ext2_get_inode+0x9c/0x160 [ext2]
   ext2_iget+0x63/0x4b0 [ext2]

Depending on s_inodes_per_group, the truncated group number may also
land inside the filesystem, so that some other inode is read in place of
inode 0.  Values from 1 to 10 make the reserved inodes reachable through
file handles.

ext4 rejects s_first_ino < EXT4_GOOD_OLD_FIRST_INO at mount time since
commit c37e9e013469 ("ext4: add more inode number paranoia checks").  Do
the same for ext2.  As s_first_ino is an int, this also rejects values
of 0x80000000 and above, which turn negative and make every inode except
the root inode look reserved.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 fs/ext2/super.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index a40f530872a4..8a4412231394 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1014,6 +1014,11 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
 	} else {
 		sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
 		sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
+		if (sbi->s_first_ino < EXT2_GOOD_OLD_FIRST_INO) {
+			ext2_msg(sb, KERN_ERR, "error: invalid first ino: %u",
+				 le32_to_cpu(es->s_first_ino));
+			goto failed_mount;
+		}
 		if ((sbi->s_inode_size < EXT2_GOOD_OLD_INODE_SIZE) ||
 		    !is_power_of_2(sbi->s_inode_size) ||
 		    (sbi->s_inode_size > blocksize)) {
-- 
2.43.7


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 11:17 [PATCH 1/2] ext2: Reject a superblock with an invalid s_first_ino Peng Hao
2026-11-24 11:17 ` [PATCH 2/2] ext2: Set the superblock UUID Peng Hao
2026-11-24 11:22 ` [PATCH 1/2] ext2: Reject a superblock with an invalid s_first_ino sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox