Re: [PATCH] libext2fs: fix to read the bitmaps for image file correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 20, 2018 at 06:42:29AM +0000, Kazuya Mio wrote:
> Thank you for your kind advices. However, after applying the patch,
> debugfs caused segfault by the following steps:
> 
> # mke2fs -t ext4 /dev/sda8
> # e2image /dev/sda8 test.img
> # debugfs -R stats -i test.img
> debugfs 1.44.0 (7-Mar-2018)
> Segmentation fault
> 
> According to the following backtrace, read_bitmaps() called by
> ext2fs_read_inode_bitmap() reads not only inode bitmap, but also block bitmap.
> We would need to consider about do_inode/do_block arguments in read_bitmaps().

Thanks for pointing that out.  I was using dumpe2fs to do my testing,
so I didn't notice that how debugfs was calling
ext2fs_read_inode_bitmap() and ext2fss_read_block_bitmap() separately.
I'll fix this up in the commit before I push it out.

diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
index 0c4fecc48..0b532dbf9 100644
--- a/lib/ext2fs/rw_bitmaps.c
+++ b/lib/ext2fs/rw_bitmaps.c
@@ -255,7 +255,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
 	if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
 		blk = (fs->image_header->offset_inodemap / fs->blocksize);
 		ino_cnt = fs->super->s_inodes_count;
-		while (ino_cnt > 0) {
+		while (inode_bitmap && ino_cnt > 0) {
 			retval = io_channel_read_blk64(fs->image_io, blk++,
 						     1, inode_bitmap);
 			if (retval)
@@ -274,7 +274,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
 		       fs->blocksize);
 		blk_cnt = EXT2_GROUPS_TO_CLUSTERS(fs->super,
 						  fs->group_desc_count);
-		while (blk_cnt > 0) {
+		while (block_bitmap && blk_cnt > 0) {
 			retval = io_channel_read_blk64(fs->image_io, blk++,
 						     1, block_bitmap);
 			if (retval)


I'm also going to change debugfs to use ext2fs_read_bitmaps() since
for large file systems on a single HDD spindle, it's a significant
performance win to use ext2fs_read_bitmaps() since halves the number
of seeks need to pull in the bitmaps.

Regards,

						- Ted



[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux