* [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
* [PATCH 2/2] ext2: Set the superblock UUID
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 ` Peng Hao
2026-11-24 11:22 ` [PATCH 1/2] ext2: Reject a superblock with an invalid s_first_ino sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Peng Hao @ 2026-11-24 11:17 UTC (permalink / raw)
To: jack; +Cc: linux-ext4
ext2_fill_super() never sets sb->s_uuid, so everything that uses the
filesystem UUID through the VFS sees a null UUID on ext2:
- IMA/EVM policy rules with fsuuid= never match;
- EVM HMACs that include the UUID (EVM_ATTR_FSUUID) don't bind to the
filesystem;
- FS_IOC_GETFSUUID fails with -ENOTTY;
- overlayfs can't tell lower layers on different ext2 filesystems apart
and falls back to xino=off,index=off,nfs_export=off.
This was found with the BPF selftest test_ima, which creates an ext2
image, adds a "measure func=BPRM_CHECK fsuuid=<uuid>" rule and expects
a binary executed from that image to be measured. It only passes when
ext2 images are mounted by ext4 (CONFIG_EXT4_USE_FOR_EXT2), which sets
the UUID. With CONFIG_EXT2_FS=y nothing is measured:
test_test_ima:FAIL:num_samples_or_err unexpected num_samples_or_err: actual 0 != expected 1
Set the UUID from the on-disk superblock the same way ext4 does.
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
fs/ext2/super.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 8a4412231394..b4df4123313d 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1007,6 +1007,7 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_max_links = EXT2_LINK_MAX;
sb->s_time_min = S32_MIN;
sb->s_time_max = S32_MAX;
+ super_set_uuid(sb, es->s_uuid, sizeof(es->s_uuid));
if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
--
2.43.7
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] ext2: Reject a superblock with an invalid s_first_ino
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 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-24 11:22 UTC (permalink / raw)
To: Peng Hao; +Cc: linux-ext4, tytso
Sashiko has reviewed this 2-patch series and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124111708.24204-1-flyingpeng@tencent.com
^ permalink raw reply [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