From patchwork Sat Feb 6 03:35:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 44698 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BD7C7B7D01 for ; Sat, 6 Feb 2010 14:35:47 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752561Ab0BFDfq (ORCPT ); Fri, 5 Feb 2010 22:35:46 -0500 Received: from THUNK.ORG ([69.25.196.29]:38716 "EHLO thunker.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751914Ab0BFDfp (ORCPT ); Fri, 5 Feb 2010 22:35:45 -0500 Received: from root (helo=closure.thunk.org) by thunker.thunk.org with local-esmtp (Exim 4.50 #1 (Debian)) id 1NdbSR-0002i8-CD; Fri, 05 Feb 2010 22:35:43 -0500 Received: from tytso by closure.thunk.org with local (Exim 4.69) (envelope-from ) id 1NdbSN-0001td-D5; Fri, 05 Feb 2010 22:35:39 -0500 Date: Fri, 5 Feb 2010 22:35:39 -0500 From: tytso@mit.edu To: Eric Sandeen Cc: ext4 development Subject: Re: [PATCH] resize2fs: fix uninit group test accessing invalid memory Message-ID: <20100206033539.GA321@thunk.org> References: <4B5E0966.3040704@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4B5E0966.3040704@redhat.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on thunker.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 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" --- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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 &