All of lore.kernel.org
 help / color / mirror / Atom feed
From: Theodore Tso <tytso@mit.edu>
To: Miao Xie <miaox@cn.fujitsu.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH] [e2fsprogs] e2fsck: fix segmentation fault when block size is greater than 8192
Date: Fri, 2 Jan 2009 18:30:46 -0500	[thread overview]
Message-ID: <20090102233046.GF4758@mit.edu> (raw)
In-Reply-To: <4948BF24.3040601@cn.fujitsu.com>

On Wed, Dec 17, 2008 at 04:58:12PM +0800, Miao Xie wrote:
> When I did fsck a filesystem with large blocksize(greater than 8192),
> segmentation fault occured. The cause is the size of b_data array that is
> defined as a fixed size in buffer_head structure.

Here's a better patch which avoids the need for two calls to malloc
for each buffer_head strcture.

						- Ted

commit e35d548b59e24af9f7fc18396e8880df96d1bc51
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Fri Jan 2 18:14:42 2009 -0500

    e2fsck: Fix journal replay for block sizes greater than 8k
    
    E2fsck was using a fixed-size 8k buffer for replaying blocks from the
    journal.  So attempts to replay a journal on filesystems greater than
    8k would cause e2fsck to crash with a segfault.
    
    Thanks to Miao Xie <miaox@cn.fujitsu.com> for reporting this problem.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h
index 0e4f951..60cc682 100644
--- a/e2fsck/jfs_user.h
+++ b/e2fsck/jfs_user.h
@@ -15,7 +15,6 @@
 #include "e2fsck.h"
 
 struct buffer_head {
-	char		b_data[8192];
 	e2fsck_t	b_ctx;
 	io_channel 	b_io;
 	int	 	b_size;
@@ -23,6 +22,7 @@ struct buffer_head {
 	int	 	b_dirty;
 	int	 	b_uptodate;
 	int	 	b_err;
+	char		b_data[1024];
 };
 
 struct inode {
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 10f5095..adbd3db 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -68,8 +68,10 @@ int journal_bmap(journal_t *journal, blk_t block, unsigned long *phys)
 struct buffer_head *getblk(kdev_t kdev, blk_t blocknr, int blocksize)
 {
 	struct buffer_head *bh;
+	int bufsize = sizeof(*bh) + kdev->k_ctx->fs->blocksize -
+		sizeof(bh->b_data);
 
-	bh = e2fsck_allocate_memory(kdev->k_ctx, sizeof(*bh), "block buffer");
+	bh = e2fsck_allocate_memory(kdev->k_ctx, bufsize, "block buffer");
 	if (!bh)
 		return NULL;
 

      reply	other threads:[~2009-01-02 23:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-17  8:58 [PATCH] [e2fsprogs] e2fsck: fix segmentation fault when block size is greater than 8192 Miao Xie
2009-01-02 23:30 ` Theodore Tso [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=20090102233046.GF4758@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=miaox@cn.fujitsu.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 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.