Skip to contentSkip to conversation

befs: fix shift-out-of-bounds in befs_check_sb

PATCH New Gowtham S Bhushan 1 participant 1 message Oct 26 Befs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 befs: fix shift-out-of-bounds in befs_check_sb

The consistency check for the block_size by using the block_shift caused integer overflow. Thus a max limit to the block_shift was defined named BEFS_MAX_BLOCK_SHIFT in befs.h. Also check for the block_shift was added so that overflow does not occur.

Reported-by [email protected]
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 fs/befs/befs.h  |  2 +-
 fs/befs/super.c | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
fs/befs/befs.h +1 -1
index 7cd47245694d..c395eb5e9a10 100644
@@ -13,7 +13,7 @@
 
 /* used in debug.c */
 #define BEFS_VERSION "0.9.3"
-
+#define BEFS_MAX_BLOCK_SHIFT 31
 
 typedef u64 befs_blocknr_t;
 /*
fs/befs/super.c +10 -0
index 7c50025c99d8..e515e98cb3f4 100644
@@ -88,6 +88,16 @@ befs_check_sb(struct super_block *sb)
 		return BEFS_ERR;
 	}
 
+	/*
+	 * block_shift check added so that overflow does not
+	 * occer during the block_size check
+	 */
+
+	if (befs_sb->block_shift > BEFS_MAX_BLOCK_SHIFT) {
+		befs_error(sb, "block_size too large, Corruption likely. ");
+		return BEFS_ERR;
+	}
+
 	/*
 	 * block_shift and block_size encode the same information
 	 * in different ways as a consistency check.
Signature · 1 line
2.56.0