linux/fs/minix
Michael Bommarito fb3e566caf
minix: avoid overflow in bitmap block count calculation
minix_check_superblock() uses minix_blocks_needed() to verify that the
on-disk imap and zmap block counts are large enough for the advertised
inode and zone counts.

The helper currently performs DIV_ROUND_UP() in unsigned int arithmetic.
A Minix v3 image can set s_ninodes or s_zones near UINT_MAX so the
addition inside DIV_ROUND_UP() wraps to zero. That makes a zero imap/zmap
block count look valid, after which minix_fill_super() can dereference
s_imap[0] or s_zmap[0] even though no bitmap buffers were allocated.

Impact: mounting a crafted Minix v3 image whose s_ninodes or s_zones is
near UINT_MAX makes minix_check_superblock() accept a zero bitmap-block
count and minix_fill_super() dereference s_imap[0]/s_zmap[0], panicking
the kernel.

The divisor is the bitmap capacity in bits, blocksize * 8, which is
always a power of two: minix_fill_super() obtains the block size through
sb_set_blocksize(), and blk_validate_block_size() rejects any size that
is not a power of two. Use DIV_ROUND_UP_POW2(), which divides before
adding the round-up term and so cannot overflow for a power-of-two
divisor.

Fixes: 8c97a6ddc9 ("minix: Add required sanity checking to minix_check_superblock()")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
Link: https://patch.msgid.link/20260618143922.3066874-1-michael.bommarito@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-07-01 15:26:24 +02:00
..
bitmap.c minix: Correct errno in minix_new_inode 2026-02-18 14:04:42 +01:00
dir.c minix: Track metadata bhs in fs-private inode part 2026-03-26 15:03:32 +01:00
file.c minix: Track metadata bhs in fs-private inode part 2026-03-26 15:03:32 +01:00
inode.c minix: release the sb buffer_head when setting the v3 block size fails 2026-05-22 12:20:49 +02:00
itree_common.c minix: Track metadata bhs in fs-private inode part 2026-03-26 15:03:32 +01:00
itree_v1.c fs/minix: remove expected error message in block_to_path() 2020-08-12 10:58:00 -07:00
itree_v2.c fs/minix: remove expected error message in block_to_path() 2020-08-12 10:58:00 -07:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
minix.h minix: avoid overflow in bitmap block count calculation 2026-07-01 15:26:24 +02:00
namei.c Fix a drop_nlink warning in minix_rename 2025-11-05 13:45:21 +01:00