From b684f018357f942f051ab172d882d97c7dec64bf Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 30 Aug 2019 20:39:05 +0200 Subject: [PATCH] ext2: fix panic mounting ext2-overwritten-with-BFS volumes I have two partitions which used to be ext2, but have long since been reinitialized as BFS. However, the ext2 superblock is still here, and the ext2 filesystem will detect it. It crashes later on trying to access an Inode at block -1, so just add a check for that to avoid the crash. Change-Id: Ie2ed6a969ea3ffd343dedfe45a15dfc37af05804 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1800 Reviewed-by: waddlesplash --- src/add-ons/kernel/file_systems/ext2/Volume.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/file_systems/ext2/Volume.cpp b/src/add-ons/kernel/file_systems/ext2/Volume.cpp index 91bddff28d..cf9bff9347 100644 --- a/src/add-ons/kernel/file_systems/ext2/Volume.cpp +++ b/src/add-ons/kernel/file_systems/ext2/Volume.cpp @@ -207,7 +207,10 @@ ext2_super_block::IsValid() || BlocksPerGroup() != (1UL << BlockShift()) * 8 || InodeSize() > (1UL << BlockShift()) || RevisionLevel() > EXT2_MAX_REVISION - || ReservedGDTBlocks() > (1UL << BlockShift()) / 4) { + || ReservedGDTBlocks() > (1UL << BlockShift()) / 4 + || NumInodes() == 0 + || InodeSize() == 0 + || FreeInodes() > NumInodes()) { return false; } @@ -536,6 +539,8 @@ Volume::GetInodeBlock(ino_t id, off_t& block) block = group->InodeTable(Has64bitFeature()) + ((id - 1) % fSuperBlock.InodesPerGroup()) / fInodesPerBlock; + if (block < 0) + return B_BAD_DATA; return B_OK; }