Skip to contentSkip to conversation

limit minixfs dir_pages on corrupted dir i_size, CVE-2006-6058

PATCH Superseded Eric Sandeen 2 participants 2 messages Aug 9, 2007 VFS

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 limit minixfs dir_pages on corrupted dir i_size, CVE-2006-6058

This attempts to address CVE-2006-6058
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-6058

first reported at http://projects.info-pull.com/mokb/MOKB-17-11-2006.html

Essentially a corrupted minix dir inode reporting a very large i_size will loop for a very long time in minix_readdir, minix_find_entry, etc, because on EIO they just move on to try the next page. This is under the BKL, printk'ing as well. This can lock up the machine for a very long time. A simple approach is to at least limit the nr. of pages attempted to no more than s_max_size. (s_max_size is about 256MB for V1, but 2GB for V2; this could still result in a lot of EIO reads in the V2 case, should the retry loops in minix_readdir & friends be short-circuited somehow instead? A simple "break" rather than "continue" on error would certainly resolve it, too...)

fs/minix/dir.c +9 -1
@@ -42,7 +42,15 @@ minix_last_byte(struct inode *inode, uns
 
 static inline unsigned long dir_pages(struct inode *inode)
 {
-	return (inode->i_size+PAGE_CACHE_SIZE-1)>>PAGE_CACHE_SHIFT;
+	loff_t size = inode->i_size;
+
+	if (size > minix_sb(inode->i_sb)->s_max_size) {
+		printk("%s: inode %lld i_size > s_max_size\n",
+			__FUNCTION__, inode->i_size);
+		size = minix_sb(inode->i_sb)->s_max_size;
+	}
+
+	return (size+PAGE_CACHE_SIZE-1)>>PAGE_CACHE_SHIFT;
 }
 
 static int dir_commit_chunk(struct page *page, unsigned from, unsigned to)
#1 lore raw

PATCH v2 1/1 limit minixfs printks on corrupted dir i_size, CVE-2006-6058

Perhaps this is simpler, and preferable. Thanks to adilger for reminding me about printk_ratelimit. :)

----

This attempts to address CVE-2006-6058
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-6058

first reported at http://projects.info-pull.com/mokb/MOKB-17-11-2006.html

Essentially a corrupted minix dir inode reporting a very large i_size will loop for a very long time in minix_readdir, minix_find_entry, etc, because on EIO they just move on to try the next page. This is under the BKL, printk-storming as well. This can lock up the machine for a very long time. Simply ratelimiting the printks gets things back under control.

fs/minix/itree_v1.c +2 -1
Index: linux-2.6.22-rc4/fs/minix/itree_v1.c
===================================================================
@@ -27,7 +27,8 @@ static int block_to_path(struct inode * 
 	if (block < 0) {
 		printk("minix_bmap: block<0\n");
 	} else if (block >= (minix_sb(inode->i_sb)->s_max_size/BLOCK_SIZE)) {
-		printk("minix_bmap: block>big\n");
+		if (printk_ratelimit())
+			printk("minix_bmap: block>big\n");
 	} else if (block < 7) {
 		offsets[n++] = block;
 	} else if ((block -= 7) < 512) {
fs/minix/itree_v2.c +2 -1
Index: linux-2.6.22-rc4/fs/minix/itree_v2.c
===================================================================
@@ -28,7 +28,8 @@ static int block_to_path(struct inode * 
 	if (block < 0) {
 		printk("minix_bmap: block<0\n");
 	} else if (block >= (minix_sb(inode->i_sb)->s_max_size/sb->s_blocksize)) {
-		printk("minix_bmap: block>big\n");
+		if (printk_ratelimit())
+			printk("minix_bmap: block>big\n");
 	} else if (block < 7) {
 		offsets[n++] = block;
 	} else if ((block -= 7) < 256) {