Hello, minix_check_superblock() checks that s_firstdatazone is within the filesystem, but does not check that it follows the inode table. The inode table starts after the superblock and bitmaps and occupies ceil(s_ninodes / inodes_per_block) blocks. If s_firstdatazone points inside that range, normal file-data allocation can overwrite raw inode records. On a crafted Minix V3 image with s_firstdatazone=5, uid 1000 wrote ordinary file data over the inode for an existing root-owned file. After unmounting and remounting, that file had mode 0104755 and size 680. Executing it changed the child from uid/euid/suid 1000 to euid 0 and allowed it to read a root-only file outside the Minix mount. The trigger requires a privileged process to mount a crafted Minix image read-write on a mount that honors setuid bits. After that mount, the attacker needs write access to a file on the volume. The test does not use an unprivileged mount. The s_firstdatazone=8 geometry control and the MS_NOSUID control do not escalate. HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7 source version: v7.3-23088-g8d7fe9885c62f (Linux 7.4.0-rc4) compiler: gcc 11.4.0, GNU ld 2.38 The full console output and exact kernel configuration are available from me on request. The reproduction package includes the C harness, image builders, payload, and initramfs. The patched kernel rejects the s_firstdatazone=5 image with EINVAL and accepts the s_firstdatazone=8 control. The check compares the first data zone with the first block after the complete inode table. It handles Minix V1 separately because its inode size differs from Minix V2/V3. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: shaos Thanks, shaos --- fs/minix/inode.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/minix/inode.c b/fs/minix/inode.c index 9fb938ec58689..943ea1515f95b 100644 --- a/fs/minix/inode.c +++ b/fs/minix/inode.c @@ -176,6 +176,7 @@ static bool minix_check_superblock(struct super_block *sb) { struct minix_sb_info *sbi = minix_sb(sb); unsigned long block; + unsigned long inodes_per_block; if (sbi->s_log_zone_size != 0) { printk("minix-fs error: zone size must equal block size. " @@ -207,6 +208,17 @@ static bool minix_check_superblock(struct super_block *sb) return false; } + if (sbi->s_version == MINIX_V1) + inodes_per_block = MINIX_INODES_PER_BLOCK; + else + inodes_per_block = sb->s_blocksize / sizeof(struct minix2_inode); + + /* The inode table must not overlap the first data zone. */ + block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks + + DIV_ROUND_UP(sbi->s_ninodes, inodes_per_block); + if (sbi->s_firstdatazone < block) + return false; + /* * s_max_size must not exceed the block mapping limitation. This check * is only needed for V1 filesystems, since V2/V3 support an extra level -- 2.34.1