[PATCH] Do not allow reading beyond the inode maps EOF (1 of 6)

[email protected] Wed, 7 Jul 2004 16:41:35 -0500
Newsgroups gmane.comp.file-systems.jfs.patches
Message-ID <[email protected]>
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/06/14 15:19:58-05:00 [email protected] 
#   JFS: Don't allow reading beyond the inode map's EOF
#   
#   If we try to read inodes that are beyond the size of the inode map,
#   __read_metapages would read unitialized pages into the inode map's
#   address space.  If the inode map is later grown in order to allocate
#   more inodes, the page is initialized and written under a different
#   address space.  Having the stale page in the page cache prevents the
#   properly initialized page from being read, and results in errors.
#   
#   This problem can be provoked by an nfs client trying to read an inode
#   that does not exist.
#   
#   Signed-off-by: Dave Kleikamp <[email protected]>
# 
diff -Nru a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
--- a/fs/jfs/jfs_metapage.c	2004-07-07 16:37:39 -05:00
+++ b/fs/jfs/jfs_metapage.c	2004-07-07 16:37:39 -05:00
@@ -225,8 +225,16 @@
 
 	if (absolute)
 		mapping = inode->i_sb->s_bdev->bd_inode->i_mapping;
-	else
+	else {
+		/*
+		 * If an nfs client tries to read an inode that is larger
+		 * than any existing inodes, we may try to read past the
+		 * end of the inode map
+		 */
+		if ((lblock << inode->i_blkbits) >= inode->i_size)
+			return NULL;
 		mapping = inode->i_mapping;
+	}
 
 	hash_ptr = meta_hash(mapping, lblock);
 again: