Messages in this thread Patch in this message | | | Date | Mon, 24 Aug 1998 14:03:26 +0100 | From | "Stephen C. Tweedie" <> | Subject | Re: [PATCH] minor ext2 bug |
| |
Hi,
On Tue, 4 Aug 1998 17:02:37 -0400 (EDT), Chris Loveland <cwl@mars.iol.unh.edu> said:
> Included below is a small patch which fixes an ext2 problem. The problem > was that if read_inode_bitmap failed to successfully read the block from > disk sb->u.ext2_sb.s_inode_bitmap[0] was set to NULL and > sb-> u.ext2_sb.s_inode_bitmap_number was set to the block_group trying to > be read. A successive call to load_inode_bitmap with the same value > for block_group would end up returning 0 as the index into the bitmap > array so an attempt to use the bitmap would result in a NULL pointer > dereference.
It's definitely a bug, yes.
> In general load_inode_bitmap checked for this NULL value but the > special case return path which is removed in the patch below did not.
The special case path is an important performance optimisation: it short-circuits a significant amount of code in the common case where we are repeatedly allocating from the same block group.
The better fix is below: make sure that the bitmap has been loaded before returning the short-circuit value. The corresponding code in fs/ext2/balloc.c already does this correctly, but the patch below improves that short-circuit by a few extra instructions too.
--Stephen
---------------------------------------------------------------- --- fs/ext2/balloc.c~ Sat May 9 06:55:06 1998 +++ fs/ext2/balloc.c Mon Aug 24 12:36:09 1998 @@ -213,7 +213,7 @@ if (sb->u.ext2_sb.s_loaded_block_bitmaps > 0 && sb->u.ext2_sb.s_block_bitmap_number[0] == block_group && sb->u.ext2_sb.s_block_bitmap[block_group]) { - slot = 0; + return 0; } /* * Or can we do a fast lookup based on a loaded group on a filesystem --- fs/ext2/ialloc.c~ Sat May 9 06:55:06 1998 +++ fs/ext2/ialloc.c Mon Aug 24 12:32:32 1998 @@ -101,7 +101,8 @@ "block_group = %d, groups_count = %lu", block_group, sb->u.ext2_sb.s_groups_count); if (sb->u.ext2_sb.s_loaded_inode_bitmaps > 0 && - sb->u.ext2_sb.s_inode_bitmap_number[0] == block_group) + sb->u.ext2_sb.s_inode_bitmap_number[0] == block_group && + sb->u.ext2_sb.s_inode_bitmap[0] != NULL) return 0; if (sb->u.ext2_sb.s_groups_count <= EXT2_MAX_GROUP_LOADED) { if (sb->u.ext2_sb.s_inode_bitmap[block_group]) { ---------------------------------------------------------------- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html
| |