ext2: Set the superblock UUID
PATCH 1/1 ext2: Set the superblock UUID
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.
--- fs/ext2/super.c | 1 + 1 file changed, 1 insertion(+)
fs/ext2/super.c +1 -0
@@ -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 ;
Signature · 1 line
2.43.7
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] ext2: integer underflow in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] ext2: integer underflow in ext2_get_inode() when s_first_ino is 0 [1]
--
commit b9543efa7f637c4ab3ed734748dff30bc4e4d9aa
Author: Peng Hao <[email protected]>
ext2: Set the superblock UUID
This commit populates sb->s_uuid from the on-disk ext2 superblock in ext2_fill_super() via super_set_uuid().
fs/ext2/super.c static int ext2_fill_super(struct super_block *sb, struct fs_context *fc) · line 1016
Quoted 12 lines
fs/ext2/super.c +1
-0@@ -1010,6 +1010,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 ;
[Severity: High]
This problem wasn't introduced by this patch, but can loading sbi->s_first_ino from es->s_first_ino in the else branch right below cause an integer underflow in ext2_get_inode() [1]?
fs/ext2/super.c:ext2_fill_super() {
...
if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
sbi->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
} else {
sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
...
}fs/ext2/inode.c:ext2_get_inode() {
...
if ((ino != EXT2_ROOT_INO && ino < EXT2_FIRST_INO(sb)) ||
ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count))
goto Einval;
block_group = (ino - 1) / EXT2_INODES_PER_GROUP(sb);
gdp = ext2_get_group_desc(sb, block_group, NULL);
...
}If a corrupted filesystem image has es->s_first_ino == 0 (or >= 0x80000000, which sign-extends the signed int sbi->s_first_ino), looking up ino 0 via open_by_handle_at() -> ext2_fh_to_dentry() -> ext2_nfs_get_inode() -> ext2_iget() -> ext2_get_inode() passes the ino < EXT2_FIRST_INO(sb) check. Computing ino - 1 then underflows unsigned ino_t to ULONG_MAX, triggering a WARN(1) in ext2_get_group_desc() or reading an unintended group descriptor if 32-bit truncation of block_group wraps below s_groups_count.
[1] https://sashiko.dev/#/bug/linux-5ea0eb49-c55e-4623-9285-ee790480d577
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1