All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] resize2fs: fix uninit group test accessing invalid memory
@ 2010-01-25 21:13 Eric Sandeen
  2010-02-06  3:35 ` tytso
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2010-01-25 21:13 UTC (permalink / raw)
  To: ext4 development

Commit 74128f8d7e93fe633aa87951319a4afd252a4494 added tests
for uninit groups, but did it after the group counter
increment in 2 loops, so we were testing past the end
of the ->group_desc[] array:

==19668== Invalid read of size 2
==19668==    at 0x40518C: resize_fs (resize2fs.c:1824)
==19668==    by 0x405A46: main (main.c:451)
==19668==  Address 0x5a0d002 is not stack'd, malloc'd or (recently) free'd
==19668== 
==19668== Invalid read of size 2
==19668==    at 0x405391: resize_fs (resize2fs.c:1864)
==19668==    by 0x405A46: main (main.c:451)
==19668==  Address 0x5a0d002 is not stack'd, malloc'd or (recently) free'd
==19668== 

Found this running the regression suite through valgrind.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 1984442..b706dd7 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -1818,9 +1818,6 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
 		    (blk == ext2fs_blocks_count(fs->super)-1)) {
 			ext2fs_bg_free_blocks_count_set(fs, group, group_free);
 			ext2fs_group_desc_csum_set(fs, group);
-			group++;
-			count = 0;
-			group_free = 0;
 			uninit = (ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT)
 				  );
 			ext2fs_super_and_bgd_loc(fs, group, &super_blk,
@@ -1832,6 +1829,9 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
 			else
 				old_desc_blocks = fs->desc_blocks +
 					fs->super->s_reserved_gdt_blocks;
+			group++;
+			count = 0;
+			group_free = 0;
 		}
 	}
 	ext2fs_free_blocks_count_set(fs->super, total_free);
@@ -1857,10 +1857,10 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
 		    (ino == fs->super->s_inodes_count)) {
 			ext2fs_bg_free_inodes_count_set(fs, group, group_free);
 			ext2fs_group_desc_csum_set(fs, group);
+			uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT);
 			group++;
 			count = 0;
 			group_free = 0;
-			uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT);
 		}
 	}
 	fs->super->s_free_inodes_count = total_free;


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] resize2fs: fix uninit group test accessing invalid memory
  2010-01-25 21:13 [PATCH] resize2fs: fix uninit group test accessing invalid memory Eric Sandeen
@ 2010-02-06  3:35 ` tytso
  0 siblings, 0 replies; 2+ messages in thread
From: tytso @ 2010-02-06  3:35 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development

On Mon, Jan 25, 2010 at 03:13:10PM -0600, Eric Sandeen wrote:
> Commit 74128f8d7e93fe633aa87951319a4afd252a4494 added tests
> for uninit groups, but did it after the group counter
> increment in 2 loops, so we were testing past the end
> of the ->group_desc[] array:

This patch is not correct; the test for uninit and the calculation for
old_desc_blk needs to be for the next group, not the previous block.
I believe this patch is the correct one instead.

						- Ted

commit 40b09fbe01fac8722b699b29f796e18550d68c84
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Fri Feb 5 22:25:03 2010 -0500

    resize2fs: Fix fix uninit group test accessing invalid memory
    
    Commit 74128f8 added tests for uninit groups, but it could access past
    the end of the group_desc[] array after processing the last group:
    
    ==19668== Invalid read of size 2
    ==19668==    at 0x40518C: resize_fs (resize2fs.c:1824)
    ==19668==    by 0x405A46: main (main.c:451)
    ==19668==  Address 0x5a0d002 is not stack'd, malloc'd or (recently) free'd
    ==19668==
    ==19668== Invalid read of size 2
    ==19668==    at 0x405391: resize_fs (resize2fs.c:1864)
    ==19668==    by 0x405A46: main (main.c:451)
    ==19668==  Address 0x5a0d002 is not stack'd, malloc'd or (recently) free'd
    ==19668==
    
    It was found by Eric Sandeen running the regression suite through
    valgrind.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 75c4721..346fd53 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -1819,6 +1819,8 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
 				group_free;
 			ext2fs_group_desc_csum_set(fs, group);
 			group++;
+			if (group >= fs->group_desc_count)
+				break;
 			count = 0;
 			group_free = 0;
 			uninit = (fs->group_desc[group].bg_flags &
@@ -1859,6 +1861,8 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
 				group_free;
 			ext2fs_group_desc_csum_set(fs, group);
 			group++;
+			if (group >= fs->group_desc_count)
+				break;
 			count = 0;
 			group_free = 0;
 			uninit = (fs->group_desc[group].bg_flags &

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-02-06  3:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-25 21:13 [PATCH] resize2fs: fix uninit group test accessing invalid memory Eric Sandeen
2010-02-06  3:35 ` tytso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.