linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tytso@mit.edu
To: Eric Sandeen <sandeen@redhat.com>
Cc: ext4 development <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH] resize2fs: fix uninit group test accessing invalid memory
Date: Fri, 5 Feb 2010 22:35:39 -0500	[thread overview]
Message-ID: <20100206033539.GA321@thunk.org> (raw)
In-Reply-To: <4B5E0966.3040704@redhat.com>

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 &

      reply	other threads:[~2010-02-06  3:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-25 21:13 [PATCH] resize2fs: fix uninit group test accessing invalid memory Eric Sandeen
2010-02-06  3:35 ` tytso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100206033539.GA321@thunk.org \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).