f2fs: check log_blocksize bounds in __f2fs_commit_super
PATCH 1/1 f2fs: check log_blocksize bounds in __f2fs_commit_super
Syzbot reported a shift-out-of-bounds panic in SECTOR_FROM_BLOCK() during superblock writeback via __f2fs_commit_super().
When mounting a corrupted filesystem image where log_blocksize is set to 0, f2fs attempts to perform recovery or commit the superblock status. SECTOR_FROM_BLOCK() relies on F2FS_LOG_SECTORS_PER_BLOCK(sbi), which evaluates to (sbi->log_blocksize - 9). When log_blocksize is 0, this calculates 0 - 9 = -9, causing an unsigned underflow (4294967287) and triggering a UBSAN shift out-of-bounds error when shifting sector addresses.
Fix this by validating sbi->log_blocksize at the top of __f2fs_commit_super() and returning -EFSCORRUPTED if it is less than 9 (the minimum valid sector shift exponent).
--- fs/f2fs/super.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/super.c +3 -0
@@ -3934,6 +3934,9 @@ static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio,blk_opf_t opf =REQ_OP_WRITE |REQ_SYNC |REQ_PREFLUSH |REQ_FUA ;int ret; +if (unlikely (sbi->log_blocksize <9 )) +return -EFSCORRUPTED ; +folio_lock (folio);folio_wait_writeback (folio);if (update)
Signature · 1 line
2.47.3